/* ============================================================
   QED Vault — the one stylesheet.
   QED palette (navy #011e30 ink, yellow #ffd166 accent, off-white ground)
   worn with an Apple-like temperament: generous space, large soft radii,
   barely-there shadows, and translucent chrome. Motion is two curves: --ease
   (calm, for movement and state) and --ease-out (entrances); durations are
   --dur-fast / --dur. Every animation is reduced-motion aware. Tokens are the
   source of truth; components read them.
   ============================================================ */

:root {
  /* ---- QED palette ---- */
  --navy:        #011e30;  /* primary dark surface, strong headings */
  --navy-900:    #0a4563;  /* body copy on light */
  --navy-300:    #155b7d;  /* muted labels, captions */
  --ink:         #0d1b2a;  /* default text */
  --cyan:        #c6e1f3;  /* secondary copy on navy */
  --yellow:      #ffd166;  /* accent: primary action fill, highlights */
  --yellow-900:  #ffc336;  /* accent, darker step: borders, rules */
  --bg:          #f7f7f7;  /* the page ground */
  --surface:     #ffffff;  /* cards, panels, bubbles */
  --surface-2:   #f2f3f5;  /* insets, hover fills */
  --line:        #e5e7eb;  /* hairlines, card borders */
  --line-2:      #d9d9d9;  /* input borders */
  --danger:      #dc2626;
  --danger-bg:   #fdecec;
  --go:          #12805a;  /* ready / success */
  --go-bg:       #e6f7f0;
  --wait:        #b8841f;  /* processing */
  --wait-bg:     #faf1df;

  /* ---- Type ---- */
  --f-display: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-body:    "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono:    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --text-xs:  0.75rem;    /* 12 */
  --text-sm:  0.8125rem;  /* 13 */
  --text-md:  0.875rem;   /* 14 */
  --text-base:0.9375rem;  /* 15 */
  --text-lg:  1.0625rem;  /* 17 */
  --text-xl:  1.375rem;   /* 22 */
  --text-2xl: 1.75rem;    /* 28 */
  --text-3xl: 2.25rem;    /* 36 */

  --w-medium: 500;
  --w-semi:   600;
  --w-bold:   700;
  --w-black:  800;
  --lh-tight: 1.15;
  --lh-body:  1.6;

  /* ---- Space (4px grid) ---- */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* ---- Radii ---- */
  --r-sm: 8px;  --r-md: 12px;  --r-lg: 16px;  --r-xl: 22px;  --r-pill: 980px;

  /* ---- Shadows — soft, low, Apple-like ---- */
  --shadow-1: 0 1px 2px rgba(1, 30, 48, 0.05), 0 8px 24px -18px rgba(1, 30, 48, 0.28);
  --shadow-2: 0 2px 8px rgba(1, 30, 48, 0.06), 0 24px 60px -30px rgba(1, 30, 48, 0.34);
  --shadow-pop: 0 12px 40px -12px rgba(1, 30, 48, 0.30);

  /* ---- Motion — one calm easing ---- */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);  /* strong ease-out for entrances */
  --dur-fast: 0.14s;
  --dur: 0.24s;

  --sidebar-w: 288px;
  --measure: 46rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }  /* a class's display must not defeat the attribute */

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--f-body);
  font-size: var(--text-base);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { font-family: var(--f-display); line-height: var(--lh-tight); color: var(--navy); }
a { color: var(--navy-900); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--yellow-900); outline-offset: 2px; border-radius: var(--r-sm); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 42px; padding: 0 var(--s-5); border: 1px solid transparent; border-radius: var(--r-md);
  font-size: var(--text-md); font-weight: var(--w-semi); color: var(--ink);
  background: var(--surface); transition: transform var(--dur-fast) var(--ease),
    background var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-solid { background: var(--navy); color: #fff; }
.btn-solid:hover { background: #012a44; }
.btn-accent { background: var(--yellow); color: var(--navy); border-color: var(--yellow-900); }
.btn-accent:hover { background: var(--yellow-900); }
.btn-ghost { background: transparent; border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line-2); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { height: 34px; padding: 0 var(--s-3); font-size: var(--text-sm); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   Forms
   ============================================================ */
label { display: block; font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300); margin-bottom: var(--s-2); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=search], input[type=tel], textarea, select {
  width: 100%; padding: var(--s-3) var(--s-4); font: inherit; font-size: var(--text-base);
  color: var(--ink); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-md); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea { resize: vertical; line-height: var(--lh-body); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--navy-300); box-shadow: 0 0 0 3px rgba(21, 91, 125, 0.14);
}
.field { margin-bottom: var(--s-5); }
.field-errors, .errorlist { list-style: none; color: var(--danger); font-size: var(--text-sm); margin-top: var(--s-2); }
.hint { font-size: var(--text-sm); color: var(--navy-300); margin-top: var(--s-2); }

/* ============================================================
   Auth gate (login / signup)
   ============================================================ */
.gate { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.gate-hero {
  background: linear-gradient(160deg, var(--navy) 0%, #012a44 100%);
  color: #fff; padding: var(--s-12) var(--s-10); display: flex; flex-direction: column; justify-content: center; gap: var(--s-5);
}
.gate-hero .brand { color: #fff; }
.gate-hero h1 { color: #fff; font-size: var(--text-3xl); font-weight: var(--w-black); }
.gate-hero .accent-word { color: var(--yellow); }
.gate-hero p { color: var(--cyan); font-size: var(--text-lg); max-width: 34ch; }
.gate-kicker { font-family: var(--f-mono); text-transform: uppercase; letter-spacing: 0.14em; font-size: var(--text-xs); color: var(--yellow); }
.gate-form { display: flex; flex-direction: column; justify-content: center; padding: var(--s-12) var(--s-10); }
.gate-form .inner { width: 100%; max-width: 380px; margin: 0 auto; }
.gate-form h2 { font-size: var(--text-2xl); margin-bottom: var(--s-6); }
.social-row { display: flex; flex-direction: column; gap: var(--s-3); }
.btn-social { border: 1px solid var(--line-2); background: var(--surface); font-weight: var(--w-semi); }
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--navy-300); font-size: var(--text-sm); margin: var(--s-5) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.gate-alt { margin-top: var(--s-5); font-size: var(--text-md); color: var(--navy-300); }
@media (max-width: 820px) { .gate { grid-template-columns: 1fr; } .gate-hero { display: none; } }

/* ============================================================
   App shell — sidebar + main
   ============================================================ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; overflow: hidden; }

.sidebar {
  background: rgba(247, 247, 247, 0.86); backdrop-filter: saturate(1.4) blur(18px);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: var(--s-5) var(--s-5) var(--s-3); }
.brand { display: inline-flex; align-items: center; gap: var(--s-2); font-family: var(--f-display); font-weight: var(--w-black); font-size: var(--text-lg); color: var(--navy); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--yellow); color: var(--navy); display: grid; place-items: center; font-weight: var(--w-black); font-size: 14px; border: 1px solid var(--yellow-900); }
.sidebar-new { padding: 0 var(--s-4) var(--s-3); }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: var(--s-2) var(--s-3); min-height: 0; }
.side-label { font-size: var(--text-xs); font-weight: var(--w-bold); text-transform: uppercase; letter-spacing: 0.08em; color: var(--navy-300); padding: var(--s-3) var(--s-3) var(--s-2); }
.conv-link {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  padding: var(--s-3) var(--s-3); border-radius: var(--r-md); color: var(--ink); font-size: var(--text-md);
  transition: background var(--dur-fast) var(--ease);
}
.conv-link:hover { background: var(--surface-2); text-decoration: none; }
.conv-link.active { background: var(--surface); box-shadow: var(--shadow-1); font-weight: var(--w-semi); }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
/* Stretch the title's hit target over the whole row so the padding and gaps click
   through to the chat; the delete control is raised above this overlay below. */
.conv-title::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.conv-del { position: relative; z-index: 1; flex: none; opacity: 0; width: 28px; height: 28px; display: grid; place-items: center; color: var(--navy-300); background: none; border: none; padding: 0; border-radius: var(--r-sm); font-size: var(--text-lg); line-height: 1; }
.conv-link:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger); background: var(--danger-bg); }
.sidebar-foot { border-top: 1px solid var(--line); padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.foot-links { display: flex; gap: var(--s-2); }
.foot-links .btn { flex: 1; }
.foot-user { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.sidebar-foot .who { font-size: var(--text-sm); color: var(--navy-300); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The "more" menu: anchored to its trigger, scaling up from it. */
.foot-menu { position: relative; }
.foot-menu .icon-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--navy); }
.menu {
  position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 30; min-width: 190px;
  padding: var(--s-1); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-md); box-shadow: var(--shadow-2);
  transform-origin: bottom right; animation: menu-in 160ms var(--ease);
}
.menu form { margin: 0; }
.menu-item {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--s-2);
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); border: none; background: none;
  font-size: var(--text-md); color: var(--ink); text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item svg { color: var(--navy-300); flex: none; }
.menu-item-danger:hover { background: var(--danger-bg); color: var(--danger); }
@keyframes menu-in { from { opacity: 0; transform: scale(0.96) translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .menu { animation: fade-in var(--dur) ease; } }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; background: var(--surface); }
/* Narrow viewports collapse the shell into a drawer + top bar; the full
   responsive layer lives in one block at the end of this file so its overrides
   win over the component defaults above. */
.topbar { height: 58px; flex: none; display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-6); background: rgba(255,255,255,0.72); backdrop-filter: saturate(1.4) blur(16px); box-shadow: 0 1px 0 rgba(1,30,48,0.05), 0 10px 16px -16px rgba(1,30,48,0.24); }
.topbar h1 { font-size: var(--text-lg); font-weight: var(--w-bold); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: var(--s-1); padding: 3px var(--s-3); border-radius: var(--r-pill); font-size: var(--text-xs); font-weight: var(--w-semi); white-space: nowrap; background: var(--surface-2); color: var(--navy-300); border: 1px solid var(--line); }
.chip-accent { background: var(--yellow); color: var(--navy); border-color: var(--yellow-900); }
.grow { flex: 1; }

