/* ==========================================================================
   צ'אט AI לפסיכולוגים — stylesheet
   ROOM3 Threshold dark theme · Ink canvas · Surface text · accent as signal
   Hebrew RTL · mobile-first
   --------------------------------------------------------------------------
   Contents
     1. Design tokens
     2. Reset & base
     3. Focus & selection
     4. Buttons
     5. Form controls
     6. App shell & header
     7. Gate (sign-in / MFA)
     8. Passkey offer & status
     9. Chat thread (blank-page text stream)
    10. Composer
    11. Notices & errors
    12. Admin panel & tables
    13. Desktop layout (≥640px)
    14. Small-screen tweaks (<640px)
    15. Motion preferences
   ========================================================================== */

/* 1. Design tokens
   ------------------------------------------------------------------------ */
:root {
  color-scheme: dark;              /* one theme only — native controls follow */
  font-synthesis: none;

  /* Type — serif for headings and message text, sans for UI chrome */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; /* web fonts removed per owner: device system font everywhere */
  --leading-hebrew: 1.75;

  /* ROOM3 Threshold brand kit — dark family only (this app has no light theme).
     Mapping (kit token → app var):
       Ink        #151713 → --bg-base, --on-accent
       Rule-dark  #2D312C → --bg-raised
       Threshold  #677064 → --bg-chip (as a 28% tint, so it still lifts off
                            both Ink and Rule-dark; solid it is too light for a
                            surface and only 3.5:1 on Ink, so never text)
       Surface    #F2F1EB → --text, --text-chip; hairlines as 8% / 16% tints
       Muted-dark #A5ADA2 → --text-muted, --text-faint (the kit has one muted
                            tier on dark; Threshold fails AA as small text)
       Accent     #A8F23A → --accent. A signal, not body text: fills carry Ink
                            text (13.2:1), otherwise rings, borders, dots, icons.
       Danger     #E05A4F → --danger-bg / --danger-border tints; --danger-text
                            keeps its lighter tint (#E05A4F is 3.6:1 on
                            Rule-dark, below AA for the drawer's danger row).
     No hue outside the kit: every derived value is an alpha tint of a token. */

  /* Surfaces */
  --bg-base: #151713;              /* Ink — page canvas                       */
  --bg-raised: #2D312C;            /* Rule-dark — composer bar, fields, drawer */
  --bg-chip: rgba(103, 112, 100, 0.28); /* Threshold tint — user chip, raised hover */
  --bg-row-hover: rgba(242, 241, 235, 0.03);

  /* Hairlines & borders — Surface tints, visible on Ink and Rule-dark alike */
  --hairline: rgba(242, 241, 235, 0.08);
  --hairline-strong: rgba(242, 241, 235, 0.16);

  /* Text */
  --text: #F2F1EB;                 /* Surface */
  --text-chip: #F2F1EB;
  --text-muted: #A5ADA2;           /* Muted-dark — icons, secondary text */
  --text-faint: #A5ADA2;           /* Muted-dark — hints (size carries the hierarchy) */

  /* Accent — signal only */
  --accent: #A8F23A;
  --accent-hover: rgba(168, 242, 58, 0.88);  /* accent settling toward Ink; Ink text stays >10:1 */
  --accent-tint: rgba(168, 242, 58, 0.24);
  --on-accent: #151713;            /* Ink on accent fills: 13.2:1 */

  /* Feedback */
  --danger-text: #e39287;
  --danger-bg: rgba(224, 90, 79, 0.12);
  --danger-border: rgba(224, 90, 79, 0.45);
  --warn-text: #dcb978;
  --warn-border: rgba(220, 185, 120, 0.5);

  /* Radii */
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-bar: 28px;
  --r-pill: 999px;

  /* Focus ring */
  --ring: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}

/* 2. Reset & base
   ------------------------------------------------------------------------ */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg-base); }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }

[hidden] { display: none !important; }

h1, h2 { font-family: var(--font-display); color: var(--text); }
h1 { margin: 0; font-size: 18px; font-weight: 500; line-height: 1.25; }
h2 { margin: 10px 0; font-size: 28px; font-weight: 500; line-height: 1.3; }

svg { display: block; flex-shrink: 0; }

/* Announced to assistive tech, invisible on screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* 3. Focus & selection
   ------------------------------------------------------------------------ */
/* Outline (not just box-shadow) so component rules that set their own
   box-shadow can never wipe out the keyboard focus indicator. */
:where(button, input, textarea, select, [tabindex], a.secondary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--ring);
}

::selection { background: var(--accent-tint); }

/* 4. Buttons — pills
   ------------------------------------------------------------------------ */
button {
  cursor: pointer;
  min-height: 44px;
  padding: 10px 22px;
  border-radius: var(--r-pill);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease,
              color 0.15s ease, transform 0.06s ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: default; opacity: 0.45; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.secondary {
  background: var(--bg-raised);
  border-color: var(--hairline);
  color: var(--text);
}
.secondary:hover:not(:disabled) {
  background: var(--bg-chip);
  border-color: var(--hairline-strong);
}

/* The button base above targets the element, not the class, so toolbox entry
   links spelled as <a class="secondary"> need the shared geometry here. */
.gate a.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 22px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.text-button {
  background: transparent;
  color: var(--text-muted);
  padding-inline: 14px;
}
.text-button:hover:not(:disabled) {
  background: var(--bg-raised);
  color: var(--text);
}

.danger {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger-text);
}
.danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger-text); }

/* 5. Form controls
   ------------------------------------------------------------------------ */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

input, textarea, select {
  width: 100%;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

input { min-height: 48px; }
select { min-height: 48px; max-width: 100%; }
option { color: var(--text); background: var(--bg-raised); }

input:hover, textarea:hover, select:hover { border-color: var(--hairline-strong); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--accent);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }

/* Keep browser autofill from flashing a light field onto the dark canvas. */
input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--bg-raised) inset;
  caret-color: var(--text);
}

textarea { resize: vertical; min-height: 76px; max-height: 200px; line-height: 1.7; }

