/* ============================================================================
   XNK Trợ lý — premium design system
   XNK brand identity: navy frame (#1B2A6B) · orange spark (#F26522) · white
   surfaces · soft depth. Built phone-first. Tailwind CDN handles a few layout
   utilities; everything that carries the brand lives here.
   ========================================================================== */

:root {
  /* ── XNK brand palette ──────────────────────────────────────────────
     Brand = Navy #1B2A6B (frame) · Orange #F26522 (accent) · white surfaces.
     The teal-/amber- slot NAMES are kept on purpose (the whole codebase
     references them); their VALUES are now the XNK navy/orange ramps. To
     re-skin, swap the values here — nothing else needs touching.
     (NB: never write an asterisk-slash pair in this comment — it closes it.) */

  /* Navy ramp (slots named --teal-*) — the frame: sidebar, headers, primary */
  --teal-900: #0D1336;
  --teal-800: #131D52;
  --teal-700: #1B2A6B;   /* primary — XNK Navy */
  --teal-600: #26377E;
  --teal-500: #374A9C;
  --teal-200: #B7C0E2;
  --teal-100: #D6DBF0;
  --teal-50:  #ECEEF8;

  /* Orange ramp (slots named --amber-*) — the accent: highlights, KPIs, sparks */
  --amber-600: #C24E16;
  --amber-500: #F26522;   /* accent — XNK Orange */
  --amber-400: #F88A52;
  --amber-100: #FCE0D2;

  /* Surfaces / ink — white-forward, cool neutral (brand: white background) */
  --bg:         #F4F6FB;
  --bg-tint:    #E9EDF7;
  --surface:    #FFFFFF;
  --surface-2:  #F7F9FC;
  --ink:        #141A2E;
  --ink-soft:   #3A4256;
  --muted:      #727A8C;
  --line:       #DFE3EC;
  --line-soft:  #EDF0F6;

  /* Feedback (semantic — independent of brand) */
  --warn-bg:   #FFF7E6;
  --warn-line: #EAB24D;
  --warn-ink:  #7A5A12;

  /* Depth — navy-tinted, layered */
  --sh-xs: 0 1px 2px rgba(20,26,55,.06);
  --sh-sm: 0 2px 8px rgba(20,26,55,.06), 0 1px 2px rgba(20,26,55,.05);
  --sh-md: 0 6px 20px rgba(20,26,55,.08), 0 2px 6px rgba(20,26,55,.05);
  --sh-lg: 0 18px 50px rgba(13,19,54,.16), 0 6px 16px rgba(13,19,54,.08);
  --sh-teal: 0 8px 22px rgba(27,42,107,.26);
  --sh-amber: 0 6px 18px rgba(242,101,34,.30);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --ease: cubic-bezier(.22,.61,.36,1);
  --sidebar-w: 280px;
  --drawer-w: 420px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html, body, button, input, textarea {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  /* atmospheric depth: cool light from top, faint engineered dot-grid */
  background-image:
    radial-gradient(1200px 600px at 78% -8%, rgba(242,101,34,.10), transparent 60%),
    radial-gradient(900px 540px at -6% 0%, rgba(27,42,107,.10), transparent 55%),
    radial-gradient(rgba(27,42,107,.05) 1px, transparent 1px);
  background-size: auto, auto, 22px 22px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01";
}

/* ===== App shell ===== */
.app { display: flex; height: 100dvh; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  /* Ambient dark blue: a luminous blue glow up top over a deep navy-blue base. */
  background:
    radial-gradient(125% 78% at 26% -8%, rgba(74,110,224,.34), transparent 60%),
    linear-gradient(168deg, #223573 0%, #141E3C 100%);
  color: #EAF0FF;
  position: relative;
  z-index: 40;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 18px 16px 14px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--amber-400), var(--amber-600));
  color: var(--teal-900); font-weight: 800; font-size: 14px; letter-spacing: -.02em;
  box-shadow: var(--sh-amber), inset 0 1px 0 rgba(255,255,255,.4);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; line-height: 1; }
.brand-sub  { font-size: 11px; color: var(--teal-200); margin-top: 3px; letter-spacing: .02em; }

