/* Runs — live view. Ledger style: every colour comes from tokens.css. */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { font-size: 11.5px; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--rule); padding: 0 8px; min-height: 26px; cursor: pointer; border-radius: 0; }
button:hover:not(:disabled) { border-color: var(--frame); }
button:disabled { color: var(--mute); opacity: .5; cursor: default; }
button[aria-pressed="true"] { background: var(--inv); color: var(--invOn); font-weight: 700; border-color: var(--inv); }
select, input { background: var(--panel2); border: 1px solid var(--frame); border-radius: 0; min-height: 28px; padding: 0 6px; min-width: 0; }
h1, h3, p, dl, dd, figure { margin: 0; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); height: 100dvh; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--frame); }
.detail { min-width: 0; overflow-y: auto; padding: 0 12px 40px; }

/* ---------- sidebar ---------- */
.side-head { padding: 8px 10px; display: grid; gap: 6px; border-bottom: 1px solid var(--frame); }
.side-top { display: flex; align-items: center; gap: 8px; }
.sync { flex: 1; text-align: right; font-size: 9px; letter-spacing: .08em; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-off { color: var(--staleOn); background: repeating-linear-gradient(-45deg, var(--stale) 0 6px, transparent 6px 7px), var(--stale); padding: 2px 5px; font-weight: 700; }
.field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field select, .field input { flex: 1; }
.search { border: 1px solid var(--frame); background: var(--panel2); padding-left: 7px; color: var(--mute); }
.search input { border: 0; background: transparent; color: var(--ink); }
.search:focus-within { outline: 2px solid var(--sel); outline-offset: 1px; }
.search input:focus-visible { outline: none; }
.list-head, .row-link { display: grid; grid-template-columns: minmax(0, 1fr) 48px 44px; gap: 6px; align-items: center; }
.list-head { grid-template-columns: minmax(0, 1fr) 48px 44px 28px; padding: 4px 6px 4px 14px; border-bottom: 1px solid var(--rule); }
.list-head span:not(:first-child) { text-align: right; }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.group-title { font-size: 8.5px; font-weight: 700; letter-spacing: .1em; color: var(--mute); background: var(--group); padding: 4px 14px; position: sticky; top: 0; z-index: 1; }
.row { display: grid; grid-template-columns: 7px minmax(0, 1fr) 34px; align-items: stretch; min-height: 27px; border-bottom: 1px solid var(--rule2); background: var(--rowDim); }
.row .tx-bar { width: 7px; height: auto; }
.tx-quiet { background: transparent; }
.row-run, .row-stale { background: var(--rowRun); }
.row-run .row-name, .row-stale .row-name { font-weight: 700; }
.row-fail { background: var(--rowAbn); }
.row-link { text-decoration: none; padding: 0 6px 0 7px; }
.row-main { display: flex; align-items: center; gap: 6px; min-width: 0; }
.row-link:hover .row-name { text-decoration: underline; }
.row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-num { text-align: right; color: var(--mute); white-space: nowrap; }
.row-run .row-num:last-child { color: var(--ink); font-weight: 700; }
.row-pick { border: 0; border-left: 1px solid var(--rule2); background: transparent; padding: 0; min-height: 26px; color: var(--mute); display: grid; place-items: center; }
.row-pick[aria-pressed="true"] { background: transparent; color: var(--ink); }
.row-sel { box-shadow: inset 0 0 0 2px var(--sel); background: var(--panel2); }
.pickbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--inv); color: var(--invOn); font-weight: 700; }
.pickbar span { flex: 1; }
.pickbar a { background: var(--sel); color: var(--selOn); padding: 8px 10px; text-decoration: none; }
.pickbar button { min-height: 32px; color: var(--ink); }

/* ---------- shared pieces ---------- */
.loading { margin: 10px; padding: 18px 10px; text-align: center; font-size: 9.5px; letter-spacing: .1em; color: var(--mute); border: 1px solid var(--rule); }
.empty { margin: 10px 0; padding: 14px; border: 1px solid var(--frame); background: var(--panel2); display: grid; gap: 6px; justify-items: start; }
.side .empty { margin: 10px; }
.empty p { color: var(--mute); }
.mk { display: inline-block; width: 7px; height: 7px; flex: none; background: var(--series-0); }
.mk-1 { background: var(--series-1); border-radius: 50%; }
.mk-2 { background: var(--series-2); transform: rotate(45deg); }
.mk-3 { background: var(--hollow); border: 1.5px solid var(--series-3); }
.sw { position: relative; display: inline-block; width: 26px; height: 9px; flex: none; }
.sw svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sw path, .tile-plot path { fill: none; vector-effect: non-scaling-stroke; stroke-width: 1.5; }
.sw .mk { position: absolute; left: 50%; top: 50%; margin: -3.5px 0 0 -3.5px; }
.chip-inv, .chip-sel { height: 13px; }