/* ============================================================
   Chat thread
   ============================================================ */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread-inner { max-width: var(--measure); margin: 0 auto; padding: var(--s-8) var(--s-6) var(--s-12); display: flex; flex-direction: column; gap: var(--s-8); }
.turn { display: flex; gap: var(--s-4); }
.turn .avatar { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: var(--text-sm); font-weight: var(--w-bold); }
.turn.user .avatar { background: var(--navy); color: #fff; }
.turn.assistant .avatar { background: var(--yellow); color: var(--navy); border: 1px solid var(--yellow-900); }
.turn .body { flex: 1; min-width: 0; padding-top: 3px; }
.turn .role { font-size: var(--text-sm); font-weight: var(--w-bold); color: var(--navy-300); margin-bottom: var(--s-1); }
.bubble { font-size: var(--text-lg); line-height: var(--lh-body); color: var(--ink); }
.turn-attachments { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s-2); margin-bottom: var(--s-3); }
.turn-attachment { display: block; width: 128px; height: 128px; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line-2); background: var(--surface-2); transition: border-color var(--dur-fast) var(--ease); }
.turn-attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (hover: hover) and (pointer: fine) { .turn-attachment:hover { border-color: var(--navy-300); } }
.turn-file { display: inline-flex; align-items: center; gap: var(--s-2); max-width: 240px; height: 32px; padding: 0 var(--s-3); border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--surface-2); font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300); }
.turn-file svg { flex: none; }
.turn-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: var(--s-3) 0; }
.bubble ul, .bubble ol { margin: var(--s-3) 0; padding-left: var(--s-6); }
.bubble li { margin: var(--s-1) 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: var(--s-5) 0 var(--s-3); }
.bubble pre { background: var(--navy); color: #eaf2f8; padding: var(--s-4); border-radius: var(--r-md); overflow-x: auto; margin: var(--s-3) 0; font-family: var(--f-mono); font-size: var(--text-md); }
.bubble code { font-family: var(--f-mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--navy-900); text-decoration: underline; }
.bubble blockquote { border-left: 3px solid var(--yellow); padding-left: var(--s-4); color: var(--navy-300); margin: var(--s-3) 0; }
.bubble table { border-collapse: collapse; margin: var(--s-3) 0; font-size: var(--text-md); display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: var(--s-2) var(--s-3); text-align: left; }
.bubble th { background: var(--surface-2); font-weight: var(--w-semi); color: var(--navy); }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: var(--s-5) 0; }
.cursor::after { content: "▋"; color: var(--navy-300); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.sources { margin-top: var(--s-4); border-top: 1px dashed var(--line-2); padding-top: var(--s-3); }
.sources-label { font-size: var(--text-xs); font-weight: var(--w-bold); text-transform: uppercase; letter-spacing: 0.08em; color: var(--navy-300); margin-bottom: var(--s-2); }
/* Sources: a wrapping row of compact numbered pills; clicking one opens a single
   shared detail panel below (one open at a time), height-capped so the block can
   never outgrow a page no matter how many sources or how long the snippets. */
.source-chips { display: flex; flex-flow: row wrap; gap: var(--s-2); align-items: flex-start; }
.source-chip { display: inline-flex; align-items: center; gap: var(--s-2); max-width: 16rem; padding: var(--s-1) var(--s-3); border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); font-size: var(--text-sm); color: var(--ink); cursor: pointer; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.source-chip:active { transform: scale(0.98); }
.source-chip[aria-expanded="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.source-chip[aria-expanded="true"] .n { background: #fff; color: var(--navy); }
.source-chip .ns { flex: none; display: inline-flex; gap: 3px; }
.source-chip .doc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-chip .n, .source-row .n { flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: var(--w-bold); }
.source-chip .more { flex: none; align-self: center; font-size: 11px; font-weight: var(--w-bold); color: var(--navy-300); }
.source-chip[aria-expanded="true"] .more { color: rgba(255, 255, 255, 0.85); }
.source-panels { max-height: 46vh; overflow-y: auto; }
.source-detail { display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-3); padding: var(--s-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.source-detail[hidden] { display: none; }
.source-row { display: flex; align-items: flex-start; gap: var(--s-2); font-size: var(--text-sm); line-height: 1.5; }
.source-row .loc { flex: none; padding: 1px var(--s-2); border-radius: var(--r-sm); background: var(--wait-bg); color: var(--wait); font-size: var(--text-xs); font-weight: var(--w-semi); white-space: nowrap; }
.source-row a.loc { text-decoration: none; cursor: pointer; }
.source-row a.loc:hover { text-decoration: underline; }
.source-row .snip { color: var(--navy-300); min-width: 0; }
@media (hover: hover) and (pointer: fine) { .source-chip:hover { background: var(--surface); border-color: var(--line-2); } }
.turn-error { color: var(--danger); background: var(--danger-bg); border: 1px solid #f4c9c9; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-size: var(--text-md); }

/* Retrieval steps: a collapsible thinking trace */
.steps { margin-bottom: var(--s-3); }
.steps-toggle { display: none; align-items: center; gap: var(--s-2); width: 100%; padding: 0; background: none; border: none; font: inherit; font-size: var(--text-sm); color: var(--navy-300); text-align: left; cursor: pointer; }
.steps[data-done] .steps-toggle { display: inline-flex; }
.steps-chevron { flex: none; font-size: var(--text-md); line-height: 1; transition: transform var(--dur) var(--ease); }
.steps:not([data-collapsed]) .steps-chevron { transform: rotate(90deg); }
.steps-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps-list { display: grid; grid-template-rows: 1fr; transition: grid-template-rows var(--dur) var(--ease); }
.steps[data-collapsed] .steps-list { grid-template-rows: 0fr; }
.steps-inner { display: flex; flex-direction: column; gap: var(--s-1); min-height: 0; overflow: hidden; }
.steps[data-done] .steps-inner { padding-top: var(--s-2); }
.step { position: relative; display: flex; align-items: center; gap: var(--s-2); font-size: var(--text-sm); color: var(--navy-300); transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out); }
@starting-style { .step { opacity: 0; transform: translateY(6px); } }
.step:not(:last-child)::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: -4px; width: 2px; background: var(--line); }
.step-mark { flex: none; position: relative; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-2); }
.step[data-state="active"] .step-mark { border-top-color: var(--wait); animation: spin 0.7s linear infinite; }
.step[data-state="done"] .step-mark { border-color: var(--go); background: var(--go-bg); }
.step-mark::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; font-weight: var(--w-bold); color: var(--go); transform: scale(0.5); opacity: 0; transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out); }
.step[data-state="done"] .step-mark::after { transform: scale(1); opacity: 1; }
.step[data-state="done"] .step-label { color: var(--navy-900); }
.step-detail { color: var(--navy-300); font-size: var(--text-xs); }

