/*
 * SIFA chat shell — chat-specific tokens, layout, and component styles.
 * Surfaces, text, brand, and status colors live in theme.css (single
 * source of truth). This file owns chat-only tokens: bubbles, wallpaper,
 * channels, layout, radius, motion, elevation, and backward-compat
 * aliases.
 */

:root {
  /* Outgoing bubble — WhatsApp dark-mode outbound (#005C4B); inbound is
     the panel-2 dark teal so the contrast matches WhatsApp Web. */
  --out-grad:    linear-gradient(135deg, #005C4B 0%, #005C4B 100%);
  --out-border:  transparent;
  --out-text:    #E9EDEF;
  --out-meta:    rgba(233,237,239,0.65);
  --bubble-in:   #202C33;
  --bubble-text: #E9EDEF;
  --in-border:   var(--hairline);

  /* Wallpaper — WhatsApp's chat-area background is essentially flat;
     we keep faint primary tints so the doodle layer reads without
     overwhelming the bubbles. */
  --wallpaper-1: rgba(0,168,132,0.03);
  --wallpaper-2: rgba(0,168,132,0.02);
  --wallpaper-3: rgba(83,189,235,0.02);

  /* Channel hues — four distinct gradients so agents distinguish at a glance */
  --ch-whatsapp-a: #00A884;     /* WhatsApp green (canonical) */
  --ch-whatsapp-b: #008069;
  --ch-sms-a:      #4F8CFF;     /* SMS = blue, traditional */
  --ch-sms-b:      #1A4ED8;
  --ch-web-a:      #00A884;     /* web = WhatsApp green (matches the theme) */
  --ch-web-b:      #008069;
  --ch-ussd-a:     #F59E0B;     /* USSD = amber — feature-phone vibe */
  --ch-ussd-b:     #C2580E;

  /* Backward-compat aliases (JS code references --green) */
  --green:       var(--primary);
  --green-dim:   var(--primary-dim);
  --green-bubble: transparent;     /* outgoing now uses --out-grad */
  --error:       var(--err);
  --read-blue:   #53BDEB;        /* WhatsApp read-receipt blue */
  --tick-grey:   rgba(233,237,239,0.45);  /* delivered/sent tick colour */
  --doodle-tint: rgba(0,168,132,0.04);    /* WhatsApp green tint */

  /* Layout */
  --rail-w:    72px;          /* slightly bigger for breath */
  --list-w:    30%;
  --list-min:  320px;
  --list-max:  420px;

  /* Radius */
  --r-chip:    999px;
  --r-btn:     12px;
  --r-input:   12px;
  --r-card:    16px;
  --r-modal:   20px;
  --r-bubble:  20px;

  /* Elevation */
  --e1: 0 1px 2px rgba(0,0,0,0.18), 0 0 0 1px rgba(255,255,255,0.04);
  --e2: 0 4px 12px rgba(0,0,0,0.24), 0 1px 3px rgba(0,0,0,0.18);
  --e3: 0 12px 32px rgba(0,0,0,0.36), 0 4px 12px rgba(0,0,0,0.24);
  --glow: 0 0 0 4px var(--primary-soft), 0 8px 24px var(--primary-glow);

  /* Motion */
  --t-fast:  150ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --t-base:  220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --t-slow:  320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Chat-specific light-theme overrides. Surfaces / text / brand / status
   come from theme.css; only the bubble/wallpaper/elevation tokens that
   are unique to the chat shell live here. */
:root[data-theme="light"] {
  /* WhatsApp Web light: outbound is #D9FDD3, inbound is white. The
     tiny darker border on outbound gives the bubble its definition
     on the beige chat-area background. */
  --out-grad:    linear-gradient(135deg, #D9FDD3 0%, #D9FDD3 100%);
  --out-border:  rgba(11,20,26,0.06);
  --out-text:    #111B21;
  --out-meta:    rgba(11,20,26,0.50);
  --bubble-in:   #FFFFFF;
  --bubble-text: #111B21;
  --in-border:   rgba(11,20,26,0.08);

  /* Wallpaper — WhatsApp chat-area is mostly the flat beige (#EFEAE2);
     these alphas just texture the doodle layer faintly so it reads on
     light without competing with bubbles. */
  --wallpaper-1: rgba(0,168,132,0.04);
  --wallpaper-2: rgba(0,168,132,0.02);
  --wallpaper-3: rgba(83,189,235,0.02);

  --doodle-tint: rgba(11,20,26,0.03);

  --e1: 0 1px 2px rgba(11,20,26,0.04), 0 0 0 1px rgba(11,20,26,0.04);
  --e2: 0 4px 12px rgba(11,20,26,0.06), 0 1px 3px rgba(11,20,26,0.04);
  --e3: 0 12px 32px rgba(11,20,26,0.10), 0 4px 12px rgba(11,20,26,0.06);

  /* Backward-compat overrides for the light theme */
  --read-blue:   #53BDEB;        /* WhatsApp blue */
  --tick-grey:   rgba(11,20,26,0.45);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --t-fast: 0ms;
    --t-base: 0ms;
    --t-slow: 0ms;
  }
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", "Helvetica Neue", Helvetica,
               "Lucida Grande", Arial, sans-serif;
  font-size: 14.5px;
  font-feature-settings: "ss01" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[hidden] { display: none !important; }

.display {
  font-family: "Cabinet Grotesk", "Inter", -apple-system, sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tabular { font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--err); margin-top: 12px; font-size: 13px; }
.link {
  background: transparent; border: 0; color: var(--muted-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px; border-radius: 50%;
  transition: background var(--t-fast), color var(--t-fast);
}
.link:hover { background: var(--hover); color: var(--text); }
.icon-btn { width: 40px; height: 40px; }

/* SIFA-296: refresh-button spinner. While the manual refresh is in
   flight the icon spins so the user gets a tactile confirmation that
   their tap registered. */
@keyframes sifa-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
#chat-refresh-btn.is-loading svg {
  animation: sifa-spin 0.8s linear infinite;
  opacity: 0.75;
}
#chat-refresh-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Chat-list unread badge — small accent pill on the SIFA inbox row
   showing how many unread bubbles are below the fold. Hidden when 0. */
.chat-list-item-row2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-list-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent, #d97706);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  flex-shrink: 0;
  margin-left: auto;
}

/* Sound-toggle off-state: dimmer to read as "muted". */
#chat-sound-toggle[aria-pressed="false"] svg { opacity: 0.55; }

/* 2026-05-14 turbo button (per-youth OpenAI Realtime opt-in). Pill
   shape so it visibly reads as a toggle, not a regular header icon.
   OFF: muted outline + grey "OFF" text. ON: warm orange fill +
   glowing bolt + clear "ON" text. */
.turbo-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 120ms, background-color 120ms, border-color 120ms, transform 120ms;
}
.turbo-btn .turbo-label { line-height: 1; white-space: nowrap; }
.turbo-btn:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--text);
}
.turbo-btn.is-on {
  color: #fff;
  background: #f59e0b;
  border-color: #f59e0b;
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.45));
}
.turbo-btn.is-on:hover { transform: scale(1.04); }
.turbo-btn[aria-pressed="true"] svg path { fill: currentColor; }
@media (max-width: 480px) {
  /* On narrow phones, drop the label — bolt alone in pill */
  .turbo-btn .turbo-label { display: none; }
  .turbo-btn { padding: 0 8px; }
}

/* Universal focus ring — accessibility */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
  border-radius: 6px;
}

/* ============= AUTH SCREEN ============= */
.auth-screen {
  position: relative;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  overflow: hidden;
  padding: 24px;
}

/* Layered mesh gradient backdrop. Three big radial blobs + a soft scan
   layer — atmospheric without being noisy. */
.auth-screen::before {
  content: ""; position: absolute; inset: -10%;
  background:
    radial-gradient(60% 50% at 15% 20%,  var(--wallpaper-1) 0%, transparent 60%),
    radial-gradient(50% 60% at 85% 30%,  var(--wallpaper-2) 0%, transparent 65%),
    radial-gradient(70% 40% at 50% 90%,  var(--wallpaper-3) 0%, transparent 70%),
    radial-gradient(40% 60% at 80% 80%,  var(--primary-soft) 0%, transparent 70%);
  filter: blur(28px);
  z-index: 0;
  pointer-events: none;
}
.auth-band { display: none; }   /* legacy element, no longer needed */

.auth-card {
  position: relative; z-index: 1;
  background: var(--panel);
  padding: 40px 44px 32px;
  border-radius: 28px;
  width: min(440px, 100%);
  box-shadow: var(--e3);
  border: 1px solid var(--hairline);
}
.auth-card h1 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: var(--text);
}
.auth-card p { margin: 4px 0 20px; line-height: 1.5; }
.auth-card input {
  width: 100%; margin: 8px 0; padding: 14px 16px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--r-input); font-size: 16px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
/* Override Chrome's autofill blue/yellow tint — only the box-shadow inset
   trick beats the !important UA stylesheet. Long transition defers Chrome's
   own auto-bg animation indefinitely. */
.auth-card input:-webkit-autofill,
.auth-card input:-webkit-autofill:hover,
.auth-card input:-webkit-autofill:focus,
.auth-card .otp-cell:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  caret-color: var(--text);
  transition: background-color 999999s ease-in-out 0s;
}

/* Phone-row — country chooser button + local-number input as a paired
   segmented control. The picker dropdown is absolute-positioned under
   the row when expanded. */
.auth-card .phone-row {
  position: relative;
  display: flex; gap: 8px; align-items: stretch;
  margin: 8px 0;
}
.auth-card .country-pick {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 12px;
  margin: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  font-size: 15px; font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  width: auto;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.auth-card .country-pick:hover {
  background: var(--hover);
  transform: none;
  box-shadow: none;
}
.auth-card .country-pick[aria-expanded="true"] {
  background: var(--hover);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.auth-card .country-pick[aria-expanded="true"] .country-caret {
  transform: rotate(180deg);
}
.auth-card .country-flag {
  font-size: 18px; line-height: 1;
}
.auth-card .country-code {
  font-variant-numeric: tabular-nums;
}
.auth-card .country-caret {
  color: var(--muted);
  margin-left: 2px;
  transition: transform var(--t-fast);
}
.auth-card .phone-row #phone-local {
  flex: 1;
  margin: 0;
  min-width: 0;
}

/* Country dropdown — list of options with flag, name, and dial code.
   Sits below the phone-row, scrollable if list grows beyond 6 items. */
.auth-card .country-dropdown {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  z-index: 10;
  min-width: 240px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-card);
  box-shadow: var(--e3, var(--e2));
  padding: 6px;
  animation: dropdown-in 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.auth-card .country-option {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px 10px;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: calc(var(--r-card) - 4px);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast);
}
.auth-card .country-option:hover,
.auth-card .country-option:focus-visible {
  background: var(--panel-2);
  outline: none;
  transform: none;
  box-shadow: none;
}
.auth-card .country-option[aria-selected="true"] {
  background: var(--primary-soft);
  color: var(--primary);
}
.auth-card .country-option .country-flag { font-size: 18px; }
.auth-card .country-option .country-name {
  color: var(--text);
}
.auth-card .country-option[aria-selected="true"] .country-name {
  color: var(--primary);
  font-weight: 600;
}
.auth-card .country-option .country-dial {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

/* OTP cells — six individual digit inputs. Hidden #code input mirrors the
   joined value so existing JS (codeInput.value) keeps working unchanged. */
.auth-card .otp-cells {
  display: flex; gap: 8px;
  margin: 12px 0 4px;
}
.auth-card .otp-cell {
  flex: 1 1 0; width: auto; min-width: 0;
  height: 56px; padding: 0;
  margin: 0;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--in-border, var(--border));
  border-radius: var(--r-input);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast),
              background var(--t-fast);
}
.auth-card .otp-cell:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.auth-card .otp-cell.filled {
  background: var(--panel-2);
  border-color: var(--primary-soft);
}


