/* ==========================================================================
   دليل / Daleel — Arabic RTL interface.

   Third redesign pass. Two things changed structurally from the previous
   (blue/white portal) pass:

     - The directory moved off the homepage and behind a hamburger button
       into a slide-in drawer — an index you open on demand, collapsed to
       an accordion per authority (click to reveal its services), rather
       than a grid that occupied permanent scroll space.
     - The composer is a true flex:none sibling of the scrolling thread, not
       a sticky element living inside it — it cannot drift toward the
       middle/top of the screen when the thread is short, only ever the
       bottom of the column.

   Messages now carry a small avatar (bot: the sparkle mark; citizen: a
   plain person glyph) so each turn's speaker is legible at a glance without
   reading the text. The served-by model badge is gone — it was internal
   diagnostic information, not something a citizen needs to see.

   Palette stays blue + white with the manual light/dark/system toggle from
   the previous pass.

   CSS logical properties (inline-start/end, margin-inline, border-start-*)
   are used throughout, so nothing is mirrored by hand.

   Sections:
     1  tokens                8  answer card + citations
     2  base + a11y           9  related-services follow-ups
     3  app shell             10 clarify / refusal / error
     4  topbar + drawer       11 loading indicator
     5  hero + stats          12 keyframes
     6  composer (fixed)      13 responsive + reduced motion
     7  messages + avatars
   ========================================================================== */

/* --- 1. tokens ---------------------------------------------------------- */
:root {
  --paper: #f5f8fd;
  --surface: #ffffff;
  --surface-2: #eef3fc;
  --surface-3: #e3ebf9;

  --border: #dbe4f3;
  --border-strong: #c3d2ec;

  --text: #0b1220;
  --text-dim: #55637c;
  --text-faint: #8794ac;

  /* primary: blue. --accent clears 4.7:1 on --paper/--surface, safe for
     text as well as fills. */
  --accent: #2f6fed;
  --accent-strong: #1d4ed8;
  --accent-bright: #4c86ff;
  --accent-soft: rgba(47, 111, 237, .10);
  --accent-line: rgba(47, 111, 237, .28);

  /* secondary: a narrow-band cyan, used only for citation numerals and the
     odd accent dot — never for anything that competes with the primary
     blue for attention. */
  --accent-2: #0c8fa3;
  --accent-2-soft: rgba(12, 143, 163, .12);
  --accent-2-line: rgba(12, 143, 163, .30);

  --warn: #92660a;
  --warn-soft: rgba(146, 102, 10, .10);
  --danger: #c0272a;
  --danger-soft: rgba(192, 39, 42, .07);

  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 30, 60, .05), 0 2px 8px rgba(15, 30, 60, .05);
  --shadow: 0 1px 2px rgba(15, 30, 60, .05), 0 10px 30px rgba(15, 30, 60, .09);
  --shadow-lg: 0 2px 6px rgba(15, 30, 60, .06), 0 24px 60px rgba(15, 30, 60, .15);
  --shadow-accent: 0 8px 22px rgba(47, 111, 237, .20);

  --ease: cubic-bezier(.22, .68, .28, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --fast: .16s;
  --med: .24s;

  --col-w: 50rem;
  --drawer-w: 320px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --paper: #070c16;
    --surface: #0d1526;
    --surface-2: #111b30;
    --surface-3: #16213a;

    --border: #1d2a45;
    --border-strong: #28395c;

    --text: #eaf0fb;
    --text-dim: #93a2c2;
    --text-faint: #5f6f92;

    --accent: #5b8dff;
    --accent-strong: #8fb1ff;
    --accent-bright: #6f9dff;
    --accent-soft: rgba(91, 141, 255, .16);
    --accent-line: rgba(91, 141, 255, .34);

    --accent-2: #34c6da;
    --accent-2-soft: rgba(52, 198, 218, .14);
    --accent-2-line: rgba(52, 198, 218, .34);

    --warn: #e3b656;
    --warn-soft: rgba(227, 182, 86, .14);
    --danger: #f0817d;
    --danger-soft: rgba(240, 129, 125, .12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow: 0 2px 10px rgba(0, 0, 0, .42);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .58);
    --shadow-accent: 0 8px 22px rgba(0, 0, 0, .5);
  }
}