.new-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin: 4px 14px 10px; padding: 12px 14px;
  border-radius: var(--r-md); border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.07); color: #fff;
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .16s var(--ease), transform .12s var(--ease), border-color .16s;
}
.new-btn:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.28); }
.new-btn:active { transform: translateY(1px) scale(.99); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.conv {
  padding: 11px 12px; margin: 3px 0; border-radius: var(--r-md);
  cursor: pointer; transition: background .14s var(--ease);
  display: flex; flex-direction: column; gap: 2px;
}
.conv:hover { background: rgba(255,255,255,.07); }
.conv.active { background: rgba(255,255,255,.13); box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.conv.active::before { content: ""; }
.conv-title {
  font-size: 13.5px; font-weight: 500; line-height: 1.35; color: #E7ECF7;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.conv-meta { font-size: 11px; color: var(--teal-200); }
.conv-empty { color: var(--teal-200); font-size: 13px; text-align: center; padding: 28px 12px; opacity: .8; }
.sidebar-foot {
  padding: 12px 16px; font-size: 11px; color: var(--teal-200);
  border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: 7px;
}
.logout-link {
  margin-left: auto; color: var(--teal-200); text-decoration: none; font-weight: 600;
  padding: 3px 9px; border-radius: 7px; transition: background .14s, color .14s;
}
.logout-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: #56d364; box-shadow: 0 0 0 3px rgba(86,211,100,.2); }

/* ===== Main column ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; min-height: 60px;
  background: rgba(247,249,252,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft); z-index: 20;
}
.icon-btn {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px;
  display: none; place-items: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); color: var(--teal-700);
  box-shadow: var(--sh-xs); transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--teal-50); }
.icon-btn:active { transform: scale(.94); }
.topbar-title { font-weight: 700; font-size: 15.5px; color: var(--teal-800); letter-spacing: -.01em; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-spacer { flex: 1; }
.topbar-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px;
  border-radius: 999px; background: var(--teal-50); color: var(--teal-700);
  font-size: 12px; font-weight: 600; border: 1px solid var(--teal-100);
}

/* ===== Thread ===== */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 24px 0 12px; }
.thread-inner { max-width: 820px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 22px; }

/* ===== Empty / hero ===== */
.hero { min-height: 64vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 20px; }
.hero-mark {
  width: 66px; height: 66px; border-radius: 19px; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--teal-600), var(--teal-800));
  color: var(--amber-400); font-weight: 800; font-size: 22px; letter-spacing: -.02em;
  box-shadow: var(--sh-lg), inset 0 1px 0 rgba(255,255,255,.12);
  margin-bottom: 22px; animation: rise .6s var(--ease) both;
}
.hero-title { font-size: clamp(26px, 4vw, 34px); font-weight: 800; letter-spacing: -.025em; color: var(--teal-900); margin: 0 0 10px; animation: rise .6s var(--ease) .06s both; }
.hero-sub { font-size: 15.5px; line-height: 1.6; color: var(--ink-soft); max-width: 470px; margin: 0 0 28px; animation: rise .6s var(--ease) .12s both; }
/* (2026-07-08) .suggest* card styles removed with the hero suggestion cards — anh Thịnh's ask. */

/* ===== Messages ===== */
.msg-row { display: flex; animation: rise .42s var(--ease) both; }
.msg-row.user { justify-content: flex-end; }

.bubble-user {
  background: linear-gradient(160deg, var(--teal-600), var(--teal-800));
  color: #fff; border-radius: 22px 22px 6px 22px;
  padding: 13px 18px; max-width: 80%; line-height: 1.55; font-size: 15.5px;
  white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--sh-teal);
}

.bubble-bot {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: 6px 22px 22px 22px; padding: 18px 20px;
  max-width: 92%; box-shadow: var(--sh-sm); position: relative;
}
.bubble-bot.refused { background: var(--warn-bg); border-color: var(--warn-line); }
.bubble-bot.refused .msg-text { color: var(--warn-ink); }

/* No-copy (anh Thịnh, 2026-07-10): bot answers, source excerpts and enlarged
   illustrations can't be selected or long-press-copied on phones;
   app.js:setupCopyGuard blocks copy / right-click / image-drag on the same
   containers. The composer and the user's own bubbles stay selectable.
   (Screenshots are outside any web app's control — this deters casual
   copy-paste, it is not DRM.) */
