:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1b2333;
  --muted: #5d6b82;
  --border: #dde3ee;
  --accent: #1f5eff;
  --accent-weak: #e7eeff;
  --danger: #c62f3b;
  --ok: #19804a;
  --ok-weak: #e3f5ea;
  --add: #e6f6ec;
  --del: #fde8ea;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Chart series (validated categorical slots 1–2, light and dark). */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e9edf4;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d;
    --surface: #1a202b;
    --text: #e6eaf2;
    --muted: #97a3b8;
    --border: #2c3442;
    --accent: #6d95ff;
    --accent-weak: #22304f;
    --danger: #ff6b76;
    --ok: #4cc584;
    --ok-weak: #18352a;
    --add: #18352a;
    --del: #3d1d22;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #252c39;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 600; }

.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

.account { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); }

.main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

h1 { font-size: 22px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
h2 { font-size: 17px; margin: 0; display: flex; align-items: center; gap: 8px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

label { display: block; font-weight: 600; font-size: 14px; margin: 10px 0 4px; }
.label-row { display: flex; align-items: center; gap: 6px; margin: 10px 0 4px; }
.label-row label { margin: 0; }

input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=time], textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea.editor { font-family: var(--mono); font-size: 13px; line-height: 1.45; min-height: 60vh; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; }
.check input { width: auto; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }

button, .btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.small, .btn.small { padding: 3px 9px; font-size: 13px; }
.btn { text-decoration: none; }

.help {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  padding: 0;
  line-height: 20px;
  flex: none;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td code, .mono { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--accent-weak); color: var(--accent); }
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.off { background: var(--border); color: var(--muted); }

.versions li { list-style: none; padding: 8px 0; border-bottom: 1px solid var(--border); }
.versions { padding: 0; margin: 0; max-height: 65vh; overflow: auto; }
.versions .meta { font-size: 13px; color: var(--muted); }

.diff { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 65vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.diff div { padding: 0 8px; }
.diff .add { background: var(--add); }
.diff .del { background: var(--del); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.diff .same { color: var(--muted); }
.diff .gap { color: var(--muted); font-style: italic; }

pre.view { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow: auto; background: var(--bg); padding: 10px; border-radius: 6px; margin: 0; }

.modal { border: 1px solid var(--border); border-radius: 10px; padding: 0; width: min(860px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
.modal::backdrop { background: rgb(0 0 0 / .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px; }
.icon-btn { border: 0; background: transparent; font-size: 24px; line-height: 1; padding: 0 6px; }

.error { color: var(--danger); margin: 8px 0; white-space: pre-line; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--danger); color: #fff; }

.qr { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 8px; }
.qr img { width: 280px; height: 280px; }

.hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; text-decoration: none; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
td.num { font-variant-numeric: tabular-nums; }
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 860px) { .grid-2.even { grid-template-columns: 1fr; } }
.ok-text { color: var(--ok); margin: 8px 0; }
details { margin-top: 6px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; }
textarea { font: inherit; }

/* Date pickers: native calendar popup, themed field; the picker icon follows light/dark. */
input[type=datetime-local], input[type=date], input[type=time] { max-width: 260px; font-variant-numeric: tabular-nums; color-scheme: light dark; }
input[type=datetime-local]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .7; }
input[type=datetime-local]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* File picker: the native "Choose File" button styled like the other buttons. */
input[type=file] {
  display: block; width: 100%; padding: 8px; font: inherit; font-size: 14px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 8px; background: var(--bg); cursor: pointer;
}
input[type=file]:hover { border-color: var(--accent); }
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent-weak); color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--accent); color: #fff; }

/* Dialogs */
.badge.warn { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
tr.attention td { background: color-mix(in srgb, var(--danger) 6%, transparent); }
table.dialogs td:nth-child(2) { max-width: 460px; overflow-wrap: anywhere; }
.hold { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); }
.hold.held { background: var(--accent-weak); border-color: var(--accent); }
.chat { display: flex; flex-direction: column; gap: 8px; height: 56vh; min-height: 320px; overflow-y: auto; padding: 8px 2px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); }
.msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--accent-weak); border-color: transparent; }
.msg.operator { background: var(--ok-weak); border-color: var(--ok); }
.msg.broadcast { background: var(--surface); border-style: dashed; }
.msg-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.compose { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }
.compose textarea { resize: vertical; }
.touches { list-style: none; padding: 0; margin: 8px 0 0; }
.touches li { padding: 4px 0; }
@media (max-width: 860px) { .chat { height: 50vh; } .msg { max-width: 92%; } }

/* Journal */
table.audit td { vertical-align: top; }
table.audit td:nth-child(4) { min-width: 200px; }
table.audit td:nth-child(5) { max-width: 520px; overflow-wrap: anywhere; }
.changes { list-style: none; padding: 0; margin: 0; }
.changes li { padding: 2px 0; }
.changes code { font-size: 12px; }
.small-text { font-size: 12px; margin-top: 2px; }

/* ---------- analytics ---------- */
.subnav { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--border); }
.subnav a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: var(--surface); color: var(--text); padding: 5px 12px; font-size: 13px; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-2 > .card { margin: 0; }
.grid-2 h3 { font-size: 14px; margin: 12px 0 8px; }
.stat .hint { margin-top: 2px; }
.chart-fig { margin: 0; }
.chart-fig figcaption { font-weight: 600; margin-bottom: 6px; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--border); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .series-1 { fill: var(--series-1); }
svg.chart .series-2 { fill: var(--series-2); }
svg.chart .hit { fill: transparent; }
svg.chart .day:hover .hit, svg.chart .day:focus .hit { fill: var(--text); fill-opacity: 0.05; }
svg.chart .day:focus { outline: none; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.swatch.series-1 { background: var(--series-1); }
.swatch.series-2 { background: var(--series-2); }
.chart-tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgb(0 0 0 / 0.12); font-variant-numeric: tabular-nums; }
.chart-tip .tip-head { font-weight: 600; margin-bottom: 2px; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 12px; }
.bar { height: 12px; border-radius: 0 4px 4px 0; }
.bar.series-1 { background: var(--series-1); }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.gap-link { color: var(--muted); }
table.questions td { vertical-align: top; }
table.questions td:nth-child(2) { min-width: 280px; max-width: 560px; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
}

/* answer check (eval) */
svg.chart .trend-line { fill: none; stroke: var(--series-1); stroke-width: 2; }
svg.chart .trend-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; cursor: default; }
svg.chart .trend-dot.bad { fill: var(--danger); }
.eval-progress { margin-top: 12px; }
.eval-progress progress { width: 100%; height: 8px; margin-top: 6px; accent-color: var(--accent); }
table.eval-runs tr.clickable { cursor: pointer; }
table.eval-runs tr.clickable:hover td { background: var(--accent-weak); }
.alert-card { border-color: var(--danger); }
.alert-card ul { margin: 6px 0 0; padding-left: 20px; }
.eval-results { display: flex; flex-direction: column; gap: 10px; }
.eval-result { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.eval-question { font-weight: 600; }
.eval-result details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.eval-answer { white-space: pre-wrap; margin-top: 6px; padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 14px; }