/* 6. App shell & header
   ------------------------------------------------------------------------ */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.header {
  padding-top: env(safe-area-inset-top);
  background: var(--bg-base);
}


/* The mark stands alone — no tile, no border. It is the kit's reverse SVG,
   inline, with its own strokes (never recolored) in an LTR wrapper (never
   mirrored). The box is 1em: the artwork fills 75% of its viewBox, which is
   the ink the old glyph had at the same font-size, so each context keeps
   sizing the mark through font-size. */
.brand {
  display: block;
  flex-shrink: 0;
  width: 1em;
  height: 1em;
  font-size: 22px;
  line-height: 1;
  direction: ltr;
}
.brand svg { display: block; width: 100%; height: 100%; }


/* Directional glyphs point the other way in RTL. */
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }


/* 7. Gate (sign-in / MFA) — no card: a calm column on the open page
   ------------------------------------------------------------------------ */
.gate {
  width: calc(100% - 40px);
  max-width: 400px;
  margin: 36px auto;
  padding: 0;
  background: none;
  border: none;
}

.gate-icon {
  margin-bottom: 18px;
  font-size: 44px;
  line-height: 1;
  text-align: center;
}
.gate-icon .brand { margin-inline: auto; font-size: inherit; }

.eyebrow {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);        /* accent is a signal, not text */
}

.gate h2 { margin-top: 0; font-size: 34px; font-weight: 400; text-align: center; }
.gate > p {
  margin: 8px 0;
  text-align: center;
  color: var(--text-muted);
  line-height: var(--leading-hebrew);
}

.gate form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 28px;
}
.gate form label { margin-bottom: -8px; }
.gate form .primary { margin-top: 10px; }

/* Waiting list */
.waitlist-join { margin-top: 18px; width: 100%; }
.waitlist-join > .text-button { width: 100%; font-size: 14px; }
.waitlist-join form { margin-top: 12px; text-align: start; }
.waitlist-done {
  margin-top: 12px; padding: 14px 16px; border-radius: 12px; text-align: start;
  background: rgba(168, 242, 58, 0.08); border: 1px solid var(--accent-tint);
}
.waitlist-done p { margin: 0; font-size: 14px; line-height: 1.8; }
.waitlist-done .waitlist-done-title { font-weight: 600; }
.waitlist-admin { margin: 0 0 22px; }
.waitlist-admin h3 { margin: 0 0 12px; font-size: 17px; }
.waitlist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.waitlist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; background: var(--bg-chip); border: 1px solid var(--hairline);
}
.waitlist-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.waitlist-info strong { font-size: 15px; overflow-wrap: anywhere; }
.waitlist-chip {
  align-self: flex-start; margin-top: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; color: var(--warn-text); border: 1px solid var(--warn-border);
}
.waitlist-meta { font-size: 12.5px; color: var(--text-muted); overflow-wrap: anywhere; }
.waitlist-actions { display: flex; gap: 8px; }
.waitlist-actions .primary, .waitlist-actions .secondary { min-height: 44px; padding: 8px 16px; font-size: 14px; }

.small { font-size: 12px; line-height: 1.8; color: var(--text-muted); }
.gate .small { margin: 22px 0 0; text-align: center; color: var(--text-faint); }

/* MFA specifics */
#mfa-setup {
  margin: 20px 0;
  padding: 16px 0 4px;
  font-size: 13px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  border-block: 1px solid var(--hairline);
}
#mfa-setup > p:first-child { margin-top: 0; color: var(--text-muted); }
#mfa-setup label { margin-top: 12px; }
#mfa-setup textarea { margin-bottom: 12px; }
#mfa-secret { font-family: ui-monospace, "Courier New", monospace; letter-spacing: 0.04em; }
#mfa-uri { font-size: 12px; min-height: 0; }

#verification { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }

#mfa-code {
  font-size: 20px;
  letter-spacing: 0.35em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#mfa-error { margin-top: 12px; text-align: center; }
#mfa-cancel { display: block; margin: 14px auto 0; }

/* 8. Passkey offer & status
   ------------------------------------------------------------------------ */
.passkey-offer, .passkey-status, .notice {
  width: calc(100% - 40px);
  max-width: 700px;
  margin-inline: auto;
}

.passkey-offer {
  margin-block: 16px;
  padding: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
}
.passkey-offer h2 { margin: 0 0 14px; font-size: 20px; }
.passkey-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.passkey-offer .error-text { margin-top: 10px; }

.passkey-status { margin-block: 12px; font-size: 14px; color: var(--text); }

/* Status lines: the accent is a dot beside the words, never the words. */
.passkey-status::before,
.local-badge::before,
.local-progress.ready .local-progress-head > span:first-child::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-inline-end: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

/* 9. Chat thread — a blank page
   --------------------------------------------------------------------------
   Messages keep the .bubble class (JS contract). The assistant writes
   straight onto the canvas; the user's turn is a small chip. The measure is
   enforced with padding on the scroll container itself, so the JS-managed
   children (#empty, #messages) need no wrapper. */
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.thread {
  flex: 1 1 0;
  min-height: 220px;
  --measure: 700px;
  display: flex;
  flex-direction: column;
  padding-block: 24px 48px;
  padding-inline: max(20px, calc((100% - var(--measure)) / 2));
  overflow-y: auto;
  /* both-edges keeps the column optically centered over the composer. */
  scrollbar-gutter: stable both-edges;
}
.thread > * { flex-shrink: 0; }
/* The scroller spans the full width, so an outset ring would be clipped. */
.thread:focus-visible { outline-offset: -2px; box-shadow: none; }

/* Empty state: a large mark and a serif line, centered in the canvas. */
.empty { margin-block: auto; padding: 8px 8px 24px; text-align: center; color: var(--text-muted); }
.empty > .brand {
  margin-inline: auto;
  font-size: 52px;
}
.empty h2 {
  margin: 18px 0 10px;
  font-size: 30px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text);
}
.empty p { margin: 0; font-size: 15px; line-height: var(--leading-hebrew); }

.bubble {
  max-width: 100%;
  margin: 0 0 28px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  overflow-wrap: anywhere;
}