/* Turn + source-chip entrances (live turns only; server-rendered history stays static) */
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }
.turn.is-new { animation: rise-in var(--dur) var(--ease-out) both; }
.turn.is-new .source-chip { animation: rise-in var(--dur) var(--ease-out) both; }
.turn.is-new .source-chip:nth-child(2) { animation-delay: 40ms; }
.turn.is-new .source-chip:nth-child(3) { animation-delay: 80ms; }
.turn.is-new .source-chip:nth-child(4) { animation-delay: 120ms; }
.turn.is-new .source-chip:nth-child(n+5) { animation-delay: 160ms; }

/* First-token skeleton — a shimmer in place of a lonely caret while the model starts */
.skeleton { display: flex; flex-direction: column; gap: var(--s-2); padding-top: var(--s-1); }
.skeleton span { height: 12px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.skeleton span:nth-child(1) { width: 92%; }
.skeleton span:nth-child(2) { width: 78%; }
.skeleton span:nth-child(3) { width: 56%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Regenerate the last answer */
.turn-foot { margin-top: var(--s-3); }
.retry-btn { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3); background: none; border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--navy-300); font-size: var(--text-sm); font-weight: var(--w-medium); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.retry-btn:active { transform: scale(0.97); }
.retry-btn svg { width: 14px; height: 14px; }
@media (hover: hover) and (pointer: fine) { .retry-btn:hover { background: var(--surface-2); color: var(--navy); border-color: var(--line-2); } }

/* Empty state */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: var(--s-4); padding: var(--s-8); }
.empty .mark { width: 64px; height: 64px; border-radius: 18px; background: var(--yellow); color: var(--navy); display: grid; place-items: center; font-size: 30px; font-weight: var(--w-black); border: 1px solid var(--yellow-900); box-shadow: var(--shadow-2); }
.empty h2 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
.empty p { color: var(--navy-300); max-width: 40ch; }
/* QED mark (the qed.tech logo) fills the brand tiles instead of a letter. Placed
   after every tile's base rule so its `background` shorthand cannot reset the image. */
.brand-mark, .turn.assistant .avatar, .empty .mark {
  background-image: url("qed-mark.6c54b6ea9d6a.svg"); background-repeat: no-repeat;
  background-position: center; color: transparent;
}
.brand-mark, .turn.assistant .avatar { background-size: 58%; }
.empty .mark { background-size: 54%; }

/* ============================================================
   Composer
   ============================================================ */
.composer { flex: none; padding: var(--s-4) var(--s-6) var(--s-6); border-top: 1px solid var(--line); background: var(--surface); }
.composer-inner { max-width: var(--measure); margin: 0 auto; }
.composer-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
/* The deep-research toggle is a real <button> chip in the control row: quiet by
   default (plain .chip), lit with .chip-accent (added in app.js) when engaged. */
