/* Fido Intake — AI interview chat surface
   ---------------------------------------------------------------------------
   Light, warm, editorial. Paper and ink, one cyan accent taken from the
   fidodesign.net brand colour. No dark surfaces, no glass, no glow.

   Palette tokens live on the intake wrapper (assets/intake.css); every use
   here carries a literal fallback so this file also stands alone.

   Contract IDs styled: #fi-chat #fi-chat-log #fi-chat-status #fi-chat-form
   #fi-chat-input #fi-chat-send #fi-chat-done #fi-chat-progress-text
   #fi-chat-bar-fill .fi-chat__bar span
   --------------------------------------------------------------------------- */

/* =========================================================================
   1. Shell
   ========================================================================= */

#fi-chat,
.fi-chat {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 26px 26px 22px;
  color: var(--fi-ink, #16181c);
  background: var(--fi-card, #fff);
  border: 1px solid var(--fi-line, #e6e1d9);
  border-radius: var(--fi-radius-lg, 14px);
  box-shadow: 0 1px 2px rgba(22, 24, 28, 0.04), 0 12px 32px -18px rgba(22, 24, 28, 0.22);
  font-size: 1rem;
  line-height: 1.55;
  /* The card never grows past the viewport, so the composer stays on screen
     above a phone keyboard (dvh tracks the visual viewport). */
  max-height: min(78vh, 760px);
  max-height: min(78dvh, 760px);
  scroll-margin-block: 16px;
}

#fi-chat[hidden],
.fi-chat[hidden],
#fi-chat-done[hidden],
#fi-chat-status[hidden] {
  display: none;
}

/* Visually hidden but announced. */
.fi-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* =========================================================================
   2. Head — eyebrow, title, progress
   ========================================================================= */

#fi-chat .fi-chat__head {
  flex: 0 0 auto;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--fi-line, #e6e1d9);
}

#fi-chat .fi-chat__eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fi-ink-faint, #6b7178);
}

#fi-chat .fi-chat__title {
  margin: 0 0 10px;
  font-size: 1.35rem;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--fi-ink, #16181c);
}

#fi-chat .fi-chat__progress-text {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--fi-ink-soft, #4c5359);
  font-variant-numeric: tabular-nums;
}

#fi-chat .fi-chat__bar {
  height: 6px;
  border-radius: 999px;
  background: var(--fi-line, #e6e1d9);
  overflow: hidden;
}

#fi-chat .fi-chat__bar span,
#fi-chat-bar-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--fi-accent-fill, #00dee2);
  /* Width is set from progress.filled/total as the contract specifies, and it
     steps rather than animating: animating a layout property is jank bait and
     the movement is pure decoration. */
}

/* =========================================================================
   3. Log
   ========================================================================= */

#fi-chat .fi-chat__log {
  flex: 1 1 auto;
  min-height: 90px;
  margin: 0;
  padding: 20px 2px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--fi-line-strong, #8f877c) transparent;
}

#fi-chat .fi-chat__msg:last-child {
  margin-bottom: 0;
}

#fi-chat .fi-chat__msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0 0 16px;
  max-width: 100%;
}

#fi-chat .fi-chat__msg--ai {
  align-items: flex-start;
}

#fi-chat .fi-chat__msg--client {
  align-items: flex-end;
}

#fi-chat .fi-chat__who {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fi-ink-faint, #6b7178);
}

#fi-chat .fi-chat__msg--ai .fi-chat__who {
  color: var(--fi-accent, #0b6b69);
}