.auth-card button {
  width: 100%; padding: 14px; border: 0;
  background: var(--primary);
  color: white; font-weight: 600; font-size: 15px;
  border-radius: var(--r-btn);
  cursor: pointer; margin-top: 12px;
  transition: transform var(--t-fast), background var(--t-fast),
              box-shadow var(--t-fast);
}
.auth-card button:hover {
  background: var(--primary-dim);
  transform: translateY(-1px);
  box-shadow: var(--e2);
}
.auth-card button:active { transform: translateY(0); }

/* Step view-swap. Auth-card has two sections — request, verify.
   JS flips data-step; only one visible. */
.auth-card .auth-step { display: block; }
.auth-card[data-step="request"]      .step-verify         { display: none; }
.auth-card[data-step="verify"]       .step-request        { display: none; }

/* Back link on the verify view — small, low-emphasis, leads with caret. */
.auth-card .back-link {
  display: inline-flex; align-items: center; gap: 4px;
  width: auto;
  margin: 0 0 12px;
  padding: 6px 10px 6px 4px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  border-radius: var(--r-btn);
  transition: color var(--t-fast), background var(--t-fast);
}
.auth-card .back-link:hover {
  color: var(--text);
  background: var(--panel-2);
  transform: none;
  box-shadow: none;
}

.auth-card .footer { margin-top: 24px; }
.auth-card a {
  color: var(--primary); text-decoration: none; font-weight: 500;
}
.auth-card a:hover { text-decoration: underline; }

.link-btn {
  width: 100%; padding: 10px; border: 0; background: transparent;
  color: var(--primary); font-weight: 500; font-size: 14px;
  cursor: pointer; margin-top: 8px;
}
.link-btn:hover { text-decoration: underline; background: transparent !important; }
.link-btn:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }
/* `.link-btn` (0,1,0) loses specificity to `.auth-card button` (0,1,1),
   which forced solid-primary bg + white text — so link buttons rendered
   solid and went invisible on hover (white text on the transparent
   card). Scope a winning rule (0,2,1 / 0,3,1) so they render as real
   link-style buttons with visible text in both states. */
.auth-card button.link-btn {
  background: transparent; color: var(--primary);
}
.auth-card button.link-btn:hover {
  background: transparent; color: var(--primary);
  text-decoration: underline; transform: none; box-shadow: none;
}
.auth-card button.link-btn:disabled { color: var(--muted); }

/* OTP resend + channel-switch action row. Two link-style buttons
   inline so the youth can recover without leaving the OTP step. */
.otp-actions {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin-top: 4px;
}
.otp-actions .link-btn { width: auto; padding: 6px 10px; margin: 0; }
.otp-actions-sep { color: var(--muted); }

/* Delivery-status banner: muted by default; flips to a soft error
   tone when every provider failed and the server returned method=mock. */
#delivery-status.is-failed {
  color: var(--danger, #b54708);
  background: rgba(255, 152, 0, 0.08);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 4px;
  font-weight: 500;
}

.brand-row {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 28px; padding-bottom: 20px;
  border-bottom: 1px solid var(--hairline);
}
.brand-mark {
  width: 52px; height: 52px; border-radius: 16px;
  background: var(--brand-mark);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-weight: 700; font-size: 24px; letter-spacing: -0.02em;
  box-shadow: 0 0 0 4px var(--brand-mark-soft), var(--e2);
}
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-text strong {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 19px; font-weight: 700; letter-spacing: -0.01em;
}
.auth-toggle { text-align: center; margin: 20px 0 0; }

/* ============= APP SHELL (post-login) ============= */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) clamp(var(--list-min), var(--list-w), var(--list-max)) 1fr;
  height: 100vh;
  height: 100dvh;     /* mobile-safe: address bar doesn't break viewport */
  width: 100vw;
  overflow: hidden;
  background: var(--bg);
}

/* User role: youth only chat with SIFA, so the inbox is overhead.
   Collapse to a 2-column layout (slim rail + full-width chat) and
   hide the conversation list entirely. The rail keeps the profile +
   logout entries; nav icons (Chats / Status) hide because there's
   nothing to navigate between. */
body[data-role="user"] .app-shell {
  --rail-w: 320px;
  grid-template-columns: var(--rail-w) 1fr;
}
body[data-role="user"] .chat-list {
  display: none;
}
/* Right-side companion deprecated for user role — its content (Today,
   Points, Educate footer) absorbed into the left rail. Quick Actions
   chips dropped because they duplicated chatbot capability. */
body[data-role="user"] .companion {
  display: none;
}
/* Chat header: hide the entire header for user role on DESKTOP only
   (≥1024px, where the brand rail is visible and carries SIFA identity).
   On tablet (≤1023px) and mobile (≤768px) the rail is hidden, so the
   chat-header restores SIFA brand + menu — it's the user's only
   navigation surface at those widths. Agents keep the header at every
   breakpoint. (SIFA-88: was `min-width: 721px`, which mis-hid the
   header across the entire tablet range where the rail wasn't shown.) */
@media (min-width: 1024px) {
  body[data-role="user"] .chat-header {
    display: none;
  }
}

/* ---------- User-role rail: brand-led wide sidebar (Apple Music feel)
   Dark warm canvas, cream text, sienna brand. Replaces the icon-only
   layout used for agents. ---------- */
.rail-brand,
.rail-profile {
  display: none;     /* hidden by default; user-role flips them on */
}

/* SIFA-116: hide the youth-only rail companion cards (Points, Quick
   actions, etc.) when the signed-in user isn't role=user. Otherwise
   they leak into the 72px-wide admin/agent rail and render squashed.
   Mirrors the existing default-hide pattern used by .rail-day-card,
   .rail-brand, and .rail-profile. */
body:not([data-role="user"]) .rail .companion-card {
  display: none;
}

/* SIFA-116: agent empty-state — centered card in the chat-pane when
   admin/agent has no conversation selected. Hidden via the
   .agent-only class for youth role; toggled via JS when
   currentTargetPhone is empty in agent mode. */
.agent-empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.agent-empty-state-card {
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.agent-empty-state-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--panel-2, #f4ecdc);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.agent-empty-state h2 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.agent-empty-state p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
}
/* When the empty-state is visible, hide the thread, composer, and
   the chat-header meta so the user clearly sees nothing-selected. */
body.agent-no-target #thread,
body.agent-no-target #composer,
body.agent-no-target .chat-header .chat-header-meta strong,
body.agent-no-target #presence,
body.agent-no-target #handling-banner {
  display: none !important;
}

body[data-role="user"] .rail {
  background: #3D2918;
  color: #F1EADF;
  padding: 22px 18px;
  align-items: stretch;
  border-right: 0;
  gap: 14px;
  /* Strictly viewport-bound. Internal scrolling lives inside the
     Quick Actions card when expanded — the rail itself never scrolls. */
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

/* Lock the top elements at their natural heights — only Quick Actions
   absorbs the remaining vertical space. Without flex-shrink: 0 on
   these, all cards shrink proportionally on overflow. */
body[data-role="user"] .rail-brand,
body[data-role="user"] .rail-day-card,
body[data-role="user"] .rail .points-card {
  flex-shrink: 0;
}

/* Quick Actions: collapsed = natural; expanded = take whatever's left
   (basis 0 so it doesn't push siblings off-screen); internal chip
   list scrolls if the card runs out of room. */
body[data-role="user"] .rail .actions-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 auto;
}
body[data-role="user"] .rail .actions-card.expanded {
  flex: 1 1 0;
}
body[data-role="user"] .rail .actions-card .action-chips {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
body[data-role="user"] .rail .actions-card .action-chips::-webkit-scrollbar {
  width: 6px;
}
body[data-role="user"] .rail .actions-card .action-chips::-webkit-scrollbar-track {
  background: transparent;
}
body[data-role="user"] .rail .actions-card .action-chips::-webkit-scrollbar-thumb {
  background: rgba(27, 26, 23, 0.12);
  border-radius: 999px;
}

/* Pin the bottom controls (profile chip + logout + Powered by Educate)
   to the bottom of the rail. flex-shrink: 0 keeps them at their natural
   height; margin-top: auto on rail-bottom (already set) absorbs any
   leftover space ABOVE so the bottom row stays flush at the floor when
   Quick Actions is collapsed. When expanded, the actions-card with
   flex: 1 1 0 fills the space instead. */
body[data-role="user"] .rail-bottom,
body[data-role="user"] .companion-foot {
  flex-shrink: 0;
}
body[data-role="user"] .companion-foot {
  margin-top: 4px;       /* small breath above footer; bottom is 0 */
  margin-bottom: 0;
}

/* Claymorphism — soft, puffy warm-cream tiles floating on the dark
   brown rail. Layered shadows: top inner highlight (light from above)
   + bottom inner shade (self-cast) + outer warm drop. Cards feel
   tactile + cohesive against the dark "table". */
body[data-role="user"] .rail .companion-card {
  background: #F4ECDC;
  border: 0;
  border-radius: 18px;
  padding: 20px 20px 18px;
  margin: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    inset 0 -2px 0 rgba(140, 80, 50, 0.08),
    0 6px 16px rgba(0, 0, 0, 0.22),
    0 18px 30px rgba(0, 0, 0, 0.10);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
body[data-role="user"] .rail .companion-card h3 {
  color: var(--text);
}
body[data-role="user"] .rail .companion-eyebrow {
  color: var(--brand-mark);
}
body[data-role="user"] .rail .today-rows li {
  border-bottom-color: rgba(27, 26, 23, 0.08);
}
body[data-role="user"] .rail .today-label {
  color: var(--muted);
}
body[data-role="user"] .rail .today-value {
  color: var(--text);
}
body[data-role="user"] .rail .companion-card-foot {
  color: var(--muted);
}
body[data-role="user"] .rail .points-num {
  color: var(--text);
}
body[data-role="user"] .rail .points-suffix {
  color: var(--muted);
}

/* Card header that doubles as a toggle (Quick actions). Reset the
   <button> defaults so it reads identical to a non-button header,
   plus a chevron that rotates on collapse. */
.companion-card-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}
.companion-card-toggle:hover .companion-card-chevron {
  color: var(--text);
}
.companion-card-chevron {
  color: var(--muted);
  flex-shrink: 0;
  transition: transform var(--t-fast), color var(--t-fast);
}
.companion-card-toggle[aria-expanded="false"] .companion-card-chevron {
  transform: rotate(-90deg);
}
.companion-card-toggle[aria-expanded="false"] + .action-chips {
  display: none;
}
/* When the toggle is in its collapsed state, drop the bottom margin
   that companion-card-header normally has so the card reads as a
   tight pill instead of a card with empty space. */
.companion-card-toggle {
  margin-bottom: 12px;
}
.companion-card-toggle[aria-expanded="false"] {
  margin-bottom: 0;
}

/* Action chips on the clay tile — slightly smaller-scale claymorphism
   so they read as elements within the card, not floating on the rail. */
body[data-role="user"] .rail .action-chip {
  background: rgba(255, 255, 255, 0.85);
  border: 0;
  border-radius: 14px;
  color: var(--text);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 1),
    inset 0 -1px 0 rgba(140, 80, 50, 0.06),
    0 2px 4px rgba(0, 0, 0, 0.06);
}
body[data-role="user"] .rail .action-chip:hover {
  background: #FFFFFF;
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 1),
    inset 0 -1px 0 rgba(140, 80, 50, 0.08),
    0 6px 12px rgba(0, 0, 0, 0.10);
}
body[data-role="user"] .rail .action-chip .action-text strong {
  color: var(--text);
}
body[data-role="user"] .rail .action-chip .action-caret {
  color: var(--muted);
}
body[data-role="user"] .rail .action-chip:hover .action-caret {
  color: var(--brand-mark);
}
body[data-role="user"] .rail-top,
body[data-role="user"] .rail-nav {
  display: none;
}