/* The manual toggle: identical dark values, forced regardless of OS. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #070c16;
  --surface: #0d1526;
  --surface-2: #111b30;
  --surface-3: #16213a;
  --border: #1d2a45;
  --border-strong: #28395c;
  --text: #eaf0fb;
  --text-dim: #93a2c2;
  --text-faint: #5f6f92;
  --accent: #5b8dff;
  --accent-strong: #8fb1ff;
  --accent-bright: #6f9dff;
  --accent-soft: rgba(91, 141, 255, .16);
  --accent-line: rgba(91, 141, 255, .34);
  --accent-2: #34c6da;
  --accent-2-soft: rgba(52, 198, 218, .14);
  --accent-2-line: rgba(52, 198, 218, .34);
  --warn: #e3b656;
  --warn-soft: rgba(227, 182, 86, .14);
  --danger: #f0817d;
  --danger-soft: rgba(240, 129, 125, .12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 2px 10px rgba(0, 0, 0, .42);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .58);
  --shadow-accent: 0 8px 22px rgba(0, 0, 0, .5);
}
:root[data-theme="light"] { color-scheme: light; }

/* --- 2. base + accessibility --------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.85;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background var(--med) var(--ease), color var(--med) var(--ease);
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.msg--user .msg__content :focus-visible,
.composer__send:focus-visible,
.svc__ask:focus-visible,
.option:focus-visible {
  outline-color: currentColor;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

::selection { background: var(--accent-soft); color: var(--text); }

button { font: inherit; color: inherit; }

/* generic icons: stroke/border-drawn, no icon font or image request. */
.icon { display: inline-block; width: 16px; height: 16px; flex: none; }
.icon-plus { position: relative; }
.icon-plus::before, .icon-plus::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 2px;
}
.icon-plus::before { inset-inline-start: 7px; top: 1px; width: 2px; height: 14px; }
.icon-plus::after { top: 7px; inset-inline-start: 1px; width: 14px; height: 2px; }

.icon-x { position: relative; width: 16px; height: 16px; display: inline-block; flex: none; }
.icon-x::before, .icon-x::after {
  content: "";
  position: absolute;
  top: 7px; inset-inline-start: 1px;
  width: 14px; height: 2px;
  border-radius: 2px;
  background: currentColor;
}
.icon-x::before { transform: rotate(45deg); }
.icon-x::after { transform: rotate(-45deg); }

.icon-list { display: flex; flex-direction: column; justify-content: space-between; width: 16px; height: 12px; flex: none; }
.icon-list span { display: block; height: 2px; border-radius: 2px; background: currentColor; }
.icon-list span:nth-child(2) { width: 70%; }

/* --- 3. app shell ---------------------------------------------------------
   One column: topbar, the scrolling thread, and the composer as a fixed
   flex:none footer. The directory lives in a separate overlay drawer (see
   section 4), not in this column at all. */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--paper);
  overflow: hidden;
}

/* The column itself. .app only establishes the viewport box and hosts the
   drawer overlay; .main is what actually holds topbar / thread / composer.
   It MUST be a flex column with min-height:0 — without that it is a plain
   block, #thread's `flex:1; min-height:0` are inert, the thread grows to
   its content height, and .app's overflow:hidden clips the conversation
   with no way to scroll to it. */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* --- 4. topbar + drawer ---------------------------------------------------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.burger { display: flex; flex-direction: column; gap: 4px; width: 17px; }
.burger span { display: block; height: 2px; border-radius: 2px; background: currentColor; }

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }

/* --- the logo mark: a CSS gradient tile + an inline SVG sparkle/compass
   star. Deliberately abstract rather than a letterform — "guide" is carried
   by the compass motif, not by a دال. */