.bubble:last-child { margin-bottom: 0; }

/* A new exchange gets a slightly deeper breath of whitespace. */
.bubble + .bubble.user { margin-top: 40px; }

.content {
  white-space: pre-wrap;
  unicode-bidi: plaintext;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: var(--leading-hebrew);
}

/* The user's words: a compact chip hugging the inline-start edge (right in
   RTL). The block (not the text) is positioned, so dir="auto" content keeps
   its natural start edge. The "אתם" label stays for assistive tech only. */
.bubble.user {
  width: fit-content;
  max-width: 75%;
  margin-inline-end: auto;
  padding: 8px 16px;
  border-radius: 18px;
  background: var(--bg-chip);
}
.bubble.user .content { color: var(--text-chip); font-size: 17px; line-height: 1.6; }
.bubble.user .speaker {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The assistant's words: warm white, directly on the page, full measure.
   The label recedes to a whisper (JS rewrites it on partial answers). */
.bubble.assistant .content { color: var(--text); }

.speaker {
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-faint);
}

/* Streaming affordance: a breathing dot beside the label, plus placeholder
   text while the reply is still empty. */
.bubble.streaming .speaker::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-inline-start: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
  animation: pulse 1.1s ease-in-out infinite;
}
.bubble.streaming .content:empty::after {
  content: "מנסח תשובה…";
  color: var(--text-muted);
  animation: pulse 1.6s ease-in-out infinite;
}
.bubble.streaming.search-waiting .content:empty::after {
  content: "מנסח תשובה · חיפוש אינטרנט מופעל…";
}

/* Live web-search indicator: appears above the answer the moment the server
   reports real search queries, and stays with the finished message. */
.search-line {
  margin-block-end: 6px;
  font-size: .82rem;
  color: var(--text-muted);
}
.search-line::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-inline-end: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}
.bubble.streaming .search-line::before { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Action row under a finished reply. DOM order is copy → more, so in RTL the
   row hugs the right edge with copy outermost (Pi's row, mirrored). */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
  margin-inline-start: -6px;       /* optically align the first glyph with the text */
}
.msg-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
}
.msg-actions svg { width: 16px; height: 16px; }
.msg-actions button:hover:not(:disabled) { background: var(--bg-raised); color: var(--text); }
.msg-actions button.active { color: var(--accent); }
.msg-actions button.active svg { fill: var(--accent-tint); }
.msg-actions button:disabled { opacity: 0.5; }

/* Rendered markdown inside assistant replies (built by markdown.js as DOM
   nodes). Each text block resolves its own direction, so an English paragraph
   inside a Hebrew answer still reads start-to-end correctly. */
.bubble.assistant .content :is(p, h3, h4, h5, h6, li, blockquote, th, td) { unicode-bidi: plaintext; }
.bubble.assistant .content > :first-child { margin-top: 0; }
.bubble.assistant .content > :last-child { margin-bottom: 0; }

.bubble.assistant .content p { margin: 0 0 14px; }

.bubble.assistant .content :is(h3, h4, h5, h6) {
  margin: 22px 0 8px;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
}
.bubble.assistant .content .md-h1 { font-size: 24px; }
.bubble.assistant .content .md-h2 { font-size: 21px; }
.bubble.assistant .content .md-h3 { font-size: 19px; }
.bubble.assistant .content .md-h4 { font-size: 18px; color: var(--text-muted); }

.bubble.assistant .content strong { font-weight: 700; }
.bubble.assistant .content em { font-style: italic; }
.bubble.assistant .content del { color: var(--text-muted); }

/* Links read as text; the accent is only the underline. */
.bubble.assistant .content a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
.bubble.assistant .content a:hover { text-decoration-thickness: 2px; }

.bubble.assistant .content code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bg-raised);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 0.82em;
  unicode-bidi: isolate;
}
.bubble.assistant .content pre {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--bg-row-hover);  /* a breath off Ink; the hairline draws the block */
  direction: ltr;
  text-align: left;
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
}
.bubble.assistant .content pre code {
  padding: 0;
  border-radius: 0;
  background: none;
  font-size: 14px;
  line-height: 1.6;
  white-space: inherit;
}

.bubble.assistant .content :is(ul, ol) { margin: 0 0 14px; padding: 0; padding-inline-start: 1.4em; }
.bubble.assistant .content li { margin: 4px 0; }
.bubble.assistant .content li::marker { color: var(--text-muted); }
.bubble.assistant .content li > :is(ul, ol) { margin: 4px 0 0; }

.bubble.assistant .content blockquote {
  margin: 0 0 14px;
  padding: 2px 0;
  padding-inline-start: 14px;
  border-inline-start: 3px solid var(--accent);
  color: var(--text-muted);
}
.bubble.assistant .content blockquote > :first-child { margin-top: 0; }
.bubble.assistant .content blockquote > :last-child { margin-bottom: 0; }

.bubble.assistant .content hr { margin: 16px 0; border: none; border-top: 1px solid var(--hairline); }

.bubble.assistant .content .md-table { margin: 0 0 14px; overflow-x: auto; }
.bubble.assistant .content table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: normal;
}
.bubble.assistant .content :is(th, td) {
  padding: 6px 10px;
  border-bottom: 1px solid var(--hairline);
  text-align: start;
  vertical-align: top;
}
/* Neutralise the admin-table chrome (filled header, hover, min-widths). */
.bubble.assistant .content th {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border-radius: 0;
  border-bottom-color: var(--hairline-strong);
  white-space: normal;
}
.bubble.assistant .content td { min-width: 0; }
.bubble.assistant .content tbody tr:hover td { background: none; }
.bubble.assistant .content tbody tr:last-child td { border-bottom: none; }
.bubble.assistant .content .md-left { text-align: left; }
.bubble.assistant .content .md-center { text-align: center; }
.bubble.assistant .content .md-right { text-align: right; }

/* 10. Composer
   ------------------------------------------------------------------------ */
/* Quiet footer: page background, aligned to the thread's reading column.
   The thread dissolves into it through a short fade instead of being cut
   by a line. */
