:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1b2330; --muted: #5d6878; --line: #dde2ea;
  --accent: #1f4f8f; --accent-ink: #fff; --user: #e8eef8; --hit: #fff6cc; --err: #a4262c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161c; --panel: #1b212a; --ink: #e6eaf0; --muted: #9aa5b5; --line: #2c3541;
          --accent: #6ea3e6; --accent-ink: #0c1118; --user: #223149; --hit: #4a4217; --err: #ff8a8f; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--err); }
.grow { flex: 1; }

body.centered { display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 24px; width: 100%; max-width: 380px; }
.login h1 { margin: 0 0 4px; }
.login form { display: grid; gap: 6px; margin-top: 12px; }
.login label { font-size: 14px; color: var(--muted); margin-top: 6px; }
input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); width: 100%; }
.login button { margin-top: 14px; }
button.primary, .login button, .btn { background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 8px; padding: 10px 16px; cursor: pointer; text-decoration: none;
  display: inline-block; font-weight: 600; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.ghost, a.ghost { background: none; border: 0; color: var(--ink); cursor: pointer;
  padding: 6px 8px; text-decoration: none; border-radius: 6px; }

.bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.bar form { margin: 0; }
body.chat { display: flex; flex-direction: column; height: 100dvh; }
.layout { display: flex; flex: 1; min-height: 0; }
.list { width: 260px; border-right: 1px solid var(--line); background: var(--panel);
  padding: 12px; overflow-y: auto; }
.list ul { list-style: none; margin: 12px 0 0; padding: 0; }
.list li { display: flex; align-items: center; }
.conv { flex: 1; text-align: left; background: none; border: 0; padding: 8px; border-radius: 6px;
  cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.active, .conv:hover { background: var(--user); }
.list .primary { width: 100%; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.hint { color: var(--muted); max-width: 640px; margin: auto; text-align: center; }
.msg { max-width: 820px; padding: 10px 14px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.bot > :first-child { margin-top: 0; } .msg.bot > :last-child { margin-bottom: 0; }
.msg.err { color: var(--err); }
.msg .status { color: var(--muted); font-size: 14px; }
.msg .live { white-space: pre-wrap; }
.msg table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 8px; }
a.cite { display: inline-block; font-size: 13px; background: var(--user); border-radius: 6px;
  padding: 0 6px; text-decoration: none; margin: 0 2px; }
.nocite { font-size: 13px; color: var(--err); border: 1px dashed var(--err); border-radius: 6px;
  padding: 0 6px; }
.composer { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line);
  background: var(--panel); }
.composer textarea { flex: 1; resize: none; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); min-height: 48px; }

.srcpage { max-width: 900px; margin: 0 auto; padding: 16px; }
.srcpage h1 { font-size: 20px; margin: 4px 0 12px; overflow-wrap: anywhere; }
.srcpage h2 { font-size: 16px; margin-top: 24px; }
.meta { display: grid; grid-template-columns: 70px 1fr; gap: 2px 10px; margin: 0 0 10px; }
.meta dt { color: var(--muted); } .meta dd { margin: 0; overflow-wrap: anywhere; }
.para { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; }
.para.hit { background: var(--hit); border-color: var(--accent); }
.para.quoted { opacity: .75; }
.pno { font-size: 12px; color: var(--muted); }
.ptext { white-space: pre-wrap; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
iframe.pdf { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; margin-top: 8px; }
.atts { padding-left: 20px; }

@media (max-width: 760px) {
  .list { position: fixed; top: 48px; bottom: 0; left: 0; z-index: 5; width: 82vw; max-width: 320px;
    transform: translateX(-100%); transition: transform .15s; }
  body.list-open .list { transform: none; box-shadow: 0 0 40px #0006; }
  .msg { max-width: 94%; }
  .user.muted, .bar .user { display: none; }
}
@media (min-width: 761px) { #toggle-list { display: none; } }
