/* RegulaTech palette: deep teal ground, white cards, gold and olive accents.
   Layout uses logical properties (inline-start/end) so Arabic and English mirror automatically. */
:root {
  --paper: #083334;
  --paper-raised: #0b3c3d;
  --ink: #f4f6f2;
  --ink-soft: #c3d3d2;
  --ink-faint: #9fb7b6;
  --rule: #1f5253;
  --rule-strong: #3b7273;
  --blue: #e2c76f;
  --blue-wash: #2a4a3a;
  --orange: #f29a76;
  --orange-wash: #3d3a1c;
  --olive: #595f1d;
  --green: #8fd1a8;
  --green-wash: #164a3d;
  --card: #ffffff;
  --card-ink: #083334;
  --card-soft: #4f6b6b;
  --card-rule: #d5dfdd;
  --card-wash: #eef3f1;
  --font-sans: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --font-label: var(--font-mono);
  --tracking-label: 0.1em;
  --tracking-tight: -0.01em;
  --tracking-display: -0.035em;
  --case-label: uppercase;
  --body-line: 1.55;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 10px 28px -12px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --drawer-hidden: translateX(-105%);
  color-scheme: dark;
}

/* Arabic letters must join, so no tracking or capitals, and diacritics need taller lines. */
:root:lang(ar) {
  --font-sans: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
  --font-label: var(--font-sans);
  --tracking-label: 0;
  --tracking-tight: 0;
  --tracking-display: 0;
  --case-label: none;
  --body-line: 1.85;
}

:root[dir="rtl"] { --drawer-hidden: translateX(105%); }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: var(--body-line);
  color: var(--ink);
  background-color: var(--paper);
}
:root:lang(ar) body { font-size: 16px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, select, textarea { font: inherit; color: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Library ---------- */

.library {
  border-inline-end: 1.5px solid var(--rule-strong);
  background: var(--paper-raised);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 20px 20px 18px;
  border-bottom: 1.5px solid var(--rule-strong);
}
.brand-mark { color: var(--ink); display: grid; place-items: center; }
.brand-text { flex: 1; min-width: 0; }
.brand-name { margin: 0; font-weight: 700; font-size: 18px; line-height: 1.3; letter-spacing: -0.01em; text-align: start; unicode-bidi: plaintext; }
.brand-sub { margin: 0; font-family: var(--font-label); font-size: 12px; color: var(--ink-faint); text-transform: var(--case-label); letter-spacing: 0.08em; }
:root:lang(ar) .brand-sub { letter-spacing: 0; }
:root[dir="rtl"] .brand-name { text-align: right; }

.sidebar-start { padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.btn-new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 10px 14px; border: 0; border-radius: var(--radius);
  background: var(--blue); color: var(--paper); font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: filter 150ms var(--ease), transform 150ms var(--ease);
}
.btn-new-chat:hover { filter: brightness(1.08); }
.btn-new-chat:active { transform: translateY(1px); }
.btn-new-chat:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.panel { padding: 20px; border-bottom: 1px solid var(--rule); }
.panel:last-child { border-bottom: 0; }

/* Sponsor credit, just above "how we check answers". The logo has a white ground, so it sits on a white tile. */
.sponsor {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
}
.sponsor-logo { flex: none; width: 40px; height: 40px; padding: 3px; border-radius: 8px; background: var(--card); object-fit: contain; }
.sponsor-text { min-width: 0; }
.sponsor-label { margin: 0; font-family: var(--font-label); font-size: 11.5px; letter-spacing: var(--tracking-label); text-transform: var(--case-label); color: var(--ink-faint); }
.sponsor-name { margin: 0; font-weight: 600; font-size: 14.5px; line-height: 1.3; unicode-bidi: plaintext; }
:root[dir="rtl"] .sponsor-name { text-align: right; }

.eyebrow {
  margin: 0 0 12px;
  font-family: var(--font-label);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: var(--case-label);
  color: var(--ink-faint);
}

.dropzone {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 16px;
  border: 1.5px dashed var(--ink-faint);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 150ms var(--ease), background-color 150ms var(--ease), transform 150ms var(--ease);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--blue); background: var(--blue-wash); }
.dropzone:active { transform: scale(0.99); }
.drop-title { font-weight: 600; }
.drop-hint { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }

.upload-error { margin: 10px 0 0; font-size: 13.5px; color: var(--orange); white-space: pre-line; overflow-wrap: anywhere; }

.selection-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.link-button { background: none; border: 0; padding: 2px 4px; color: var(--blue); cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; border-radius: 4px; }
.link-button:hover { text-decoration: underline; }

.doc-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.doc-list:empty { display: none; }

.doc {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-block: 10px;
  padding-inline: 12px 8px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-inline-start: 3px solid var(--ink-faint);
  border-radius: var(--radius);
  transition: opacity 150ms var(--ease);
}
.doc[data-status="ready"] { border-inline-start-color: var(--green); }
.doc[data-status="error"] { border-inline-start-color: var(--orange); }
.doc[data-status="processing"], .doc[data-status="queued"], .doc.is-verifying { border-inline-start-color: var(--blue); }
.doc.is-off { opacity: 0.62; border-inline-start-color: var(--ink-faint); }
.doc.is-verifying .spinner { margin-top: 6px; flex: none; }
.doc-check { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--blue); cursor: pointer; }
.doc-text { flex: 1; min-width: 0; }
.doc-title { margin: 0; font-weight: 600; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.doc-meta { margin: 4px 0 0; font-family: var(--font-label); font-size: 12px; line-height: 1.5; color: var(--ink-soft); }
.doc-meta .flag { color: var(--orange); }
.doc-error { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--orange); }
.progress { height: 3px; margin-top: 8px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--blue); transform-origin: left; transition: transform 400ms var(--ease); }
:root[dir="rtl"] .progress > span { transform-origin: right; }