/* ---------- detail head ---------- */
.d-head { padding: 10px 0 6px; }
.back { display: none; }
.d-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.d-title h1 { font-size: 16px; font-weight: 700; letter-spacing: .02em; overflow-wrap: anywhere; }
.d-sub { color: var(--mute); font-size: 10px; margin-top: 2px; overflow-wrap: anywhere; }
.d-stats { display: flex; flex-wrap: wrap; gap: 1px; background: var(--rule); border: 1px solid var(--frame); margin-top: 8px; }
.d-stats div { background: var(--panel2); padding: 5px 9px; flex: 1 1 auto; }
.d-stats dt { font-size: 8.5px; letter-spacing: .08em; color: var(--mute); }
.d-stats dd { font-weight: 700; font-size: 12px; white-space: nowrap; }
.legend { border: 1px solid var(--frame); background: var(--rule); display: grid; gap: 1px; margin-top: 8px; }
.leg { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto 44px 28px; gap: 8px; align-items: center; background: var(--panel2); padding: 0 0 0 8px; min-height: 28px; }
.leg-main { display: flex; align-items: center; gap: 6px; min-width: 0; }
.leg-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.leg-name:hover { text-decoration: underline; }
.leg-num { color: var(--mute); text-align: right; white-space: nowrap; }
.leg button { border: 0; border-left: 1px solid var(--rule2); min-height: 28px; padding: 0; }

.toolbar { position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 0; background: var(--ground); border-bottom: 1px solid var(--frame); }
.toolbar .search { flex: 1 1 180px; }
.seg { display: flex; align-items: center; }
.seg .t-label { margin-right: 6px; }
.seg button { margin-left: -1px; min-width: 44px; }

/* ---------- metric groups ---------- */
.group { margin-top: 10px; border: 1px solid var(--frame); background: var(--panel2); }
.group > summary { display: flex; align-items: baseline; gap: 10px; padding: 6px 9px; cursor: pointer; list-style: none; background: var(--panel); }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: '▸'; color: var(--mute); width: 8px; }
.group[open] > summary::before { content: '▾'; }
.group[open] > summary { border-bottom: 1px solid var(--frame); }
.group-name { font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.group-meta { margin-left: auto; font-size: 9px; letter-spacing: .08em; color: var(--mute); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); overflow: hidden; }
.tiles .tile { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin: 0 -1px -1px 0; }
.tiles + .values { border-top: 1px solid var(--frame); }
.tile { background: var(--panel2); padding: 7px 9px 5px; min-width: 0; }
.tile-head { display: flex; align-items: flex-start; gap: 6px; }
.tile-name { flex: 1; font-weight: 700; overflow-wrap: anywhere; }
.tile-tag { font-size: 8.5px; letter-spacing: .08em; color: var(--mute); white-space: nowrap; padding-top: 2px; }
.tile-zoom { border: 0; min-height: 18px; padding: 0 3px; color: var(--mute); background: transparent; }
.tile-readout { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; min-height: 17px; margin: 3px 0 5px; }
.ro-label { font-size: 8.5px; letter-spacing: .08em; color: var(--mute); }
.ro { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.tile-body { display: grid; grid-template-columns: 40px minmax(0, 1fr); height: 140px; }
.tile-y { position: relative; }
.tile-y span { position: absolute; right: 5px; transform: translateY(-50%); font-size: 9px; color: var(--mute); white-space: nowrap; }
.tile-plot { position: relative; border-left: 1px solid var(--frame); border-bottom: 1px solid var(--frame); touch-action: pan-y; cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tile-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tile-plot .grid { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 1 3; }
.tile-plot .line-raw { stroke: var(--trainRaw); stroke-width: 1; }
.tile-marks { position: absolute; inset: 0; pointer-events: none; }
.tile-marks .mk { position: absolute; margin: -3.5px 0 0 -3.5px; }
.tile-cross { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--sel); pointer-events: none; }
.tile-x { display: flex; justify-content: space-between; margin-left: 40px; padding-top: 2px; font-size: 9px; color: var(--mute); }
.values { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); overflow: hidden; }
.val { border-right: 1px solid var(--rule2); border-bottom: 1px solid var(--rule2); margin: 0 -1px -1px 0; display: flex; gap: 10px; align-items: baseline; justify-content: space-between; background: var(--panel2); padding: 4px 9px; min-width: 0; }
.val-key { color: var(--mute); overflow-wrap: anywhere; min-width: 0; }
.val-nums { display: flex; gap: 10px; flex: none; max-width: 70%; overflow-wrap: anywhere; text-align: right; }
.val-nums span { display: inline-flex; gap: 4px; align-items: center; }

