:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6a66; --line: #e2e0da;
  --quote-bar: #c8a400; --hl: #ffe680; --hl-line: #fff8d6;
  --user-bg: #1d1d1b; --user-ink: #ffffff; --danger: #b3261e;
  --reply-bg: #fbf3d5; --classic-bg: #ecebe7;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.doc { font-family: Georgia, "PT Serif", "Times New Roman", serif; }

/* chat on the left, document reader always open on the right */
.layout { height: 100dvh; display: grid; grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); grid-template-rows: minmax(0, 1fr); }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head h1 { font-size: 16px; margin: 0; flex: 1; }
.counter { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.is-full { color: var(--danger); }
.reset { padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font-size: 13px; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.user { align-self: flex-end; max-width: 85%; background: var(--user-bg); color: var(--user-ink); padding: 8px 12px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
/* assistant bubbles mirror the user bubble; only the background tells the
   quote answer (warm, like the highlight) from the classic RAG one (gray) */
.asst { align-self: flex-start; max-width: 85%; display: flex; flex-direction: column; gap: 10px; background: var(--reply-bg); padding: 8px 12px; border-radius: 14px 14px 14px 4px; }
.asst.classic { background: var(--classic-bg); }
.reply { white-space: pre-wrap; }
.pending { color: var(--muted); }
.error { color: var(--danger); }

/* a quote reads as plain text; the one open on the right gets a thin bar */
.quote { display: block; text-align: left; color: inherit; background: none; border: 0; border-left: 2px solid transparent; margin-left: -10px; padding: 0 0 0 8px; border-radius: 0; white-space: pre-wrap; }
.quote:hover { background: rgba(0, 0, 0, .03); }
.quote.active { border-left-color: var(--quote-bar); }

.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer-row { display: flex; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { border: 1px dashed #bdbab2; background: transparent; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); text-align: left; }
.composer input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; }
.send { padding: 0 16px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; }

.reader { overflow: auto; min-height: 0; background: var(--panel); }
.reader-head { position: sticky; top: 0; background: var(--panel); padding: 12px 28px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.reader-source { font-size: 13px; color: var(--muted); text-align: right; }
.reader-body { padding: 18px 28px 90px; max-width: 680px; }
.reader-empty { color: var(--muted); }

.doc h1 { font-size: 20px; margin: 0 0 12px; }
.doc h2, .doc h3 { font-size: 16px; margin: 20px 0 8px; }
.doc p { margin: 0 0 10px; white-space: pre-wrap; }
.doc .is-hl { background: var(--hl-line); margin-left: -12px; margin-right: -12px; padding: 4px 12px; border-left: 3px solid var(--quote-bar); }
.doc mark { background: var(--hl); padding: 1px 0; border-radius: 2px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 40vh; }
  .chat { border-right: 0; }
  .reader { border-top: 2px solid var(--line); }
  .reader-head, .reader-body { padding-left: 16px; padding-right: 16px; }
}
