[hidden] { display: none !important; }
:root {
  --paper: #f1f3f6;
  --sheet: #ffffff;
  --ink: #1a2233;
  --muted: #5d6779;
  --line: #d8dde5;
  --accent: #2b49b8;
  --accent-deep: #1e3790;
  --mark: #ffe46b;
  --error: #b3261e;
  --ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --read: "Newsreader", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10141c;
    --sheet: #171c26;
    --ink: #e6e9ef;
    --muted: #9aa3b4;
    --line: #2a3140;
    --accent: #8ea6ff;
    --accent-deep: #b6c5ff;
    --mark: #6b5a12;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.topbar {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--read); font-weight: 600; font-size: 1.2rem; }
.source-link { color: var(--muted); font-size: 0.875rem; text-underline-offset: 3px; }
.source-link:hover { color: var(--ink); }

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

/* Shelf */
.shelf {
  padding: 36px 28px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.headline {
  font-family: var(--read);
  font-weight: 500;
  font-size: 2.1rem;
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
}
.lede { color: var(--muted); margin: 0 0 28px; }

.drop {
  display: flex; flex-direction: column; gap: 4px;
  padding: 22px 20px;
  background: var(--sheet);
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.is-drag { border-color: var(--accent); }
.drop.is-drag { background: color-mix(in srgb, var(--accent) 7%, var(--sheet)); }
.drop:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop-title { font-weight: 600; }
.drop-sub { color: var(--muted); font-size: 0.875rem; }

.docs-head { display: flex; justify-content: space-between; align-items: baseline; margin: 28px 0 8px; }
.docs-head h2 { font-size: 0.95rem; font-weight: 600; margin: 0; }
.docs { list-style: none; margin: 0; padding: 0; }
.doc {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.doc-icon {
  flex-shrink: 0; width: 36px; height: 44px;
  display: grid; place-items: center;
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.04em;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 3px 10px 3px 3px;
  color: var(--muted);
}
.doc-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.doc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 0.82rem; color: var(--muted); }
.doc.is-uploading .doc-meta { animation: blink 1.4s ease-in-out infinite; }
.doc.is-error .doc-meta { color: var(--error); }
.doc.is-ready .doc-icon { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
@keyframes blink { 50% { opacity: .45; } }

.text-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent-deep); font-size: 0.875rem; font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px;
}
.privacy { font-size: 0.8rem; color: var(--muted); margin-top: 24px; }

/* Thread */
.thread-wrap { display: flex; flex-direction: column; min-height: 0; }
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 40px max(28px, calc((100% - 720px) / 2)) 24px;
}
.empty { margin-top: 12vh; max-width: 42ch; }
.empty-title { font-family: var(--read); font-size: 1.6rem; margin: 0 0 6px; }
.empty-sub { color: var(--muted); margin: 0; }

.msg { margin-bottom: 28px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user p {
  margin: 0;
  max-width: 34rem;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
}
.msg.bot .answer {
  font-family: var(--read);
  font-size: 1.15rem;
  line-height: 1.6;
  max-width: 64ch;
}
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer code { font-size: .9em; background: var(--sheet); padding: 1px 5px; border-radius: 4px; }
.answer a { color: var(--accent); }
.thinking { color: var(--muted); margin: 0; animation: blink 1.4s ease-in-out infinite; }
.msg.is-error p { color: var(--error); margin: 0; }

/* The memorable element: highlighted source passages */
.sources { margin-top: 14px; max-width: 64ch; }
.sources summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent-deep);
  width: fit-content;
}
.sources ol { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 12px; }
.source { padding-left: 14px; border-left: 2px solid var(--line); }
.excerpt { font-family: var(--read); font-size: 1rem; line-height: 1.65; margin: 0 0 4px; }
.excerpt mark {
  background: linear-gradient(transparent 12%, var(--mark) 12%, var(--mark) 88%, transparent 88%);
  color: inherit;
  padding: 0 2px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.source-meta { margin: 0; font-size: 0.8rem; color: var(--muted); display: flex; gap: 10px; }

/* Composer */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  margin: 0 max(28px, calc((100% - 720px) / 2)) 24px;
  padding: 8px 8px 8px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; background: transparent;
  padding: 8px 0; max-height: 160px; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  border: 0; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-weight: 600; padding: 10px 20px;
}
@media (prefers-color-scheme: dark) { .send { color: #0d1324; } }
.send:hover:not(:disabled) { background: var(--accent-deep); }
.send:disabled { opacity: .6; cursor: progress; }

/* Mobile */
@media (max-width: 820px) {
  body { height: auto; min-height: 100%; }
  .app { grid-template-columns: 1fr; }
  .shelf { border-right: 0; border-bottom: 1px solid var(--line); padding: 28px 20px; overflow: visible; }
  .headline { font-size: 1.75rem; }
  .thread { padding: 28px 20px 16px; overflow: visible; }
  .empty { margin-top: 0; }
  .composer { position: sticky; bottom: 12px; margin: 0 12px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
  .topbar { padding: 14px 20px; }
}

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