.composer-area {
  --measure: 700px;
  position: relative;
  padding-block: 6px max(12px, env(safe-area-inset-bottom));
  padding-inline: max(14px, calc((100% - var(--measure)) / 2));
  background: var(--bg-base);
}
.composer-area::before {
  content: "";
  position: absolute;
  inset: -32px 0 100%;
  background: linear-gradient(to top, var(--bg-base), rgba(21, 23, 19, 0));
  pointer-events: none;
}

/* Field label is announced to screen readers but hidden visually. */
#message-form > label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* One rounded bar: text at the inline-start, then send, then the voice
   button at the inline-end edge (left in RTL). */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 7px;
  padding-inline-start: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--r-bar);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within { border-color: var(--hairline-strong); }
/* Keyboard focus in the field rings the whole bar in accent (1px border + 1px shadow = 2px). */
.composer:has(textarea:focus-visible) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 0;
  min-height: 60px;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
}
/* Where the field can grow with its content, drop the resize grip. */
@supports (field-sizing: content) {
  .composer textarea { field-sizing: content; resize: none; min-height: 40px; }
}
/* The bar itself carries the focus indicator. */
.composer textarea:focus-visible { box-shadow: none; outline: none; }

.composer button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}

/* Send: a muted arrow at rest, accent fill with an Ink arrow once there is something to send. */
.send {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.send:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.send:disabled {
  opacity: 1;
  background: var(--bg-raised);
  border-color: var(--hairline);
  color: var(--text-muted);
}

/* Voice: the prominent accent circle with Ink sound-wave bars. */
.voice {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.voice:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.voice.recording { animation: recording 1.4s ease-out infinite; }

@keyframes recording {
  0% { box-shadow: 0 0 0 0 rgba(168, 242, 58, 0.55); }
  100% { box-shadow: 0 0 0 10px rgba(168, 242, 58, 0); }
}

.composer-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-inline: 14px;
  font-size: 11px;
  color: var(--text-faint);
}
#status { color: var(--text-muted); }


/* 11. Notices & errors
   ------------------------------------------------------------------------ */
/* Domain-move banner: same flat treatment, accent border instead of warn. */
.move-banner {
  margin-block: 12px;
  padding: 2px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  border-inline-start: 2px solid var(--accent);
}
.move-banner p { margin: 0 0 6px; }
.move-banner-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* A split export: one download button per part, each marked once it was saved. */
.export-parts {
  margin-block: 12px;
  padding: 2px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  border-inline-start: 2px solid var(--accent);
}
.export-parts p { margin: 0 0 6px; }
.export-parts ul { margin: 0 0 8px; padding: 0; list-style: none; }
.export-parts li { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.export-part-state { color: var(--text-muted); }

/* No card fill — colored text behind a thin start border, in keeping with
   the flat page. */
.notice {
  margin-block: 12px;
  padding: 2px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--warn-text);
  border-inline-start: 2px solid var(--warn-border);
}

.error-box {
  margin-bottom: 14px;
  padding: 2px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--danger-text);
  border-inline-start: 2px solid var(--danger-border);
}
.error-box p { margin: 0 0 10px; }

.error-text { margin: 0; font-size: 13px; color: var(--danger-text); }

/* 12. Admin panel & tables
   ------------------------------------------------------------------------ */
.admin-panel {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin-inline: auto;
  padding: 24px 20px 28px;
  overflow: auto;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-heading h2 { font-size: 24px; }

#admin-status { font-size: 13px; color: var(--text-muted); }

.add-user-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 20px 0;
  padding: 18px 0;
  border-block: 1px solid var(--hairline);
}
.add-user-form > div { flex: 1; min-width: 160px; }
.add-user-form select { width: 100%; }

.table-scroll {
  margin: 28px 0;
  overflow-x: auto;
  border-radius: var(--r-sm);
}

/* Components above may set their own box-shadow at equal specificity to
   the global focus rule; re-assert the ring so it wins on keyboard focus. */
.primary:focus-visible,
.secondary:focus-visible,
.danger:focus-visible,
.text-button:focus-visible,
.send:focus-visible,
.voice:focus-visible,
.table-scroll:focus-visible {
  box-shadow: var(--ring);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: start;
}

caption {
  padding: 0 2px 12px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  text-align: start;
  color: var(--text);
}

th, td {
  padding: 12px 14px;
  text-align: start;
  border-bottom: 1px solid var(--hairline);
  overflow-wrap: anywhere;
}

th {
  white-space: nowrap;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-raised);
  border-bottom-color: transparent;
}
th:first-child { border-start-start-radius: var(--r-sm); border-end-start-radius: var(--r-sm); }
th:last-child { border-start-end-radius: var(--r-sm); border-end-end-radius: var(--r-sm); }

td { min-width: 100px; color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-row-hover); }
td button { white-space: nowrap; min-height: 38px; padding: 6px 16px; }

/* 13. Desktop layout (≥640px)
   ------------------------------------------------------------------------ */
@media (min-width: 640px) {
  .app { height: 100vh; height: 100dvh; }



  .gate { margin: 72px auto; }
  .gate h2 { font-size: 40px; }

  .thread {
    padding-block: 40px 72px;
    padding-inline: max(40px, calc((100% - var(--measure)) / 2));
  }
  .bubble { margin-bottom: 32px; }
  .bubble + .bubble.user { margin-top: 48px; }
  .empty > .brand { font-size: 64px; }
  .empty h2 { font-size: 38px; }
  .empty p { font-size: 16px; }

  .composer-area {
    padding-block: 8px max(16px, env(safe-area-inset-bottom));
    padding-inline: max(40px, calc((100% - var(--measure)) / 2));
  }

  .admin-panel { padding: 28px 32px 32px; }
}

/* 14. Small-screen tweaks (<640px)
   ------------------------------------------------------------------------ */
@media (max-width: 639px) {
  /* Lock viewport height only while the chat is open, so the composer
     stays pinned above the keyboard. */
  .app:has(.chat:not([hidden])) { height: 100vh; height: 100dvh; }

  .thread { min-height: 100px; }
  .panel-heading { align-items: flex-start; }
  .admin-panel { padding: 16px 16px 20px; }
  .gate { margin: 28px auto; }
}