#deep-toggle { cursor: pointer; font-family: inherit; }
#deep-toggle:hover { border-color: var(--line-2); color: var(--navy); }
#deep-toggle[aria-pressed="true"]:hover { background: var(--yellow-900); }
#deep-toggle .chip-ico { flex: none; opacity: 0.85; }
.model-select { display: inline-flex; align-items: center; gap: var(--s-2); }
.model-select select { width: auto; height: 36px; padding: 0 var(--s-8) 0 var(--s-3); font-size: var(--text-md); font-weight: var(--w-semi); border-radius: var(--r-pill); background: var(--surface-2); border-color: var(--line); appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23155b7d' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--s-3) center; }
.composer-box { display: flex; align-items: flex-end; gap: var(--s-3); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-xl); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5); box-shadow: var(--shadow-1); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.composer-box:focus-within { border-color: var(--navy-300); box-shadow: 0 0 0 3px rgba(21,91,125,0.12); }
.composer-box textarea { border: none; background: none; padding: var(--s-2) 0; max-height: 200px; box-shadow: none; font-size: var(--text-lg); }
.composer-box textarea:focus { box-shadow: none; }
.send-btn { flex: none; width: 42px; height: 42px; padding: 0; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; border: none; transition: background var(--dur) var(--ease), transform var(--dur-fast) var(--ease); }
.send-btn:hover { background: #012a44; }
.send-btn:disabled { background: var(--line-2); color: var(--surface); }
.send-btn:active { transform: scale(0.94); }
.send-btn .icon-stop { display: none; }
.send-btn.busy { background: var(--navy); }
.send-btn.busy:hover { background: #012a44; }
.attach-btn { flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; background: none; color: var(--navy-300); display: grid; place-items: center; border: none; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.attach-btn:hover { background: var(--surface-2); color: var(--navy); }
.attach-btn:disabled { color: var(--line-2); }
.chat-docs { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-2); list-style: none; padding: 0; }
.chat-docs:empty { display: none; }
.chat-doc { display: inline-flex; align-items: center; gap: var(--s-2); max-width: 260px; padding: 3px var(--s-2) 3px var(--s-3); border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); font-size: var(--text-xs); }
.chat-doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--w-semi); color: var(--navy-300); }
.chat-doc-badge { flex: none; }
.chat-doc-x { flex: none; width: 18px; height: 18px; padding: 0; border: none; background: none; color: var(--navy-300); display: grid; place-items: center; border-radius: 50%; }
.chat-doc-x:hover { background: var(--line); color: var(--navy); }
.chat-doc-progress { flex: none; width: 48px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.chat-doc-progress-fill { display: block; height: 100%; width: 0; background: var(--navy-300); border-radius: 2px; transition: width var(--dur) var(--ease); }
.chat-doc-busy .chat-doc-progress-fill { width: 40%; transition: none; animation: chat-doc-load 1.1s var(--ease) infinite; }
@keyframes chat-doc-load { from { transform: translateX(-120%); } to { transform: translateX(320%); } }
@media (prefers-reduced-motion: reduce) { .chat-doc-busy .chat-doc-progress-fill { animation: none; width: 100%; } }
.send-btn.busy .icon-send { display: none; }
.send-btn.busy .icon-stop { display: block; }
.composer-foot { text-align: center; font-size: var(--text-xs); color: var(--navy-300); margin-top: var(--s-3); }
.context-notice { width: min(var(--measure), calc(100% - 2 * var(--s-6))); margin: var(--s-3) auto 0; padding: var(--s-3) var(--s-4); background: var(--wait-bg); color: var(--wait); border: 1px solid #ecd9ae; border-radius: var(--r-md); font-size: var(--text-sm); text-align: center; }

/* ============================================================
   Content pages (models list, assistant form, documents)
   ============================================================ */
.page { flex: 1; overflow-y: auto; }
.page-inner { max-width: 64rem; margin: 0 auto; padding: var(--s-10) var(--s-8) var(--s-12); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-8); }
.page-head h1 { font-size: var(--text-3xl); font-weight: var(--w-black); }
.page-head p { color: var(--navy-300); margin-top: var(--s-2); }
.back-link { font-size: var(--text-md); color: var(--navy-300); display: inline-flex; align-items: center; gap: var(--s-1); margin-bottom: var(--s-4); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-pad { padding: var(--s-6); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s-4); }
.model-card { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-5); text-decoration: none; color: inherit; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.model-card:hover { text-decoration: none; box-shadow: var(--shadow-2); }
@media (hover: hover) and (pointer: fine) { .model-card:hover { transform: translateY(-2px); } }
.model-card h3 { font-size: var(--text-xl); }
.model-card .meta { font-size: var(--text-sm); color: var(--navy-300); }
.model-card .badge { align-self: flex-start; }
.badge { display: inline-flex; align-items: center; gap: var(--s-1); padding: 2px var(--s-3); border-radius: var(--r-pill); font-size: var(--text-xs); font-weight: var(--w-semi); }
.badge-model { background: var(--surface-2); color: var(--navy-300); border: 1px solid var(--line); font-family: var(--f-mono); }
.badge-ready { background: var(--go-bg); color: var(--go); }
.badge-processing { background: var(--wait-bg); color: var(--wait); }
.badge-failed { background: var(--danger-bg); color: var(--danger); }

.new-tile { display: grid; place-items: center; gap: var(--s-2); min-height: 132px; border: 2px dashed var(--line-2); border-radius: var(--r-lg); color: var(--navy-300); font-weight: var(--w-semi); transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease), background var(--dur) var(--ease); }
.new-tile:hover { text-decoration: none; border-color: var(--yellow-900); color: var(--navy); background: #fffdf5; }
.new-tile .plus { font-size: 28px; }

/* Two-column form layout */
.form-cols { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: var(--s-6); align-items: start; }
@media (max-width: 900px) { .form-cols { grid-template-columns: 1fr; } }
.section-title { font-size: var(--text-xl); font-weight: var(--w-bold); letter-spacing: -0.02em; margin-bottom: var(--s-4); }

/* Dropzone + document list */
.dropzone { border: 2px dashed var(--line-2); border-radius: var(--r-lg); padding: var(--s-8); text-align: center; color: var(--navy-300); transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); cursor: pointer; }
.dropzone.drag { border-color: var(--yellow-900); background: #fffdf5; color: var(--navy); }
.dropzone strong { color: var(--navy); }
.dropzone .icon { display: block; margin: 0 auto var(--s-2); color: var(--navy-300); }
.doc-list { list-style: none; margin-top: var(--s-3); display: flex; flex-direction: column; gap: var(--s-1); }
.doc-row {
  position: relative;
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3) var(--s-1) var(--s-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.doc-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(1, 30, 48, 0.06); border-radius: 0 0 var(--r-md) var(--r-md); overflow: hidden; }
.doc-progress-fill { display: block; height: 100%; background: var(--wait); transition: width var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .doc-row:hover { border-color: var(--line-2); box-shadow: var(--shadow-1); }
  .doc-row:hover .doc-chev { transform: translateX(2px); color: var(--navy-300); }
}
.doc-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) 0; background: none; border: none; text-align: left; color: inherit; cursor: pointer;
}
.doc-open:active { transform: scale(0.995); }
.doc-file-icon { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--surface-2); color: var(--navy-300); }
.doc-file-icon svg { width: 16px; height: 16px; }
.doc-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.doc-row .doc-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--w-semi); font-size: var(--text-md); color: var(--ink); }
.doc-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-xs); color: var(--navy-300); }
.doc-sub.failed { color: var(--danger); }
.doc-trailing { flex: none; display: flex; align-items: center; gap: var(--s-2); }
.doc-warn { padding: 2px var(--s-2); border-radius: var(--r-pill); font-size: var(--text-xs); font-weight: var(--w-semi); background: var(--wait-bg); color: var(--wait); white-space: nowrap; }
.doc-tag { padding: 2px var(--s-2); border-radius: var(--r-pill); font-size: var(--text-xs); font-weight: var(--w-semi); background: var(--surface-2); color: var(--navy-300); white-space: nowrap; }
.doc-chev { flex: none; color: var(--line-2); transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.icon-btn { background: none; border: none; color: var(--navy-300); padding: var(--s-1) var(--s-2); border-radius: var(--r-sm); font-size: var(--text-md); }
.icon-btn:hover { color: var(--danger); background: var(--danger-bg); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-2); border-top-color: var(--wait); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Document store management: toolbar, list header, pagination, bulk action bar. */
.doc-toolbar { display: flex; gap: var(--s-3); margin-top: var(--s-5); flex-wrap: wrap; }
.doc-search { flex: 1; min-width: 200px; height: 44px; display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); color: var(--navy-300); }
.doc-search input { flex: 1; border: none; background: none; padding: var(--s-3) 0; font: inherit; color: var(--ink); outline: none; }
.doc-toolbar select { width: auto; min-width: 160px; height: 44px; padding: 0 var(--s-8) 0 var(--s-4); border: 1px solid var(--line); border-radius: var(--r-md); background-color: var(--surface); font: inherit; color: var(--ink); cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23155b7d' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--s-3) center; }
.doc-list-head { display: flex; align-items: center; justify-content: space-between; margin-top: var(--s-5); padding: 0 var(--s-1); font-size: var(--text-sm); color: var(--navy-300); }
.doc-selall { display: flex; align-items: center; gap: var(--s-2); font-weight: var(--w-semi); cursor: pointer; }
.doc-selall input, .doc-check { width: 16px; height: 16px; accent-color: var(--navy); flex: none; }
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--s-4); margin-top: var(--s-5); font-size: var(--text-sm); }
.page-link { padding: var(--s-2) var(--s-3); border: 1px solid var(--line-2); border-radius: var(--r-md); color: var(--navy); font-weight: var(--w-semi); }
.page-link:hover { background: var(--surface-2); text-decoration: none; }
.page-link.disabled { opacity: 0.4; pointer-events: none; }
.page-info { color: var(--navy-300); }
.doc-actions { position: fixed; left: 50%; transform: translateX(-50%); bottom: var(--s-6); z-index: 90; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-pill); box-shadow: var(--shadow-2); }
.doc-actions[hidden] { display: none; }
.doc-actions-count { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300); padding-left: var(--s-2); }
.doc-actions-count strong { color: var(--navy); }
.doc-assign { position: relative; }
.doc-model-menu { position: absolute; bottom: calc(100% + var(--s-2)); left: 0; width: 240px; padding: var(--s-3); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.doc-model-menu[hidden] { display: none; }
.doc-model-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-3); }
.doc-model-list label { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2); border-radius: var(--r-sm); font-size: var(--text-sm); font-weight: var(--w-medium); cursor: pointer; }
.doc-model-list label:hover { background: var(--surface-2); }
.doc-model-list input { width: 15px; height: 15px; accent-color: var(--navy); }
.doc-model-acts { display: flex; justify-content: flex-end; gap: var(--s-2); }
.dropzone.busy { opacity: 0.6; pointer-events: none; }