.brand__mark {
  flex: none;
  position: relative;
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background:
    radial-gradient(120% 110% at 26% 14%, rgba(255, 255, 255, .30), transparent 58%),
    linear-gradient(145deg, var(--accent-bright), var(--accent-strong));
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.brand__spark { width: 60%; height: 60%; }

.brand__names { display: flex; flex-direction: column; min-width: 0; }
.brand__name {
  font-size: 1.14rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -.01em;
}
.brand__tag {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions { display: flex; align-items: center; gap: 8px; flex: none; }

.topbar__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast), color var(--fast);
}
.topbar__btn:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.topbar__btn--icon { padding: 8px; }
.topbar__btn-label { white-space: nowrap; }

.theme-toggle__icon {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  position: relative;
  overflow: hidden;
}
.theme-toggle__icon::before {
  content: "";
  position: absolute;
  inset-inline-start: 50%;
  inset-block: -1px;
  width: 50%;
  background: currentColor;
}
.topbar__btn[data-theme="light"] .theme-toggle__icon::before { opacity: 0; }
.topbar__btn[data-theme="dark"] .theme-toggle__icon::before { inset-inline-start: -1px; width: calc(100% + 2px); }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(6, 12, 24, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--med) var(--ease);
}
.app.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }

/* The directory: an off-canvas drawer on every viewport size, opened by the
   hamburger button — an index you reach for, not one that sits in the way
   of the homepage. inset-inline-start (not transform) so it is correct in
   RTL with no mirroring math. */
.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-start: -100%;
  width: min(88vw, var(--drawer-w));
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  box-shadow: none;
  transition: inset-inline-start var(--med) var(--ease-out);
}
.app.drawer-open .drawer { inset-inline-start: 0; box-shadow: var(--shadow-lg); }

.drawer__head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 10px;
}
.drawer__title { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }

.drawer .search { position: relative; flex: none; margin: 4px 16px 10px; }
.search__icon {
  position: absolute;
  inset-inline-start: 13px;
  top: 50%;
  width: 12px; height: 12px;
  margin-top: -5px;
  border: 2px solid var(--text-dim);
  border-radius: 50%;
  pointer-events: none;
  transition: border-color var(--med) var(--ease);
}
.search__icon::after {
  content: "";
  position: absolute;
  inset-inline-start: 1px;
  top: 11px;
  width: 6px; height: 2px;
  border-radius: 2px;
  background: var(--text-dim);
  transform: rotate(45deg);
  transition: background var(--med) var(--ease);
}
.directory__search {
  width: 100%;
  font-family: inherit;
  font-size: 0.88rem;
  padding: 9px 14px;
  padding-inline-start: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--med) var(--ease), box-shadow var(--med) var(--ease);
}
.directory__search::placeholder { color: var(--text-faint); }
.directory__search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search:focus-within .search__icon { border-color: var(--accent); }
.search:focus-within .search__icon::after { background: var(--accent); }

.directory__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* Generous gap between authorities — the thing that was cramped before. */
  gap: 14px;
  padding: 4px 16px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.directory__empty {
  margin: 10px 16px 0;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  font-size: 0.88rem;
  color: var(--text-dim);
}

/* --- authority accordion ---
   NOTE: this card must NOT have `overflow: hidden` — combined with the
   panel's `grid-template-rows: 0fr` collapse animation below, an
   overflow-hidden ancestor made Chromium compute the card's auto-height
   from the collapsed (0fr) state instead of its actual visible content,
   shrinking every card to ~28px regardless of what was rendered inside.
   The panel's OWN children already clip the collapsed state (see
   .auth__panel > *), so the outer card needs no clipping of its own —
   only rounded corners on the parts that can paint a background. */
.auth {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  transition: border-color var(--med) var(--ease);
  animation: card-in .4s var(--ease) calc(.06s + var(--i, 0) * 35ms) both;
}
.auth:hover, .auth.is-open { border-color: var(--accent-line); }