/* ---------- media ---------- */
.media { display: grid; gap: 1px; background: var(--rule); }
.media-field { background: var(--panel2); padding: 8px 9px; }
.media-field h3 { font-size: 11.5px; margin-bottom: 6px; }
.media-runs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.media-item { display: grid; gap: 4px; align-content: start; min-width: 0; }
.media-item figcaption { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; min-height: 28px; }
.media-run { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.media-dl { margin-left: auto; font-size: 9px; letter-spacing: .08em; }
.media-item img, .media-item video { display: block; max-width: 100%; max-height: 70vh; border: 1px solid var(--rule); background: var(--hollow); }
.media-img { border: 0; padding: 0; background: transparent; min-height: 0; cursor: zoom-in; justify-self: start; }
.media-item small { color: var(--mute); }
.media-missing { padding: 20px 10px; border: 1px solid var(--rule); color: var(--mute); }

/* ---------- config ---------- */
.cfg-tools { padding: 6px 9px; border-bottom: 1px solid var(--rule); }
.cfg-scroll { overflow-x: auto; }
.cfg { border-collapse: collapse; width: 100%; }
.cfg th, .cfg td { text-align: left; padding: 4px 9px; border-bottom: 1px solid var(--rule2); vertical-align: top; overflow-wrap: anywhere; }
.cfg th { font-size: 9.5px; letter-spacing: .04em; border-bottom: 1px solid var(--frame); white-space: nowrap; }
.cfg td:first-child { color: var(--mute); white-space: nowrap; }
.cfg .diff td { font-weight: 700; color: var(--ink); }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--frame); background: var(--panel2); color: var(--ink); padding: 0; max-width: none; max-height: none; }
dialog::backdrop { background: color-mix(in srgb, var(--ground) 80%, transparent); }
.dialog-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 6px 6px 6px 10px; border-bottom: 1px solid var(--frame); }
.dialog-head strong { overflow-wrap: anywhere; }
.zoom { width: min(1200px, 96vw); }
.zoom .tile { padding: 10px 14px; }
.zoom .tile-body { height: min(60vh, 520px); }
.zoom .tile-head { display: none; }
.viewer { max-width: 96vw; }
.viewer img { display: block; max-width: 96vw; max-height: calc(96dvh - 50px); }

/* ---------- phone ---------- */
@media (max-width: 899px) {
  html, body { height: auto; }
  body { font-size: 12px; }
  .app { display: block; height: auto; }
  .side { border-right: 0; min-height: 100dvh; }
  .list { overflow: visible; }
  .detail { display: none; overflow: visible; padding: 0 10px 40px; }
  .show-detail .side { display: none; }
  .show-detail .detail { display: block; }
  .back { display: inline-flex; align-items: center; min-height: 40px; font-weight: 700; text-decoration: none; }
  .side-head { position: sticky; top: 0; z-index: 2; background: var(--panel); }
  .group-title { position: static; }
  select, input { min-height: 40px; font-size: 16px; }
  button { min-height: 40px; }
  .row { min-height: 40px; grid-template-columns: 7px minmax(0, 1fr) 44px; }
  .list-head { grid-template-columns: minmax(0, 1fr) 48px 44px 38px; }
  .row-pick { min-height: 40px; }
  .pickbar { position: sticky; bottom: 0; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .tile-zoom { min-height: 28px; min-width: 32px; }
  .tiles, .values { grid-template-columns: minmax(0, 1fr); }
  .tile-body { height: 150px; }
  .leg { grid-template-columns: 26px minmax(0, 1fr) 44px 40px; min-height: 40px; }
  .leg-step { display: none; }
  .leg button { min-height: 40px; }
  .zoom { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; }
  .zoom .tile-body { height: calc(100dvh - 150px); }
}
