/* ============================================================
   Malic — chamber at dusk
   Gold speaks for the synthesis; violet/teal/rose are the three
   panelist voices. Hue = speaker, everywhere in the interface —
   the user is a speaker too (mirrored right rule, sans voice).
   ============================================================ */

:root {
  --ink: #161b24;        /* page ground */
  --ink-deep: #10141b;   /* recessed: code, sidebar */
  --panel: #1e2531;      /* raised surface */
  --panel-2: #273040;    /* raised surface, hover/active */
  --line: #2e3746;
  --line-soft: #273040;
  --text: #e9ecf2;
  --text-soft: #c6ccda;
  --muted: #9da7ba;
  --faint: #8490a5;      /* smallest legible tier — keeps 4.5:1 on ink & panel */

  --gold: #d9a967;       /* synthesis */
  --gold-dim: rgba(217, 169, 103, 0.14);
  --violet: #a78bdb;     /* panelist-1 · Opus */
  --teal: #6fb8ad;       /* panelist-2 · Sonnet */
  --rose: #d98ba3;       /* panelist-3 · Haiku */
  --red: #e08897;        /* errors */

  --font-ui: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --font-prose: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-display: 'Young Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;

  /* one sans + one mono micro-label scale, used for every eyebrow/caption */
  --microlabel: 600 0.7rem/1 var(--font-ui);
  --microlabel-ls: 0.13em;
  --microlabel-mono: 500 0.66rem/1 var(--font-mono);
  --microlabel-mono-ls: 0.14em;

  --col: 42rem;          /* ~75ch of serif prose */
  --sidebar-w: 272px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

button { font-family: var(--font-ui); }

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

/* ---------- sidebar ---------- */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--ink-deep);
  border-right: 1px solid var(--line-soft);
  outline: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 12px;
}

.wordmark {
  font: 400 1.4rem/1 var(--font-display);
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.wordmark-mark {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 7px;
  margin-bottom: 8px;
  background: var(--gold);
  border-radius: 1px;
  transform: rotate(45deg);
}

.new-chat {
  border: 1px solid rgba(217, 169, 103, 0.45);
  background: none;
  color: var(--gold);
  font: 600 0.76rem/1 var(--font-ui);
  letter-spacing: 0.02em;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
}
.new-chat:hover { background: var(--gold-dim); }

.convo-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.convo-item {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 7px 6px 7px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: 400 0.85rem/1.35 var(--font-ui);
  text-align: left;
  cursor: pointer;
}
.convo-item:hover { background: var(--panel); color: var(--text-soft); }
.convo-item.active { background: var(--panel); color: var(--text); }

.convo-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.convo-tool {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  min-width: 24px;
  min-height: 24px;
  border: none;
  background: none;
  color: var(--faint);
  font-size: 0.85rem;
  line-height: 1;
  padding: 3px;
  border-radius: 5px;
  cursor: pointer;
  visibility: hidden;
}
.convo-item:hover .convo-tool,
.convo-item:focus-within .convo-tool { visibility: visible; }
.convo-tool:hover { color: var(--text-soft); background: var(--panel-2); }
.convo-del:hover { color: var(--red); }
@media (hover: none) {
  .convo-tool { visibility: visible; }
}

.convo-rename {
  flex: 1;
  min-width: 0;
  background: var(--ink-deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: 400 0.85rem/1.3 var(--font-ui);
  padding: 4px 8px;
}
.convo-rename:focus { outline: 1px solid var(--gold); }

.convo-empty {
  padding: 10px;
  color: var(--faint);
  font: 400 0.82rem/1.5 var(--font-ui);
}

.sidebar-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
}
.sidebar-foot .org {
  font: var(--microlabel-mono);
  letter-spacing: 0.28em; /* wide tracking is the PRAKSES brandmark — deliberate outlier */
  color: var(--faint);
}
.sidebar-foot .foot-note {
  font: 400 0.68rem/1 var(--font-ui);
  color: var(--faint);
}

/* ---------- app column ---------- */

.app {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line-soft);
}

#menu-btn {
  border: none;
  background: none;
  color: var(--muted);
  padding: 8px;
  margin-left: -8px;
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
#menu-btn:hover { color: var(--text); background: var(--panel); }

#topbar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 500 0.88rem/1 var(--font-ui);
  color: var(--muted);
  margin: 0;
}

#chat-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-col {
  max-width: var(--col);
  margin: 0 auto;
  padding: 28px 22px 12px;
}