#fi-chat .fi-chat__bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 12px 12px 12px 4px;
  border: 1px solid var(--fi-bubble-line, #dcd5ca);
  background: var(--fi-surface-alt, #f5f2ed);
  color: var(--fi-ink, #16181c);
  font-size: 0.97rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#fi-chat .fi-chat__msg--client .fi-chat__bubble {
  border-radius: 12px 12px 4px 12px;
  border-color: var(--fi-tint-line, #c4ecec);
  background: var(--fi-tint, #e4f8f8);
}

#fi-chat .fi-chat__msg--failed .fi-chat__bubble {
  border-color: var(--fi-danger, #b3261e);
  border-style: dashed;
}

/* Thinking indicator ----------------------------------------------------- */

#fi-chat .fi-chat__msg--thinking .fi-chat__bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 76px;
  min-height: 40px;
  color: var(--fi-ink-faint, #6b7178);
}

#fi-chat .fi-chat__dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#fi-chat .fi-chat__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: fi-chat-pulse 1.25s ease-in-out infinite;
}

#fi-chat .fi-chat__dot:nth-child(2) { animation-delay: 0.16s; }
#fi-chat .fi-chat__dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes fi-chat-pulse {
  0%, 80%, 100% { opacity: 0.28; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-2px); }
}

/* =========================================================================
   4. Status + retry
   ========================================================================= */

#fi-chat .fi-chat__status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--fi-danger-ink, #8c1d18);
  background: var(--fi-danger-bg, #fdf3f2);
  border: 1px solid var(--fi-danger-line, #f0d5d1);
  border-radius: var(--fi-radius, 8px);
}

#fi-chat .fi-chat__status:empty {
  display: none;
}

#fi-chat .fi-chat__status-text {
  flex: 1 1 14rem;
  min-width: 0;
}

#fi-chat .fi-chat__retry {
  flex: 0 0 auto;
  padding: 7px 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--fi-surface, #fff);
  background: var(--fi-danger-ink, #8c1d18);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

#fi-chat .fi-chat__retry:hover {
  background: #6f1614;
}

/* =========================================================================
   5. Composer
   ========================================================================= */

#fi-chat .fi-chat__composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px 10px;
  margin: 0;
  padding: 14px 0 max(0px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--fi-line, #e6e1d9);
  scroll-margin-block: 20px;
}

#fi-chat .fi-chat__label {
  grid-column: 1 / -1;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fi-ink-faint, #6b7178);
}

#fi-chat-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 46px;
  max-height: 132px;
  margin: 0;
  padding: 11px 13px;
  font: inherit;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--fi-ink, #16181c);
  background: var(--fi-surface, #fff);
  border: 1px solid var(--fi-line-strong, #8f877c);
  border-radius: var(--fi-radius, 8px);
  resize: none;
  overflow-y: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#fi-chat-input::placeholder {
  color: var(--fi-ink-faint, #6b7178);
  opacity: 1;
}

#fi-chat-input:focus {
  outline: none;
  border-color: var(--fi-accent, #0b6b69);
  box-shadow: 0 0 0 3px var(--fi-accent-ring, rgba(11, 107, 105, 0.28));
}

#fi-chat .fi-chat__composer.is-busy #fi-chat-input {
  color: var(--fi-ink-soft, #4c5359);
  background: var(--fi-surface-quiet, #f7f5f1);
}

#fi-chat-send {
  min-height: 46px;
  padding: 0 20px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fi-btn-ink, #fff);
  background: var(--fi-btn, #16181c);
  border: 1px solid transparent;
  border-radius: var(--fi-radius, 8px);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

#fi-chat-send:hover:not(:disabled) {
  background: var(--fi-btn-hover, #33383f);
}

#fi-chat-send:disabled {
  cursor: progress;
  opacity: 0.55;
}

/* =========================================================================
   6. Completion panel
   ========================================================================= */

#fi-chat .fi-chat__done {
  flex: 1 1 auto;
  min-height: 0;
  margin: 18px 0 0;
  padding: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* On a wide screen the completed brief is a document, not a chat pane: let it
   size the card and let the page scroll, so nothing is buried in a nested
   scroll box. The height cap stays where it earns its keep — on phones, where
   the composer has to stay above the keyboard (and is already hidden here). */
@media (min-width: 760px) {
  #fi-chat.is-done {
    max-height: none;
  }

  #fi-chat.is-done .fi-chat__done {
    overflow-y: visible;
  }
}

#fi-chat .fi-chat__done:focus {
  outline: none;
}

/* No focus ring on the brief: it is focusable only programmatically
   (tabindex="-1"), never by Tab, so it is not a WCAG 2.4.7 target — and a
   3px ring around the whole panel reads as a defect. #fi-chat-send and the
   textarea carry the visible focus states. */
#fi-chat .fi-chat__done:focus-visible {
  outline: none;
}