/* 15. Motion preferences
   ------------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .bubble.streaming .content:empty::after { opacity: 1; }
  .bubble.streaming .search-line::before { animation: none; }
  .voice.recording { box-shadow: 0 0 0 4px var(--accent-tint); }
}


/* 16. Side drawer & slim header
   --------------------------------------------------------------------------
   The signed-in page is a blank sheet: thread, composer, and one hamburger.
   Every action and setting lives in a drawer that slides in from the
   inline-start edge (right in RTL). The start side is also the side where
   off-canvas content can never create horizontal scroll. */

/* Slim bar. Sticky so the hamburger stays reachable when the page itself
   scrolls (admin view on small screens). */
.header {
  position: sticky;
  top: 0;
  z-index: 5;
}

/* Fixed three-column grid: the mark stays dead-center whether or not the
   hamburger is showing. */
.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: 48px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
}
.topbar .menu-toggle { grid-area: 1 / 3; } /* reading end in RTL */
.topbar .brand { grid-area: 1 / 1; justify-self: start; font-size: 20px; } /* usage.md: logo at the reading start (right in Hebrew), 44px column keeps its 0.25x clear space */

/* Ghost circles: hamburger and the drawer's close button. */
.menu-toggle,
.drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
}
.menu-toggle:hover:not(:disabled) { background: var(--bg-raised); color: var(--text); }
.drawer-close:hover:not(:disabled) { background: var(--bg-chip); color: var(--text); }
.menu-toggle[aria-expanded="true"] { color: var(--text); }
.menu-toggle:focus-visible { box-shadow: var(--ring); }

/* Page scroll is locked while the drawer is open. */
html.drawer-open,
html.drawer-open body { overflow: hidden; }

/* Backdrop — --bg-base with alpha. */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(21, 23, 19, 0.72);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.24s ease, visibility 0s linear 0.24s;
  -webkit-tap-highlight-color: transparent;
}
.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.24s ease, visibility 0s;
}

/* The panel. visibility:hidden (delayed until the slide-out ends) keeps the
   closed drawer out of the tab order and away from assistive tech. */
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: min(300px, 85vw);
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-raised);
  border-inline-end: 1px solid var(--hairline);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-100%);
  transition: transform 0.24s ease, opacity 0.24s ease, visibility 0s linear 0.24s;
}
[dir="rtl"] .drawer { transform: translateX(100%); }
.drawer.open,
[dir="rtl"] .drawer.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: transform 0.24s ease, opacity 0.24s ease, visibility 0s;
}
.drawer > * { flex-shrink: 0; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  margin-bottom: 8px;
  padding-inline-start: 12px;
}
.drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}
.drawer-title .brand { font-size: 18px; }

/* Groups are separated by a hairline, nothing heavier. */
.drawer-group { display: flex; flex-direction: column; gap: 2px; padding-block: 8px; }
.drawer-group + .drawer-group { border-top: 1px solid var(--hairline); }
/* A group whose every button is [hidden] (e.g. during MFA) collapses. */
.drawer-group:not(.drawer-model):not(:has(> :not([hidden]))) { display: none; }

/* Menu rows: icon + label, full width. These buttons keep their original
   .secondary / .danger / .text-button classes (JS/HTML contract), so the pill
   chrome is reset here with enough specificity to win over the hover rules. */
.drawer .drawer-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
  text-align: start;
}
.drawer .drawer-item svg { color: var(--text-muted); }
.drawer .drawer-item:hover:not(:disabled) { background: var(--bg-chip); border-color: transparent; color: var(--text); }
/* Same ring as --ring, with the gap matched to the drawer surface. */
.drawer .drawer-item:focus-visible,
.drawer-close:focus-visible { box-shadow: 0 0 0 2px var(--bg-raised), 0 0 0 4px var(--accent); }

.drawer .drawer-item.danger { color: var(--danger-text); }
.drawer .drawer-item.danger svg { color: inherit; }
.drawer .drawer-item.danger:hover:not(:disabled) { background: var(--danger-bg); border-color: transparent; color: var(--danger-text); }

/* Admin row doubles as the way back: label and tint follow aria-expanded. */
.drawer .drawer-item .when-expanded,
.drawer .drawer-item[aria-expanded="true"] .when-collapsed { display: none; }
.drawer .drawer-item[aria-expanded="true"] .when-expanded { display: inline; }
.drawer .drawer-item[aria-expanded="true"] svg { color: var(--accent); }

/* Model row: the ordinary form label above a full-width field. */
.drawer-model { gap: 0; padding: 12px 12px 14px; }
.drawer-model label { margin-bottom: 6px; font-size: 12px; }
.model-select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 14px;
  text-overflow: ellipsis;
  background: var(--bg-base);
}
.model-select:disabled { opacity: 0.55; }

/* Foot: account, exit, and the two small-print lines, pinned to the bottom. */
.drawer-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}
.identity {
  margin: 0;
  padding: 4px 12px 6px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.drawer-foot .privacy,
.drawer-foot .disclaimer {
  margin: 0;
  padding-inline: 12px;
  font-size: 11px;
  line-height: 1.7;
  text-align: start;
  color: var(--text-faint);
}
.drawer-foot .privacy { margin-top: 10px; }
.drawer-foot .disclaimer { margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer.open, .drawer-backdrop, .drawer-backdrop.open { transition: none; }
}

@media print {
  .drawer, .drawer-backdrop, .menu-toggle { display: none !important; }
}

/* 17. MFA choice — pick a second factor
   --------------------------------------------------------------------------
   Shown inside the #mfa gate when no factor is enrolled yet. Two full-width
   rows in the gate column; the pill chrome from section 4 is reset here, the
   same way the drawer rows do it. The passkey row carries a quiet
   "recommended" tag — tint only, no second call-to-action colour. */
.mfa-choice {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* A <p> inside the block, so .gate > p does not reach it. */
#mfa-choice-description,
.mfa-choice > p {
  margin: 0 0 14px;
  text-align: center;
  color: var(--text-muted);
  line-height: var(--leading-hebrew);
}

.mfa-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 14px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--text);
  font-weight: 400;
  text-align: start;
  -webkit-tap-highlight-color: transparent;
}
.mfa-option:hover:not(:disabled) {
  background: var(--bg-chip);
  border-color: var(--hairline-strong);
}
/* Outline + ring come from section 3; the border joins in. */
.mfa-option:focus-visible { border-color: var(--accent); }