/* Brand block at the top */
body[data-role="user"] .rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 16px;
}

/* Day card — sits between brand and bottom. Calendar-tear-off feel:
   eyebrow, big serif numeral, day name, date. Earns the dark middle
   space without competing with the chat. (Streak pill removed
   2026-06-12 — placeholder, not real backend data.) */
.rail-day-card {
  display: none;     /* user-role flips this on */
}
body[data-role="user"] .rail-day-card {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: #F4ECDC;
  border: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    inset 0 -2px 0 rgba(140, 80, 50, 0.08),
    0 6px 16px rgba(0, 0, 0, 0.22),
    0 18px 30px rgba(0, 0, 0, 0.10);
}
body[data-role="user"] .rail-day-eyebrow {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--brand-mark);
}
body[data-role="user"] .rail-day-num {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 56px; font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--text);
  margin: 6px 0 8px;
  font-variant-numeric: tabular-nums;
}
body[data-role="user"] .rail-day-name {
  font-size: 14px; font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
body[data-role="user"] .rail-day-date {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 1px;
}
body[data-role="user"] .rail-brand .brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  font-size: 20px;
  /* keeps sienna fill from .brand-mark base rule */
}
body[data-role="user"] .rail-brand .brand-text strong {
  display: block;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 17px; font-weight: 700;
  letter-spacing: -0.01em;
  color: #F1EADF;
  line-height: 1.1;
  margin-bottom: 2px;
}
body[data-role="user"] .rail-brand .brand-text .muted {
  font-size: 11.5px;
  color: rgba(241,234,223,0.62);
  letter-spacing: 0.01em;
}

/* Profile chip + logout sit at the bottom */
body[data-role="user"] .rail-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  padding: 0;
}
body[data-role="user"] .rail-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(241,234,223,0.06);
  border: 1px solid rgba(241,234,223,0.10);
  border-radius: var(--r-btn);
}
body[data-role="user"] .rail-profile-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand-mark);
  color: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-weight: 700; font-size: 11.5px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
body[data-role="user"] .rail-profile-text {
  flex: 1; min-width: 0;
  overflow: hidden;
}
body[data-role="user"] .rail-profile-text strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #F1EADF;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
body[data-role="user"] .rail-profile-text .muted {
  font-size: 11px;
  color: rgba(241,234,223,0.60);
  white-space: nowrap;
}
body[data-role="user"] .rail-profile-text .rail-profile-sifa-id {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: rgba(241,234,223,0.78);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
  cursor: help;
}

/* Logout — wider button on dark, label visible */
body[data-role="user"] #logout-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-btn);
  background: transparent;
  color: rgba(241,234,223,0.72);
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast),
              border-color var(--t-fast);
}
body[data-role="user"] #logout-btn:hover {
  background: rgba(241,234,223,0.06);
  border-color: rgba(241,234,223,0.10);
  color: #F1EADF;
}
.rail-icon-label {
  font-size: 13px;
  font-weight: 500;
  display: none;
}
body[data-role="user"] #logout-btn .rail-icon-label {
  display: inline;
}

body[data-role="user"] .rail-nav {
  display: none;
}

/* Companion panel — supportive content right of the chat thread.
   Visible only for the user role (agents/admins keep their 3-pane
   inbox layout untouched). Hides on narrow viewports so mobile
   keeps the chat-only experience. */
.companion {
  display: none;
  background: var(--panel);
  border-left: 1px solid var(--hairline);
  padding: 24px 20px;
  overflow-y: auto;
  flex-direction: column;
  gap: 14px;
}
/* Companion aside is hidden for user role globally — its content was
   merged into the left rail. Mobile gets the same single-pane chat. */
@media (max-width: 980px) {
  body[data-role="user"] .app-shell {
    grid-template-columns: var(--rail-w) 1fr;
  }
}

.companion-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-card);
  padding: 18px 18px 16px;
  box-shadow: var(--e1);
}
.companion-card-header {
  margin-bottom: 12px;
}
.companion-eyebrow {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--brand-mark);
  margin-bottom: 4px;
}
.companion-card h3 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 15px; font-weight: 700;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}
.companion-card-foot {
  margin: 12px 0 0;
}

/* Today rows — labelled values, tabular nums, dashed when no data. */
.today-rows {
  list-style: none;
  margin: 0; padding: 0;
  display: flex; flex-direction: column;
}
.today-rows li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--in-border, var(--hairline));
}
.today-rows li:last-child { border-bottom: 0; }
.today-label { color: var(--muted); }
.today-value {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Points card — recognition. Hero numeral only; tier system lands as
   separate feature work later. */
.points-hero {
  display: flex; align-items: baseline; gap: 4px;
  margin: 4px 0 0;
}
.points-num {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 32px; font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.points-suffix {
  font-size: 13px; font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

/* Action chips — reusable card-as-control pattern; same primitive
   could surface in a slide-up overlay later (per brief §04). */
.action-chips {
  display: flex; flex-direction: column; gap: 8px;
}
.action-chip {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 32px 11px 12px;     /* right padding leaves room for caret */
  margin: 0;
  background: var(--panel-2);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-btn);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast);
}
.action-chip:hover {
  background: var(--panel);
  border-color: var(--primary);
  transform: translateY(-1px);
}
.action-chip .action-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--brand-mark-soft);
  color: var(--brand-mark);
  flex-shrink: 0;
}
.action-chip .action-text {
  display: flex; flex-direction: column; gap: 1px;
  min-width: 0;
  flex: 1;
}
.action-chip .action-text strong {
  font-weight: 600;
  color: var(--text);
}
.action-chip .action-caret {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%) translateX(-4px);
  color: var(--muted);
  opacity: 0;
  transition: opacity var(--t-fast), transform var(--t-fast),
              color var(--t-fast);
}
.action-chip:hover .action-caret {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
  color: var(--primary);
}

/* Companion footer — small attribution. Anchors the panel and
   communicates platform identity without competing with content. */
.companion-foot {
  margin-top: auto;
  padding: 16px 4px 4px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.companion-foot a {
  color: var(--text);
  text-decoration: none;
  transition: color var(--t-fast);
}
.companion-foot a:hover {
  color: var(--primary);
}
.companion-foot strong {
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.005em;
}

/* --- Left rail (icons sidebar) --- */
.rail {
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0;
  gap: 4px;
}
.rail-top { padding-bottom: 8px; }
.rail-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-weight: 700; font-size: 18px;
  box-shadow: var(--e1);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.rail-avatar:hover {
  background: var(--primary-soft); color: var(--primary);
  transform: scale(1.04);
}

.rail-nav { flex: 1; display: flex; flex-direction: column; gap: 6px; padding-top: 12px; }
.rail-bottom { padding-top: 8px; }
.rail-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast),
              box-shadow var(--t-fast);
}
.rail-icon:hover { background: var(--hover); color: var(--text); }
.rail-icon.active {
  color: var(--primary); background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary-soft);
}

/* --- Chat list (middle column) --- */
.chat-list {
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  min-width: 0;
  /* min-height:0 is required so .chat-list-items can shrink below its
     intrinsic height inside the parent grid track and trigger overflow. */
  min-height: 0;
}
.chat-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px; background: transparent;
  height: auto;
}
.chat-list-title {
  font-size: 22px; margin: 0;
  letter-spacing: -0.01em;
  color: var(--text);
}
.chat-list-actions { display: flex; gap: 4px; }

.chat-list-search {
  padding: 0 16px 12px; background: var(--panel);
}
.search-box {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2);
  border-radius: var(--r-input); padding: 10px 16px;
  color: var(--muted);
  transition: background var(--t-fast);
}
.search-box:focus-within { background: var(--panel-3); }
.search-box input {
  flex: 1; background: transparent; border: 0; color: var(--text);
  font-size: 14px; outline: none;
}
.search-box input::placeholder { color: var(--muted); }
.search-icon { color: var(--muted); }

.chat-list-items {
  list-style: none; margin: 0; padding: 8px 12px 24px;
  overflow-y: auto; flex: 1 1 0; min-height: 0;
  display: flex; flex-direction: column; gap: 4px;
  /* Slim, near-invisible scrollbar — present when needed, otherwise out
     of the way. Matches the dark surface, never the OS default. */
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}
.chat-list-items::-webkit-scrollbar { width: 6px; }
.chat-list-items::-webkit-scrollbar-track { background: transparent; }
.chat-list-items::-webkit-scrollbar-thumb {
  background: var(--hairline); border-radius: 3px;
}
.chat-list-items::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.chat-list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 12px; cursor: pointer;
  border-radius: var(--r-card);
  transition: background var(--t-fast), transform var(--t-fast);
  position: relative;
}
.chat-list-item:hover { background: var(--hover); }
.chat-list-item.active {
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}
.chat-list-item-body { flex: 1; min-width: 0; }
.chat-list-item-row1 {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.chat-list-name {
  font-size: 15px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.chat-list-time {
  color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.chat-list-item-row2 {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 4px;
}
.chat-list-preview {
  color: var(--muted); font-size: 13.5px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.chat-list-empty {
  padding: 24px 12px; text-align: center; cursor: default;
}

.avatar-circle {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-mark);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-weight: 700; font-size: 17px; flex-shrink: 0;
  box-shadow: var(--e1);
}
.avatar-circle.small { width: 38px; height: 38px; font-size: 14px; border-radius: 50%; }
.avatar-circle.channel-whatsapp {
  background: linear-gradient(135deg, var(--ch-whatsapp-a), var(--ch-whatsapp-b));
}
.avatar-circle.channel-sms {
  background: linear-gradient(135deg, var(--ch-sms-a), var(--ch-sms-b));
}
.avatar-circle.channel-web {
  background: linear-gradient(135deg, var(--ch-web-a), var(--ch-web-b));
}
.avatar-circle.channel-ussd {
  background: linear-gradient(135deg, var(--ch-ussd-a), var(--ch-ussd-b));
}

/* Channel chip — pill, gradient bg, uppercase tracked label */
.channel-badge {
  display: inline-flex; align-items: center;
  font-size: 9.5px; font-weight: 700;
  letter-spacing: 0.7px; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--r-chip);
  color: #fff;
}
.channel-badge.channel-whatsapp {
  background: linear-gradient(135deg, var(--ch-whatsapp-a), var(--ch-whatsapp-b));
}
.channel-badge.channel-sms {
  background: linear-gradient(135deg, var(--ch-sms-a), var(--ch-sms-b));
}
.channel-badge.channel-web {
  background: linear-gradient(135deg, var(--ch-web-a), var(--ch-web-b));
}
.channel-badge.channel-ussd {
  background: linear-gradient(135deg, var(--ch-ussd-a), var(--ch-ussd-b));
}

/* Unread count pill — primary periwinkle */
.unread-pill {
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 22px; height: 22px; padding: 0 7px;
  border-radius: var(--r-chip);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--panel);
}

/* --- Chat pane (right column) --- */
.chat-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
  position: relative;
}
.chat-header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
  height: auto; min-height: 68px;
  position: relative;
  z-index: 2;
}
.chat-back { display: none; }
.chat-header-meta { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.chat-header-meta strong {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--text);
}
.chat-header-meta .muted { font-size: 12.5px; }