.bubble-bot, .drawer, .img-lightbox {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.bubble-bot img, .img-lightbox-img { -webkit-user-drag: none; }

/* Rich answer text */
.msg-text { font-size: 16px; line-height: 1.68; color: var(--ink); }
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text p { margin: 0 0 11px; }
.msg-text strong { font-weight: 700; color: var(--teal-800); }
.msg-text em { font-style: normal; background: linear-gradient(transparent 62%, var(--amber-100) 0); padding: 0 1px; }
.msg-h { font-size: 17.5px; font-weight: 800; letter-spacing: -.01em; color: var(--teal-900); margin: 4px 0 10px; line-height: 1.3; }
.msg-ul, .msg-ol { margin: 4px 0 12px; padding-left: 4px; list-style: none; }
.msg-ul li, .msg-ol li { position: relative; padding-left: 26px; margin: 7px 0; }
.msg-ul li::before {
  content: ""; position: absolute; left: 6px; top: .66em;
  width: 7px; height: 7px; border-radius: 50%; background: var(--amber-500);
  box-shadow: 0 0 0 3px var(--amber-100);
}
.msg-ol { counter-reset: ol; }
.msg-ol li { counter-increment: ol; }
.msg-ol li::before {
  content: counter(ol); position: absolute; left: 0; top: .12em;
  width: 20px; height: 20px; border-radius: 7px; display: grid; place-items: center;
  background: var(--teal-700); color: #fff; font-size: 11.5px; font-weight: 700;
}
.msg-callout {
  margin: 12px 0; padding: 12px 16px; border-radius: 0 12px 12px 0;
  background: linear-gradient(90deg, var(--amber-100), var(--surface-2));
  border-left: 4px solid var(--amber-500); color: var(--ink-soft);
  font-size: 14.5px; line-height: 1.6;
}
.msg-callout strong { color: var(--amber-600); }

/* Citation chips */
.citation-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 21px; height: 21px; padding: 0 6px; margin: 0 2px;
  border: none; border-radius: 7px; cursor: pointer; vertical-align: 1px;
  background: var(--teal-50); color: var(--teal-700);
  font-size: 11.5px; font-weight: 800; font-feature-settings: "tnum";
  box-shadow: inset 0 0 0 1px var(--teal-100);
  transition: background .12s, color .12s, transform .08s;
}
.citation-chip:hover { background: var(--teal-700); color: #fff; box-shadow: var(--sh-teal); }
.citation-chip:active { transform: scale(.9); }

/* Always-visible cited-source line ("📎 Nguồn tham khảo") under each answer.
   Complements the inline [N] chips: the document NAME is visible without a tap,
   and each row opens the same source drawer. */
.msg-refs {
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 6px;
}
.msg-refs-label {
  font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted);
}
.msg-ref {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; width: 100%;
  text-align: left; padding: 8px 12px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-left: 3px solid var(--teal-700); border-radius: var(--r-sm);
  transition: background .14s, border-color .14s, transform .08s;
}
.msg-ref:hover { background: var(--teal-50); border-left-color: var(--amber-500); }
.msg-ref:active { transform: scale(.99); }
.msg-ref-n {
  flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 6px;
  display: inline-grid; place-items: center;
  background: var(--teal-700); color: #fff; font-size: 11px; font-weight: 800;
  font-feature-settings: "tnum";
}
.msg-ref-doc { font-size: 13.5px; font-weight: 700; color: var(--teal-800); line-height: 1.4; }
.msg-ref-sec { font-size: 12.5px; font-weight: 500; color: var(--ink-soft); }
.msg-ref-sec::before { content: "· "; color: var(--muted); }

/* Cited illustration card (requirement #3) — a real picture under the answer,
   paired with the worked example. Full width, tap to enlarge. */
.msg-image-card {
  margin-top: 14px; padding-top: 13px; border-top: 1px dashed var(--line);
  animation: rise .26s var(--ease) both;
}
.img-main {
  display: block; width: 100%; max-height: 380px; object-fit: contain;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  cursor: zoom-in; box-shadow: var(--sh-xs);
  transition: box-shadow .16s var(--ease), border-color .16s;
}
.img-main:hover { box-shadow: var(--sh-md); border-color: var(--amber-400); }
.img-cap {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft); line-height: 1.45;
}

/* Inline per-point illustrations (req #3 rework, 2026-06-23): instead of one big card
   dumped at the bottom, a compact captioned thumbnail tucks under the exact line it
   illustrates (belt diagram under the belt bullet, etc.). */