.messages { margin-bottom: var(--s-5); }
.msg { padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-size: var(--text-md); margin-bottom: var(--s-2); }
.msg.success { background: var(--go-bg); color: var(--go); }
.msg.error { background: var(--danger-bg); color: var(--danger); }

.empty-note { color: var(--navy-300); font-size: var(--text-md); padding: var(--s-4) 0; }

/* Anchor titles inside rows shouldn't underline on hover. */
.conv-title { color: inherit; }
.conv-title:hover { text-decoration: none; }

/* Document multi-select on the model form (CheckboxSelectMultiple). */
.doc-picker { max-height: 340px; overflow-y: auto; }
.doc-picker ul { list-style: none; padding: 0; margin: 0; }
.doc-picker li, .doc-picker > div { list-style: none; }
.doc-picker label { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-2); border: 1px solid var(--line); border-radius: var(--r-md); font-size: var(--text-md); font-weight: var(--w-medium); cursor: pointer; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.doc-picker label:hover { background: var(--surface-2); border-color: var(--line-2); }
.doc-picker input[type=checkbox] { width: 16px; height: 16px; flex: none; accent-color: var(--navy); }
.doc-picker .kb-hide { display: none; }
.knowledge-toolbar { display: flex; gap: var(--s-2); margin-bottom: var(--s-3); }
.knowledge-toolbar .doc-search { flex: 1; min-width: 0; }
.knowledge-meta { font-size: var(--text-sm); color: var(--navy-300); margin-bottom: var(--s-3); }
.knowledge-meta strong { color: var(--navy); }

/* Organization indicator / switcher in the sidebar head. */
.org-name { margin-top: 10px; font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300);
  display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-name::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--go); flex: none; }
.org-switch { position: relative; margin-top: 10px; }
.org-current { display: flex; align-items: center; gap: 6px; width: 100%; padding: 0; border: none;
  background: none; cursor: pointer; font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300); }