/* Online dot — pulsing mint */
.chat-header-meta strong::after {
  content: ""; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--mint); margin-left: 8px;
  animation: presence-pulse 2.4s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes presence-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(0.85); }
}

.chat-header-actions { display: flex; gap: 4px; align-items: center; }

/* In-conversation search — slides into place where the search button was.
   Keeps the chat header height stable so the thread doesn't reflow. */
.thread-search-bar {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-input);
  padding: 4px 8px 4px 12px;
  min-width: 240px;
}
.thread-search-bar:focus-within { border-color: var(--primary); }
.thread-search-bar input {
  flex: 1; background: transparent; border: 0; color: var(--text);
  font-size: 13.5px; outline: none; min-width: 0;
}
.thread-search-bar input::placeholder { color: var(--muted); }

/* Match-highlight on bubbles. Subtle ring rather than a yellow flash so
   it's readable on the dark surface. */
.bubble.search-hit {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  transition: outline-color var(--t-fast);
}

/* Voice-note recording indicator (shown above the composer while
   MediaRecorder is active). Subtle — communicates "we're listening"
   without taking over the chat. */
.voice-recording {
  position: absolute;
  bottom: 100%;
  left: 16px; right: 16px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--alert);
  border-radius: var(--r-card);
  padding: 8px 14px;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
}
.voice-recording .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--alert);
  animation: vrec-pulse 1s ease-in-out infinite;
}
.voice-recording .voice-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
@keyframes vrec-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
.composer { position: relative; }
.composer-btn.send.recording {
  background: var(--alert) !important;
  color: #fff;
}

/* Inline audio bubble — match the conversation surface. */
.media-audio {
  width: 100%;
  max-width: 280px;
  margin-bottom: 6px;
  border-radius: 18px;
}

/* Agent-only UI: shown only when <body class="role-agent"> */
.agent-only { display: none; }
body.role-agent .agent-only { display: inline-flex; }

/* Admin-only UI: shown only when <body class="role-admin"> */
.admin-only { display: none !important; }
body.role-admin .admin-only { display: block !important; }
body.role-admin .menu-item.admin-only { display: block !important; }

/* Handling-state banner — replaces the small Bot/You pill.
   Sits above the thread; swaps color + copy based on data-attribution. */
.handling-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
  position: relative;
}
.handling-banner::before {
  /* Left rail of color, dot pulse styles match the state */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  transition: background var(--t-base);
}
.handling-banner[data-attribution="agent"]::before { background: var(--accent); }

.handling-state {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.handling-state .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  flex-shrink: 0;
  animation: presence-pulse 2.4s ease-in-out infinite;
}
.handling-banner[data-attribution="agent"] .handling-state .dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255,107,157,0.18);
}
.handling-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.handling-title {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--text);
}

.handling-action {
  background: var(--primary); color: white;
  border: 0; cursor: pointer;
  padding: 9px 16px; border-radius: var(--r-btn);
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
  transition: background var(--t-fast), transform var(--t-fast),
              box-shadow var(--t-fast);
}
.handling-action:hover {
  background: var(--primary-dim);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--primary-glow);
}
/* In agent mode, the action button becomes "Release" — softer tone */
.handling-banner[data-attribution="agent"] .handling-action {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--hairline);
}
.handling-banner[data-attribution="agent"] .handling-action:hover {
  background: var(--hover);
  box-shadow: var(--e1);
}

/* Thread — WhatsApp-style tiled doodle layered behind the soft
   radial washes. Pattern uses 4 small warm-alpha glyphs (dot, ring,
   leaf, crescent) on a 96px tile. Alpha is low enough to read as
   warmth, not content. */
.thread {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 24px 6% 16px;
  display: flex; flex-direction: column; gap: 4px;
  background-color: var(--bg);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><circle cx='14' cy='14' r='0.9' fill='rgba(140,80,50,0.10)'/></svg>"),
    radial-gradient(60% 80% at 80% 0%, var(--wallpaper-1) 0%, transparent 60%),
    radial-gradient(50% 70% at 0% 50%, var(--wallpaper-3) 0%, transparent 60%),
    radial-gradient(60% 60% at 100% 100%, var(--wallpaper-2) 0%, transparent 60%);
  background-size: 28px 28px, auto, auto, auto;
  background-repeat: repeat, no-repeat, no-repeat, no-repeat;
  background-attachment: local;
}
.thread > * { color: var(--text); }

/* Bubbles — softer, more rounded, with subtle motion. Width is capped
   in absolute px so on a wide canvas (user role full-width chat) bubbles
   don't stretch beyond comfortable reading length. */
.bubble {
  position: relative;
  max-width: min(68%, 540px);
  padding: 10px 14px 10px;
  border-radius: var(--r-bubble);
  word-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
  font-size: 14.5px;
  box-shadow: var(--e1);
  white-space: pre-wrap;
  animation: bubble-in var(--t-slow) both;
  transition: box-shadow var(--t-fast);
}
@keyframes bubble-in {
  from { transform: translateY(6px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* Out: gradient + white text + subtle glow on hover */
.bubble.out {
  align-self: flex-end;
  background: var(--out-grad);
  border: 1px solid var(--out-border);
  color: var(--out-text);
  margin-right: 8px;
  border-bottom-right-radius: 6px;     /* asymmetric — youth-friendly */
}
.bubble.out:hover { box-shadow: var(--e2); }

/* In: surface bg + primary text */
.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--bubble-text);
  margin-left: 8px;
  border: 1px solid var(--in-border);
  border-bottom-left-radius: 6px;
}

/* Bubble groupings — adjacent same-sender bubbles tighten + soften corners */
.bubble + .bubble.out:not(.first) { margin-top: -2px; border-top-right-radius: 6px; }
.bubble + .bubble.in:not(.first)  { margin-top: -2px; border-top-left-radius: 6px; }

/* Tail removed — replaced with pure radius asymmetry. Cleaner, more modern. */
/* WhatsApp-style tails on first-of-sequence bubbles. Square the
   matching top corner on the bubble itself so the tail's flat edge
   sits flush — without this, the rounded corner curves away from the
   tail and they look detached. */
.bubble.first.in  { border-top-left-radius: 0; }
.bubble.first.out { border-top-right-radius: 0; }

.bubble.first.in::before {
  content: "";
  position: absolute;
  top: 0; left: -8px;
  width: 8px; height: 14px;
  background: var(--bubble-in);
  clip-path: polygon(100% 0, 100% 100%, 0 0);
}
.bubble.first.out::before {
  content: "";
  position: absolute;
  top: 0; right: -8px;
  width: 8px; height: 14px;
  background: #E6DFCA;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* Bubble row — wraps each non-system bubble in a flex row so the
   SIFA avatar (incoming side) lives in real auto-layout. No fragile
   absolute positioning; the row sizes itself, the bubble flexes, and
   the avatar takes its natural width. Auto-responsive at every
   breakpoint without per-viewport tweaks. */
.bubble-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  margin: 0;
}
.bubble-row.in  { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }

/* Date dividers — WhatsApp-style "Leo / Jana / Jumanne / 13 Jun" pill
   that separates bubbles from different days. Injected by
   `_maybeInsertDateDivider` in chat.js so a refresh that pulls
   history spanning multiple days doesn't render as a confusing wall
   of HH:MM-only timestamps. */
.date-divider {
  align-self: center;
  margin: 12px auto;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.6);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 12px;
  user-select: none;
}
@media (prefers-color-scheme: dark) {
  .date-divider {
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.06);
  }
}

/* SIFA avatar — only on first-of-sequence incoming rows. Subsequent
   rows in a run keep the same column width via visibility: hidden
   so bubbles stay vertically aligned. */
.bubble-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-mark);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  box-shadow: var(--e1);
  align-self: flex-start;
  margin-top: 0;
}
.bubble-row:not(.first) .bubble-avatar {
  visibility: hidden;
}

/* When a bubble lives inside a row, it can't use its own
   align-self / margin-left/right anymore — the row handles those.
   The bubble's max-width caps still apply. */
.bubble-row .bubble.in,
.bubble-row .bubble.out {
  align-self: auto;
  margin-left: 0;
  margin-right: 0;
}

.bubble.system {
  align-self: center;
  background: rgba(255,185,73,0.10);
  color: var(--warn);
  font-style: italic; font-size: 12.5px;
  padding: 8px 14px; border-radius: var(--r-chip); max-width: 80%;
  border: 1px solid rgba(255,185,73,0.20);
}

/* Inline meta (timestamp + ticks) — bottom-right inside the bubble.
   Bumped from 10.5px → 11.5px and incoming color shifted to muted-2
   so the timestamp clears WCAG AA on both bubble surfaces. The prior
   --muted on a dark incoming bubble landed at ~4.4:1 in dark mode and
   the 0.75-alpha white on a green gradient was hard to read at small
   sizes. */
.bubble .meta {
  display: inline-flex; align-items: center; gap: 4px;
  float: right; margin: 4px 0 -2px 12px;
  color: var(--muted-2); font-size: 11.5px; line-height: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  user-select: none;
  letter-spacing: 0.01em;
}
.bubble.out .meta { color: var(--out-meta); }
.bubble .ticks { display: inline-flex; }
.bubble .ticks svg {
  display: block;
  color: var(--tick-grey);    /* default (sent / delivered) — grey */
}
.bubble.out .ticks.read svg { color: var(--read-blue); }   /* read — WhatsApp blue */

/* Trace tag — tiny `#<id>` next to the timestamp. Used by support to
   find the canonical n8n_chat_histories row for a bubble. Designed to
   be present but not distracting (faded, monospace, 10.5px). Click
   copies the full ID. */
.bubble .trace-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0;
  opacity: 0.45;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
  transition: opacity 120ms ease, background-color 120ms ease;
}
.bubble .trace-tag:hover { opacity: 0.85; }
.bubble .trace-tag.copied {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.08);
}

/* ---------------------------------------------------------------------------
   Dynamic inline form modal (sifa-form-*)
   Rendered from a `form` SSE event payload by `renderInlineForm` in
   chat.js. One stylesheet covers every form kind in FORM_REGISTRY —
   adding a new form needs no CSS changes.
   ------------------------------------------------------------------------ */