.auth__head {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  font-family: inherit;
  text-align: start;
  padding: 12px 14px;
  border: none;
  border-radius: var(--r);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.auth__head:hover { background: var(--accent-soft); }
.auth__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.auth__icon svg { width: 18px; height: 18px; }
.auth__meta { flex: 1; min-width: 0; }
.auth__name { font-size: 0.9rem; font-weight: 700; line-height: 1.4; }
.auth__count { font-size: 0.7rem; color: var(--text-dim); }
.auth__chev {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  font-size: 0.64rem;
  color: var(--text-faint);
  transition: transform var(--med) var(--ease-out), color var(--fast);
}
.auth.is-open .auth__chev { transform: rotate(180deg); color: var(--accent); }

/* Smooth expand/collapse via grid-template-rows 0fr -> 1fr, so the panel
   grows to exactly its own content height without measuring in JS. */
.auth__panel {
  display: grid;
  grid-template-rows: 0fr;
  visibility: hidden;
  opacity: 0;
  transition: grid-template-rows var(--med) var(--ease-out), opacity var(--med) var(--ease), visibility var(--med) linear;
}
.auth.is-open .auth__panel { grid-template-rows: 1fr; visibility: visible; opacity: 1; }
.auth__panel > .auth__inner,
.auth__panel > * { min-height: 0; overflow: hidden; }

.svclist { list-style: none; margin: 0; padding: 0 14px 12px; }
.svc {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.svc:first-child { border-top: none; }
.svc__name { flex: 1; min-width: 100px; font-size: 0.85rem; line-height: 1.5; }
.svc:hover .svc__name { color: var(--accent); }
.svc__ask {
  flex: none;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.svc__ask:hover { background: var(--accent); color: #fff; border-color: transparent; }

.auth__portal {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 4px 14px 12px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--fast);
}
.auth__portal::after { content: "←"; font-size: .9em; }
.auth__portal:hover { border-bottom-color: var(--accent-line); }

.directory__list.is-refiltered .auth:not([hidden]) {
  animation: card-in .3s var(--ease) calc(var(--i, 0) * 20ms) both;
}

/* --- the single scroll region --- */
.thread {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.thread:focus { outline: none; }
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}

/* --- 5. hero + stats ------------------------------------------------------
   The search-first landing view. Removed once .app.is-chatting. */
.hero {
  max-width: var(--col-w);
  margin: 0 auto;
  padding: 40px 24px 28px;
  text-align: center;
}
.app.is-chatting .hero { display: none; }

.hero__mark {
  position: relative;
  width: 60px; height: 60px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: 18px;
  background:
    radial-gradient(120% 110% at 26% 14%, rgba(255, 255, 255, .30), transparent 58%),
    linear-gradient(145deg, var(--accent-bright), var(--accent-strong));
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, .22);
  animation: rise .5s var(--ease) both;
}
.hero__mark .brand__spark { width: 62%; height: 62%; }

.hero__title {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 1.15rem + 1.6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -.015em;
  max-width: 26ch;
  margin-inline: auto;
  animation: rise .5s var(--ease) .08s both;
}
.hero__text {
  margin: 0 auto;
  max-width: 46ch;
  color: var(--text-dim);
  font-size: 0.98rem;
  animation: rise .5s var(--ease) .13s both;
}

/* Populated by script.js from the SAME directory payload the drawer
   renders — one source of truth, no hardcoded coverage numbers. */
.hero__stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  animation: rise .5s var(--ease) .17s both;
}
.hero__stats:empty { display: none; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}
.stat__value { font-size: 1.15rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat__label { font-size: 0.72rem; color: var(--text-dim); }

.hero__browse {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding: 9px 18px;
  border-radius: var(--r-pill);
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--fast), color var(--fast), background var(--fast);
  animation: rise .5s var(--ease) .25s both;
}
.hero__browse:hover { border-style: solid; border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }

/* --- 6. composer (fixed footer, not sticky) --------------------------------
   A flex:none sibling of #thread inside .main — always the last thing in
   the column, always visible, never able to drift upward when the thread
   is short. */
.composer-wrap {
  flex: none;
  padding: 10px 22px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--col-w);
  margin: 0 auto;
  padding: 9px 8px 9px 18px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  transition: border-color var(--med) var(--ease), box-shadow var(--med) var(--ease), background var(--med) var(--ease);
}
.composer:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer__icon {
  flex: none;
  width: 17px; height: 17px;
  border: 2px solid var(--text-faint);
  border-radius: 50%;
  position: relative;
}
.composer__icon::after {
  content: "";
  position: absolute;
  inset-inline-start: 2px;
  top: 14px;
  width: 8px; height: 2px;
  border-radius: 2px;
  background: var(--text-faint);
  transform: rotate(45deg);
}
.composer:focus-within .composer__icon,
.composer:focus-within .composer__icon::after { border-color: var(--accent); background: var(--accent); }
.composer__input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 1rem;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text);
}
.composer__input:focus { outline: none; }
.composer__input::placeholder { color: var(--text-faint); }
.composer__input:disabled { opacity: .6; }

