:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --hair: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e8f1fc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --ref: #52514e;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b42e2e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7;
    --muted: #9b9991; --hair: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a; --series-1: #3987e5; --series-2: #d95926;
    --ref: #c3c2b7; --good-ink: #0ca30c; --critical-ink: #e66767; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #9b9991; --hair: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a; --series-1: #3987e5; --series-2: #d95926;
  --ref: #c3c2b7; --good-ink: #0ca30c; --critical-ink: #e66767; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; min-height: 100vh; }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pad { padding: 16px; }
.hidden { display: none !important; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--hair); }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--ink-2); text-decoration: none; border: 0; background: none; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

main { max-width: 980px; margin: 0 auto; padding: 16px 16px 120px; outline: none; }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--hair); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: none; border-color: transparent; color: var(--accent-ink); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* upload */
.drop { display: block; border: 2px dashed var(--axis); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer;
  background: var(--surface); transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-wash); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop strong { display: block; font-size: 1.1rem; margin: 8px 0 2px; }
.drop svg { color: var(--accent); }

.doc { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); }
.doc .ico { flex: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent-ink); font-weight: 700; font-size: .8rem; }
.doc .body { flex: 1; min-width: 0; }
.doc .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.bad { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical-ink); }
.pill.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); }
.pill.ai { background: var(--accent-wash); color: var(--accent-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin: 14px 0; overflow-x: auto; }
.tab { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; padding: 0 12px; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* issues */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.issue { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.issue input[type=checkbox] { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); }
.issue .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.issue .ttl { font-weight: 650; }
.issue p { margin: 6px 0 0; color: var(--ink-2); }
.sev { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; color: var(--ink-2); }
details.changes { margin-top: 8px; }
details.changes summary { cursor: pointer; color: var(--accent-ink); font-weight: 600; font-size: .9rem; min-height: 32px; display: flex; align-items: center; }
.diff { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .82rem; display: grid; gap: 4px; margin-top: 6px; overflow-x: auto; }
.diff div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.diff .old { color: var(--critical-ink); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff .new { color: var(--good-ink); }
.group-title { margin: 22px 0 8px; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--hair); }
.actionbar .inner { max-width: 980px; margin: 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

/* progress */
.progress { text-align: center; padding: 36px 16px; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--accent-wash); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* dashboard */
.hero { display: grid; gap: 14px; }
.hero .label { color: var(--ink-2); font-weight: 600; }
.hero .value { font-size: 3rem; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.meter { height: 12px; border-radius: 999px; background: var(--accent-wash); overflow: hidden; position: relative; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--accent); }
.meter > i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ref); }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--hair); border-radius: 12px; padding: 12px; }
.tile .k { font-size: .82rem; color: var(--ink-2); font-weight: 600; }
.tile .v { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.tile .d { font-size: .82rem; color: var(--muted); }
.up { color: var(--good-ink); } .down { color: var(--critical-ink); }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--hair); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--ink-2); margin: 4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.key.box { height: 10px; width: 10px; border-radius: 3px; }
.key.ref { background: repeating-linear-gradient(90deg, var(--ref) 0 4px, transparent 4px 7px); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--hair);
  border-radius: 10px; padding: 8px 10px; font-size: .85rem; box-shadow: 0 6px 24px rgba(0,0,0,.14); min-width: 120px; max-width: 260px; }
.tip .t { color: var(--muted); font-size: .78rem; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.insights { margin: 0; padding-left: 20px; }
.insights li + li { margin-top: 6px; }
.hb { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 8px 10px; align-items: center; font-size: .9rem; }
.hb .bar { height: 14px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.hb .bar > span { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hb .bar > i { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ref); }
.hb .me { font-weight: 700; }
.hb .val { font-variant-numeric: tabular-nums; color: var(--ink-2); text-align: right; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td { padding: 8px 6px; border-bottom: 1px solid var(--hair); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; position: sticky; top: 0; background: var(--surface); }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; max-height: 520px; overflow-y: auto; }
select, input[type=text], input[type=password], input[type=search] { min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--hair); background: var(--surface); width: 100%; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* history */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 22px; bottom: 0; width: 2px; background: var(--hair); }
.timeline li:last-child::before { display: none; }
.timeline .node { position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--hair); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 16px;
  border-radius: 12px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
.notice { border-left: 3px solid var(--warning); padding: 8px 12px; background: var(--surface-2); border-radius: 0 10px 10px 0; font-size: .9rem; color: var(--ink-2); }