.mfa-option svg { color: var(--text-muted); }
.mfa-option:hover:not(:disabled) svg { color: var(--text); }

.mfa-option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.mfa-option-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}
.mfa-option-label {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
}
.mfa-option-hint {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

/* Recommended: a tinted border, an accent icon, and the small tag. */
.mfa-option-recommended { border-color: var(--accent-tint); }
.mfa-option-recommended:hover:not(:disabled) { border-color: var(--accent); }
.mfa-option-recommended svg,
.mfa-option-recommended:hover:not(:disabled) svg { color: var(--accent); }

.mfa-option-tag {
  flex-shrink: 0;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-tint);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.7;
}

/* While the passkey ceremony runs JS sets aria-busy on the pressed row and
   disables both; the busy row stays fully legible. */
.mfa-option[aria-busy="true"]:disabled { opacity: 0.8; }

@media (min-width: 640px) {
  .mfa-choice { gap: 12px; margin-top: 24px; }
  .mfa-option { padding: 16px 18px; }
}

/* 18. Boot splash - shown until the auth state resolves */
.boot {
  display: grid;
  place-items: center;
  min-height: 60vh;
}
.boot .brand { font-size: 30px; animation: boot-pulse 1.6s ease-in-out infinite; }
@keyframes boot-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .boot .brand { animation: none; } }
.boot[hidden] { display: none; }

/* Local-model badge + drawer info row */
/* Local-model download progress: persistent bar above the composer */
.local-progress {
  margin: 0 14px 8px;
  padding: 10px 12px 12px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
}
.local-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.local-progress.ready .local-progress-head { color: var(--text); font-weight: 600; margin-bottom: 0; }
.local-progress.ready .local-progress-track,
.local-progress.ready .local-progress-pct { display: none; }
.local-progress-pct {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.local-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-chip);
  overflow: hidden;
}
.local-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.local-progress[hidden] { display: none; }

.error-detail {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  font-family: ui-monospace, monospace;
  word-break: break-all;
  text-align: left;
}

.local-badge {
  flex-basis: 100%;
  order: -1;
  font-size: 11px;
  color: var(--text-muted);
}
.local-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.local-info .text-button { font-size: 12px; padding: 4px 6px; min-height: 32px; }