.sifa-form-modal {
  position: fixed; inset: 0;
  background: rgba(15, 18, 22, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 2000;
  padding: 16px;
  animation: sifa-form-fade 180ms ease-out;
}
@keyframes sifa-form-fade {
  from { background: rgba(15, 18, 22, 0); }
  to   { background: rgba(15, 18, 22, 0.55); }
}
.sifa-form-card {
  background: var(--card-bg, #fff);
  border-radius: 18px 18px 6px 6px;
  width: 100%; max-width: 480px;
  max-height: 88vh; overflow-y: auto;
  padding: 20px 18px 14px;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
  animation: sifa-form-slide 220ms ease-out;
}
@keyframes sifa-form-slide {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@media (min-width: 640px) {
  .sifa-form-modal { align-items: center; }
  .sifa-form-card  { border-radius: 14px; }
}
.sifa-form-title {
  font-size: 17px; font-weight: 600;
  margin: 0 0 4px;
  color: var(--text-primary, #1c1f23);
}
.sifa-form-desc {
  font-size: 13.5px; color: var(--muted-2, #6b7280);
  margin: 0 0 14px;
}
.sifa-form-body { display: flex; flex-direction: column; gap: 12px; }
.sifa-form-row { display: flex; flex-direction: column; gap: 4px; }
.sifa-form-label {
  font-size: 13px; font-weight: 500;
  color: var(--text-primary, #1c1f23);
}
.sifa-form-row input,
.sifa-form-row select,
.sifa-form-row textarea {
  font-size: 16px;          /* >=16px defeats iOS auto-zoom */
  font-family: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border, #d4d8de);
  border-radius: 8px;
  background: var(--input-bg, #fff);
  color: var(--text-primary, #1c1f23);
  outline: none;
  transition: border-color 120ms;
}
.sifa-form-row input:focus,
.sifa-form-row select:focus,
.sifa-form-row textarea:focus {
  border-color: var(--accent, #b67250);
}
.sifa-form-row textarea { resize: vertical; }
.sifa-form-help {
  font-size: 12px; color: var(--muted-2, #6b7280);
}
.sifa-form-error {
  font-size: 13px; color: var(--err, #b8392a);
  padding: 8px 10px; margin-top: 4px;
  background: rgba(184, 57, 42, 0.08);
  border-radius: 6px;
}
.sifa-form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 8px;
}
.sifa-form-cancel,
.sifa-form-submit {
  font-size: 14.5px; font-weight: 500;
  padding: 9px 18px;
  border-radius: 22px;
  cursor: pointer;
  border: 1px solid transparent;
}
.sifa-form-cancel {
  background: transparent;
  color: var(--muted-1, #4b5563);
  border-color: var(--border, #d4d8de);
}
.sifa-form-submit {
  background: var(--accent, #b67250); color: #fff;
}
.sifa-form-submit:disabled {
  opacity: 0.65; cursor: not-allowed;
}

/* Typing indicator — SIFA-signature wave.
   Three dots step through the warm-palette gradient (sienna → terracotta
   → taupe) and rise in a soft wave, one after another. Restrained motion
   per CLAUDE.md §11; the palette spread is what makes it ours. */
.typing {
  align-self: flex-start;
  padding: 14px 18px;
  background: var(--bubble-in);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-bubble);
  border-bottom-left-radius: 6px;
  margin-left: 8px;
  box-shadow: var(--e1);
  display: inline-flex; align-items: center; gap: 6px;
  animation: bubble-in var(--t-slow) both;
}
.typing span {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  animation: typing-wave 1.2s infinite cubic-bezier(0.45, 0.05, 0.55, 0.95);
  will-change: transform, opacity;
}
.typing span:nth-child(1) { background: var(--brand-mark); animation-delay: 0s; }
.typing span:nth-child(2) { background: #D58464;          animation-delay: 0.15s; }
.typing span:nth-child(3) { background: #D0C3A5;          animation-delay: 0.30s; }

@keyframes typing-wave {
  0%, 80%, 100% { transform: translateY(0) scale(0.85); opacity: 0.55; }
  40%           { transform: translateY(-4px) scale(1); opacity: 1; }
}

/* --- Reply buttons (WhatsApp interactive quick-reply pills) --- */
.bubble-buttons {
  display: flex; flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.bubble-button {
  background: var(--panel);
  border: 1px solid var(--in-border, var(--hairline));
  padding: 11px 16px;
  color: var(--text);
  font-weight: 600; font-size: 14px;
  letter-spacing: -0.005em;
  text-align: center;
  cursor: pointer;
  border-radius: var(--r-btn);
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast);
}
.bubble-button:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}
/* Selected — the option the youth tapped. Solid sienna with white text,
   matching the v5 brief's pain-pick / outcome chip pattern. */
.bubble-button.selected,
.bubble-button[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
}
/* Consumed — historical context, no longer interactive. Muted text but
   stays readable; no opacity dimming (which made labels unreadable). */
.bubble-button:disabled, .bubble-button.consumed {
  color: var(--muted-2);
  cursor: default;
}
.bubble-button.consumed:hover {
  background: var(--panel);
  border-color: var(--in-border, var(--hairline));
  color: var(--muted-2);
  transform: none;
}
/* Inside outgoing bubbles, buttons need their own background since the
   bubble itself is already a gradient. We don't currently render
   buttons on outgoing — defensive only. */
.bubble.out .bubble-button { background: rgba(255,255,255,0.20); border-color: rgba(255,255,255,0.30); color: white; }

/* --- Image attach preview chip (sits above the composer) --- */
.attach-preview {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2);
  padding: 12px 24px;
  border-top: 1px solid var(--hairline);
}
.attach-preview img {
  width: 48px; height: 48px; border-radius: 10px; object-fit: cover;
  box-shadow: var(--e1);
}
.attach-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- Media inside a bubble --- */
.bubble .media {
  display: block;
  max-width: 100%;
  border-radius: 12px;
  margin: -2px -4px 6px -4px;
  cursor: zoom-in;
  background: rgba(0,0,0,0.15);
  transition: transform var(--t-fast);
}
.bubble .media:hover { transform: scale(0.99); }

/* Inline player when an n8n / AI reply contains a video file URL. */
.bubble .media-video {
  width: 100%;
  max-width: 100%;
  background: rgba(0,0,0,0.4);
  cursor: default;
}
.bubble .media-video:hover { transform: none; }

/* YouTube / Vimeo embeds — fixed 16:9 frame, full bubble width. */
.bubble .media-embed {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  margin: -2px -4px 6px -4px;
  border: 0;
  background: rgba(0,0,0,0.6);
}

/* Auto-linkified URLs inside bubble text. Inherit the bubble's
 * text colour so outbound (white-on-orange) and inbound (dark-on-
 * cream) read consistently; the underline + hover give the affordance. */
.bubble .msg-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.bubble .msg-link:hover { opacity: 0.85; }

/* Document chip (non-image attachment, e.g. PDF). Opens in new tab. */
.bubble .media-doc {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; margin: 0 -4px 6px -4px;
  background: rgba(255, 255, 255, 0.18);
  color: inherit; text-decoration: none;
  border-radius: 12px; font-weight: 500; font-size: 14px;
  transition: background var(--t-fast);
}
.bubble.in .media-doc { background: rgba(0, 0, 0, 0.06); }
.bubble .media-doc:hover { background: rgba(255, 255, 255, 0.28); }
.bubble.in .media-doc:hover { background: rgba(0, 0, 0, 0.10); }
.bubble .media-doc svg { flex-shrink: 0; }

/* --- Composer — elevated, no top border --- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px 14px;
  background: transparent;
  position: relative;
}
.composer-btn {
  background: transparent; border: 0; cursor: pointer;
  width: 42px; height: 42px; border-radius: var(--r-btn);
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast);
}
.composer-btn:hover { background: var(--hover); color: var(--text); }

/* Send button — sienna primary by default; disables to a neutral
   muted state when the input is empty or whitespace-only. */
.composer-btn.send {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 6px 16px var(--primary-glow);
  transition: background var(--t-fast), color var(--t-fast),
              transform var(--t-fast), box-shadow var(--t-fast);
}
.composer-btn.send:hover {
  background: var(--primary-dim);
  transform: scale(1.06);
}
.composer-btn.send:disabled,
.composer-btn.send:disabled:hover {
  background: rgba(27, 26, 23, 0.08);
  color: rgba(27, 26, 23, 0.30);
  opacity: 0.7;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

/* Attachment button retired per product decision (no file upload in
   the youth chat for now). Hide the button + the hidden file input;
   chat.js's attachment-related code stays inert because the elements
   exist in the DOM but are never displayed/triggered. */
#attach-btn,
#attach-input,
#attach-preview {
  display: none !important;
}

/* Read-receipt ticks — slightly larger to read clearly at the
   timestamp's font-size. */
.bubble .ticks svg {
  width: 18px;
  height: 12px;
}

/* Input pill — WhatsApp-style: emoji lives INSIDE on the left; the
   pill itself has soft cream bg, no visible border, sienna ring on
   focus only. Flex layout aligns emoji + textarea on the same
   vertical center — no absolute positioning, no overlap. */
.composer-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 6px;
  background: var(--panel-2);
  border-radius: 22px;
  transition: box-shadow var(--t-fast);
}
/* Focus ring lives on the WRAP (entire pill), not on the textarea
   inside it — so the whole pill highlights, not just the inner input.
   The universal :focus-visible (line ~137) is suppressed for the
   textarea below. */
.composer-input-wrap:focus-within {
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.composer-input-wrap textarea:focus,
.composer-input-wrap textarea:focus-visible {
  box-shadow: none;
  outline: none;
}
.composer-input-wrap .emoji-anchor {
  position: static;
  flex-shrink: 0;
  display: inline-flex;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  padding: 11px 0px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 20px;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
}
.composer textarea::placeholder {
  color: rgba(27, 26, 23, 0.25);   /* warm near-black at 25% — solid but reads as placeholder */
}
.composer-emoji-inline {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* transition: background var(--t-fast), color var(--t-fast); */
}
.composer-emoji-inline:hover {
  background: rgba(27, 26, 23, 0.06);
  color: var(--text);
}
/* Emoji panel anchors to the LEFT of the in-pill button so the
   panel extends rightward from the emoji's position. */
.composer-input-wrap .emoji-panel {
  left: 0;
  right: auto;
}

/* --- Kebab menu (chat header overflow) --- */
.menu-anchor { position: relative; }
.emoji-anchor { position: relative; display: inline-block; }
.emoji-panel {
  position: absolute; left: 0; bottom: calc(100% + 8px);
  width: 260px; z-index: 50;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow: var(--e3);
  padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
  animation: menu-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.emoji-cell {
  background: transparent; border: 0; cursor: pointer;
  font-size: 20px; line-height: 1;
  padding: 6px; border-radius: 6px;
  transition: background var(--t-fast);
}
.emoji-cell:hover { background: var(--hover); }
.menu {
  position: absolute; right: 0; top: 100%;
  margin-top: 8px;
  min-width: 260px; z-index: 50;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow: var(--e3);
  padding: 8px;
  display: flex; flex-direction: column;
  gap: 2px;
  animation: menu-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes menu-in {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.menu-item {
  background: transparent; border: 0; cursor: pointer;
  text-align: left;
  padding: 10px 14px;
  color: var(--text); font-size: 14px; font-weight: 500;
  border-radius: 10px;
  transition: background var(--t-fast);
}
.menu-item:hover { background: var(--hover); }
.menu-item.menu-about {
  cursor: default; color: var(--muted); font-size: 12px;
  padding: 8px 14px 4px; font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.menu-item.menu-about:hover { background: transparent; }
.menu-divider { height: 1px; background: var(--hairline); margin: 4px 8px; }

/* Failed-send retry */
.bubble.out.failed {
  background: var(--bubble-in);
  color: var(--err);
  border: 1px solid rgba(255,84,112,0.20);
}
.bubble.out.failed .meta { color: var(--err); }
.bubble.out.failed .retry {
  display: inline-flex; align-items: center; cursor: pointer;
  color: var(--err); margin-left: 4px; font-weight: 700;
}
.bubble.out.failed .retry:hover { text-decoration: underline; }

/* Modal/dialog */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,15,27,0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: backdrop-in var(--t-base);
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-modal);
  padding: 28px;
  width: min(460px, 90vw);
  box-shadow: var(--e3);
  animation: modal-in var(--t-slow);
}
@keyframes modal-in {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal h2 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  margin: 0 0 12px; font-size: 22px; font-weight: 700;
  letter-spacing: -0.01em;
}
.modal p { margin: 0 0 20px; color: var(--muted-2); line-height: 1.5; white-space: pre-wrap; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button {
  background: var(--panel-2); border: 1px solid var(--hairline);
  color: var(--primary);
  padding: 10px 18px; cursor: pointer; font-weight: 600; font-size: 13.5px;
  border-radius: var(--r-btn);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.modal-actions button:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.modal-actions button.danger {
  color: white;
  background: var(--err);
  border-color: var(--err);
}
.modal-actions button.danger:hover {
  background: #FF3856;
}

/* ============= ADMIN PORTAL MODAL ============= */
.admin-modal {
  position: fixed; inset: 0; z-index: 150;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.admin-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,15,27,0.55);
  backdrop-filter: blur(4px);
  cursor: pointer;
  animation: backdrop-in var(--t-base);
}
.admin-modal-card {
  position: relative; z-index: 1;
  width: min(520px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-modal);
  box-shadow: var(--e3);
  padding: 24px 28px 22px;
  animation: modal-in var(--t-slow);
}
.admin-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.admin-modal-header h2 {
  font-size: 22px; margin: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.admin-modal-card > p { margin: 0 0 16px; line-height: 1.5; }
.admin-modal-card code {
  background: var(--panel-2); padding: 1px 6px; border-radius: 4px;
  font-size: 12px; font-family: ui-monospace, monospace;
}

.admin-status {
  background: var(--panel-2);
  border-radius: var(--r-card);
  padding: 14px 16px;
  margin-bottom: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.admin-status-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px;
}
.admin-status-label { color: var(--muted-2); font-weight: 500; }
.admin-status-value {
  font-family: ui-monospace, monospace; font-size: 13px;
}
.admin-status-value.set { color: var(--mint); font-weight: 600; }
.admin-status-value.unset { color: var(--muted); }

.admin-versions {
  list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px;
}
.admin-version-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; border-bottom: 1px solid var(--hairline);
}
.admin-version-row:last-child { border-bottom: 0; }
#prompts-body {
  font-family: ui-monospace, monospace; font-size: 12.5px;
  width: 100%; resize: vertical;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
}

.admin-field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.admin-field label {
  font-size: 13px; font-weight: 600; color: var(--text);
}
.admin-field input {
  padding: 11px 14px;
  background: var(--panel-2);
  border: 1px solid var(--hairline);
  color: var(--text); font-size: 14.5px;
  border-radius: var(--r-input);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.admin-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.admin-hint { margin-top: 2px; }

.admin-error {
  background: rgba(255,84,112,0.10);
  border: 1px solid rgba(255,84,112,0.20);
  border-radius: var(--r-card);
  padding: 10px 14px; margin-bottom: 12px;
}

.admin-modal-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; padding-top: 16px;
  border-top: 1px solid var(--hairline);
}
.admin-modal-actions-right { display: flex; gap: 8px; }

.primary-btn {
  background: var(--primary); color: white;
  border: 0; cursor: pointer;
  padding: 10px 18px; border-radius: var(--r-btn);
  font-size: 13.5px; font-weight: 600;
  transition: background var(--t-fast), transform var(--t-fast),
              box-shadow var(--t-fast);
}
.primary-btn:hover { background: var(--primary-dim); box-shadow: var(--e2); transform: translateY(-1px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ghost-btn {
  background: transparent; color: var(--muted-2);
  border: 1px solid var(--hairline);
  cursor: pointer;
  padding: 10px 18px; border-radius: var(--r-btn);
  font-size: 13.5px; font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
}
.ghost-btn:hover { background: var(--hover); color: var(--text); }

/* Toast — top-right, slide in from right, primary-tinted */
#toast-host {
  position: fixed;
  top: 24px; right: 24px; left: auto; bottom: auto;
  transform: none;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
  pointer-events: none;
  align-items: flex-end;
}
.toast {
  pointer-events: none;
  background: var(--panel);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--r-card);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--e3);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--primary);
  animation: toast-in var(--t-slow) ease-out,
             toast-out 220ms ease-in 2.6s forwards;
  max-width: min(360px, 80vw);
}
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(20px); opacity: 0; }
}

/* --- Tablet + Mobile: rail hidden, chat-pane fills viewport ---
   The user-role app-shell defaults to a 320px-rail + 1fr-chat grid, which
   wins on specificity against .app-shell's plain mobile override. We
   restate the override at user-role specificity so the chat-pane gets
   the full viewport width below 1024px (SIFA-88). */
@media (max-width: 1023px) {
  .app-shell,
  body[data-role="user"] .app-shell {
    grid-template-columns: 1fr;
  }
  .rail, .chat-list, .chat-pane {
    grid-column: 1; grid-row: 1;
  }
  .rail, .chat-list { display: none; }
  body.show-list .chat-list { display: flex; }
  body.show-list .rail { display: flex; }
  body.show-list .chat-pane { display: none; }
  .chat-back { display: inline-flex; }

  /* SIFA-129: youth has no inbox column — keep it hidden even when
     show-list is on so the rail occupies the full width and there's
     no empty middle pane. */
  body[data-role="user"].show-list .chat-list { display: none; }

  /* SIFA-129: only youth-on-mobile-show-list sees the rail-back
     button. Admin/agent rely on the existing chat-list-item tap to
     return to a conversation. Desktop never enters show-list. */
  body[data-role="user"].show-list .rail-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    padding: 8px 12px;
    margin: 0 0 8px;
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
  }
  body[data-role="user"].show-list .rail-back:hover {
    background: rgba(255, 255, 255, 0.14);
  }
}

/* SIFA-129: hidden by default at every viewport — the @media override
   above only enables it for youth-on-mobile-show-list. */
.rail-back { display: none; }

/* --- Mobile-only tweaks (≤768px): tighter padding, narrower bubbles --- */
@media (max-width: 768px) {
  .thread { padding: 16px 12px 12px; }
  .bubble { max-width: 80%; }
  .composer { padding: 12px 12px 16px; }
  .auth-card { padding: 32px 28px; border-radius: 24px; }
}

/* ============================================================
   Install page — branded landing, platform-card grid.
   Mirrors the auth-screen visual language: brand row at top, cream
   canvas with subtle wallpaper washes, white cards with warm taupe
   hairlines, sienna accents.
   ============================================================ */
.install-body {
  padding: 48px 20px 64px;
  background: var(--bg); color: var(--text);
  font-family: "Inter", -apple-system, sans-serif;
  position: relative; min-height: 100vh;
  line-height: 1.6;
}
.install-body::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 50% at 15% 15%, var(--brand-mark-soft) 0%, transparent 55%),
    radial-gradient(50% 55% at 85% 25%, var(--wallpaper-2) 0%, transparent 60%),
    radial-gradient(45% 50% at 50% 95%, var(--primary-soft) 0%, transparent 70%);
  z-index: 0; pointer-events: none;
}
.install-wrap {
  position: relative; z-index: 1;
  max-width: 880px; margin: 0 auto;
}

/* Brand row */
.install-brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 32px;
}
.install-brand .brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  font-size: 22px;
}
.install-brand .brand-text strong {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
  display: block;
}

/* Hero */
.install-hero {
  margin-bottom: 28px;
}
.install-hero h1 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700; letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 12px;
  max-width: 18ch;
  line-height: 1.1;
}
.install-lede {
  font-size: 16px; color: var(--muted-2);
  margin: 0;
  max-width: 56ch;
}

/* Hero install CTA — the one-tap PWA install button. Only revealed
   when the browser fires beforeinstallprompt; otherwise the user
   follows the platform cards below. */
.install-cta-primary {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 22px;
  margin-top: 18px;
  background: var(--primary);
  color: #FFFFFF;
  border: 0;
  border-radius: var(--r-btn);
  font-family: inherit;
  font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast),
              box-shadow var(--t-fast);
}
.install-cta-primary:hover {
  background: var(--primary-dim);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px var(--primary-glow);
}
.install-cta-primary:active { transform: translateY(0); }
.install-cta-primary:disabled {
  opacity: 0.7; cursor: default;
  transform: none;
  box-shadow: none;
}

/* Platform grid */
.platform-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.platform-card {
  background: var(--panel);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-card);
  padding: 22px 22px 18px;
  box-shadow: var(--e1);
  display: flex; flex-direction: column; gap: 18px;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.platform-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--e2);
}
.platform-head {
  display: flex; align-items: center; gap: 12px;
}
.platform-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--brand-mark-soft);
  color: var(--brand-mark);
  flex-shrink: 0;
}
.platform-meta h2 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  margin: 0; color: var(--text);
}
.platform-meta p { margin: 2px 0 0; }

