:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #5f6b7a;
  --border: #e1e5ea;
  --accent: #2456d6;
  --accent-text: #ffffff;
  --ok: #157347;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d5;
  --none: #4b5563;
  --none-bg: #eceff3;
  --error: #b42318;
  --quote-bg: #f2f5fb;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1f25;
    --text: #e7ebf0;
    --muted: #9aa5b1;
    --border: #2c333b;
    --accent: #6b93ff;
    --accent-text: #0b1020;
    --ok: #6fd39b;
    --ok-bg: #173325;
    --warn: #f3c46b;
    --warn-bg: #3a2d10;
    --none: #b7c0ca;
    --none-bg: #262c33;
    --error: #ff8a80;
    --quote-bg: #1f2630;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-links { display: flex; gap: 16px; font-size: 14px; }
a { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 16px;
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .main { order: -1; } /* on phones, asking comes first */
  .topbar { flex-direction: column; align-items: flex-start; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.block + .block { margin-top: 20px; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 8px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
input[type="file"] { width: 100%; font-size: 13px; }
button {
  margin-top: 8px;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: progress; }
button.link {
  background: none;
  color: var(--error);
  padding: 0 4px;
  margin: 0;
  font-weight: 400;
  font-size: 13px;
}

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.doc-name { overflow-wrap: anywhere; }
.doc-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

.admin summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.status { font-size: 13px; min-height: 1em; overflow-wrap: anywhere; }
.status.ok { color: var(--ok); }
.status.err { color: var(--error); }

.ask { display: flex; gap: 10px; align-items: flex-start; }
.ask textarea { flex: 1; resize: vertical; }
.ask button { margin-top: 0; white-space: nowrap; }

.result-head { display: flex; align-items: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.answered { color: var(--ok); background: var(--ok-bg); }
.badge.partial { color: var(--warn); background: var(--warn-bg); }
.badge.insufficient_context { color: var(--none); background: var(--none-bg); }

.answer { font-size: 16px; margin: 12px 0; white-space: pre-wrap; }
.notice { color: var(--warn); background: var(--warn-bg); font-size: 13px; padding: 8px 10px; border-radius: 6px; margin: 0 0 12px; }
.marker {
  margin: 0 1px;
  padding: 0 5px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  background: var(--quote-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  vertical-align: 1px;
}

.citations { padding-left: 0; list-style: none; margin: 0; display: grid; gap: 10px; }
.citations li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  scroll-margin-top: 20px;
  transition: box-shadow 0.2s;
}
.citations li.flash { box-shadow: 0 0 0 2px var(--accent); }
.cite-source { font-size: 13px; color: var(--muted); }
.cite-source strong { color: var(--text); }
.citations blockquote {
  margin: 6px 0 0;
  padding: 6px 10px;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  overflow-wrap: anywhere;
}

.meta { color: var(--muted); font-size: 12px; margin-top: 12px; }
.error { color: var(--error); overflow-wrap: anywhere; }
.intro { color: var(--muted); margin-top: 24px; font-size: 14px; }
.intro ol { padding-left: 20px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Admin-only controls appear once an admin key is entered (see syncAdminControls). */
body:not(.has-admin-key) .admin-only {
  display: none;
}