/* ---------- hero (empty state) ---------- */

.hero {
  margin: 8vh auto 0;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 20px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
}
.hero > * { animation: rise 0.55s ease both; }
.hero > :nth-child(2) { animation-delay: 0.08s; }
.hero > :nth-child(3) { animation-delay: 0.16s; }
.hero > :nth-child(4) { animation-delay: 0.24s; }
.hero > :nth-child(5) { animation-delay: 0.32s; }

.hero-mark { width: 132px; height: auto; }
.hero-mark path { stroke-dasharray: 100; animation: draw 0.9s ease 0.15s both; }
@keyframes draw {
  from { stroke-dashoffset: 100; }
  to { stroke-dashoffset: 0; }
}
@keyframes appear {
  from { opacity: 0; }
}
.hero-mark rect { animation: appear 0.5s ease 0.85s both; }

/* chat-mode mark: one voice, drawn the same way the panel lines are */
.hero-mark-chat { width: 68px; }
.hero-mark-chat circle { stroke-dasharray: 100; animation: draw 0.9s ease 0.15s both; }

.hero-title {
  margin: 0;
  font: 400 clamp(2.3rem, 5vw, 3.2rem)/1.12 var(--font-display);
  letter-spacing: 0.004em;
}

.hero-sub {
  margin: 0;
  max-width: 31rem;
  font: 400 0.97rem/1.65 var(--font-ui);
  color: var(--muted);
}

.hero-voices {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font: 500 0.78rem/1.2 var(--font-ui);
  color: var(--muted);
}
.voice-chip.chip-gold { color: var(--gold); border-color: rgba(217, 169, 103, 0.4); }

/* panel deliberations as top chips (replaces the dropdown ledger) */
.panel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.panel-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font: 500 0.8rem/1.2 var(--font-ui);
  color: var(--faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.panel-chip:hover { color: var(--text-soft); }
.panel-chip[aria-selected='true'] {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}
.panel-chip .dot { width: 6px; height: 6px; }
.panel-chip-synth .dot { width: 7px; height: 7px; }
.panel-chip .dot.failed { background: none; border: 1px solid var(--faint); }

.voice-arrow { color: var(--faint); font-size: 0.85rem; }

/* starters read as an editorial index, not stacked cards */
.starters {
  width: 100%;
  display: flex;
  flex-direction: column;
  margin-top: 4px;
}

.starters-eyebrow {
  font: var(--microlabel);
  letter-spacing: var(--microlabel-ls);
  text-transform: uppercase;
  color: var(--faint);
  padding-bottom: 10px;
}

.starter {
  text-align: left;
  padding: 13px 2px;
  border: none;
  border-top: 1px solid var(--line-soft);
  background: none;
  color: var(--muted);
  font: 400 1rem/1.5 var(--font-prose);
  cursor: pointer;
  transition: color 0.15s ease, padding-left 0.15s ease;
}
.starter:last-child { border-bottom: 1px solid var(--line-soft); }
.starter:hover {
  color: var(--text-soft);
  padding-left: 10px;
}

/* ---------- voice identity ---------- */

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hue, var(--muted));
  flex-shrink: 0;
}
.dot-diamond {
  border-radius: 1.5px;
  transform: rotate(45deg);
  background: var(--gold);
}

/* ---------- messages ---------- */

/* rhythm: a question sits close to its answer; turns sit apart */
.msg { margin: 44px 0; }
.msg-user + .msg-assistant,
.msg-user + .msg-error,
.msg-assistant + .msg-error { margin-top: 16px; }
.chat-col > .msg:first-child { margin-top: 8px; }

.msg-user { display: flex; flex-direction: column; align-items: flex-end; }

/* the user is a speaker in the record: mirrored border grammar, sans voice */
.msg-user .bubble {
  max-width: 85%;
  padding: 2px 16px 2px 0;
  border-right: 2px solid var(--line);
  color: var(--text-soft);
  font: 400 0.97rem/1.6 var(--font-ui);
  text-align: right;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.voice-label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
  font: var(--microlabel);
  letter-spacing: var(--microlabel-ls);
  text-transform: uppercase;
  color: var(--gold);
}
.voice-label .voice-note {
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--faint);
}

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.75); }
  50% { opacity: 1; transform: scale(1); }
}
@keyframes pulse-diamond {
  0%, 100% { opacity: 0.25; transform: rotate(45deg) scale(0.75); }
  50% { opacity: 1; transform: rotate(45deg) scale(1); }
}
.dot.thinking { animation: pulse 1.2s ease-in-out infinite; }
.dot-diamond.thinking { animation: pulse-diamond 1.2s ease-in-out infinite; }