/* Numbered step list */
.step-list {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column;
  gap: 10px;
  font-size: 14.5px;
}
.step-list li {
  display: flex; gap: 12px; align-items: flex-start;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.step-list strong { color: var(--text); font-weight: 600; }

/* Notification CTA card */
.install-cta {
  background: var(--panel);
  border: 1px solid var(--in-border, var(--hairline));
  border-radius: var(--r-card);
  padding: 22px 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  box-shadow: var(--e1);
  margin-bottom: 24px;
}
.install-cta-text { min-width: 0; }
.install-cta h3 {
  font-family: "Cabinet Grotesk", Inter, sans-serif;
  font-size: 16px; font-weight: 700;
  margin: 0 0 4px; color: var(--text);
}
.install-cta p { margin: 0; }
.install-cta button {
  padding: 12px 18px;
  background: var(--primary);
  color: #FFFFFF;
  border: 0; border-radius: var(--r-btn);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), transform var(--t-fast),
              box-shadow var(--t-fast);
}
.install-cta button:hover {
  background: var(--primary-dim);
  transform: translateY(-1px);
  box-shadow: var(--e2);
}
.install-cta-status {
  grid-column: 1 / -1;
  margin: 0;
}
.install-cta-status:empty { display: none; }

/* Back link */
.install-back {
  margin: 0; padding: 0;
  text-align: center;
}
.install-back a {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted);
  font-weight: 500; font-size: 14px;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--r-btn);
  transition: color var(--t-fast), background var(--t-fast);
}
.install-back a:hover {
  color: var(--text);
  background: var(--panel-2);
}

/* Mobile — stack the platform grid + CTA. */
@media (max-width: 720px) {
  .install-body { padding: 28px 16px 48px; }
  .install-wrap { max-width: 100%; }
  .install-brand { margin-bottom: 24px; }
  .install-hero { margin-bottom: 20px; }
  .platform-grid { grid-template-columns: 1fr; gap: 12px; }
  .platform-card { padding: 18px 18px 16px; gap: 14px; }
  .install-cta {
    grid-template-columns: 1fr;
    text-align: left;
    padding: 20px;
  }
  .install-cta button { width: 100%; }
}