/* Once the brief is on screen it owns the card: the transcript steps aside so
   there is one scroll region rather than two nested ones. The conversation
   stays in the DOM (nothing is destroyed). */
#fi-chat.is-done .fi-chat__log {
  display: none;
}

#fi-chat.is-done .fi-chat__done {
  margin-top: 20px;
}

#fi-chat .fi-chat__done-title {
  margin: 0 0 2px;
  font-size: 2rem;
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--fi-ink, #16181c);
}

/* A hairline rule under the title, drawn from the accent. */
#fi-chat .fi-chat__done-title::after {
  content: "";
  display: block;
  width: 44px;
  height: 3px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--fi-accent-fill, #00dee2);
}

#fi-chat .fi-chat__answers {
  margin: 22px 0 0;
}

#fi-chat .fi-chat__answer-label {
  margin: 0 0 3px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fi-ink-faint, #6b7178);
}

#fi-chat .fi-chat__answer-value {
  margin: 0 0 16px;
  padding-left: 12px;
  border-left: 2px solid var(--fi-line, #e6e1d9);
  color: var(--fi-ink, #16181c);
  font-size: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#fi-chat .fi-chat__promise {
  margin: 22px 0 2px;
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--fi-ink, #16181c);
  background: var(--fi-accent-wash, #eefafa);
  border: 1px solid var(--fi-accent-line, #c2dedd);
  border-radius: var(--fi-radius, 8px);
}

/* =========================================================================
   7. Focus visibility
   ========================================================================= */

#fi-chat button:focus-visible,
#fi-chat textarea:focus-visible,
#fi-chat a:focus-visible {
  outline: 3px solid var(--fi-accent, #0b6b69);
  outline-offset: 2px;
}

/* =========================================================================
   8. Small screens — down to 360px
   ========================================================================= */

@media (max-width: 560px) {
  #fi-chat,
  .fi-chat {
    padding: 18px 15px 14px;
    border-radius: 12px;
    max-height: min(82vh, 720px);
    max-height: min(82dvh, 720px);
  }

  #fi-chat .fi-chat__title {
    font-size: 1.18rem;
  }

  #fi-chat .fi-chat__done-title {
    font-size: 1.5rem;
  }

  #fi-chat .fi-chat__bubble {
    max-width: 94%;
  }

  #fi-chat .fi-chat__log {
    padding-top: 16px;
  }

  #fi-chat .fi-chat__composer {
    gap: 6px 8px;
    padding-top: 12px;
  }

  #fi-chat-send {
    padding: 0 16px;
  }
}

@media (max-width: 560px) {
  .fi-wrap[data-fido-intake] .fi-chat__head,
  .fido-intake .fi-chat__head {
    padding-bottom: 14px;
    margin-bottom: 14px;
  }

  /* A quieter header buys the transcript room on a phone, where the keyboard
     takes most of the height. */
  .fi-wrap[data-fido-intake] .fi-chat__title,
  .fido-intake .fi-chat__title {
    font-size: 1.12rem;
  }

  .fi-wrap[data-fido-intake] .fi-chat__eyebrow,
  .fido-intake .fi-chat__eyebrow {
    font-size: 0.66rem;
  }

  .fi-wrap[data-fido-intake] .fi-chat__progress-text,
  .fido-intake .fi-chat__progress-text {
    font-size: 0.8rem;
  }
}

@media (max-width: 380px) {
  #fi-chat,
  .fi-chat {
    padding: 16px 12px 12px;
  }

  #fi-chat .fi-chat__bubble {
    max-width: 100%;
    padding: 10px 12px;
  }

  #fi-chat-send {
    padding: 0 13px;
    font-size: 0.9rem;
  }
}

/* Landscape phones: give the transcript the whole screen. */
@media (max-height: 480px) {
  #fi-chat,
  .fi-chat {
    max-height: 100vh;
    max-height: 100dvh;
  }
}

/* =========================================================================
   9. Motion preferences
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  #fi-chat .fi-chat__bar span,
  #fi-chat-bar-fill,
  #fi-chat-input,
  #fi-chat-send {
    transition: none;
  }

  #fi-chat .fi-chat__dot {
    animation: none;
    opacity: 0.7;
    transform: none;
  }
}
