/*
 * 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 — warm peach gradient, matches the v5 brief's user
     bubbles (page 6/8 mockups). On dark theme it stays subtle. */
  --out-grad:    linear-gradient(135deg, #BC6946 0%, #D58464 100%);
  --out-border:  transparent;
  --out-text:    #FFFFFF;
  --out-meta:    rgba(255,255,255,0.92);
  --bubble-in:   #1A1A2E;
  --bubble-text: #ECEAFA;
  --in-border:   var(--hairline);

  /* Wallpaper — soft green/coral wash (was periwinkle/coral) */
  --wallpaper-1: rgba(0,168,132,0.06);
  --wallpaper-2: rgba(255,107,157,0.04);
  --wallpaper-3: rgba(52,211,153,0.03);

  /* 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:      #BC6946;     /* web = brand rust (was teal) */
  --ch-web-b:      #8C3F27;
  --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:   #34B7F1;     /* WhatsApp brand blue — punchier than #53BDEB */
  --tick-grey:   rgba(27, 26, 23, 0.45);  /* delivered/sent tick colour */
  --doodle-tint: rgba(0,168,132,0.05);   /* SIFA green tint, replacing the prior purple */

  /* 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"] {
  --out-grad:    linear-gradient(135deg, #E6DFCA 0%, #E6DFCA 100%);
  --out-border:  #D0C3A5;
  --out-text:    #1B1A17;
  --out-meta:    rgba(27,26,23,0.55);
  --bubble-in:   #FFFCF6;
  --bubble-text: #1B1A17;
  --in-border:   rgba(27,26,23,0.08);

  /* Wallpaper — soft warm parchment wash to match the brand. Was a
     WhatsApp-green/coral mix; replaced with brown/cream alphas so the
     sign-in backdrop and empty conversation pane don't bleed green. */
  --wallpaper-1: rgba(188,105,70,0.05);
  --wallpaper-2: rgba(140,63,39,0.03);
  --wallpaper-3: rgba(241,234,223,0.4);

  --doodle-tint: rgba(15,15,27,0.04);

  --e1: 0 1px 2px rgba(15,15,27,0.06), 0 0 0 1px rgba(15,15,27,0.04);
  --e2: 0 4px 12px rgba(15,15,27,0.08), 0 1px 3px rgba(15,15,27,0.06);
  --e3: 0 12px 32px rgba(15,15,27,0.12), 0 4px 12px rgba(15,15,27,0.08);
}

@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; }

/* 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; }

.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. Hairline + streak pill
   below. Earns the dark middle space without competing with the chat. */
.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-day-divider {
  margin: 14px 0 12px;
  height: 1px;
  background: rgba(27, 26, 23, 0.08);
}
body[data-role="user"] .rail-day-streak {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: var(--brand-mark);
  color: #FFFFFF;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
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;
}

/* 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; }

/* 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 */

/* 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); }

/* 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; }
}