/* ============================================================
   MOBILE RESPONSIVE
   Three-pane layout collapses to a single chat-pane on phones.
   The rail + chat-list are hidden by default; agents on mobile
   can navigate via the back button (still pending UX work).
   Until #102 (button-first UX) lands, this gives at least a
   readable mobile experience for the youth flow which is the
   primary mobile target anyway.
============================================================ */

@media (max-width: 720px) {
  .auth-card {
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    box-shadow: none;
    padding: 24px 18px;
    min-height: 100dvh;
  }
  .auth-screen { padding: 0; }

  .app-shell,
  body[data-role="user"] .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
  }
  /* On phones the agent inbox + rail collapse — youth users only see
     the single chat pane. Agent UX on phones gets its own slice. */
  .rail, .chat-list { display: none; }

  .chat-header { padding: 10px 12px; }
  .chat-header .avatar-circle { width: 36px; height: 36px; font-size: 14px; }
  .thread { padding: 12px 10px 16px; }
  .bubble { max-width: 88%; font-size: 15px; }
  .composer { padding: 10px 10px 12px; gap: 8px; }
  .composer-btn { width: 44px; height: 44px; }
  .composer-btn svg { width: 22px; height: 22px; }
  #composer-input {
    font-size: 16px; /* keeps iOS Safari from auto-zooming on focus */
    padding: 10px 14px;
  }

  /* Modals fill the screen on phones */
  .admin-modal-card {
    width: 100%; max-width: 100%; max-height: 100dvh;
    border-radius: 0; padding: 20px 16px;
    overflow-y: auto;
  }
  .emoji-panel {
    width: calc(100vw - 24px); left: 12px;
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Very small phones (iPhone SE class, ~320–380px) — tighter spacing
   so nothing feels cramped. */
@media (max-width: 380px) {
  .thread { padding: 10px 8px 14px; }
  .bubble { font-size: 14.5px; padding: 9px 12px; max-width: 90%; }
  .composer { padding: 6px 6px 8px; gap: 4px; }
  .composer-btn { width: 38px; height: 38px; }
  .composer-btn svg { width: 20px; height: 20px; }
  #composer-input { padding: 9px 12px; }
  .chat-header { padding: 8px 10px; }
  .chat-header-meta strong { font-size: 15px; }
}


/* ============= BOOTSTRAP SPLASH (2026-05-28 redesign) =============
   Shown for 2-7s while /web/auth/me resolves. Brand-first, animated,
   warmly worded — never let the user think the page broke. */
.bootstrap-splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 24px;
  background:
    radial-gradient(60% 50% at 50% 20%,
      rgba(188,105,70,0.10) 0%, transparent 60%),
    linear-gradient(180deg, #F8F1E5 0%, #F1EADF 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Cabinet Grotesk", Inter, sans-serif;
}

.bootstrap-splash[hidden] { display: none !important; }

.bootstrap-splash__inner {
  display: flex; flex-direction: column;
  align-items: center; gap: 18px;
  width: 100%; max-width: 320px;
  text-align: center;
  /* Subtle fade-in so the splash doesn't pop in jarringly. */
  animation: bootstrap-fade-in 280ms ease-out both;
}

.bootstrap-splash__mark {
  width: 72px; height: 72px;
  border-radius: 22px;
  background: #BC6946;       /* var(--brand-mark) */
  color: #F8F1E5;
  display: grid; place-items: center;
  font-weight: 700; font-size: 32px; letter-spacing: -0.02em;
  box-shadow: 0 8px 32px rgba(188,105,70,0.30);
  animation: bootstrap-mark-pulse 1800ms ease-in-out infinite;
}

.bootstrap-splash__brand {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  color: #2A2A3F;
}
.bootstrap-splash__brand strong {
  font-size: 22px; font-weight: 700; letter-spacing: 0.04em;
}
.bootstrap-splash__brand span {
  font-size: 13.5px; color: rgba(42,42,63,0.62);
  letter-spacing: 0.06em; text-transform: uppercase;
}

.bootstrap-splash__dots {
  display: inline-flex; gap: 8px;
  margin-top: 4px;
}
.bootstrap-splash__dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: #BC6946;
  animation: bootstrap-dot-wave 1200ms ease-in-out infinite;
  opacity: 0.35;
}
.bootstrap-splash__dots span:nth-child(2) { animation-delay: 160ms; }
.bootstrap-splash__dots span:nth-child(3) { animation-delay: 320ms; }

.bootstrap-splash__hint {
  margin: 4px 0 0;
  font-size: 14.5px;
  color: rgba(42,42,63,0.58);
  font-weight: 500;
}

.bootstrap-splash__stall {
  margin-top: 12px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.66);
  border: 1px solid rgba(188,105,70,0.18);
  border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  /* Fade in only when JS un-hides it after the 8s stall threshold. */
  animation: bootstrap-fade-in 220ms ease-out both;
}
.bootstrap-splash__stall p {
  margin: 0; color: rgba(42,42,63,0.72); font-size: 13.5px;
}
.bootstrap-splash__stall button {
  padding: 10px 18px;
  background: #BC6946; color: #F8F1E5;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.bootstrap-splash__stall button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(188,105,70,0.3);
}

@keyframes bootstrap-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes bootstrap-mark-pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 8px 32px rgba(188,105,70,0.30); }
  50%      { transform: scale(1.04); box-shadow: 0 12px 42px rgba(188,105,70,0.42); }
}
@keyframes bootstrap-dot-wave {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30%          { opacity: 1;    transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .bootstrap-splash__inner,
  .bootstrap-splash__mark,
  .bootstrap-splash__dots span,
  .bootstrap-splash__stall { animation: none; }
}


/* ============= Auth button — loading state (2026-05-28) =============
   Without this, clicking "Send code" only changes the label to
   "Sending code…" — the button keeps the primary green colour and
   no motion, so users on slow networks think the click didn't
   register and refresh, losing the in-flight OTP. We now:
     - replace the label with a spinner + the (smaller) text
     - dim the background so disabled state reads visually
     - block pointer-events to defeat double-clicks
*/
.auth-card button.loading {
  position: relative;
  background: var(--primary-dim);
  color: rgba(255,255,255,0.78);
  pointer-events: none;
  /* Hide the literal "Sending code…" string with a soft pulse so
     the spinner + the text together convey "in flight". */
  animation: auth-btn-loading-pulse 1400ms ease-in-out infinite;
}
.auth-card button.loading::before {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 10px;
  margin-bottom: -2px;
  border: 2px solid rgba(255,255,255,0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: auth-btn-spinner 900ms linear infinite;
}

@keyframes auth-btn-spinner {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes auth-btn-loading-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,168,132,0.0); }
  50%      { box-shadow: 0 0 0 6px rgba(0,168,132,0.18); }
}

@media (prefers-reduced-motion: reduce) {
  .auth-card button.loading,
  .auth-card button.loading::before { animation: none; }
}


/* ============= Gate screens (W-M not-registered + W-N USSD opt-in) =====
   Both screens are rendered from chat.js when /auth/me or the OTP-send
   handler reports a gate failure. Sharing one `.gate-screen` host +
   `.gate-card` shell so the brand stays consistent. Colours and
   spacing pull from the theme tokens defined in theme.css —
   `--brand-mark` (sienna), `--bg` (cream), `--text`, `--muted` —
   so a future theme tweak lands in one place. */

.gate-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 50% 20%,
      rgba(188,105,70,0.10) 0%, transparent 60%),
    linear-gradient(180deg, #F8F1E5 0%, #F1EADF 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Cabinet Grotesk", Inter, sans-serif;
}

.gate-card {
  max-width: 420px; width: 100%;
  background: #ffffff;
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: 0 6px 32px rgba(0,0,0,0.08);
  color: #2A2A3F;
  animation: gate-card-fade-in 280ms ease-out both;
}
.gate-card--centered { text-align: center; }

.gate-card__step {
  font-size: 13px;
  color: rgba(42,42,63,0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.gate-card__title {
  font-size: 22px; line-height: 1.25;
  margin: 0 0 12px;
  color: #2A2A3F;
}

.gate-card__lead {
  color: rgba(42,42,63,0.78);
  line-height: 1.55;
  margin: 0 0 18px;
}

.gate-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: #BC6946;    /* var(--brand-mark) — kept literal because
                             this screen is presented outside the chat
                             shell where theme.css variables are loaded */
  display: grid; place-items: center;
  font-size: 28px;
}

.gate-card__code-box {
  background: rgba(188,105,70,0.08);
  border: 1px solid rgba(188,105,70,0.20);
  border-radius: 10px;
  padding: 18px 16px;
  margin-bottom: 18px;
}
.gate-card__code-label {
  font-size: 13px;
  color: rgba(42,42,63,0.58);
  margin-bottom: 6px;
}
.gate-card__code {
  font-size: 28px; font-weight: 600;
  letter-spacing: 0.03em;
  color: #2A2A3F;
}

.gate-card__steps-box {
  background: rgba(188,105,70,0.08);
  border: 1px solid rgba(188,105,70,0.20);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  color: rgba(42,42,63,0.78);
  text-align: left;
}
.gate-card__steps-box strong {
  display: block;
  margin-bottom: 6px;
  color: #7a3e25;
}
.gate-card__steps-box ol,
.gate-card__list {
  margin: 0;
  padding-left: 22px;
  line-height: 1.6;
}
.gate-card__list {
  margin: 0 0 22px;
  color: rgba(42,42,63,0.78);
}

.gate-card__cta {
  width: 100%;
  padding: 14px;
  background: #BC6946;     /* var(--brand-mark) */
  color: #F8F1E5;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.gate-card__cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(188,105,70,0.30);
}
.gate-card__cta:active {
  transform: translateY(0);
}

.gate-card__hint {
  font-size: 13px;
  color: rgba(42,42,63,0.50);
  margin: 12px 0 0;
  text-align: center;
}

@keyframes gate-card-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gate-card { animation: none; }
}

/* V4.2 inline-button card — visually attached to the SIFA bubble
   above, like WhatsApp interactive-button cards. The row hugs the
   bubble's left edge + shares the bubble background; rounding only
   the bottom corners so the bubble + buttons read as ONE card. The
   adjacent bubble.in also gets its bottom-left radius dropped when
   .has-buttons is set, so the seam disappears. */
.bubble.in.has-buttons {
  border-bottom-left-radius: 4px;
  margin-bottom: 0;
}
.v42-buttons {
  display: flex;
  flex-direction: column;
  gap: 0;
  /* Avatar (28px) + bubble-row gap (8px) = 36px left indent so the
     buttons sit directly under the bubble, not under the avatar. */
  margin: 0 0 8px 36px;
  align-self: flex-start;
  max-width: min(68%, 540px);
  background: var(--bubble-in);
  border: 1px solid var(--in-border);
  border-top: none;
  border-radius: 0 0 14px 14px;
  overflow: hidden;
  animation: bubble-in var(--t-slow) both;
}
.v42-btn {
  appearance: none;
  border: none;
  border-top: 1px solid var(--hairline, rgba(0,0,0,0.06));
  background: transparent;
  color: var(--primary);
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  width: 100%;
  transition: background var(--t-fast);
}
.v42-btn:first-child { border-top: none; }
.v42-btn:hover:not(:disabled) {
  background: var(--hover, rgba(0,0,0,0.03));
}
.v42-btn:active:not(:disabled) {
  background: var(--primary-soft);
}
.v42-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.v42-buttons.tapped { opacity: 0.55; }
/* For 2-button rows (Ndio/Hapana) stack vertically — matches WhatsApp.
   The pain-point 5-button picker uses a more compact wrap layout. */
