/* START: AI chat widget (shared/_ai_chat.html.erb) */
/* Space a page keeps at the bottom so its last control stays clear of the fixed "Ask AI" button. */
:root {
  --ai-chat-clearance: 5rem;
}

.ai-chat-widget {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.ai-chat-widget * {
  pointer-events: auto;
}

/* Launcher: a dark "Ask AI" button. */
.ai-chat-head {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 48px;
  padding: 0 1rem 0 0.875rem;
  border: 0;
  border-radius: 12px;
  background: #0F1D33;
  color: #FFFFFF;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 29, 51, 0.24);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.ai-chat-head:hover {
  background: #1C2E4A;
}

.ai-chat-head:active {
  transform: scale(0.97);
}

.ai-chat-head:focus-visible {
  outline: 3px solid #7FA3D9;
  outline-offset: 2px;
}

/* Panel: 408px card on a large screen, full screen on a phone (below). */
.ai-chat-panel {
  width: 408px;
  max-width: calc(100vw - 2rem);
  height: min(688px, calc(100vh - 3rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #FFFFFF;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 29, 51, 0.22);
  color: #0F1D33;
  animation: ai-chat-slide-up 0.2s ease-out;
}

@keyframes ai-chat-slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-top {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem 0.5rem 1rem;
  background: #0F1D33;
  color: #FFFFFF;
}

.ai-chat-heading {
  flex: 1 1 auto;
  min-width: 0;
}

.ai-chat-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #FFFFFF;
}

.ai-chat-subtitle {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  color: #C9D3E3;
}

.ai-chat-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #FFFFFF;
  cursor: pointer;
}

.ai-chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.ai-chat-icon-btn:focus-visible {
  outline: 2px solid #FFFFFF;
  outline-offset: -2px;
}

.ai-chat-icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 1rem;
  background: #F8FAFC;
}

.ai-chat-message {
  display: flex;
}

.ai-chat-message.user {
  justify-content: flex-end;
}

.ai-chat-message.assistant {
  justify-content: flex-start;
}

.ai-chat-message-bubble {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 16px;
  font-size: 0.9375rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-chat-message.user .ai-chat-message-bubble {
  max-width: 82%;
  background: #003479;
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

.ai-chat-message.assistant .ai-chat-message-bubble {
  max-width: 92%;
  background: #FFFFFF;
  border: 1px solid #E2E7F0;
  color: #0F1D33;
  border-bottom-left-radius: 4px;
}

/* Three dots while the reply is on its way. */
.ai-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 0.75rem 1rem;
  background: #FFFFFF;
  border: 1px solid #E2E7F0;
  border-radius: 16px;
}

.ai-chat-typing.d-none {
  display: none;
}

.ai-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8A97AD;
  animation: ai-chat-dot 1.2s ease-in-out infinite;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-chat-dot {
  0%, 60%, 100% { opacity: 0.35; }
  30% { opacity: 1; }
}

.ai-chat-bottom {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem 0.75rem;
  border-top: 1px solid #E2E7F0;
  background: #FFFFFF;
}

/* Suggested questions: one row that scrolls sideways. */
.ai-chat-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.ai-chat-chips::-webkit-scrollbar {
  display: none;
}

.ai-chat-chip {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #CBD3E1;
  border-radius: 999px;
  background: #FFFFFF;
  color: #003479;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.ai-chat-chip:hover {
  background: #E8EEF7;
}

.ai-chat-chip:focus-visible {
  outline: 2px solid #003479;
  outline-offset: 1px;
}

.ai-chat-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ai-chat-form {
  display: flex;
  gap: 0.5rem;
}

.ai-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 0.75rem;
  border: 1px solid #CBD3E1;
  border-radius: 10px;
  background: #FFFFFF;
  color: #0F1D33;
  /* 16px keeps iPhone Safari from zooming in when the field gets focus. */
  font-size: 1rem;
}

.ai-chat-input:focus {
  border-color: #003479;
  outline: 2px solid rgba(0, 52, 121, 0.25);
  outline-offset: 0;
}

.ai-chat-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: #003479;
  color: #FFFFFF;
  cursor: pointer;
}

.ai-chat-send:hover {
  background: #002557;
}

.ai-chat-send:focus-visible {
  outline: 3px solid #7FA3D9;
  outline-offset: 2px;
}

/* Locked while a reply is on its way. */
.ai-chat-send:disabled {
  background: #8A97AD;
  cursor: not-allowed;
}

/* Phone: "Ask AI" sits above the tab bar (theme.css sets the bottom offset);
   the open panel fills the screen and the page behind it stops scrolling. */
@media (max-width: 767.98px) {
  :root {
    --ai-chat-clearance: 4.5rem;
  }

  .ai-chat-widget {
    right: 1rem;
  }

  html.ai-chat-open,
  html.ai-chat-open body {
    overflow: hidden;
  }

  .ai-chat-panel {
    position: fixed;
    inset: 0;
    z-index: 1060;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  .ai-chat-top {
    min-height: 60px;
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  }

  .ai-chat-bottom {
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  .ai-chat-input,
  .ai-chat-send {
    height: 48px;
  }

  .ai-chat-input {
    border-radius: 12px;
    padding: 0 0.875rem;
  }

  .ai-chat-send {
    width: 48px;
    border-radius: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-head,
  .ai-chat-panel,
  .ai-chat-typing span {
    transition: none;
    animation: none;
  }
}
/* END: AI chat widget */