.org-current .org-name { margin-top: 0; min-width: 0; }
.org-current .chevron { flex: none; transition: transform var(--dur-fast) var(--ease); }
.org-current[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.org-menu { top: calc(100% + 6px); bottom: auto; left: 0; right: auto; min-width: 200px; }
.org-menu .menu-item { flex-direction: column; align-items: flex-start; gap: 2px; }
.org-menu-role { font-size: var(--text-sm); color: var(--navy-300); text-transform: capitalize; }
.menu-item.is-active { background: var(--surface-2); }
.menu-item.is-active .org-menu-name::after { content: "✓"; margin-left: 6px; color: var(--go); }

/* ============================================================
   Accessibility — motion, transparency, contrast preferences
   ============================================================ */
@keyframes fade-in { from { opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) {
  .turn.is-new, .turn.is-new .source-chip { animation: fade-in var(--dur) ease both; }
  .step { transition: opacity var(--dur) ease; }
  .steps-list, .steps-chevron { transition: none; }
  .step-mark::after { transition: opacity var(--dur-fast) ease; }
  .model-card:hover { transform: none; }
  .step[data-state="active"] .step-mark { animation: pulse 1.3s ease-in-out infinite; }
  .spin { animation: pulse 1.3s ease-in-out infinite; }
  .skeleton span { animation: none; }
  .cursor::after { animation: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .sidebar { background: var(--bg); backdrop-filter: none; }
  .topbar { background: var(--surface); backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .chip, .source-chip, .step-mark { border-color: var(--navy-300); }
}

/* ============================================================
   Toasts (flash messages after a redirect)
   ============================================================ */
.toasts { position: fixed; top: var(--s-4); right: var(--s-4); z-index: 100; display: flex; flex-direction: column; gap: var(--s-2); max-width: min(92vw, 380px); }
.toast { display: flex; align-items: flex-start; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--navy-300); box-shadow: var(--shadow-2); color: var(--ink); font-size: var(--text-md); font-weight: var(--w-semi); cursor: pointer; animation: toast-in var(--dur) var(--ease); }
.toast-success { border-left-color: var(--go); background: var(--go-bg); }
.toast-error, .toast-danger, .toast-warning { border-left-color: var(--danger); background: var(--danger-bg); }
.toast-out { opacity: 0; transform: translateX(8px); transition: opacity 0.3s var(--ease), transform 0.3s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast-out { transition: none; }
}

/* ============================================================
   People (organization membership)
   ============================================================ */
.invite-form { padding: var(--s-5); margin-bottom: var(--s-8); }
.invite-row { display: flex; align-items: flex-start; gap: var(--s-3); }
.invite-row .grow { flex: 1; }
.invite-row select { width: auto; min-width: 130px; }
.invite-row .btn { flex: none; }
@media (max-width: 640px) {
  .invite-row { flex-wrap: wrap; }
  .invite-row .grow { flex-basis: 100%; }
}

.people-section { margin-bottom: var(--s-8); }
.people-section .side-label { margin-bottom: var(--s-3); }
.people-list { list-style: none; display: flex; flex-direction: column; gap: var(--s-2); }
.people-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2) var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.people-id { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 180px; }
.people-name { font-weight: var(--w-semi); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-sub { font-size: var(--text-sm); color: var(--navy-300); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-acts { display: flex; align-items: center; gap: var(--s-2); flex: none; }
.people-acts form { margin: 0; }
.people-note { font-size: var(--text-sm); color: var(--navy-300); }
.badge-owner { background: var(--yellow); color: var(--navy); border: 1px solid var(--yellow-900); }
.badge-admin { background: var(--surface-2); color: var(--navy); border: 1px solid var(--yellow-900); }
.pager { display: flex; align-items: center; justify-content: center; gap: var(--s-3); margin-top: var(--s-5); }
.people-search { margin-bottom: var(--s-3); }
.people-search input { width: 100%; max-width: 320px; }

.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); }
.field-aux { font-size: var(--text-sm); font-weight: var(--w-semi); }
.invite-detail { color: var(--navy-300); font-size: var(--text-md); margin-bottom: var(--s-5); }

/* ============================================================
   Assistant wizard — stepped create, flat edit
   ============================================================ */
.wizard-step { margin-bottom: var(--s-5); }

/* Progress: numbered dots that fill as you advance — done (navy check), current
   (yellow), upcoming (muted). Answers "where am I / how many steps left". */
.wizard-progress {
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5);
  list-style: none; counter-reset: step; margin: 0 0 var(--s-6);
}
.wizard-progress li {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--navy-300);
}
.wizard-progress li::before {
  counter-increment: step; content: counter(step);
  display: grid; place-items: center; width: 22px; height: 22px;
  border-radius: var(--r-pill); font-size: var(--text-xs);
  background: var(--surface-2); color: var(--navy-300); border: 1px solid var(--line);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.wizard-progress li[data-state="current"] { color: var(--navy); }
.wizard-progress li[data-state="current"]::before {
  background: var(--yellow); color: var(--navy); border-color: var(--yellow-900);
}
.wizard-progress li[data-state="done"] { color: var(--navy-900); }
.wizard-progress li[data-state="done"]::before {
  content: "\2713"; background: var(--navy); color: #fff; border-color: var(--navy);
}

.wizard-nav {
  display: flex; align-items: center; gap: var(--s-3);
  margin-top: var(--s-6); padding-top: var(--s-4); border-top: 1px solid var(--line);
}
.wizard-nav #wizard-next, .wizard-nav #wizard-save { margin-left: auto; }

.form-errors { color: var(--danger); font-size: var(--text-sm); margin-bottom: var(--s-3); }
.review-note { color: var(--navy-300); }

.tool-config { border-top: 1px solid var(--line); padding-top: var(--s-4); margin-top: var(--s-4); }
.tool-config-title { font-weight: var(--w-semi); color: var(--ink); margin-bottom: var(--s-3); }

/* Checkbox choices (tools, collections) read as selectable inset rows: the whole row
   is the hit target, and a pick draws a navy edge + faint tint so it reads as chosen. */
.wizard-step ul:has(input[type="checkbox"]) {
  list-style: none; display: flex; flex-direction: column; gap: var(--s-2);
}
.wizard-step ul:has(input[type="checkbox"]) li { margin: 0; }
.wizard label:has(input[type="checkbox"]) {
  display: flex; align-items: center; gap: var(--s-3); width: 100%;
  margin: 0; padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  font-size: var(--text-base); font-weight: var(--w-semi); color: var(--ink); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}
.wizard label:hover:has(input[type="checkbox"]) { background: var(--surface-2); }
.wizard label:has(input[type="checkbox"]:checked) {
  border-color: var(--navy); background: rgba(1, 30, 48, 0.04); box-shadow: var(--shadow-1);
}
.wizard label:has(input[type="checkbox"]) input {
  width: 18px; height: 18px; flex: none; accent-color: var(--navy); cursor: pointer;
}
.tool-picker { margin-top: var(--s-3); }
.tool-config input[type="number"] { max-width: 140px; }

/* Entrances — transform + opacity only, retriggered from JS, direction-aware. */
@keyframes wizard-in { from { opacity: 0; transform: translateX(14px); } }
@keyframes wizard-in-back { from { opacity: 0; transform: translateX(-14px); } }
@keyframes wizard-reveal { from { opacity: 0; transform: translateY(8px); } }
.wizard-step.anim-in { animation: wizard-in var(--dur) var(--ease-out) both; }
.wizard-step.anim-back { animation: wizard-in-back var(--dur) var(--ease-out) both; }
.tool-config.reveal { animation: wizard-reveal var(--dur) var(--ease-out) both; }

/* --- MCP connectors: an inset grouped card, its fields floating on a faint fill --- */
.mcp-connector {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-5); margin-bottom: var(--s-3); background: var(--surface-2);
}
.mcp-connector.anim-in { animation: wizard-reveal var(--dur) var(--ease-out) both; }
.mcp-grid { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: var(--s-4); }
.mcp-grid label { display: flex; flex-direction: column; gap: var(--s-2); margin: 0; }
.mcp-actions { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); flex-wrap: wrap; }
/* State and colour always agree: waiting (amber), connected (go), failed (danger). */
.mcp-status { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--text-sm); color: var(--navy-300); }
.mcp-status[data-state="loading"] { color: var(--wait); }
.mcp-status[data-state="ok"] { color: var(--go); }
.mcp-status[data-state="error"] { color: var(--danger); }
.mcp-tools { list-style: none; padding: 0; margin: var(--s-3) 0 0; font-size: var(--text-sm); color: var(--navy-300); }
.mcp-tools li { padding: var(--s-1) 0; animation: wizard-reveal var(--dur) var(--ease-out) both; }
.mcp-tools strong { color: var(--ink); font-weight: var(--w-semi); }
@media (max-width: 640px) { .mcp-grid { grid-template-columns: 1fr; } }

/* --- Collections in the store --- */
.doc-collections { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3); margin: var(--s-5) 0 var(--s-4); }
.doc-collections-label { font-size: var(--text-xs); font-weight: var(--w-bold); text-transform: uppercase; letter-spacing: 0.08em; color: var(--navy-300); }
.doc-collection-new { display: inline-flex; margin: 0; }
.doc-collection-add {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-sm); font-weight: var(--w-semi);
  color: var(--navy-300); cursor: pointer; padding: var(--s-1) var(--s-3);
  background: none; border: 1px dashed var(--line-2); border-radius: var(--r-pill);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.doc-collection-add:hover { color: var(--navy); border-color: var(--navy-300); background: var(--surface-2); }
.doc-collection-input {
  flex: none; width: 190px; height: 30px; font: inherit; font-size: var(--text-sm); line-height: 28px;
  color: var(--ink); padding: 0 var(--s-3); background: var(--surface);
  border: 1px solid var(--navy-300); border-radius: var(--r-pill); outline: none;
  box-shadow: 0 0 0 3px rgba(21, 91, 125, 0.12);
}
.doc-collection-tags { display: flex; flex-wrap: wrap; gap: var(--s-2); list-style: none; padding: 0; margin: 0; }
.doc-collection-tag {
  display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--text-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: var(--s-1) var(--s-3);
}
.doc-collection-tag form { margin: 0; display: flex; }
.doc-collection-tag button {
  border: 0; background: none; cursor: pointer; color: var(--navy-300);
  font-size: var(--text-md); line-height: 1; padding: 0;
  transition: color var(--dur-fast) var(--ease);
}
.doc-collection-tag button:hover { color: var(--danger); }

/* Reduced motion: entrances become gentle fades with no travel. */
@media (prefers-reduced-motion: reduce) {
  .wizard-step.anim-in, .wizard-step.anim-back, .tool-config.reveal,
  .mcp-connector.anim-in, .mcp-tools li { animation: fade-in var(--dur) ease both; }
}

