/* Tracer dashboard. One file, no build step, no scripts. Light and dark follow the system setting. */

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --text: #1a1e23;
  --muted: #566170;
  --border: #d6dbe1;
  --grid: #e3e6ea;
  --accent: #1d5bb8;
  --accent-text: #ffffff;
  --good: #176b2e;
  --warn: #8a5a00;
  --bad: #b01f14;
  --c1: #1d5bb8;
  --c2: #b4540a;
  --c3: #0d7569;
  --c4: #7a3fc4;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --surface: #171b21;
    --surface-2: #1f242b;
    --text: #e4e7eb;
    --muted: #98a3b0;
    --border: #2d343d;
    --grid: #262c34;
    --accent: #7db0ff;
    --accent-text: #0b1220;
    --good: #4cc26b;
    --warn: #e0ac3c;
    --bad: #ff8077;
    --c1: #7db0ff;
    --c2: #f0a45d;
    --c3: #4fc3b5;
    --c4: #bda0f5;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- shell ---- */

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 10px 16px 6px; max-width: 1100px; margin: 0 auto; }
.brand { font-weight: 700; letter-spacing: .02em; color: var(--text); text-decoration: none; }
.crumb { color: var(--muted); flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.logout { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who { color: var(--muted); }

nav { max-width: 1100px; margin: 0 auto; padding: 0 8px; }
.tabs { display: flex; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; }
.tabs a { display: block; padding: 8px 10px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
footer { max-width: 1100px; margin: 0 auto; padding: 8px 16px 24px; color: var(--muted); font-size: 12px; }

/* ---- type ---- */

h1 { overflow-wrap: anywhere; font-size: 20px; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 15px; line-height: 1.3; margin: 28px 0 8px; font-weight: 650; }
h3 { font-size: 13px; margin: 18px 0 6px; font-weight: 650; color: var(--muted); }
p { margin: 8px 0; max-width: 72ch; }
.page-head { margin-bottom: 12px; }
.sub, .note { color: var(--muted); }
.note { font-size: 12px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 4px; border-radius: 3px; overflow-wrap: anywhere; }

/* ---- controls ---- */

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin: 8px 0 16px; }
.filters label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12px; }

select, input[type="text"], input[type="password"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 4px; padding: 5px 8px; min-height: 32px; max-width: 100%;
}

button, .button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 4px; padding: 5px 12px; min-height: 32px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.actions form { margin: 0; }

/* ---- stats ---- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 8px 0 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 8px 12px; }
.stat dt { color: var(--muted); font-size: 12px; }
.stat dd { margin: 0; overflow-wrap: anywhere; }
.stat dd.num { font-size: 22px; font-weight: 650; line-height: 1.3; text-align: left; }
.stat dd.note { margin-top: 2px; }

/* ---- tables ---- */

.scroll { overflow-x: auto; max-width: 100%; }
table.data { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--border); }
table.data.narrow { width: auto; min-width: 16rem; }
.data caption { text-align: left; color: var(--muted); padding: 4px 0; }
.data th, .data td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; white-space: nowrap; }
.data thead th { background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--muted); }
.data tbody th { font-weight: 500; }
.data tbody tr:last-child > * { border-bottom: 0; }
.data .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.data .wrap { white-space: normal; overflow-wrap: anywhere; max-width: 34rem; }

.badge { display: inline-block; border: 1px solid currentColor; border-radius: 3px; padding: 0 6px; font-size: 12px; font-weight: 600; }
.badge.open { color: var(--bad); }
.badge.resolved { color: var(--good); }
.badge.ignored, .badge.unknown { color: var(--muted); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.empty { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 8px 16px 12px; max-width: 46rem; }
.empty h2 { margin-top: 8px; }

.banner { border: 1px solid var(--border); border-left: 4px solid var(--accent); background: var(--surface); padding: 8px 12px; margin: 12px 0; }
.banner.error { border-left-color: var(--bad); }
.banner strong { font-weight: 650; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }

pre.trace {
  margin: 0; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border);
  overflow: auto; max-height: 28rem; white-space: pre; tab-size: 4;
}
pre.trace.wrapped { white-space: pre-wrap; overflow-wrap: anywhere; }

ol.crumbs { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 12.5px; border: 1px solid var(--border); background: var(--surface); max-height: 20rem; overflow: auto; }
ol.crumbs li { padding: 2px 10px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
ol.crumbs li:last-child { border-bottom: 0; }
.lvl { display: inline-block; min-width: 5ch; font-weight: 600; text-transform: uppercase; font-size: 11px; }
.lvl.error { color: var(--bad); }
.lvl.warn { color: var(--warn); }

/* ---- charts ---- */

.chart { margin: 8px 0 16px; max-width: 760px; }
.chart-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
.svg-chart { display: block; width: 100%; min-width: 560px; height: auto; }
.svg-chart.short { min-width: 480px; }
.svg-chart .grid { stroke: var(--grid); stroke-width: 1; }
.svg-chart .tick, .svg-chart .axis-title, .svg-chart .note { fill: var(--muted); font: 12px var(--sans); }
.svg-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.svg-chart .line.s1 { stroke: var(--c1); }
.svg-chart .line.s2 { stroke: var(--c2); stroke-dasharray: 7 3; }
.svg-chart .line.s3 { stroke: var(--c3); stroke-dasharray: 2 3; }
.svg-chart .line.s4 { stroke: var(--c4); stroke-dasharray: 8 3 2 3; }
.svg-chart .area { stroke: none; opacity: .14; }
.svg-chart .area.s1, .svg-chart .dot.s1, .svg-chart .bar.s1, .svg-chart .seg.s1 { fill: var(--c1); }
.svg-chart .area.s2, .svg-chart .dot.s2, .svg-chart .bar.s2, .svg-chart .seg.s2 { fill: var(--c2); }
.svg-chart .area.s3, .svg-chart .dot.s3, .svg-chart .bar.s3, .svg-chart .seg.s3 { fill: var(--c3); }
.svg-chart .area.s4, .svg-chart .dot.s4, .svg-chart .bar.s4, .svg-chart .seg.s4 { fill: var(--c4); }
.svg-chart .track { fill: var(--surface-2); stroke: var(--border); }
.svg-chart .seg { stroke: var(--surface); stroke-width: 1; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; list-style: none; margin: 6px 0 0; padding: 0; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; border-radius: 2px; background: var(--c1); }
.swatch.s2 { background: var(--c2); }
.swatch.s3 { background: var(--c3); }
.swatch.s4 { background: var(--c4); }

/* ---- login ---- */

body.plain main { max-width: 22rem; margin: 12vh auto 0; }
body.plain form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
body.plain label { display: flex; flex-direction: column; gap: 4px; }
body.plain input { width: 100%; }

@media (max-width: 480px) {
  main { padding: 12px; }
  .stat dd.num { font-size: 19px; }
  .kv { grid-template-columns: 1fr; }
}