/* ---------- the deliberation strip (signature) ---------- */

.strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.strip-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font: 500 0.78rem/1.2 var(--font-ui);
  color: var(--muted);
}
.strip-chip:nth-child(2) .dot.thinking { animation-delay: 0.2s; }
.strip-chip:nth-child(3) .dot.thinking { animation-delay: 0.4s; }

.strip-chip.done {
  color: var(--text-soft);
  border-color: color-mix(in srgb, var(--hue) 40%, var(--line));
}
.strip-chip.failed { color: var(--faint); }
.strip-chip.failed .dot {
  background: none;
  border: 1.5px solid var(--faint);
  width: 5px;
  height: 5px;
}
.strip-chip .chip-state { font-size: 0.72rem; color: var(--faint); }
.strip-chip.done .chip-state { color: var(--hue); }

.strip-note {
  font: 400 0.78rem/1.2 var(--font-ui);
  color: var(--faint);
}

/* ---------- prose (rendered markdown) ---------- */

.prose {
  font: 400 1.03rem/1.75 var(--font-prose);
  color: var(--text);
  overflow-wrap: break-word;
}
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

.prose p { margin: 0.9em 0; }

/* headings carry the display face — the brand lives inside answers too */
.prose h1, .prose h2, .prose h3 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.004em;
  color: var(--text);
}
.prose h1 { font-size: 1.42em; line-height: 1.22; margin: 1.5em 0 0.55em; }
.prose h2 { font-size: 1.24em; line-height: 1.28; margin: 1.5em 0 0.55em; }
.prose h3 { font-size: 1.1em; line-height: 1.3; margin: 1.4em 0 0.5em; }
.prose h4, .prose h5, .prose h6 {
  font-family: var(--font-prose);
  font-weight: 600;
  font-size: 1em;
  line-height: 1.3;
  margin: 1.4em 0 0.5em;
  color: var(--text);
}

.prose ul, .prose ol { margin: 0.9em 0; padding-left: 1.6em; }
.prose li { margin: 0.35em 0; }
.prose li > p { margin: 0.35em 0; }
.prose ul ul, .prose ul ol, .prose ol ul, .prose ol ol { margin: 0.35em 0; }
.prose input[type='checkbox'] { accent-color: var(--gold); margin-right: 0.45em; }
.prose li:has(> input[type='checkbox']) { list-style: none; }

.prose blockquote {
  margin: 1em 0;
  padding: 0.1em 0 0.1em 1.1em;
  border-left: 2px solid var(--gold);
  color: var(--text-soft);
}

.prose a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(217, 169, 103, 0.4);
}
.prose a:hover { text-decoration-color: var(--gold); }

.prose hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}

.prose strong { font-weight: 700; }

.prose img { max-width: 100%; border-radius: 8px; }

.prose code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 0.1em 0.38em;
}

.prose pre {
  margin: 1.1em 0;
  padding: 14px 16px;
  overflow-x: auto;
  background: var(--ink-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.prose pre code {
  display: block;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1.65;
  color: #d5dae4;
}

/* enhanced code blocks (final render) */
.codeblock {
  margin: 1.1em 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--ink-deep);
}
.codeblock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 7px 4px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
}
.codeblock-lang {
  font: var(--microlabel-mono);
  letter-spacing: var(--microlabel-mono-ls);
  color: var(--muted);
}
.codeblock pre { margin: 0; border: none; border-radius: 0; }