.msg-block > div:first-child > :first-child { margin-top: 0; }
.msg-block .msg-image-card {
  margin: 6px 0 14px 16px; padding-top: 0; border-top: none; max-width: 380px;
}
.msg-block .img-main { max-height: 300px; }
.msg-block .img-cap { font-size: 12px; margin-top: 6px; }
/* each block renders its own list, so keep consecutive one-item lists tight */
.msg-block ul, .msg-block ol { margin: 4px 0; }

/* Tap-to-enlarge lightbox (still XNK-stamped, no download) */
.img-lightbox {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 22px;
  background: rgba(13, 19, 54, .88); backdrop-filter: blur(3px);
}
.img-lightbox-img {
  max-width: 94vw; max-height: 78vh; object-fit: contain;
  border-radius: var(--r-md); box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  border: 1px solid rgba(255, 255, 255, .18); background: #fff;
  animation: zoomIn .24s var(--ease) both;
}
.img-lightbox-cap {
  color: #EAF0FF; font-size: 13.5px; font-weight: 600; text-align: center;
  max-width: 480px; line-height: 1.5;
}
.img-lightbox-x {
  position: absolute; top: 16px; right: 16px; width: 40px; height: 40px;
  border-radius: 50%; border: none; cursor: pointer; font-size: 16px;
  background: rgba(255, 255, 255, .14); color: #fff;
  display: grid; place-items: center; transition: background .14s, transform .08s;
}
.img-lightbox-x:hover { background: rgba(255, 255, 255, .26); }
.img-lightbox-x:active { transform: scale(.92); }
@keyframes zoomIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }

/* Message actions */
.msg-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.act-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink-soft); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .14s, color .14s, border-color .14s, transform .1s;
}
.act-btn:hover { background: var(--teal-50); color: var(--teal-700); border-color: var(--teal-100); }
.act-btn:active { transform: scale(.96); }
.act-btn.tts-active { background: var(--amber-100); color: var(--amber-600); border-color: var(--amber-400); }
.act-latency { font-size: 12px; color: var(--muted); margin-left: 2px; font-feature-settings: "tnum"; }
/* Feedback 👍/👎 + escalation (Phase 5, Stage 5) */
.act-btn.fb-btn { padding: 7px 10px; }
.act-btn.fb-on { background: var(--teal-700); color: #fff; border-color: var(--teal-700); }
.act-btn.esc-btn { background: var(--amber-100); color: var(--amber-600); border-color: var(--amber-400); }
.act-btn.esc-btn:hover { background: var(--amber-400); color: #fff; }
.act-note { font-size: 12px; color: var(--ok, #1c7c4a); margin-left: 2px; font-weight: 600; }
.fb-reasons { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fb-hint { font-size: 12px; color: var(--muted); }
.fb-reason {
  padding: 5px 11px; border-radius: 999px; border: 1px dashed var(--amber-400);
  background: transparent; color: var(--amber-600); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .14s, color .14s;
}
.fb-reason:hover { background: var(--amber-100); }

/* Explicit "was this useful?" prompt (Feature 3) — a labeled one-tap row shown once
   when an answer completes. Reuses the same feedback endpoint as the old bare thumbs. */
.useful-ask {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-top: 10px; padding: 8px 12px;
  background: var(--teal-50); border: 1px solid var(--teal-100); border-radius: 12px;
}
.useful-q { font-size: 13px; font-weight: 600; color: var(--teal-800); margin-right: 2px; }
.useful-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .14s, color .14s, border-color .14s, transform .1s;
}
.useful-btn:hover { background: var(--surface-2); border-color: var(--teal-200); }
.useful-btn:active { transform: scale(.96); }
.useful-btn.up:hover { background: var(--ok-bg, #e8f6ee); color: var(--ok); border-color: var(--ok); }
.useful-btn.down:hover { background: var(--amber-100); color: var(--amber-600); border-color: var(--amber-400); }

/* Streaming cursor */
.streaming .msg-text::after {
  content: "▋"; display: inline-block; margin-left: 1px; color: var(--amber-500);
  animation: blink 1.05s steps(1) infinite; font-size: .9em;
}

/* Thinking indicator */
.thinking { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); font-size: 14.5px; padding: 2px 2px; }
.dots { display: inline-flex; gap: 5px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--teal-600); animation: bounce 1.25s var(--ease) infinite; }
.dots span:nth-child(2){ animation-delay: .16s } .dots span:nth-child(3){ animation-delay: .32s }

/* ===== Composer ===== */
.composer-bar { padding: 12px 20px 18px; background: linear-gradient(180deg, transparent, var(--bg) 38%); }

/* Hands-free auto-send countdown ("Tự động gửi sau Ns… — Sửa lại / Gửi ngay"). */
.autosend-bar {
  max-width: 820px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  padding: 7px 8px 7px 12px; border-radius: 999px;
  background: linear-gradient(180deg, var(--amber-100), var(--surface));
  border: 1px solid var(--amber-400); box-shadow: var(--sh-md);
  animation: rise .22s var(--ease) both;
}
.autosend-count {
  flex: 1 1 auto; min-width: 0; text-align: right; padding-right: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--teal-800);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.autosend-count strong {
  display: inline-block; min-width: 1.1em; text-align: center;
  color: var(--amber-600); font-weight: 800; font-variant-numeric: tabular-nums;
  animation: pulseNum 1s var(--ease) infinite;
}
.autosend-edit {
  flex: 0 0 auto; border-radius: 999px; font-size: 13px; font-weight: 700; cursor: pointer;
  white-space: nowrap; padding: 7px 14px;
  background: var(--surface); color: var(--teal-700); border: 1.5px solid var(--teal-200);
  transition: transform .12s, background .12s, border-color .12s;
}
.autosend-edit:hover { background: var(--teal-50); border-color: var(--teal-500); }
.autosend-edit:active { transform: scale(.97); }
@keyframes pulseNum { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* Transient voice-service notice (Viettel voice package paused upstream, mic denied, etc.) —
   a calm, honest line above the composer. Semantic warn colors (not brand), matching the
   autosend-bar layout so it reads as part of the composer, not an error banner. */
.voice-note {
  max-width: 820px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 14px;
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink);
  font-size: 13.5px; font-weight: 600; line-height: 1.4;
  box-shadow: var(--sh-md); animation: rise .22s var(--ease) both;
}
.voice-note-ico { flex: 0 0 auto; font-size: 15px; }

.composer-wrap {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: 8px 8px 8px 8px; box-shadow: var(--sh-md);
  transition: border-color .16s, box-shadow .16s;
}
.composer-wrap:focus-within { border-color: var(--teal-500); box-shadow: var(--sh-md), 0 0 0 4px rgba(27,42,107,.1); }
.composer {
  flex: 1; resize: none; border: none; outline: none; background: transparent;
  font-size: 16px; line-height: 1.5; color: var(--ink); padding: 11px 8px 11px 12px;
  max-height: 200px; min-height: 26px;
}
.composer::placeholder { color: var(--muted); }
.send-btn, .stop-btn {
  flex-shrink: 0; width: 50px; height: 50px; border-radius: 16px; border: none; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  transition: transform .12s var(--ease), box-shadow .16s, opacity .16s, background .16s;
}
.send-btn { background: linear-gradient(150deg, var(--teal-600), var(--teal-800)); box-shadow: var(--sh-teal); }
.send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.send-btn:active:not(:disabled) { transform: translateY(1px) scale(.96); }
.send-btn:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.stop-btn { background: linear-gradient(150deg, var(--amber-500), var(--amber-600)); box-shadow: var(--sh-amber); }
.stop-btn:active { transform: scale(.96); }
.send-btn svg, .stop-btn svg { width: 22px; height: 22px; }
.mic-btn {
  flex-shrink: 0; width: 50px; height: 50px; border-radius: 16px; cursor: pointer;
  display: grid; place-items: center; font-size: 21px; line-height: 1;
  background: rgba(27,42,107,.06); color: var(--teal-800); border: 1px solid var(--line);
  transition: transform .12s var(--ease), box-shadow .16s, background .16s, opacity .16s;
}
.mic-btn:hover:not(:disabled) { background: rgba(27,42,107,.11); transform: translateY(-1px); }
.mic-btn:active:not(:disabled) { transform: translateY(1px) scale(.96); }
.mic-btn:disabled { opacity: .5; cursor: not-allowed; }
.mic-btn.mic-recording {
  background: linear-gradient(150deg, #E5484D, #C62A2F); color: #fff; border-color: transparent;
  animation: micpulse 1.3s ease-in-out infinite;
}
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,72,77,.45); }
  50%      { box-shadow: 0 0 0 7px rgba(229,72,77,0); }
}
.mic-btn.mic-busy { opacity: .65; }
.composer-hint { max-width: 820px; margin: 9px auto 0; text-align: center; font-size: 11.5px; color: var(--muted); }
.composer-hint b { color: var(--ink-soft); font-weight: 600; }

/* ===== Source drawer ===== */
.drawer {
  width: var(--drawer-w); flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line); z-index: 45;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line-soft); }