.composer__send {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-strong));
  color: #fff;
  cursor: pointer;
  transition: transform var(--fast) var(--ease-out), filter var(--fast), opacity var(--fast);
}
.composer__send:hover:not(:disabled) { filter: brightness(1.08); transform: scale(1.05); }
.composer__send:active:not(:disabled) { transform: scale(.95); }
.composer__send:disabled { opacity: .4; cursor: default; }
.composer__send-arrow {
  width: 8px; height: 8px;
  border-inline-end: 2px solid currentColor;
  border-block-start: 2px solid currentColor;
  transform: rotate(45deg);
}
[dir="rtl"] .composer__send-arrow { transform: rotate(-135deg); }

/* --- 7. messages + avatars ------------------------------------------------
   Each turn is a row: an avatar plus its content. DOM order is
   [avatar, content] for both roles — in RTL that renders the avatar at the
   RIGHT edge of the row either way, with content filling inward, so one
   markup pattern covers both without a role-specific mirror. */
.messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: var(--col-w);
  margin: 0 auto;
  padding: 10px 22px 8px;
}
.messages:empty { display: none; }

.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  padding: 8px 2px;
  animation: msg-in .34s var(--ease-out) both;
}
.msg--user { align-self: flex-start; max-width: 84%; }
.msg--bot { align-self: stretch; }

.msg__avatar {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.msg__avatar svg { width: 60%; height: 60%; }
.msg__avatar--bot {
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-strong));
  box-shadow: var(--shadow-accent);
  color: #fff;
}
.msg__avatar--user {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}

.msg__content { flex: 1; min-width: 0; padding-top: 4px; }
.msg--user .msg__content {
  flex: none;
  padding: 11px 16px;
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-strong));
  color: #fff;
  border-radius: var(--r);
  box-shadow: var(--shadow-accent);
}
.msg__text { white-space: pre-wrap; overflow-wrap: break-word; }
.msg__meta {
  display: inline-flex;
  margin-top: 10px;
  padding: 3px 11px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-faint);
}