.icon-delete {
  flex: none; width: 28px; height: 28px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--ink-faint); cursor: pointer; line-height: 1; font-size: 16px;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.icon-delete:hover { background: var(--orange-wash); color: var(--orange); }

.empty-note { margin: 12px 0 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-soft); }

.convo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.convo-list:empty { display: none; }
.convo { position: relative; }
.convo-open {
  display: block; width: 100%; padding-block: 8px; padding-inline: 10px 36px;
  text-align: start; background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
.convo-open:hover { background: var(--paper); border-color: var(--rule); }
.convo[aria-current="true"] .convo-open { background: var(--blue-wash); border-color: var(--blue); }
.convo-title { display: block; font-size: 14px; font-weight: 500; line-height: 1.45; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-meta { display: block; margin-top: 2px; font-family: var(--font-label); font-size: 12px; line-height: 1.4; color: var(--ink-faint); }
.convo .icon-delete { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); }

.how ol { margin: 0; padding-inline-start: 18px; font-size: 13.5px; line-height: 1.6; color: var(--ink-soft); display: grid; gap: 6px; }
.how strong { color: var(--ink); font-weight: 600; }

.scrim { display: none; }

/* ---------- Desk ---------- */

.desk { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }

/* A title in the other language still lines up with its neighbours. */
:root[dir="ltr"] :is(.convo-title, .doc-title, .attach-name) { text-align: left; }
:root[dir="rtl"] :is(.convo-title, .doc-title, .attach-name) { text-align: right; }
:root:lang(ar) .eyebrow { font-size: 13px; }

/* No top bar: the language switch (and, on narrow screens, the library button) float over the thread's top corners. */
.float-button {
  position: absolute; z-index: 4; top: 12px;
  display: inline-grid; place-items: center; min-width: 40px; height: 36px; padding: 0 10px;
  background: var(--paper-raised); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  opacity: 0.5;
  transition: opacity 150ms var(--ease), border-color 150ms var(--ease);
}
.float-button:hover, .float-button:focus-visible { opacity: 1; border-color: var(--blue); }
.lang-toggle { inset-inline-end: 16px; }
.menu-open { inset-inline-start: 16px; display: none; opacity: 0.85; }

.banner {
  margin: 0; padding: 10px 20px;
  background: var(--olive); color: var(--ink);
  border-bottom: 1px solid var(--blue); font-size: 14px;
}
.banner code { font-family: var(--font-mono); font-size: 13px; }

.thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 60px clamp(16px, 4vw, 56px) 40px; }