/* tables */
.table-wrap {
  margin: 1.1em 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font: 400 0.87rem/1.55 var(--font-ui);
}
.prose thead th {
  text-align: left;
  font-weight: 600;
  padding: 9px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  white-space: nowrap;
}
.prose tbody td {
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  vertical-align: top;
  color: var(--text-soft);
}
.prose tbody tr:first-child td { border-top: none; }
.prose th.num, .prose td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* math */
.prose .katex { font-size: 1.02em; }
.prose .katex-display { margin: 1em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* streaming caret */
@keyframes blink { 50% { opacity: 0; } }
.is-pending .prose > :last-child::after {
  content: '▍';
  margin-left: 2px;
  color: var(--gold);
  font-family: var(--font-ui);
  animation: blink 1s steps(2) infinite;
}

/* ---------- syntax highlighting (chamber palette) ---------- */

.hljs-keyword, .hljs-literal, .hljs-selector-tag, .hljs-meta { color: var(--violet); }
.hljs-string, .hljs-regexp, .hljs-selector-class, .hljs-addition { color: #8fc6bc; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--gold); }
.hljs-comment, .hljs-quote { color: var(--faint); font-style: italic; }
.hljs-title, .hljs-name, .hljs-section { color: #e3c08f; }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-variable, .hljs-template-variable { color: var(--rose); }
.hljs-built_in, .hljs-type, .hljs-class { color: #b9a8e8; }
.hljs-deletion { color: var(--red); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ---------- deliberation ledger ---------- */

.ledger {
  margin-top: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(30, 37, 49, 0.5);
}

.ledger summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  list-style: none;
  font: var(--microlabel);
  letter-spacing: var(--microlabel-ls);
  text-transform: uppercase;
  color: var(--muted);
  border-radius: 10px;
}
.ledger summary::-webkit-details-marker { display: none; }
.ledger summary:hover { color: var(--text-soft); }

.ledger-dots { display: inline-flex; gap: 4px; }
.ledger-dots .dot { width: 6px; height: 6px; }
.ledger-dots .dot.failed { background: none; border: 1px solid var(--faint); width: 4px; height: 4px; }

.ledger-chevron {
  margin-left: auto;
  color: var(--faint);
  transition: transform 0.18s ease;
}
.ledger[open] .ledger-chevron { transform: rotate(180deg); }

.ledger-body {
  padding: 2px 14px 16px;
  display: grid;
  gap: 18px;
}

.voice { border-left: 2px solid var(--hue, var(--line)); padding-left: 14px; }
.voice-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 6px 0 7px;
  font: var(--microlabel);
  letter-spacing: var(--microlabel-ls);
  text-transform: uppercase;
  color: var(--hue, var(--muted));
}
.voice-head .voice-model {
  font: var(--microlabel-mono);
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--faint);
}
.voice .prose {
  font-size: 0.93rem;
  line-height: 1.65;
  color: var(--text-soft);
}
/* hue = speaker holds inside each voice's own prose */
.voice .prose a {
  color: var(--hue);
  text-decoration-color: color-mix(in srgb, var(--hue) 40%, transparent);
}
.voice .prose blockquote { border-left-color: var(--hue); }
.voice-error { font: 400 0.85rem/1.5 var(--font-ui); color: var(--red); }

/* ---------- errors (ADR 0004: inline, visually distinct) ---------- */

.msg-error {
  border: 1px solid rgba(224, 136, 151, 0.35);
  background: rgba(224, 136, 151, 0.07);
  border-radius: 12px;
  padding: 12px 16px;
}
.msg-error .error-label {
  font: var(--microlabel-mono);
  letter-spacing: var(--microlabel-mono-ls);
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 6px;
}
.msg-error .error-text {
  font: 400 0.89rem/1.55 var(--font-ui);
  color: #ecaab6;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg-error .msg-actions { opacity: 1; }
.msg-error .ledger { background: rgba(30, 37, 49, 0.7); }

/* ---------- message actions ---------- */

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; }
@media (hover: none) {
  .msg-actions { opacity: 0.75; }
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  border: none;
  background: none;
  color: var(--faint);
  font: 500 0.72rem/1 var(--font-ui);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.action-btn:hover { background: var(--panel); color: var(--muted); }
.action-btn svg { flex-shrink: 0; }
.action-btn.primary { color: var(--gold); }
.action-btn.primary:hover { background: var(--gold-dim); color: var(--gold); }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  border: none;
  background: none;
  color: var(--faint);
  font: 500 0.68rem/1 var(--font-mono);
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.copy-btn:hover { background: var(--panel-2); color: var(--muted); }

/* inline editor for user messages */
.bubble-edit { width: 100%; max-width: 85%; }
.bubble-edit textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: 400 0.96rem/1.5 var(--font-ui);
  padding: 10px 12px;
  resize: vertical;
}
.bubble-edit textarea:focus { outline: none; border-color: rgba(217, 169, 103, 0.45); }
.bubble-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 6px;
}

/* ---------- composer ---------- */

.composer-wrap {
  position: relative;
  flex-shrink: 0;
  padding: 6px 22px 16px;
}

.jump-latest {
  position: absolute;
  top: -46px;
  right: 22px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(8, 10, 14, 0.5);
}
.jump-latest:hover { color: var(--text); border-color: var(--muted); }

.composer {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within {
  border-color: rgba(217, 169, 103, 0.45);
  box-shadow: 0 0 0 3px rgba(217, 169, 103, 0.07);
}

#input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  resize: none;
  color: var(--text);
  font: 400 0.98rem/1.5 var(--font-ui);
  max-height: 220px;
  padding: 4px 0;
}
#input::placeholder { color: var(--faint); }
#input:focus { outline: none; }

#send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--gold);
  color: #241b0e;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.15s ease;
}
#send:disabled { opacity: 0.35; cursor: default; }
#send .icon-stop { display: none; }
#send.stop {
  background: var(--panel-2);
  color: var(--text-soft);
  border: 1px solid var(--line);
  opacity: 1;
}
#send.stop .icon-send { display: none; }
#send.stop .icon-stop { display: block; }