/* --- 8. answer card + citations --- */
.card {
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card__head { position: relative; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.card__head::after {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  bottom: -1px;
  width: 48px; height: 1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.card__service { font-size: 1.08rem; font-weight: 700; line-height: 1.5; letter-spacing: -.01em; }
.card__authority { font-size: 0.83rem; color: var(--text-dim); }

.answer__body > :first-child { margin-top: 0; }
.answer__body > :last-child { margin-bottom: 0; }
.answer__p { margin: 0 0 10px; font-size: 0.96rem; }
.answer__list { margin: 0 0 12px; padding-inline-start: 22px; }
.answer__list li { margin-bottom: 6px; font-size: 0.96rem; }
.answer__list li::marker { color: var(--accent); }
.answer__list.is-ordered { list-style: none; counter-reset: step; padding-inline-start: 0; }
.answer__list.is-ordered li {
  position: relative;
  counter-increment: step;
  padding-inline-start: 30px;
}
.answer__list.is-ordered li::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  width: 20px; height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}
.answer__body strong { font-weight: 600; color: var(--text); }

.card__source {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.9;
  color: var(--text-dim);
}
.card__source a { color: var(--accent); word-break: break-all; }
.card__source-label { font-weight: 600; color: var(--text); margin-bottom: 8px; }
.card__source-row { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 6px 8px; margin-bottom: 8px; }
.card__source-row:last-child { margin-bottom: 0; }
.card__source-ref { color: var(--text-dim); }

/* Numbered like a research answer's citation list — a detail cue that also
   makes several sources easy to tell apart at a glance. */
.srcnum {
  flex: none;
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--accent-2-soft);
  color: var(--accent-2);
  font-size: 0.66rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.srcflag {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  border: 1px solid currentColor;
}
.srcflag--gov { color: var(--accent); background: var(--accent-soft); }
.srcflag--other { color: var(--warn); background: var(--warn-soft); }

.conf {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  margin-inline-start: 8px;
  vertical-align: middle;
}
.conf--high { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
.conf--partial { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }

/* --- 9. related-services follow-ups ---------------------------------------
   Once an answer names its authority, its siblings in that same authority
   (from the SAME directory payload the drawer uses) become one-tap
   follow-ups — no extra request, no backend change. */
.related { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.related__label { font-size: 0.76rem; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.related__list { display: flex; flex-wrap: wrap; gap: 7px; }
.related__chip {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.related__chip:hover { background: var(--accent); color: #fff; }

/* --- 10. clarifying options, refusal, error --------------------------- */
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.option {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease-out);
}
.option:hover:not(:disabled) { background: var(--accent); color: #fff; transform: translateY(-1px); }
.option:active:not(:disabled) { transform: translateY(0) scale(.98); }
.option:disabled { opacity: .4; cursor: default; }

.msg--refusal { border-inline-start: 3px solid var(--danger); padding-inline-start: 15px; }
.msg--error { color: var(--danger); }
.msg--error .msg__text { font-weight: 500; }
.retry {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  margin-top: 10px;
  padding: 6px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.retry:hover { background: var(--danger); color: #fff; }

/* --- 11. loading indicator -------------------------------------------- */
.loading { display: flex; align-items: center; gap: 12px; color: var(--text-dim); }
.loading__label {
  font-size: 0.85rem;
  font-weight: 500;
  background: linear-gradient(90deg, var(--text-dim) 20%, var(--accent) 50%, var(--text-dim) 80%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: sweep 2.1s linear infinite;
}
.typing { display: inline-flex; gap: 5px; align-items: flex-end; }
.typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-bright), var(--accent));
  animation: wave 1.25s var(--ease) infinite;
}
.typing span:nth-child(2) { animation-delay: .16s; }
.typing span:nth-child(3) { animation-delay: .32s; }

/* --- 12. keyframes ------------------------------------------------------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes wave {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30%           { transform: translateY(-5px); opacity: 1; }
}
@keyframes sweep {
  from { background-position: 100% 0; }
  to   { background-position: -100% 0; }
}

/* --- 13. responsive ------------------------------------------------------ */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { padding: 10px 14px; gap: 8px; }
  .topbar__btn-label { display: none; }
  .topbar__btn { padding: 8px; }
  .brand__name { font-size: 1.05rem; }
  .brand__tag { display: none; }
  .hero { padding: 30px 16px 22px; }
  .hero__stats { flex-wrap: wrap; }
  .composer-wrap { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); }
  .messages { padding: 6px 14px 8px; }
  .msg--user { max-width: 92%; }
  .drawer { width: min(90vw, 300px); }
}

@media (hover: none) {
  .composer__send:hover, .svc__ask:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .thread { scroll-behavior: auto; }
}