.welcome { max-width: 760px; margin: 6vh auto 0; }
.welcome h1 {
  margin: 0 0 8px;
  font-size: clamp(38px, 6vw, 72px);
  line-height: 1.05;
  letter-spacing: var(--tracking-display);
  font-weight: 700;
}
:root:lang(ar) .welcome h1 { line-height: 1.3; }
.welcome p { color: var(--ink-soft); max-width: 58ch; }
.examples { display: grid; gap: 10px; margin-top: 22px; }
.example {
  text-align: start; padding: 14px 16px;
  background: var(--paper-raised); border: 1px solid var(--rule); border-radius: var(--radius);
  cursor: pointer; transition: border-color 150ms var(--ease), transform 150ms var(--ease), box-shadow 150ms var(--ease);
}
.example:hover { border-color: var(--rule-strong); transform: translateY(-1px); box-shadow: var(--shadow); }
.example:active { transform: translateY(0); }

.turn { max-width: 860px; margin: 0 auto 28px; animation: rise 300ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.q-wrap { display: flex; flex-direction: column; align-items: flex-end; }
.q-wrap.is-editing { align-items: stretch; }
.q {
  max-width: 78%;
  padding: 12px 16px;
  background: var(--card); color: var(--card-ink);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}
.q-text { white-space: pre-wrap; text-align: start; }
.q-meta { display: block; margin-top: 6px; font-family: var(--font-label); font-size: 12px; color: var(--card-soft); text-align: start; }
.q-actions { display: flex; margin-top: 2px; opacity: 0; transition: opacity 120ms var(--ease); }
.q-wrap:hover .q-actions, .q-wrap:focus-within .q-actions { opacity: 1; }
.q-edit {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px;
  background: transparent; border: 0; border-radius: 6px; color: var(--ink-soft); font-size: 13px; cursor: pointer;
}
.q-edit:hover { color: var(--ink); background: var(--paper-raised); }
@media (hover: none) { .q-actions { opacity: 1; } }

.edit-form { background: var(--card); color: var(--card-ink); padding: 12px; border-radius: var(--radius); }
.edit-input {
  display: block; width: 100%; resize: vertical; min-height: 84px; padding: 10px 12px;
  background: var(--card-wash); color: var(--card-ink);
  border: 1.5px solid var(--card-rule); border-radius: 8px;
}
.edit-input:focus { border-color: var(--card-ink); outline: none; }
.edit-hint { margin: 8px 0; font-size: 13px; color: var(--card-soft); }
.edit-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-actions .btn-primary { padding: 8px 18px; }
.btn-on-card { padding: 8px 16px; background: transparent; border: 1px solid var(--card-rule); border-radius: 999px; color: var(--card-ink); cursor: pointer; font-weight: 500; }
.btn-on-card:hover { background: var(--card-wash); }

.a {
  margin-top: 8px;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.trail { border-bottom: 1px solid var(--rule); }
.trail summary {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; cursor: pointer; list-style: none;
  font-family: var(--font-label); font-size: 12.5px; color: var(--ink-soft);
}
.trail summary::-webkit-details-marker { display: none; }
.trail summary::before { content: "▸"; transition: transform 150ms var(--ease); }
.trail[open] summary::before { transform: rotate(90deg); }
:root[dir="rtl"] .trail summary::before { content: "◂"; }
:root[dir="rtl"] .trail[open] summary::before { transform: rotate(-90deg); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--rule); border-top-color: var(--blue); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.trail ol { margin: 0; padding-block: 0 12px; padding-inline: 40px 18px; font-family: var(--font-label); font-size: 12.5px; color: var(--ink-soft); display: grid; gap: 3px; overflow-wrap: anywhere; }
.trail li.view { color: var(--green); }
.trail li.err { color: var(--orange); }
.progress-note { padding: 0 18px 10px; font-size: 13px; color: var(--ink-soft); font-style: italic; }
:root:lang(ar) .progress-note { font-style: normal; }

.body { padding: 18px 22px 8px; overflow-wrap: anywhere; }
.body:empty { display: none; }
.body h1, .body h2, .body h3 { margin: 22px 0 8px; line-height: 1.4; letter-spacing: var(--tracking-tight); }
.body h1 { font-size: 21px; }
.body h2 { font-size: 18px; }
.body h3 { font-size: 16px; }
.body > :first-child { margin-top: 0; }
.body p, .body li { max-width: 74ch; }
.body code { font-family: var(--font-mono); font-size: 0.88em; background: var(--paper); border: 1px solid var(--rule); padding: 0 4px; border-radius: 2px; }
.body pre { background: var(--paper); border: 1px solid var(--rule); padding: 12px; overflow-x: auto; border-radius: var(--radius); }
.body pre code { border: 0; padding: 0; background: none; }
/* Mixed Arabic/English: each block's direction is set in markdown.js; these keep it readable. */
.body :is(p, li, h1, h2, h3, h4, td, th, blockquote) { text-align: start; }
.body > :is(p, h1, h2, h3, h4, blockquote):dir(rtl) { margin-left: auto; }  /* hug the block's own start edge */
.body > :is(p, h1, h2, h3, h4, blockquote):dir(ltr) { margin-right: auto; }
.body code, .body pre, .cite { direction: ltr; unicode-bidi: isolate; }
.body pre { text-align: left; }
.body blockquote { margin: 12px 0; padding: 4px 14px; border-inline-start: 3px solid var(--blue); color: var(--ink-soft); }
.body table { border-collapse: collapse; margin: 12px 0; font-size: 13.5px; display: block; overflow-x: auto; max-width: 100%; }
.body th, .body td { border: 1px solid var(--rule); padding: 6px 10px; text-align: start; vertical-align: top; }
/* Typeset equations: always left to right, isolated from Arabic text around them. */
.body .math { direction: ltr; unicode-bidi: isolate; overflow-wrap: normal; }
.body .math .katex { font-size: 1.08em; }
.body .math-display { display: block; margin: 12px 0; padding: 10px 16px; max-width: 74ch; overflow-x: auto; overflow-y: hidden;
  background: var(--paper); border: 1px solid var(--rule); border-inline-start: 3px solid var(--blue); border-radius: var(--radius); }
:root[dir="rtl"] .body .math-display { border-left-width: 1px; border-right: 3px solid var(--blue); }  /* the box is LTR inside; its accent follows the page */
.body .math-display .katex-display { margin: 0; text-align: center; }
.body .math .katex-error { color: var(--orange); font-family: var(--font-mono); font-size: 0.9em; }
.body th { background: var(--paper); font-weight: 600; }

.cite {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 0 2px; padding: 0 6px;
  font-family: var(--font-label); font-size: 12px; line-height: 20px;
  color: var(--blue); background: var(--blue-wash);
  border: 1px solid transparent; border-radius: 2px;
  cursor: pointer; vertical-align: 1px; max-width: 100%;
  transition: border-color 120ms var(--ease);
}
.cite:hover { border-color: var(--blue); }

.notice { margin: 0 22px 12px; padding: 8px 12px; font-size: 13.5px; background: var(--orange-wash); border-inline-start: 3px solid var(--orange); }

.sources { padding: 12px 22px 16px; border-top: 1px dashed var(--rule); }
.sources .eyebrow { margin-bottom: 8px; }
.source-list { display: flex; flex-wrap: wrap; gap: 6px; }
.source-list .cite.viewed { color: var(--green); background: var(--green-wash); }

/* ---------- Composer ---------- */

.composer {
  padding: 12px clamp(12px, 4vw, 56px) 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1.5px solid var(--rule-strong);
  background: var(--paper-raised);
}
.composer-card {
  max-width: 860px; margin: 0 auto;
  background: var(--card); color: var(--card-ink);
  border-radius: 20px;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  padding: 10px 12px 8px;
  transition: border-color 150ms var(--ease);
}
.composer-card:focus-within { border-color: var(--blue); }
.composer-card textarea {
  display: block; width: 100%; resize: none; max-height: 200px;
  padding: 4px 6px; background: transparent; color: var(--card-ink); border: 0; outline: none;
}
.composer-card textarea::placeholder { color: var(--card-soft); }
/* The send button is pinned so it stays in its corner however the chips wrap. */
.composer-bar { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; min-height: 40px; padding-inline-end: 48px; }

.icon-button {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  background: transparent; border: 0; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1;
  transition: background-color 120ms var(--ease);
}
.icon-button:hover { background: var(--paper); }
.icon-button.on-card { color: var(--card-ink); }
.icon-button.on-card:hover { background: var(--card-wash); }
.icon-button.on-card:focus-visible, .chip:focus-visible, .btn-send:focus-visible, .attach-remove:focus-visible, .btn-on-card:focus-visible { outline-color: var(--card-ink); }
.menu-close { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; min-height: 32px;
  background: transparent; color: var(--card-ink);
  border: 1px solid var(--card-rule); border-radius: 999px;
  font-size: 13px; font-weight: 500; line-height: 1.3; cursor: pointer;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease);
}
.chip:hover { background: var(--card-wash); }
.chip[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: var(--paper); }
.chip[aria-pressed="true"]:hover { filter: brightness(1.05); }
.chip-glyph { font-family: var(--font-mono); font-weight: 600; }
/* Software / units pickers styled as chips, sitting beside "show hand calculation". */
.chip-select { gap: 4px; padding-inline-end: 6px; min-width: 0; }
.chip-select:focus-within { border-color: var(--card-ink); }
.chip-label { color: var(--card-soft); white-space: nowrap; }
.chip-select select {
  border: 0; background: transparent; color: var(--card-ink); font-size: 13px; font-weight: 600;
  padding: 0; cursor: pointer; max-width: 170px; min-width: 0; text-overflow: ellipsis; outline: none;
}
.chip-select select option { background: var(--card); color: var(--card-ink); }

.btn-send {
  position: absolute; inset-inline-end: 0; bottom: 0;
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  background: var(--card-ink); color: var(--card);
  border: 0; border-radius: 50%; cursor: pointer;
  transition: transform 150ms var(--ease), opacity 150ms var(--ease);
}
.btn-send:hover { transform: scale(1.05); }
.btn-send:active { transform: scale(0.96); }
:root[dir="rtl"] .send-icon { transform: scaleX(-1); }
.send-spinner { display: none; border-color: rgba(255, 255, 255, 0.3); border-top-color: var(--card); }
.btn-send.is-busy .send-icon { display: none; }
.btn-send.is-busy .send-spinner { display: inline-block; }

.btn-primary {
  padding: 12px 22px; border: 0; border-radius: 999px;
  background: var(--card-ink); color: var(--card); font-weight: 600; cursor: pointer;
  transition: filter 150ms var(--ease), transform 150ms var(--ease);
}
.btn-primary:hover { filter: brightness(1.2); }
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  padding: 6px 12px; border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: transparent; cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: border-color 150ms var(--ease), background-color 150ms var(--ease);
}
.btn-ghost:hover { border-color: var(--blue); background: var(--paper); }