/* ============================================================
   Edit sheet — a translucent panel that slides in from the right
   for one document. Enters and exits along the same path (spatial
   consistency); the scrim dims the page behind a focused task.
   ============================================================ */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 200; background: rgba(1, 30, 48, 0.28);
  backdrop-filter: blur(2px); opacity: 0; transition: opacity var(--dur) var(--ease);
}
.sheet-scrim.open { opacity: 1; }
.sheet-scrim[hidden] { display: none; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 201;
  width: min(440px, 94vw); display: flex; flex-direction: column;
  background: rgba(255, 255, 255, 0.86); backdrop-filter: saturate(1.6) blur(24px);
  border-left: 1px solid rgba(255, 255, 255, 0.5); box-shadow: var(--shadow-pop);
  transform: translateX(100%); opacity: 0;
  transition: transform var(--dur) var(--ease-out), opacity var(--dur) var(--ease-out);
}
.sheet.open { transform: translateX(0); opacity: 1; }
.sheet[hidden] { display: none; }
.sheet-head {
  flex: none; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4); border-bottom: 1px solid var(--line);
}
.sheet-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--surface-2); color: var(--navy-300); }
.sheet-title { flex: 1; min-width: 0; font-size: var(--text-lg); font-weight: var(--w-bold); letter-spacing: -0.01em; word-break: break-word; overflow-wrap: anywhere; }
.sheet-close { flex: none; color: var(--navy-300); }
.sheet-close:hover { color: var(--navy); background: var(--surface-2); }
.sheet-body { flex: 1; overflow-y: auto; padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-5); }
.sheet-status { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.sheet-status-row { display: flex; align-items: center; gap: var(--s-2); }
.sheet-status-text { font-size: var(--text-sm); color: var(--navy-300); }
.sheet-status.problem { background: var(--danger-bg); border-color: #f4c9c9; }
.sheet-status.problem .sheet-status-text { color: var(--danger); }
.sheet-status.warn { background: var(--wait-bg); border-color: #ecd9ae; }
.sheet-status.warn .sheet-status-text { color: var(--wait); }
.sheet-progress { height: 6px; border-radius: var(--r-pill); background: rgba(1, 30, 48, 0.08); overflow: hidden; }
.sheet-progress span { display: block; height: 100%; background: var(--wait); border-radius: var(--r-pill); transition: width var(--dur) var(--ease); }
.sheet-facts { display: flex; flex-direction: column; gap: 0; margin: 0; }
.sheet-facts .fact { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); padding: var(--s-2) 0; border-bottom: 1px solid var(--line); }
.sheet-facts .fact:last-child { border-bottom: none; }
.sheet-facts dt { font-size: var(--text-sm); color: var(--navy-300); margin: 0; font-weight: var(--w-medium); }
.sheet-facts dd { font-size: var(--text-sm); color: var(--ink); font-weight: var(--w-semi); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--s-3); }
.sheet-section-label { font-size: var(--text-xs); font-weight: var(--w-bold); text-transform: uppercase; letter-spacing: 0.08em; color: var(--navy-300); }
.sheet-section-aux { font-size: var(--text-sm); color: var(--navy-300); }
.sheet-collections { display: flex; flex-direction: column; gap: var(--s-2); }
.coll-toggle {
  display: flex; align-items: center; gap: var(--s-3); margin: 0; padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line); border-radius: var(--r-md); font-size: var(--text-md);
  font-weight: var(--w-semi); color: var(--ink); cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.coll-toggle:hover { background: var(--surface-2); border-color: var(--line-2); }
.coll-toggle:has(input:checked) { background: #f5f9fc; border-color: var(--navy-300); }
.coll-toggle input { width: 17px; height: 17px; flex: none; accent-color: var(--navy); }
.coll-toggle span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-collections-empty { font-size: var(--text-sm); color: var(--navy-300); }
.sheet-foot {
  flex: none; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); background: rgba(255, 255, 255, 0.6);
}
@media (prefers-reduced-motion: reduce) {
  .sheet { transition: opacity var(--dur) ease; transform: none; }
  .sheet.open { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .sheet { background: var(--surface); backdrop-filter: none; }
  .sheet-scrim { backdrop-filter: none; }
  .sheet-foot { background: var(--surface); }
}
/* ============================================================
   Source reader — a centred "Quick Look" over a citation or a
   stored document: its extracted passages, the cited one lit.
   ============================================================ */
.reader-scrim {
  position: fixed; inset: 0; z-index: 200; background: rgba(1, 30, 48, 0.34);
  backdrop-filter: blur(3px); opacity: 0; transition: opacity var(--dur) var(--ease);
}
.reader-scrim.open { opacity: 1; }
.reader-scrim[hidden] { display: none; }
.reader {
  position: fixed; z-index: 201; top: 50%; left: 50%;
  width: min(720px, 94vw); max-height: min(84vh, 900px);
  display: flex; flex-direction: column;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: saturate(1.6) blur(24px);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  transform: translate(-50%, -48%) scale(0.98); opacity: 0;
  transition: transform var(--dur) var(--ease-out), opacity var(--dur) var(--ease-out);
}
.reader.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.reader[hidden] { display: none; }
.reader-head {
  flex: none; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line);
}
.reader-icon { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--surface-2); color: var(--navy-300); }
.reader-title { flex: 1; min-width: 0; font-size: var(--text-lg); font-weight: var(--w-bold); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-close { flex: none; color: var(--navy-300); }
.reader-close:hover { color: var(--navy); background: var(--surface-2); }
.reader-body { flex: 1; overflow-y: auto; padding: var(--s-5) var(--s-6); scroll-behavior: smooth; }
.reader-passage { padding: var(--s-3) var(--s-4); border-radius: var(--r-md); border-left: 3px solid transparent; }
.reader-passage + .reader-passage { margin-top: var(--s-2); }
.reader-loc { display: inline-block; margin-bottom: var(--s-2); padding: 1px var(--s-2); border-radius: var(--r-sm); background: var(--wait-bg); color: var(--wait); font-size: var(--text-xs); font-weight: var(--w-semi); }
.reader-text { font-size: var(--text-md); line-height: var(--lh-body); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-passage.is-cited { background: #fff8e6; border-left-color: var(--yellow-900); animation: cite-flash 0.9s var(--ease-out); }
@keyframes cite-flash { from { background: var(--yellow); } }
.reader-empty, .reader-loading { color: var(--navy-300); font-size: var(--text-md); padding: var(--s-6); text-align: center; }
.reader-image { text-align: center; }
.reader-image img { max-width: 100%; border-radius: var(--r-md); border: 1px solid var(--line); }

/* Inline citation — a small tappable pill the model's [n] becomes in the answer prose. */
.cite {
  display: inline; padding: 0 5px; margin: 0 1px; border: none; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--navy-900); font: inherit; font-size: 0.82em;
  font-weight: var(--w-bold); vertical-align: baseline; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.cite:hover { background: var(--yellow); color: var(--navy); }

/* A source-row backed by a stored document opens in the reader. */
.source-row.is-open { cursor: pointer; border-radius: var(--r-sm); }
@media (hover: hover) and (pointer: fine) { .source-row.is-open:hover { background: var(--surface); } }

/* Document-store row: the body opens the reader, this pencil opens the edit sheet. */
.doc-edit { flex: none; color: var(--navy-300); background: none; border: none; padding: var(--s-1) var(--s-2); border-radius: var(--r-sm); display: grid; place-items: center; transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.doc-edit:hover { color: var(--navy); background: var(--surface-2); }

@media (prefers-reduced-motion: reduce) {
  .reader { transition: opacity var(--dur) ease; transform: translate(-50%, -50%); }
  .reader.open { transform: translate(-50%, -50%); }
  .reader-passage.is-cited { animation: none; }
  .reader-body { scroll-behavior: auto; }
}
@media (prefers-reduced-transparency: reduce) {
  .reader { background: var(--surface); backdrop-filter: none; }
  .reader-scrim { backdrop-filter: none; }
}

/* ============================================================
   Native touch behaviour — applies on every viewport, matters on touch.
   Keep scrolls inside their own pane (no chaining to the page, no
   pull-to-refresh yanking the shell), remove the grey tap flash, and drop
   the double-tap zoom delay on controls so taps feel instant.
   ============================================================ */
html { overscroll-behavior-y: none; }
.thread, .sidebar-scroll, .page, .reader-body, .sheet-body, .source-panels,
.doc-model-list, .doc-picker { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
a, button, label, .conv-link, .source-chip, .chip { -webkit-tap-highlight-color: transparent; }
button, a, .conv-link, label[for], summary { touch-action: manipulation; }
/* ============================================================
   Artifact panel — the conversation's working object beside the chat.
   The shell grid gains a third column while .has-artifact is on; on
   narrow viewports (see the responsive block) the panel overlays instead.
   ============================================================ */
.app.has-artifact { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) minmax(340px, 38%); }
/* height: 100vh (like .main) so the grid row can't grow with content and the body scrolls. */
.artifact-panel { display: flex; flex-direction: column; min-width: 0; height: 100vh; background: var(--surface); border-left: 1px solid var(--line); }
.artifact-head {
  display: flex; align-items: center; gap: var(--s-2); flex: none;
  padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line);
}
.artifact-id { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.artifact-title { font-family: var(--f-display); font-weight: var(--w-bold); color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-stepper { display: flex; align-items: center; gap: var(--s-1); }
.artifact-stepper .btn { padding: 0 var(--s-2); }
.artifact-vers { font-size: var(--text-sm); color: var(--navy-300); font-variant-numeric: tabular-nums; }
.artifact-modes { display: flex; gap: var(--s-1); }
.artifact-modes .chip[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.artifact-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
.artifact-md { padding: var(--s-5) var(--s-6); }
.artifact-code { flex: 1; margin: 0; padding: var(--s-5) var(--s-6); font-family: var(--f-mono); font-size: var(--text-sm); line-height: 1.55; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); }
.artifact-frame { flex: 1; width: 100%; border: 0; background: #fff; }

/* ============================================================
   Responsive — phones and small tablets (<=820px).
   The desktop shell is a sidebar + main grid; on narrow viewports the
   sidebar leaves the flow to become an off-canvas drawer over a scrim,
   opened from a compact top bar (.mobile-bar), and every surface tightens
   its gutters and stacks. This block is last so it overrides the component
   defaults above without needing extra specificity. Safe-area insets keep
   the bars and composer clear of notches and home indicators.
   ============================================================ */

/* The mobile top bar and drawer scrim exist only on narrow viewports. */
.mobile-bar { display: none; }
.nav-scrim { display: none; }

@media (max-width: 820px) {
  /* Shell → single flex column; sidebar + scrim leave the flow (position: fixed). */
  .app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
  .main { flex: 1; min-height: 0; height: auto; }

  /* The artifact panel overlays the whole shell instead of splitting it. */
  .artifact-panel { position: fixed; inset: 0; z-index: 110; padding-top: env(safe-area-inset-top); }

  .mobile-bar {
    display: flex; align-items: center; gap: var(--s-1); flex: none;
    height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--s-2) 0;
    background: rgba(247, 247, 247, 0.9); backdrop-filter: saturate(1.4) blur(16px);
    border-bottom: 1px solid var(--line);
  }
  .mbar-btn {
    flex: none; width: 44px; height: 44px; display: grid; place-items: center;
    border: none; background: none; color: var(--navy-300); border-radius: var(--r-sm);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  }
  .mbar-btn:hover { background: var(--surface-2); color: var(--navy); }
  .mbar-btn:active { transform: scale(0.94); }
  .mbar-title { flex: 1; min-width: 0; text-align: center; font-family: var(--f-display); font-weight: var(--w-bold); font-size: var(--text-base); color: var(--navy); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Sidebar → left drawer: solid (legible over the dimmed page) and slid off-screen. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 130;
    width: min(320px, 86vw); max-height: none;
    background: var(--bg); backdrop-filter: none;
    border-right: 1px solid var(--line); border-bottom: none; box-shadow: var(--shadow-pop);
    padding-top: env(safe-area-inset-top);
    transform: translateX(-100%); transition: transform var(--dur) var(--ease-out);
    touch-action: pan-y;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scroll { max-height: none; }
  /* Touch has no hover: the per-chat delete affordance stays visible. */
  .conv-del { opacity: 1; }

  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 120;
    background: rgba(1, 30, 48, 0.34); backdrop-filter: blur(2px);
    opacity: 0; transition: opacity var(--dur) var(--ease);
  }
  .nav-scrim.open { opacity: 1; }

  /* Form controls at >=16px so iOS Safari does not zoom the page on focus. */
  input[type=text], input[type=email], input[type=password], input[type=number],
  input[type=url], input[type=search], input[type=tel], textarea, select { font-size: 16px; }

  /* Chat: the mobile bar is the single top bar — the desktop context bar is redundant. */
  .topbar { display: none; }
  .thread-inner { padding: var(--s-5) var(--s-4) var(--s-8); gap: var(--s-6); }
  .turn { gap: var(--s-3); }
  .bubble { font-size: var(--text-base); }
  .turn-attachment { width: 96px; height: 96px; }
  .composer { padding: var(--s-3) var(--s-4) max(var(--s-3), env(safe-area-inset-bottom)); }
  .composer-box { border-radius: var(--r-lg); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); }
  .send-btn { width: 44px; height: 44px; }
  .attach-btn { width: 40px; height: 40px; }
  /* Touch has no hover: give the per-chat delete a real 44px hit target. */
  .conv-del { width: 40px; height: 40px; display: grid; place-items: center; }
  .foot-menu .icon-btn { width: 40px; height: 40px; display: grid; place-items: center; }
  .context-notice { width: calc(100% - 2 * var(--s-4)); }

  /* Content pages: smaller heads, tighter gutters, single-column forms. */
  .page-inner { padding: var(--s-6) var(--s-4) var(--s-10); }
  .page-head { flex-direction: column; align-items: flex-start; gap: var(--s-2); }
  .page-head h1 { font-size: var(--text-2xl); }
  .form-cols { grid-template-columns: 1fr; }
  .grid-cards { grid-template-columns: 1fr; }

  /* Documents: full-width toolbar controls and a full-width floating action bar. */
  .doc-search { flex-basis: 100%; }
  .doc-toolbar select { flex: 1; min-width: 0; }
  .doc-actions {
    left: var(--s-3); right: var(--s-3); transform: none; flex-wrap: wrap;
    justify-content: center; border-radius: var(--r-lg);
    bottom: max(var(--s-3), env(safe-area-inset-bottom));
  }

  /* People / activity: identity and actions stack rather than crowd one line. */
  .people-row { align-items: flex-start; }
  .people-acts { flex-wrap: wrap; }
  .invite-row select, .invite-row .btn { flex: 1; }

  /* Auth gate: hero already hidden at 820px; relax the form gutters. */
  .gate-form { padding: var(--s-8) var(--s-5); }

  /* Overlays go full-bleed on a small screen. */
  .reader {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    border-radius: 0; border: none;
  }
  .reader-body { padding: var(--s-4); }
  .sheet { width: 100vw; }
}
