/* NekoNode Research · Training Telemetry
   Visual grammar faithfully inspired by mimo.xiaomi.com/rl/ + persistent runs sidebar */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --surface-3: #e9e9e7;
  --border: #e4e4e1;
  --ink: #111111;
  --ink-2: #5c5c59;
  --ink-3: #8c8c88;
  --grid: #ececea;
  --accent: #2a78d6;
  --live: #d9463f;
  --ok: #1b9e6d;
  --warn: #c78300;
  --c0: #2a78d6;
  --c1: #eb6834;
  --c2: #1baf7a;
  --c3: #eda100;
  --c4: #e87ba4;
  --c5: #008300;
  --c6: #4a3aa7;
  --c7: #e34948;
  --radius: 6px;
  --font: "Inter", -apple-system, "Segoe UI", system-ui, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  --nav-h: 48px;
  --side-w: 276px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111111;
  --surface: #161616;
  --surface-2: #1e1e1e;
  --surface-3: #2a2a2a;
  --border: #2a2a29;
  --ink: #ececea;
  --ink-2: #a3a3a0;
  --ink-3: #6f6f6c;
  --grid: #242423;
  --accent: #3987e5;
  --live: #e6554e;
  --ok: #199e70;
  --warn: #d49419;
  --c0: #3987e5;
  --c1: #d95926;
  --c2: #199e70;
  --c3: #c98500;
  --c4: #d55181;
  --c5: #2da653;
  --c6: #9085e9;
  --c7: #e66767;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.link { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--accent); }

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* -------------------------------------------------------------- sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  z-index: 30;
}
.side-head {
  height: var(--nav-h);
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.side-brand .tag {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink-2);
  letter-spacing: 0;
}
.side-search-wrap {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.side-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
}
.side-search:focus { border-color: var(--ink-3); }
.side-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}
.cat-pill {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--ink-3);
}
.cat-pill:hover { color: var(--ink); border-color: var(--ink-3); }
.cat-pill.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.side-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
}
.side-group { margin-bottom: 12px; }
.side-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.side-group-title.live { color: var(--live); }

.run-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 5px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background 0.08s ease;
}
.run-item:hover { background: var(--surface-2); }
.run-item.active {
  background: var(--surface-2);
  border-color: var(--border);
}
.run-item-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.run-item-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.run-item.active .run-item-name { font-weight: 600; }
.run-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-left: 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
}
.run-badge {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--surface-3);
  color: var(--ink-2);
}

.side-foot {
  border-top: 1px solid var(--border);
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex: none;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}
.dot.live {
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(217, 70, 63, 0.22);
  animation: pulse 1.8s infinite;
}
.dot.finished { background: var(--ok); }
.dot.crashed, .dot.failed { background: var(--warn); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(217, 70, 63, 0.28); }
  50% { box-shadow: 0 0 0 5px rgba(217, 70, 63, 0.04); }
}

/* ------------------------------------------------------------------ nav */
.content-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--nav-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  height: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--ink-2);
  position: relative;
  white-space: nowrap;
  font-size: 13.5px;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); font-weight: 500; }