.attach-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-list.is-sent { margin: 8px 0 0; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: min(240px, 100%);
  padding: 3px 6px; padding-inline-end: 4px; min-height: 36px;
  background: var(--card-wash); color: var(--card-ink); border-radius: 8px; font-size: 13px; line-height: 1.3;
}
.attach-chip.is-uploading { opacity: 0.7; }
.attach-chip .spinner { border-color: var(--card-rule); border-top-color: var(--card-ink); flex: none; }
.attach-thumb { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; flex: none; }
.attach-icon { width: 26px; text-align: center; flex: none; font-size: 15px; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attach-remove { flex: none; width: 26px; height: 26px; background: transparent; border: 0; border-radius: 6px; color: var(--card-soft); cursor: pointer; font-size: 15px; line-height: 1; }
.attach-remove:hover { background: var(--card-rule); color: var(--card-ink); }

.drop-overlay {
  position: absolute; inset: 10px; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 24px; text-align: center;
  background: rgba(8, 51, 52, 0.93);
  border: 2px dashed var(--blue); border-radius: 16px;
  pointer-events: none;
}
.drop-overlay-title { margin: 0; font-size: 20px; font-weight: 600; }
.drop-overlay-hint { margin: 0; color: var(--ink-soft); max-width: 46ch; }

.toast {
  position: fixed; z-index: 40; inset-block-end: 96px; inset-inline: 16px; margin-inline: auto;
  width: fit-content; max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  background: var(--card); color: #8f3f1d;
  border-inline-start: 4px solid var(--orange);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 14px; overflow-wrap: anywhere;
}

/* ---------- Page viewer ---------- */

.viewer {
  width: min(1000px, 94vw); height: 92vh; height: 92dvh; padding: 0;
  border: 1.5px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--paper-raised); color: var(--ink);
}
.viewer::backdrop { background: rgba(3, 26, 27, 0.7); }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; padding: 12px 18px; border-bottom: 1px solid var(--rule); }
.viewer-heading { min-width: 0; }
.viewer-head h2 { margin: 0; font-size: 17px; }
.viewer-head .eyebrow { margin: 0; overflow-wrap: anywhere; text-align: start; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; background: var(--paper); padding: 16px; display: flex; justify-content: center; align-items: flex-start; }
.viewer-body img { max-width: 100%; height: auto; background: #fff; box-shadow: var(--shadow); }

/* ---------- Narrower windows ---------- */

@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .library {
    position: fixed; z-index: 30; inset-block: 0; inset-inline-start: 0;
    width: min(340px, 88vw);
    border-inline-end: 1.5px solid var(--rule-strong);
    transform: var(--drawer-hidden);
    visibility: hidden;
    transition: transform 240ms var(--ease), visibility 240ms;
  }
  .drawer-open .library { transform: none; visibility: visible; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(3, 26, 27, 0.6);
    opacity: 0; pointer-events: none; transition: opacity 240ms var(--ease);
  }
  .drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-close { display: inline-grid; }
  .menu-open { display: inline-grid; }
}

@media (max-width: 640px) {
  .float-button { top: 10px; }
  .lang-toggle { inset-inline-end: 12px; }
  .menu-open { inset-inline-start: 12px; }
  .chip-select select { max-width: 120px; }
  .q { max-width: 92%; }
  .thread { padding-block: 18px 24px; }
  .body { padding-inline: 14px; }
  .notice { margin-inline: 14px; }
  .sources { padding-inline: 14px; }
  .viewer { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .chip { padding-inline: 10px; }
  .toast { inset-block-end: 150px; }
}

@media (pointer: coarse) {
  .icon-delete { width: 36px; height: 36px; }
  .convo-open { padding-inline-end: 44px; }
  .doc-check { width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
