:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --dim: #5c6570;
  --line: #dde1e6;
  --accent: #2f6feb;
  --accent-ink: #ffffff;
  --q-bg: #e8effc;
  --err: #b3261e;
  --err-bg: #fdecea;
  --chip: #eef1f5;
  --radius: 10px;
  /* Height of the fixed composer, re-measured by app.js: it grows with the
     textarea and is taller on a narrow screen. Everything that has to stay out
     from under it is derived from this. */
  --composer-h: 86px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --panel: #1c2026;
    --ink: #e6e9ed;
    --dim: #9aa4b0;
    --line: #2c323a;
    --accent: #5b8ff5;
    --accent-ink: #0e1116;
    --q-bg: #232c3d;
    --err: #ff8a80;
    --err-bg: #35211f;
    --chip: #262c34;
  }
}

* { box-sizing: border-box; }

/* The views, the panel and the composer all set display, which would otherwise
   beat the user-agent rule for [hidden] and leave them permanently visible. */
[hidden] { display: none !important; }

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

button, input, textarea {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ header */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  max-width: 980px;
  margin: 0 auto;
}

h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 650;
  white-space: nowrap;
}

.tabs { display: flex; gap: 4px; }
.spacer { flex: 1; }

.tab {
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--dim);
}
.tab:hover { background: var(--chip); }
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
  color: var(--dim);
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.status {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 14px 9px;
  font-size: 12.5px;
  color: var(--dim);
}

/* -------------------------------------------------------------------- main */
main {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--composer-h) + 44px);
}

.view { display: block; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.toolbar input[type=text] {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.toolbar label { color: var(--dim); font-size: 13px; }
.toolbar button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
}

.hint { color: var(--dim); font-size: 13px; margin: -4px 0 14px; }
.empty { color: var(--dim); padding: 24px 0; }

/* --------------------------------------------------------------- transcript */
/* scrollIntoView({block:'end'}) parks the turn's bottom edge at the bottom of the
   scrollport, which is where the composer is: without this the spinner, the
   elapsed counter and the answer's candidate chips end up underneath it. */
.turn { margin-bottom: 18px; }
.turn, .notice { scroll-margin-bottom: calc(var(--composer-h) + 16px); }

.notice {
  color: var(--dim);
  font-size: 13px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 10px 13px;
}

.q {
  background: var(--q-bg);
  border-radius: var(--radius);
  padding: 10px 13px;
  white-space: pre-wrap;
  margin-bottom: 8px;
}

.a {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  white-space: pre-wrap;
  /* Answers quote spec tables whose columns are aligned with spaces. Let a wide
     one scroll inside its own block; the page itself must never scroll sideways. */
  overflow-x: auto;
}

.a.error { color: var(--err); background: var(--err-bg); border-color: var(--err); }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--dim);
}

.chip {
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.badge {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11.5px;
  background: var(--chip);
}
.badge.bad { background: var(--err-bg); color: var(--err); }

/* ------------------------------------------------------------------ waiting */
.waiting { display: flex; align-items: center; gap: 10px; color: var(--dim); }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.slow { color: var(--dim); font-size: 12.5px; margin-top: 6px; }

/* ---------------------------------------------------------------- composer */
#composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#composer .inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  width: 100%;
  align-items: flex-end;
}
#q {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
#send {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius);
  padding: 11px 20px;
  cursor: pointer;
}
#send:disabled { opacity: 0.5; cursor: default; }

/* ------------------------------------------------------------------ history */
.row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.row:hover { border-color: var(--accent); }
.row-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 4px;
}
.row-q { font-weight: 550; }
.detail { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.detail .label { font-size: 12px; color: var(--dim); margin-bottom: 3px; }
.detail .body { white-space: pre-wrap; margin-bottom: 10px; }

/* ---------------------------------------------------------------- candidates */
.cand {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.cand-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.cand-title { font-weight: 550; }
.cand-snip { color: var(--dim); font-size: 13px; margin-top: 5px; }
.cand-sib { color: var(--dim); font-size: 12px; margin-top: 5px; }

/* --------------------------------------------------------------- doc panel */
#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 8;
}

#panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 9;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head strong { flex: 1; font-size: 14px; }
#panel-body {
  margin: 0;
  padding: 14px;
  overflow: auto;
  flex: 1;
  white-space: pre-wrap;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 620px) {
  h1 { font-size: 15px; }
  .bar { gap: 6px; padding: 8px 10px; }
  main { padding: 12px 10px calc(var(--composer-h) + 44px); }
  #panel { width: 100%; }
}