/* Chat list (multi-chat) in the drawer */
.drawer-group[hidden] { display: none; }
.drawer-heading { font-size: 0.78rem; color: var(--text-muted); margin: 2px 10px 4px; }
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 34vh; overflow-y: auto; }
.chat-item { display: flex; align-items: center; gap: 2px; }
.chat-open {
  flex: 1; min-width: 0; text-align: start; font: inherit; font-size: 0.9rem;
  background: none; border: 1px solid transparent; border-radius: 10px;
  padding: 8px 10px 8px 22px; color: var(--text); cursor: pointer; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-open:hover:not(:disabled) { background: var(--bg-chip); }
.chat-open.active { background: var(--bg-chip); border-color: var(--hairline); font-weight: 600; box-shadow: inset -3px 0 0 var(--accent); }
.chat-open:disabled { opacity: 0.6; cursor: default; }
.chat-delete {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 8px; padding: 6px; min-width: 44px;
  color: var(--text-muted); cursor: pointer;
}
.chat-delete:hover:not(:disabled) { color: var(--danger-text); background: var(--danger-bg); }
.chat-delete:disabled { opacity: 0.6; cursor: default; }

.chat-open:focus-visible, .chat-delete:focus-visible { outline-offset: -2px; }
.chat-list-status { margin: 4px 10px 0; font-size: 0.8rem; color: var(--text-muted); }

/* Account logout choice: native modal focus containment, system font, touch targets. */
#logout-choice { max-width: min(28rem, 90vw); font-family: system-ui, sans-serif; border-radius: 12px; padding: 24px; }
#logout-choice::backdrop { background: rgb(0 0 0 / 50%); }
#logout-choice button { min-width: 44px; min-height: 44px; margin: 4px; font: inherit; }

#file-choice { max-width: min(32rem, 90vw); }
#file-choice input, #file-choice select, #file-choice button, #passkey-menu { min-height: 44px; }
#file-choice label, #file-choice input, #file-choice select { display: block; width: 100%; margin-block: .5rem; }

/* ---------- PDF annotation: direction A chrome (dock + capsule + sheet) ---------- */
#annotate-stage { position: relative; width: 100%; flex: none; overflow: hidden; background: #fff; touch-action: none; border-radius: 4px; }
#annotate-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#annotate-stage .annotate-text-editor { position: absolute; z-index: 3; box-sizing: border-box; width: 12em; max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; resize: none; font-family: system-ui, sans-serif; line-height: 1.2; text-align: right; background: #F2F1EB; color: #151713; border: none; outline: 2px solid #A8F23A; border-radius: 4px; padding: 0; }
#annotate-stage-wrapper { min-width: 0; }
#annotate-scroll { overflow: auto; height: calc(100dvh - 290px); min-height: 280px; direction: ltr; overscroll-behavior: contain; padding-bottom: 150px; box-sizing: border-box; }
.annotate-chrome { position: fixed; z-index: 30; display: flex; align-items: center; gap: 0.5rem; background: #151713; color: #F2F1EB; border: 1px solid #677064; border-radius: 999px; padding: 0.3rem 0.5rem; box-shadow: 0 4px 18px rgba(0,0,0,0.35); }
.annotate-chrome[hidden] { display: none; }
.annotate-chrome-btn[hidden] { display: none; }
#annotate-dock { right: 12px; z-index: 32; }
#annotate-capsule { right: 50%; transform: translateX(50%); }
#annotate-popover { right: 12px; flex-direction: column; align-items: stretch; gap: 0.4rem; border-radius: 18px; z-index: 34; }
#annotate-selbubble { right: 50%; transform: translateX(50%); z-index: 34; }
#annotate-toast { right: 50%; transform: translateX(50%); z-index: 36; border-radius: 14px; padding: 0.45rem 0.8rem; max-width: min(88vw, 420px); }
#annotate-editbar { right: 0; left: 0; z-index: 40; border-radius: 0; border-right: none; border-left: none; justify-content: center; gap: 0.5rem; padding: 0.4rem 0.5rem; }
#annotate-draft-input { flex: 1; min-width: 0; min-height: 44px; border: none; outline: none; background: transparent; color: #F2F1EB; font-size: 16px; font-family: inherit; text-align: right; padding: 0 0.3rem; }
#annotate-draft-input::placeholder { color: #677064; }
#annotate-scrim { position: fixed; inset: 0; z-index: 44; background: rgba(0,0,0,0.35); }
#annotate-scrim[hidden] { display: none; }
#annotate-sheet { right: 0; left: 0; z-index: 45; flex-direction: column; align-items: stretch; border-radius: 18px 18px 0 0; border-bottom: none; padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom, 0px)); max-height: 50dvh; overflow-y: auto; }
#annotate-sheet[hidden] { display: none; }
.annotate-sheet-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.annotate-tool-btn { min-height: 52px; border-radius: 14px; border: 1px solid #677064; background: transparent; color: #F2F1EB; font-size: 1.05rem; cursor: pointer; }
.annotate-tool-btn:active { outline: 2px solid #A8F23A; }
.annotate-sheet-row { display: flex; align-items: center; justify-content: center; gap: 0.9rem; margin-top: 0.8rem; }
.annotate-chrome-btn { min-width: 48px; min-height: 48px; border: none; background: transparent; color: #F2F1EB; font-size: 1.05rem; border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0 0.55rem; }
.annotate-chrome-btn:disabled { opacity: 0.4; cursor: default; }
.annotate-chip { font-size: 1.1rem; font-weight: 600; }
#annotate-toolchip[data-tool="pen"], #annotate-toolchip[data-tool="marker"], #annotate-toolchip[data-tool="text"] { outline: 2px solid #A8F23A; outline-offset: -2px; }
.annotate-save { outline: 1px solid #677064; }
.annotate-save:not(:disabled) { color: #A8F23A; }
#annotate-page-indicator { min-width: 3.5rem; text-align: center; font-size: 1rem; font-variant-numeric: tabular-nums; }
.annotate-pop-row { display: flex; gap: 0.6rem; justify-content: center; }
.annotate-color { width: 44px; height: 44px; border-radius: 50%; border: 2px solid #677064; background: var(--c, transparent); cursor: pointer; padding: 0; }
.annotate-color[aria-pressed="true"] { outline: 2px solid #A8F23A; outline-offset: 2px; }
.annotate-color[data-color="#A8F23A"] { background: #A8F23A; }
.annotate-color[data-color="#151713"] { background: #151713; }
.annotate-color[data-color="#d23c3c"] { background: #d23c3c; }
.annotate-color[data-color="#2b5fd9"] { background: #2b5fd9; }
.annotate-preset { min-width: 56px; min-height: 44px; border-radius: 12px; border: 1px solid #677064; background: transparent; color: #F2F1EB; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0 0.6rem; }
.annotate-preset[aria-pressed="true"] { outline: 2px solid #A8F23A; outline-offset: -2px; }
.annotate-preset-line { display: block; width: 26px; background: #F2F1EB; border-radius: 4px; }
.annotate-note { font-size: 0.85rem; opacity: 0.85; margin: 0; text-align: center; }
#annotate-zoom-value { min-width: 3rem; text-align: center; font-variant-numeric: tabular-nums; }
#pdf-annotate-editor { position: relative; }
#pdf-annotate-editor button { touch-action: manipulation; }

/* Google Search grounding toggle (drawer, under model select). Off by default. */
.grounding-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-muted);
}
.grounding-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.grounding-note {
  margin: 4px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.conf-switch {
  grid-area: 1 / 2;
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}
.conf-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.conf-switch-track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--border, rgba(242, 241, 235, 0.2));
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.conf-switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text, #F2F1EB);
  transition: transform 0.15s ease;
}
.conf-switch input:checked + .conf-switch-track {
  background: var(--accent);
}
.conf-switch input:checked + .conf-switch-track::after {
  transform: translateX(-20px);
  background: var(--ink, #151713);
}
.conf-switch input:focus-visible + .conf-switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.conf-switch input:disabled + .conf-switch-track {
  opacity: 0.5;
}
.conf-switch input:disabled ~ .conf-switch-text,
.conf-switch:has(input:disabled) {
  cursor: default;
}
.conf-note {
  margin: 4px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--text-muted);
}
.conf-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  color: var(--accent);
  white-space: nowrap;
}
.chat-lock {
  display: inline-flex;
  margin-inline-end: 5px;
  color: var(--accent);
  vertical-align: baseline;
}
.grounding-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border, rgba(242, 241, 235, 0.12));
  font-size: 0.78rem;
  color: var(--text-muted);
}
.grounding-sources a { color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.grounding-sources a:hover { text-decoration: underline; }

/* Inline citation chips (NotebookLM-style) + source card */
.cit-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  margin: 0 2px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  vertical-align: super;
}
.cit-chip::after { content: attr(data-n); }
.cit-chip:hover, .cit-chip:focus-visible { background: var(--accent-tint); outline: none; }
.cit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}
.cit-card {
  background: var(--bg-raised, #1d201c);
  color: var(--text, #F2F1EB);
  width: 100%;
  max-width: 560px;
  max-height: 70vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.cit-quote {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-muted);
  border-inline-start: 3px solid var(--accent);
  padding-inline-start: 10px;
}
.cit-sources { display: flex; flex-direction: column; gap: 8px; }
.cit-sources a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  border: 1px solid rgba(242, 241, 235, 0.14);
  border-radius: 10px;
}
.cit-sources a:hover { background: var(--accent-tint); }
.cit-close { align-self: center; min-width: 120px; }

/* ---------- live voice session (Gemini 3.8 Live) ---------- */
.live-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #151713;
  color: #F2F1EB;
  padding: max(env(safe-area-inset-top), 12px) 16px max(env(safe-area-inset-bottom), 16px);
  direction: rtl;
}
.live-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.live-title h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.live-note { margin: 2px 0 0; font-size: 0.78rem; color: #677064; }
.live-timer { font-variant-numeric: tabular-nums; color: #677064; font-size: 0.9rem; padding-top: 4px; }
.live-status {
  margin: 18px 0 10px;
  text-align: center;
  font-size: 1rem;
  color: #A8F23A;
  min-height: 1.4em;
}
.live-media-out {
  margin: 0 auto 10px;
  max-width: min(92vw, 480px);
  border-radius: 14px;
  overflow: hidden;
}
.live-media-out img { display: block; width: 100%; height: auto; }
.live-media-out video { display: block; max-width: 100%; max-height: 52vh; width: auto; height: auto; margin: 0 auto; background: #000; }
.live-cam-preview {
  position: absolute;
  bottom: 96px;
  left: 16px;
  width: 108px;
  border-radius: 12px;
  border: 1px solid #677064;
  background: #000;
}
.live-transcript {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 2px;
  -webkit-overflow-scrolling: touch;
}
.live-line { margin: 0; font-size: 0.95rem; line-height: 1.5; }
.live-line .live-who {
  display: block;
  font-size: 0.72rem;
  color: #677064;
  margin-bottom: 1px;
}
.live-line.model { color: #F2F1EB; }
.live-line.user { color: #b9bdb4; }
.live-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  padding-top: 12px;
}
.live-ctl {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid #677064;
  background: transparent;
  color: #F2F1EB;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.live-ctl:active { background: #1f221d; }
.live-ctl.off { color: #677064; }
.live-ctl.live-end {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
  width: 62px;
  height: 62px;
}
body.live-open { overflow: hidden; }

/* ---------- confidential mode: unmistakable visual identity ---------- */
/* Deep slate-navy canvas instead of the Ink green-black, so the mode reads
   differently at a glance, plus a subtle diagonal "Confidential" watermark. */
body.conf-mode {
  --bg-base: #101820;
}
body.conf-mode::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360'%3E%3Ctext x='180' y='180' fill='%23F2F1EB' fill-opacity='0.055' font-family='system-ui, sans-serif' font-size='30' letter-spacing='2' transform='rotate(-30 180 180)' text-anchor='middle'%3EConfidential%3C/text%3E%3C/svg%3E");
  background-repeat: repeat;
}

/* Confidential-lane transcription panel */
.tr-panel { max-width: min(92vw, 560px); margin: 8vh auto 0; background: var(--bg-base, #151713); border: 1px solid #677064; border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.tr-note { font-size: 0.8rem; color: #677064; margin: 0; }
.tr-elapsed { font-size: 0.78rem; color: #677064; min-height: 1em; margin-top: 2px; }
.tr-picked { font-size: 0.85rem; }
.tr-label { font-size: 0.85rem; }
.tr-panel select, .tr-panel textarea { background: transparent; color: inherit; border: 1px solid #677064; border-radius: 10px; padding: 8px; font: inherit; }
.tr-panel progress { width: 100%; }
.tr-block h3 { margin: 0 0 4px; font-size: 0.95rem; }
.tr-text { white-space: pre-wrap; background: rgba(255,255,255,0.04); border-radius: 10px; padding: 10px; }
.tr-meta, .tr-wer { font-size: 0.78rem; color: #677064; }
.tr-open { overflow: hidden; }

/* transcript reading view: the transcript gets the whole screen, not a scroll box */
.tr-view-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; max-width: 720px; width: 100%; margin: 0 auto; }
.tr-view-name { margin: 0; font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.tr-view-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.85rem; color: #9aa090; }
.tr-badge { border: 1px solid #677064; border-radius: 999px; padding: 2px 10px; font-size: 0.75rem; color: #b9c0b2; }
.tr-view-actions { display: flex; gap: 8px; }
.tr-view-actions .secondary { flex: 1; padding: 10px; }
.tr-danger { color: #e08c8c; }
.tr-warn { color: #e0b15c; font-size: 0.85rem; }
.tr-view-body { flex: 1; min-height: 0; overflow-y: auto; font-size: 1.06rem; line-height: 1.95; padding: 6px 2px 48px; }
.tr-view-body .tr-text { background: none; padding: 0; }
.tr-view-body .tr-block + .tr-block { margin-top: 28px; }
.tr-view-body h3 { margin: 0 0 8px; font-size: 1rem; }
.tr-view-open { overflow: hidden; }

.tr-speaker { font-weight: 700; color: var(--accent, #4a6fa5); margin: 0.9em 0 0.15em; font-size: 0.92em; }
.tr-turn { margin: 0.15em 0 0.6em; }

/* Engine switch on the transcription screen (preview) */
.tr-engine { display: flex; gap: 0.6rem; margin: 0.25rem 0 0.75rem; }
.tr-engine-btn { flex: 1; min-height: 4.4rem; border-radius: 0.9rem; border: 2px solid var(--bg-chip, #677064);
  background: var(--bg-raised, #2D312C); color: var(--text, #F2F1EB); font-size: 1.25rem; font-weight: 700;
  line-height: 1.2; padding: 0.5rem 0.6rem; cursor: pointer; }
.tr-engine-btn:disabled { opacity: 0.5; cursor: default; }
.tr-engine-btn .tr-engine-sub { display: block; font-size: 0.8rem; font-weight: 400; color: var(--text-muted, #A5ADA2); margin-top: 0.25rem; }
.tr-engine-btn.on { border-color: var(--accent, #A8F23A); background: color-mix(in srgb, var(--accent, #A8F23A) 16%, var(--bg-raised, #2D312C)); }
.tr-engine-btn.on .tr-engine-sub { color: var(--text, #F2F1EB); }
#tr-model-row:not([hidden]) { display: flex; flex-direction: column; gap: 10px; }
