:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --border: #e1e0d9;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --you: #2a78d6;
  --bot: #eb6834;
  --target: #1baf7a;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --bad: #d03b3b;
  --bad-ink: #b12a2a;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --good-bg: #e8f5e8;
  --bad-bg: #fbeaea;
  --warn-bg: #fff6e0;
  --you-bg: rgba(42, 120, 214, 0.09);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #8f8d86;
    --grid: #2c2c2a;
    --axis: #383835;
    --you: #3987e5;
    --bot: #d95926;
    --target: #199e70;
    --accent: #3987e5;
    --good-ink: #39c239;
    --bad: #e05555;
    --bad-ink: #f08080;
    --warn-ink: #f5c04a;
    --good-bg: #13261a;
    --bad-bg: #2e1616;
    --warn-bg: #2b2310;
    --you-bg: rgba(57, 135, 229, 0.13);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #8f8d86;
  --grid: #2c2c2a;
  --axis: #383835;
  --you: #3987e5;
  --bot: #d95926;
  --target: #199e70;
  --accent: #3987e5;
  --good-ink: #39c239;
  --bad: #e05555;
  --bad-ink: #f08080;
  --warn-ink: #f5c04a;
  --good-bg: #13261a;
  --bad-bg: #2e1616;
  --warn-bg: #2b2310;
  --you-bg: rgba(57, 135, 229, 0.13);
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.brand rect { fill: var(--accent); }
.brand path { stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: var(--ink-2); padding: 6px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar nav a.active { color: var(--ink); background: var(--surface-2); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
.grid-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.stack > * + * { margin-top: 16px; }
@media (max-width: 900px) { .grid-2, .grid-even { grid-template-columns: 1fr; } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad-ink); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn .spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--ink-2); font-weight: 550; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0; }
.section-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 18px 0 8px; }
.section-label:first-child { margin-top: 0; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* confidence picker */
.conf { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.conf button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 8px 4px; cursor: pointer;
  font: inherit; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.15;
}
.conf button b { font-size: 1.1rem; color: var(--ink); }
.conf button span { font-size: .7rem; }
.conf button[aria-pressed="true"] { border-color: var(--accent); background: var(--you-bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }

/* instrument search */
.lookup { position: relative; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; max-height: 340px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
}
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; cursor: pointer; font: inherit; color: var(--ink); border-bottom: 1px solid var(--border); }
.suggest button:last-child { border-bottom: 0; }
.suggest button:hover, .suggest button.hl { background: var(--surface-2); }
.suggest .meta { font-size: .78rem; color: var(--muted); }
.suggest .empty { padding: 10px 12px; color: var(--muted); font-size: .9rem; }
.inst-card { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.inst-card .name { font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.nowrap { white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }
.inst-cell .n { font-weight: 600; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inst-cell .c { font-size: .78rem; color: var(--muted); }

.pos { color: var(--good-ink); }
.neg { color: var(--bad-ink); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge svg { width: 12px; height: 12px; flex: none; }
.badge.agree { background: var(--good-bg); color: var(--good-ink); }
.badge.dismiss { background: var(--bad-bg); color: var(--bad-ink); }
.badge.pending { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.dots i.on { background: var(--you); }

/* verdict */
.verdict { border-radius: var(--radius); padding: 16px 18px; border: 1px solid; display: flex; gap: 14px; align-items: flex-start; }
.verdict.agree { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.verdict.dismiss { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.verdict .ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; }
.verdict.agree .ico { background: var(--good); }
.verdict.dismiss .ico { background: var(--bad); }
.verdict .ico svg { width: 18px; height: 18px; }
.verdict .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.verdict.agree .label { color: var(--good-ink); }
.verdict.dismiss .label { color: var(--bad-ink); }
.verdict .headline { font-size: 1.02rem; font-weight: 600; margin-top: 2px; }
.verdict ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink-2); font-size: .9rem; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { font-size: .78rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tile .k .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tile .v { font-size: 1.55rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile .s { font-size: .8rem; color: var(--ink-2); margin-top: 2px; }
.card .tiles .tile { background: var(--surface-2); border-color: transparent; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.callout { border-radius: 10px; padding: 12px 14px; background: var(--surface-2); color: var(--ink-2); font-size: .9rem; }
.callout.warn { background: var(--warn-bg); color: var(--warn-ink); }
.callout.good { background: var(--good-bg); color: var(--good-ink); }
.callout.bad { background: var(--bad-bg); color: var(--bad-ink); }
.callout ul { margin: 4px 0 0; padding-left: 18px; }
.callout b { color: inherit; }

details { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 14px; }
details summary { cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: .9rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0 0; font-size: .88rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .8rem; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; }
.legend i.dash { border-top-style: dashed; }
.legend i.dot { width: 10px; height: 10px; border-radius: 50%; border: 0; }
.legend i.band { height: 10px; border: 0; border-radius: 2px; background: var(--you-bg); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: .78rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .14); min-width: 140px; display: none;
}
.tooltip .t { font-weight: 650; margin-bottom: 4px; color: var(--ink); }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tooltip .r b { color: var(--ink); font-weight: 600; }

.empty-state { text-align: center; padding: 48px 16px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--ink-2); max-width: 560px; margin: 0 auto 18px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; text-align: left; margin: 20px 0; }
.steps div { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-size: .9rem; color: var(--ink-2); }
.steps b { display: block; color: var(--ink); margin-bottom: 2px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; border: 1px solid var(--border); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal h2 { margin-bottom: 10px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal textarea { font-family: var(--mono); font-size: .8rem; min-height: 160px; }
pre.code { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: .8rem; overflow-x: auto; margin: 8px 0; }

main.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
main.login form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
main.login .brand { justify-content: center; margin-bottom: 4px; }
main.login p { margin: 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 60; max-width: calc(100vw - 32px); pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .topbar { gap: 10px; }
  .topbar nav a { padding: 6px 8px; font-size: .9rem; }
  .brand span { display: none; }
  .hide-sm { display: none; }
  td, th { padding-left: 6px; padding-right: 6px; }
  td .hint { display: none; }
  h1 { font-size: 1.35rem; }
}