.attach-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--faint);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.attach-btn:hover { color: var(--text-soft); background: var(--panel-2); }

/* ---------- attachments ---------- */

.attachments {
  max-width: var(--col);
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 260px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.attachment-thumb {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 6px;
  background: var(--ink-deep);
}
.attachment-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--ink-deep);
  color: var(--muted);
}
.attachment-pdf .attachment-icon { color: var(--rose); }
.attachment-text .attachment-icon { color: var(--teal); }

.attachment-meta { min-width: 0; }
.attachment-name {
  font: 500 0.8rem/1.3 var(--font-ui);
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-sub {
  font: 400 0.68rem/1.3 var(--font-ui);
  color: var(--faint);
}

.attachment-remove {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--faint);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.attachment-remove:hover { color: var(--red); background: var(--panel); }

.attach-error {
  flex-basis: 100%;
  font: 400 0.76rem/1.4 var(--font-ui);
  color: var(--red);
}

/* attachments carried inside a sent user message sit right-aligned, like the bubble */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
  max-width: 85%;
}
.msg-attachments .attachment { background: var(--panel); }

.composer-wrap.dragover .composer {
  border-color: rgba(217, 169, 103, 0.6);
  box-shadow: 0 0 0 3px rgba(217, 169, 103, 0.12);
}

.composer-meta {
  max-width: var(--col);
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.mode-switch {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: var(--ink-deep);
}
.mode-switch button {
  border: none;
  background: none;
  color: var(--faint);
  font: 500 0.75rem/1 var(--font-ui);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.mode-switch button[aria-checked='true'] {
  background: var(--panel-2);
  color: var(--text);
}

.composer-hint {
  font: 400 0.72rem/1.3 var(--font-ui);
  color: var(--faint);
  text-align: right;
}

/* ---------- responsive ---------- */

#backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(8, 10, 14, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

@media (min-width: 921px) {
  #backdrop { display: none !important; }
  body.sidebar-closed #sidebar { display: none; }
}

/* 920.98 avoids a fractional-width dead zone against the 921px JS matchMedia */
@media (max-width: 920.98px) {
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-102%);
    visibility: hidden; /* keeps the closed drawer out of the Tab order */
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }
  body.sidebar-open #sidebar {
    transform: none;
    visibility: visible;
    transition-delay: 0s;
  }
  body.sidebar-open #backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-col { padding: 20px 16px 8px; }
  .composer-wrap { padding: 4px 12px 12px; }
  .jump-latest { right: 12px; }
  .composer-hint { display: none; }
  .hero { margin-top: 5vh; }
  .msg-user .bubble, .bubble-edit { max-width: 92%; }
}

/* Narrow-phone pass: the shell is fluid, this just right-sizes the empty-state
   hero and trims chrome so ~320–480px doesn't feel oversized. */
@media (max-width: 480px) {
  .chat-col { padding: 16px 12px 8px; }
  .composer-wrap { padding: 4px 8px 10px; }
  .hero { margin-top: 3vh; gap: 16px; }
  .hero-mark { width: 96px; }
  .hero-mark-chat { width: 56px; }
  .hero-title { font-size: clamp(1.9rem, 8vw, 2.3rem); }
  .msg-user .bubble, .bubble-edit { max-width: 96%; }
  /* three-way toggle (Chat / Research / Panel) needs to fit a phone row */
  .mode-switch button { padding: 5px 9px; }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
