/* SN100 BASE miner dashboard — light base, dark selected (not auto-flipped). */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface-1:   #fcfcfb;
  --surface-2:   #f2f1ed;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --series-1:    #2a78d6;
  --series-2:    #eb6834;
  --series-3:    #1baf7a;
  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --shadow:      0 1px 2px rgba(11, 11, 11, .06), 0 8px 24px rgba(11, 11, 11, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-1:    #ffffff;
    --text-2:    #c3c2b7;
    --muted:     #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255, 255, 255, 0.10);
    --series-1:  #3987e5;
    --series-2:  #d95926;
    --series-3:  #199e70;
    --shadow:    0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-1:    #ffffff;
  --text-2:    #c3c2b7;
  --muted:     #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255, 255, 255, 0.10);
  --series-1:  #3987e5;
  --series-2:  #d95926;
  --series-3:  #199e70;
  --shadow:    0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page); color: var(--text-1);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------ header */
header {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  padding: 10px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.brand .sub { color: var(--muted); font-size: 12px; }
.spacer { flex: 1 1 auto; }
.hdr-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit; font-size: 13px; cursor: pointer;
  background: var(--surface-2); color: var(--text-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 11px;
}
button:hover, .btn:hover { background: var(--grid); }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--series-1); border-color: transparent; color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--series-1); }

/* ------------------------------------------------------------ nav */
nav {
  display: flex; gap: 2px; padding: 0 20px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); position: sticky; top: 49px; z-index: 39;
  overflow-x: auto;
}
nav button {
  background: none; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 9px 14px; color: var(--text-2); white-space: nowrap;
}
nav button:hover { background: var(--surface-2); }
nav button[aria-selected="true"] { color: var(--text-1); border-bottom-color: var(--series-1); font-weight: 600; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ------------------------------------------------------------ stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.tile .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 3px; letter-spacing: -0.02em; }
.tile .foot { color: var(--text-2); font-size: 12px; margin-top: 2px; }

/* ------------------------------------------------------------ panels/tables */
.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 18px; overflow: hidden;
}
.panel > h2 {
  margin: 0; padding: 11px 14px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
}
.panel > h2 .note { font-weight: 400; color: var(--muted); font-size: 12px; }
.panel-body { padding: 14px; }
.scroll-x { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th {
  color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; position: sticky; top: 0; background: var(--surface-1); z-index: 2;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-1); }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ------------------------------------------------------------ controls */
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
input[type="search"], input[type="text"], select {
  font: inherit; font-size: 13px; padding: 5px 9px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-1);
}
input[type="search"] { min-width: 220px; }
label.chk { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; cursor: pointer; }

/* ------------------------------------------------------------ pills / chips */
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill.good     { color: var(--good);     border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.pill.warning  { color: var(--warning);  border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.pill.serious  { color: var(--serious);  border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.pill.critical { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.chip {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  margin: 0 4px 4px 0; font-family: var(--mono);
}
.chip.on { color: var(--text-1); border-color: color-mix(in srgb, var(--series-1) 55%, transparent); }

/* ------------------------------------------------------------ score bar (magnitude, 1 series) */
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.bar-track { flex: 1 1 auto; height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-val { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-2); min-width: 42px; text-align: right; }

/* ------------------------------------------------------------ task matrix (status heatmap) */
.matrix-wrap { overflow: auto; max-height: 78vh; }
table.matrix { border-collapse: separate; border-spacing: 2px; }
table.matrix th, table.matrix td { border: none; padding: 0; }
table.matrix th.agent-h, table.matrix td.agent-c {
  position: sticky; left: 0; background: var(--surface-1); z-index: 3;
  padding: 0 8px 0 2px; text-align: left; max-width: 190px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-size: 12px;
}
/* Tall enough for the longest task id to read in full — the ids run to ~30
   chars, so a shorter header silently truncates the hardest problems. */
table.matrix thead th.task-h {
  height: 232px; vertical-align: bottom; position: sticky; top: 0;
  background: var(--surface-1); z-index: 2; padding: 0;
}
table.matrix thead th.task-h > div {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 11px; color: var(--text-2); text-transform: none; letter-spacing: 0;
  font-weight: 400; padding: 4px 0; max-height: 228px; overflow: hidden;
}
table.matrix thead th.corner { position: sticky; left: 0; top: 0; z-index: 4; background: var(--surface-1); }
.cell {
  width: 16px; height: 16px; border-radius: 3px; display: block; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--grid);
}
/* Status encoding is never color-alone: pass is solid, fail carries a 45deg
   texture, not-run stays empty. Tooltip + the per-agent table give the words. */
.cell.pass { background: var(--good); border-color: transparent; }
.cell.fail {
  border-color: transparent;
  background:
    repeating-linear-gradient(45deg,
      rgba(255,255,255,.55) 0 2px, transparent 2px 4px),
    var(--critical);
}
.cell.none { background: transparent; border-style: dashed; }
.cell:hover { outline: 2px solid var(--text-1); outline-offset: 1px; }
.legend { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; color: var(--text-2); font-size: 12px; }
.legend .k { display: flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------ hbar chart (magnitude) */
.hbar-row { display: grid; grid-template-columns: 240px 1fr 126px; gap: 10px; align-items: center; padding: 3px 0; }
.hbar-row .name { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-row .track { height: 14px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.hbar-row .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.hbar-row .val { font-size: 12px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------ drawer */
.drawer-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: none; backdrop-filter: blur(1px);
}
.drawer-bg.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(1100px, 96vw);
  background: var(--page); border-left: 1px solid var(--border); z-index: 51;
  transform: translateX(100%); transition: transform .16s ease-out;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; background: var(--surface-1);
}
.drawer-head h2 { margin: 0; font-size: 15px; }
.drawer-body { overflow: auto; padding: 16px; flex: 1 1 auto; }

/* ------------------------------------------------------------ code viewer */
.code-layout { display: grid; grid-template-columns: 260px 1fr; gap: 12px; min-height: 320px; }
.file-tree { border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 560px; background: var(--surface-1); }
.file-tree div {
  padding: 4px 9px; font-family: var(--mono); font-size: 12px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--grid);
}
.file-tree div:hover { background: var(--surface-2); }
.file-tree div.sel { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--text-1); }
.file-tree .sz { color: var(--muted); float: right; margin-left: 8px; }
pre.code {
  margin: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1);
  padding: 12px; overflow: auto; max-height: 560px; font-family: var(--mono);
  font-size: 12px; line-height: 1.55; tab-size: 4; white-space: pre;
}
pre.code .ln { color: var(--muted); user-select: none; }

/* ------------------------------------------------------------ tooltip */
#tip {
  position: fixed; z-index: 60; pointer-events: none; display: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px;
  box-shadow: var(--shadow); padding: 7px 10px; font-size: 12px; max-width: 320px;
}
#tip .t { font-weight: 600; margin-bottom: 2px; }
#tip .r { color: var(--text-2); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
/* agent hashes and hotkeys are long unbroken tokens — wrap rather than overflow */
.kv dd { margin: 0; color: var(--text-1); min-width: 0; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
code.inline { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }
pre.sh {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.6;
}
.hint { color: var(--text-2); font-size: 13px; margin: 0 0 12px; }