.tabs a.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
}
.tab-cnt {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}
.nav-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  align-self: center;
}
.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-status {
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}
.nav-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.15;
}
.nav-cell .k {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.nav-cell .v {
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.nav-cost {
  padding-right: 16px;
  border-right: 1px solid var(--border);
}
.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.mobile-menu-btn { display: none; }

/* ----------------------------------------------------------------- main */
.wrap {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 22px 42px;
  flex: 1;
}
.foot {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 22px 24px;
  color: var(--ink-3);
  font-size: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.foot a { color: var(--ink-2); }
.foot a:hover { color: var(--ink); text-decoration: underline; }

/* --------------------------------------------------------------- status */
.status {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 14px;
  overflow: hidden;
}
.status-line {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) auto auto minmax(180px, 1fr);
  align-items: center;
  gap: 10px 20px;
  padding: 14px 16px;
  font-size: 14px;
}
.status-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.status-name-text { min-width: 0; }
.status-name b {
  display: block;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-name .sub {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.status-line .big {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}
.clock-col {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.25;
}
.clock-col .mono { font-size: 14px; }
.clock-col .started {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
}
.phase {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.phase-track {
  position: relative;
  height: 4px;
  flex: 1;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.phase-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: var(--accent);
}
.phase-fill.live {
  background: repeating-linear-gradient(90deg, var(--live) 0 8px, var(--accent) 8px 16px);
}
.phase-text {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
}

.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  border-top: 1px solid var(--border);
}
.kv > div {
  padding: 10px 16px 12px;
  border-left: 1px solid var(--border);
  min-width: 0;
}
.kv > div:first-child { border-left: 0; }
.kv .k {
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kv .v {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  white-space: nowrap;
  margin-top: 2px;
  letter-spacing: -0.01em;
}
.kv .v .u { color: var(--ink-3); font-size: 11.5px; margin-left: 3px; font-weight: 400; }

.delta { font-size: 11.5px; font-weight: 400; margin-left: 5px; color: var(--ink-2); }
.delta.good { color: var(--ok); }
.delta.bad { color: var(--live); }
.delta.flat { color: var(--ink-3); }

/* -------------------------------------------------------------- notices */
.notices {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4px 14px;
  margin-bottom: 14px;
}
.notice {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.notice:first-child { border-top: 0; }
.notice .tl-tag {
  flex: none;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  padding-top: 2px;
}

/* ----------------------------------------------------------- benchmarks */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 8px;
}
.section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.bench-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  min-width: 0;
}
.bench .card-title { font-weight: 600; font-size: 12.5px; }
.bench .card-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.bench .bench-val {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  margin-top: 6px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.bench .bench-pct { font-size: 12px; font-weight: 400; color: var(--ink-2); }

/* --------------------------------------------------------------- charts */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.chart-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chart-card {
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  cursor: pointer;
  transition: border-color 0.1s ease;
}
.chart-card:hover { border-color: var(--ink-3); }
.chart-card .card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}
.chart-card .tag {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  overflow-wrap: anywhere;
  font-weight: 500;
}
.chart-card .tag .dim { color: var(--ink-3); font-weight: 400; }
.chart-card .val {
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  text-align: right;
  color: var(--ink);
  flex: none;
}
.chart-card .desc {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swatch {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.chart-plot {
  position: relative;
  width: 100%;
  height: 175px;
  margin-top: 2px;
}
.chart-grid.cols-2 .chart-plot { height: 220px; }
.ssr-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.svg-grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.svg-axis-line { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.svg-axis { font-family: var(--mono); font-size: 10px; fill: var(--ink-3); }
.svg-empty { font-family: var(--mono); font-size: 11.5px; fill: var(--ink-3); }
.svg-cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }

.chart-tip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 8;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-family: var(--mono);
  min-width: 130px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
}
.tip-head { color: var(--ink-3); margin-bottom: 2px; font-size: 10.5px; }
.tip-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip-lbl { color: var(--ink-2); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-val { color: var(--ink); font-weight: 600; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 11.5px;
  color: var(--ink-2);
  margin: 4px 0 4px;
}
.legend-item { display: inline-flex; align-items: center; gap: 4px; }

/* ------------------------------------------------------------- controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 0 0 12px;
  font-size: 12.5px;
}
.search {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  padding: 5px 9px;
  width: 280px;
  max-width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
}
.search:focus { border-color: var(--ink-3); }
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.seg a, .seg button {
  padding: 4px 9px;
  color: var(--ink-2);
  border-left: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11.5px;
}
.seg a:first-child, .seg button:first-child { border-left: 0; }
.seg a.active, .seg button.active { background: var(--ink); color: var(--bg); }
.seg a:not(.active):hover, .seg button:not(.active):hover { background: var(--surface-2); color: var(--ink); }

/* -------------------------------------------------------------- metrics */
.metrics-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.tree {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  max-height: calc(100vh - var(--nav-h) - 32px);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
}
.tree-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--ink-2);
  margin-bottom: 1px;
}
.tree-node:hover { background: var(--surface-2); color: var(--ink); }
.tree-node.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.tree-node .cnt { color: var(--ink-3); font-size: 11px; }

/* --------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.tbl th, .tbl td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.tbl th {
  font-weight: 600;
  color: var(--ink-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tbl tr:last-child td { border-bottom: 0; }

.cfg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.cfg-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.cfg-k { color: var(--ink-3); }
.cfg-v { color: var(--ink); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----------------------------------------------------------------- logs */
.log-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 74vh;
  padding: 8px 0;
}
.log-line {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  padding: 0 12px;
}
.log-line:hover { background: var(--surface-2); }
.log-ln { color: var(--ink-3); user-select: none; text-align: right; padding-right: 12px; }
.log-txt { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }

/* ---------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.56);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-desc { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.modal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 12px;
  color: var(--ink-2);
  padding: 8px 0 10px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.modal-stats b { color: var(--ink); }
.modal-chart { position: relative; height: 340px; }

/* ---------------------------------------------------------------- about */
.prose { max-width: 760px; }
.prose h2 { font-size: 17px; font-weight: 600; margin: 20px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose p { color: var(--ink-2); margin-bottom: 10px; line-height: 1.6; }
.prose pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 12px 0;
}

/* ----------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-line { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 0 0 36px rgba(0, 0, 0, 0.45);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  .nav-status { display: none; }
  .metrics-layout { grid-template-columns: 1fr; }
  .tree { position: static; max-height: none; display: flex; flex-wrap: wrap; gap: 4px; }
}
@media (max-width: 640px) {
  .chart-grid, .chart-grid.cols-2 { grid-template-columns: 1fr; }
  .wrap { padding: 14px 12px 32px; }
  .nav-inner { padding: 0 12px; }
}
