:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --text: #1c1d1f;
  --muted: #62656b;
  --border: #dddbd3;
  --accent: #1f6f5c;
  --good: #1d7a4a;
  --good-bg: #e2f3e8;
  --mid: #8a6a00;
  --mid-bg: #fbf1d0;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --info: #3b5b8c;
  --info-bg: #e5ecf7;
  --chart-1: #1f6f5c;
  --chart-2: #c26a1b;
  --grid: #e6e4dc;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --surface: #1c1e21;
    --surface-2: #24272b;
    --text: #e9e9e6;
    --muted: #a0a3a8;
    --border: #33363b;
    --accent: #4fb89c;
    --good: #6fd39c;
    --good-bg: #173726;
    --mid: #e7c45c;
    --mid-bg: #3a3116;
    --bad: #f28b82;
    --bad-bg: #44201d;
    --info: #9bb8e6;
    --info-bg: #1f2b3d;
    --chart-1: #4fb89c;
    --chart-2: #f0a35e;
    --grid: #2c2f33;
  }
}

:root[data-theme="dark"] {
  --bg: #141517;
  --surface: #1c1e21;
  --surface-2: #24272b;
  --text: #e9e9e6;
  --muted: #a0a3a8;
  --border: #33363b;
  --accent: #4fb89c;
  --good: #6fd39c;
  --good-bg: #173726;
  --mid: #e7c45c;
  --mid-bg: #3a3116;
  --bad: #f28b82;
  --bad-bg: #44201d;
  --info: #9bb8e6;
  --info-bg: #1f2b3d;
  --chart-1: #4fb89c;
  --chart-2: #f0a35e;
  --grid: #2c2f33;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.top-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; padding-top: 14px; padding-bottom: 14px; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
h1 .sub { font-weight: 400; color: var(--muted); font-size: 0.95rem; margin-left: 6px; }
h2 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.card > .muted.small { margin-top: 10px; }

.notice { border: 1px solid var(--mid); background: var(--mid-bg); color: var(--text); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.notice.error { border-color: var(--bad); background: var(--bad-bg); }
.notice.ok { border-color: var(--good); background: var(--good-bg); }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn {
  font: inherit; font-size: 0.9rem; color: var(--text); background: var(--surface-2); cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; min-height: 34px;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }
.btn.small { font-size: 0.8rem; padding: 3px 10px; min-height: 28px; }

dialog.edit { width: min(560px, calc(100vw - 32px)); }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-bottom: 8px; }
.form-row[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field.grow { flex: 1 1 180px; }
.field input {
  font: inherit; font-size: 1rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 0;
}
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ticker-field input { width: 110px; text-transform: uppercase; font-family: var(--mono); }
.edit-list { list-style: none; margin: 12px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; max-height: 50vh; overflow-y: auto; }
.edit-list li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.edit-list li:last-child { border-bottom: 0; }
.edit-list .ticker { font-weight: 700; font-family: var(--mono); min-width: 64px; }
.edit-list .name { flex: 1; min-width: 0; color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.prose { max-width: 75ch; }
.prose h3 { font-size: 0.95rem; margin: 14px 0 4px; }
.prose h3:first-child { margin-top: 0; }
.prose p, .prose ul { margin: 0 0 8px; }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 4px; }

.search input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; width: min(260px, 70vw);
}
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap:focus-visible { outline: 2px solid var(--accent); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead th { background: var(--surface-2); font-size: 0.8rem; font-weight: 600; color: var(--muted); position: sticky; top: 0; }
thead th:first-child { background: var(--surface-2); z-index: 2; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
th[aria-sort] button { color: var(--text); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .ticker { font-weight: 700; font-family: var(--mono); }
td .name { display: block; color: var(--muted); font-size: 0.8rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
td.err { color: var(--bad); text-align: left; white-space: normal; min-width: 260px; }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.na { color: var(--muted); }

.score { display: inline-block; min-width: 42px; text-align: center; font-weight: 700; border-radius: 6px; padding: 2px 6px; }
.score.hi { background: var(--good-bg); color: var(--good); }
.score.md { background: var(--mid-bg); color: var(--mid); }
.score.lo { background: var(--bad-bg); color: var(--bad); }
.cov { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 400; }

.flags { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.flag { border-radius: 6px; padding: 4px 8px; font-size: 0.9rem; }
.flag.hea { background: var(--good-bg); }
.flag.halb { background: var(--bad-bg); }
.flag.info { background: var(--info-bg); }

.method summary { cursor: pointer; list-style: none; }
.method summary::-webkit-details-marker { display: none; }
.method summary h2::before { content: "▸ "; color: var(--muted); }
.method[open] summary h2::before { content: "▾ "; }
.method[open] summary { margin-bottom: 10px; }

footer { padding-bottom: 32px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 0; width: min(980px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-inner { padding: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { font-size: 1.25rem; }
.close { font: inherit; font-size: 1.6rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.close:hover, .close:focus-visible { background: var(--surface-2); color: var(--text); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); }
.panel { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 0.95rem; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 8px; font-size: 0.88rem; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; }

dl.kv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 4px 12px; margin: 0; font-size: 0.9rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 14px; font-family: var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

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

@media (max-width: 600px) {
  body { font-size: 14px; }
  h1 .sub { display: block; margin: 2px 0 0; }
  .bar-row { grid-template-columns: 90px 1fr 34px; }
  .dialog-inner { padding: 12px; }
}