.v42-buttons.compact {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--bubble-in);
  /* Same 36px indent as the stacked variant */
  margin-left: 36px;
}
.v42-buttons.compact .v42-btn {
  flex: 1 1 auto;
  border: 1px solid var(--in-border);
  border-radius: 999px;
  padding: 8px 14px;
}

/* B1: Submit-data form modal — reuses .modal-backdrop / .modal layout
   but adds form-specific spacing. iOS Safari 16px font-size on inputs
   to defeat auto-zoom (CLAUDE.md §11 mobile lesson). */
.daily-entry-modal { max-width: 380px; }
.daily-entry-modal .modal-sub {
  margin: -4px 0 12px;
  color: var(--text-muted);
  font-size: 13.5px;
}
.daily-entry-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.daily-entry-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.daily-entry-row span { color: var(--text-muted); font-weight: 500; }
.daily-entry-row input {
  appearance: none;
  border: 1px solid var(--in-border);
  background: var(--bubble-in);
  color: var(--bubble-text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.daily-entry-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.daily-entry-err {
  margin: 0;
  color: var(--alert, #b35a4f);
  font-size: 13px;
}
.daily-entry-form .modal-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.daily-entry-form .modal-actions button {
  appearance: none;
  border: 1px solid var(--in-border);
  background: var(--bubble-in);
  color: var(--bubble-text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.daily-entry-form .modal-actions button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.daily-entry-form .modal-actions button:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Historical form summary — non-interactive panel attached under
   inbound bubbles that originally carried a form modal. Renders the
   prompt's title + field labels + a quiet "submitted" badge so the
   youth has visual continuity across page reloads.

   Visually muted vs the live form (.sifa-form-modal) so it's clearly
   read-only: paper-tan ground, no shadow, no click affordance. */
.sifa-historical-form-summary {
  margin: 8px 0 4px 0;
  padding: 10px 12px;
  background: rgba(120, 87, 35, 0.06);
  border-left: 3px solid rgba(120, 87, 35, 0.35);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: #5a4419;
  position: relative;
}
.sifa-historical-form-summary .sifa-hfs-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.sifa-historical-form-summary .sifa-hfs-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-right: 84px;  /* leaves room for the "submitted" badge */
}
.sifa-historical-form-summary .sifa-hfs-field {
  background: rgba(255, 255, 255, 0.65);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.sifa-historical-form-summary .sifa-hfs-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 11px;
  color: rgba(120, 87, 35, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* ===== Telegram-style unread indicators ============================== */
/* Divider rendered above the first unread bubble after a reload.      */
/* Sits inline in the message list, scrolls with the thread.           */
.unread-divider {
  align-self: stretch;
  text-align: center;
  margin: 16px 8px 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(78, 53, 18, 0.75);
  background: rgba(255, 233, 195, 0.55);
  border-radius: 999px;
  position: relative;
}
.unread-divider::before,
.unread-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 22%;
  height: 1px;
  background: rgba(120, 87, 35, 0.25);
}
.unread-divider::before { left: 4%; }
.unread-divider::after { right: 4%; }

/* Floating "scroll to latest" pill — only shown when the youth is    */
/* scrolled up AND there are unread messages below.                    */
#scroll-to-latest {
  position: absolute;
  right: 18px;
  bottom: 96px; /* clear of the composer */
  z-index: 4;
  background: rgba(78, 53, 18, 0.92);
  color: #fff;
  border: none;
  font: 600 13px/1 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  padding: 9px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(78, 53, 18, 0.25);
  cursor: pointer;
  transition: opacity 160ms ease-out, transform 160ms ease-out;
  opacity: 0.95;
}
#scroll-to-latest:hover { opacity: 1; transform: translateY(-1px); }
#scroll-to-latest[hidden] { display: none; }

/* ===== n8n-dispatched interactive (buttons / form) ==================== */
/* The widget sits INSIDE an inbound `.bubble.in` element, below the    */
/* body text. Reuses the bubble's max-width so the grid never escapes.  */
.n8n-interactive {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Ensure the widget paints above any sibling that picked up        */
  /* overflow:hidden — historically the dispatch buttons disappeared  */
  /* under a transformed bubble until the viewport rerendered (zoom). */
  position: relative;
  z-index: 1;
  width: 100%;
}

/* Default button layout — 2-column grid (matches the historical      */
/* dispatch nudge layout). When n8n explicitly sends layout.cols, the  */
/* more-specific .n8n-buttons-grid rule below wins.                    */
/* On phones < 360 px the grid collapses to a single column.           */
.n8n-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}
@media (max-width: 360px) {
  .n8n-buttons { grid-template-columns: 1fr; }
}
/* Single-button row — a lone button stretched across 2 cols looks    */
/* like a banner, not a CTA. Collapse to a content-width flex with a  */
/* generous min-width so the tap-target stays comfortable.             */
.n8n-buttons:has(> .n8n-btn:only-child) {
  display: flex;
  justify-content: flex-start;
  width: auto;
  max-width: 100%;
}
.n8n-buttons:has(> .n8n-btn:only-child) > .n8n-btn {
  min-width: 140px;
  max-width: 80%;
  padding-left: 24px;
  padding-right: 24px;
}

/* Explicit grid mode when dispatch.interactive.layout.cols is set     */
/* (e.g. n8n's 8-button 2×4 menu — but also overrides the 2-col       */
/* default for 1-col, 3-col, … layouts).                              */
.n8n-buttons-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: 8px;
  width: 100%;
}

.n8n-btn {
  border: 1px solid rgba(78, 53, 18, 0.25);
  background: rgba(255, 233, 195, 0.45);
  color: rgba(45, 30, 8, 1);
  font: 600 13px/1.2 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 140ms ease-out, transform 80ms ease-out;
  text-align: center;
  min-height: 38px;
}
.n8n-btn:hover { background: rgba(255, 218, 159, 0.7); }
.n8n-btn:active { transform: scale(0.97); }
.n8n-btn[disabled] {
  opacity: 0.55;
  cursor: default;
  background: rgba(0,0,0,0.04);
}
/* The single button the youth tapped — keeps full opacity + brand    */
/* color so it's clearly the chosen one even after the row goes      */
/* read-only. Other disabled siblings dim to 0.55.                   */
.n8n-btn.n8n-btn-picked[disabled] {
  opacity: 1;
  background: rgba(78, 53, 18, 0.92);
  color: #fff;
  border-color: transparent;
}

/* Form widget */
.n8n-form { padding: 4px 0; }
.n8n-form-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 2px;
  color: rgba(45, 30, 8, 1);
}
.n8n-form-desc {
  font-size: 12px;
  color: rgba(78, 53, 18, 0.75);
  margin-bottom: 6px;
}
.n8n-form-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.n8n-form-label {
  font-size: 12px;
  color: rgba(78, 53, 18, 0.85);
  font-weight: 600;
}
.n8n-form-required {
  color: rgba(204, 68, 51, 1);
  font-weight: 700;
  margin-left: 2px;
}
.n8n-form-required-hint {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  color: rgba(204, 68, 51, 0.85);
  font-style: italic;
}
.n8n-form-row input,
.n8n-form-row select,
.n8n-form-row textarea {
  font: 14px -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(120, 87, 35, 0.25);
  background: #fff;
  width: 100%;
  box-sizing: border-box;
}
.n8n-form-row input:focus,
.n8n-form-row select:focus,
.n8n-form-row textarea:focus {
  outline: 2px solid rgba(78, 53, 18, 0.35);
  outline-offset: 0;
  border-color: transparent;
}

/* Radio group — each option is a tap-target row (Telegram-poll style). */
.n8n-form-radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.n8n-form-radio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  min-height: 40px;
  background: #fff;
  border: 1px solid rgba(120, 87, 35, 0.20);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: rgba(45, 30, 8, 1);
  transition: background 120ms ease-out, border-color 120ms ease-out;
}
.n8n-form-radio:hover {
  background: rgba(255, 233, 195, 0.35);
  border-color: rgba(120, 87, 35, 0.35);
}
.n8n-form-radio input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  border: 2px solid rgba(120, 87, 35, 0.5);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  background: #fff;
  transition: border-color 120ms ease-out;
}
.n8n-form-radio input[type="radio"]:checked {
  border-color: rgba(78, 53, 18, 0.95);
}
.n8n-form-radio input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: rgba(78, 53, 18, 0.95);
}
/* Whole row highlights when its child input is checked. */
.n8n-form-radio:has(input[type="radio"]:checked) {
  background: rgba(255, 218, 159, 0.55);
  border-color: rgba(78, 53, 18, 0.6);
  font-weight: 600;
}
.n8n-form-radio input[type="radio"]:disabled,
.n8n-form-radio:has(input[type="radio"]:disabled) {
  opacity: 0.7;
  cursor: default;
}

/* Checkbox group — same Telegram-poll row design as radio. Each row    */
/* is a multi-select tap target; submitted as a list under the field    */
/* name in the callback's form_data.                                    */
.n8n-form-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.n8n-form-checkbox-group.n8n-form-error {
  outline: 2px solid rgba(204, 68, 51, 0.7);
  outline-offset: 4px;
  border-radius: 12px;
}
.n8n-form-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  min-height: 40px;
  background: #fff;
  border: 1px solid rgba(120, 87, 35, 0.20);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: rgba(45, 30, 8, 1);
  transition: background 120ms ease-out, border-color 120ms ease-out;
}
.n8n-form-checkbox:hover {
  background: rgba(255, 233, 195, 0.35);
  border-color: rgba(120, 87, 35, 0.35);
}
.n8n-form-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 2px solid rgba(120, 87, 35, 0.5);
  border-radius: 4px;
  background: #fff;
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  transition: border-color 120ms ease-out, background 120ms ease-out;
}
.n8n-form-checkbox input[type="checkbox"]:checked {
  border-color: rgba(78, 53, 18, 0.95);
  background: rgba(78, 53, 18, 0.95);
}
.n8n-form-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.n8n-form-checkbox:has(input[type="checkbox"]:checked) {
  background: rgba(255, 218, 159, 0.55);
  border-color: rgba(78, 53, 18, 0.6);
  font-weight: 600;
}
.n8n-form-checkbox input[type="checkbox"]:disabled,
.n8n-form-checkbox:has(input[type="checkbox"]:disabled) {
  opacity: 0.7;
  cursor: default;
}
.n8n-form-help {
  font-size: 11px;
  color: rgba(120, 87, 35, 0.7);
}
.n8n-form-submit {
  background: rgba(78, 53, 18, 0.92);
  color: #fff;
  border-color: transparent;
}
.n8n-form-submit:hover { background: rgba(78, 53, 18, 1); }

/* Ack result chip — appears after click / submit. */
.n8n-ack-result {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  align-self: flex-start;
  background: rgba(255, 233, 195, 0.55);
  color: rgba(78, 53, 18, 0.85);
}
.n8n-ack-result.err {
  background: rgba(204, 68, 51, 0.15);
  color: rgba(112, 25, 12, 0.95);
}