.drawer-kicker { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--amber-600); }
.drawer-title { font-weight: 700; font-size: 15.5px; color: var(--teal-900); line-height: 1.3; margin-top: 3px; }
.drawer-close { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; display: grid; place-items: center; cursor: pointer; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); }
.drawer-close:hover { background: var(--teal-50); color: var(--teal-700); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.drawer-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.drawer-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--teal-50); color: var(--teal-700); font-size: 12px; font-weight: 600; border: 1px solid var(--teal-100); }
.drawer-preview img, .drawer-preview iframe { width: 100%; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.drawer-preview iframe { height: 520px; }
.drawer-snippet { font-size: 14px; line-height: 1.6; color: var(--ink-soft); background: var(--surface-2); padding: 13px 15px; border-radius: var(--r-md); border: 1px solid var(--line-soft); white-space: pre-wrap; }
.drawer-secure { font-size: 12.5px; line-height: 1.5; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--r-md); padding: 11px 14px; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.drawer-open {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 15px; border-radius: var(--r-md);
  background: var(--teal-700); color: #fff; font-size: 13.5px; font-weight: 600; text-decoration: none; border: none; cursor: pointer;
  box-shadow: var(--sh-teal); transition: transform .12s, background .16s;
}
.drawer-open:hover { background: var(--teal-800); } .drawer-open:active { transform: scale(.97); }

/* ===== Backdrop (mobile drawers) ===== */
.backdrop { position: fixed; inset: 0; background: rgba(13,19,54,.42); backdrop-filter: blur(2px); z-index: 38; }

/* ===== Scrollbars ===== */
.thread::-webkit-scrollbar, .conv-list::-webkit-scrollbar, .drawer-body::-webkit-scrollbar { width: 9px; }
.thread::-webkit-scrollbar-thumb, .drawer-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; border: 3px solid transparent; background-clip: padding-box; }
.thread::-webkit-scrollbar-thumb:hover, .drawer-body::-webkit-scrollbar-thumb:hover { background: var(--teal-200); background-clip: padding-box; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 9px; }

/* ===== Animations ===== */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce { 0%, 70%, 100% { transform: scale(.55); opacity: .45; } 35% { transform: scale(1); opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ============================================================================
   Responsive — phone-first ergonomics (drivers on the road)
   ========================================================================== */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; box-shadow: var(--sh-lg);
    transform: translateX(-100%); transition: transform .26s var(--ease);
  }
  .sidebar.open { transform: none; animation: slideInLeft .26s var(--ease); }
  .icon-btn { display: grid; }
  .drawer {
    position: fixed; inset: 0 0 0 auto; width: min(440px, 100vw);
    box-shadow: var(--sh-lg); animation: slideIn .26s var(--ease);
  }
}

@media (max-width: 640px) {
  body { background-size: auto, auto, 20px 20px; }
  .topbar { padding: 10px 14px; min-height: 56px; }
  .thread-inner { padding: 0 14px; gap: 18px; }
  .composer-bar { padding: 10px 12px max(14px, env(safe-area-inset-bottom)); }
  .bubble-bot { max-width: 100%; padding: 16px 17px; border-radius: 6px 18px 18px 18px; }
  .bubble-user { max-width: 88%; font-size: 16px; }
  .msg-text { font-size: 16.5px; }          /* glanceable while driving */
  .hero-title { font-size: 25px; }
  .hero-sub { font-size: 15px; }
  .composer { font-size: 16.5px; }           /* >=16px stops iOS zoom-on-focus */
  .send-btn, .stop-btn, .mic-btn { width: 48px; height: 48px; }
  .src-thumb { width: calc(50% - 5px); }
  .topbar-pill { display: none; }
}
