:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --raised: #242422;
  --hover: #20201f;
  --ink: #f4f4f1;
  --ink-2: #c3c2b7;
  --muted: #8f8d86;
  --grid: #2c2c2a;
  --axis: #3a3a37;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5;
  --track: #0d366b;
  /* categorical series, dark steps (validated against #1a1a19) */
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  /* status: always paired with a text label */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  --panel-w: min(700px, 100vw);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
}

body.lock {
  overflow: hidden;
}

a {
  color: var(--ink);
  text-underline-offset: 3px;
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

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

.shell {
  margin: 0 auto;
  max-width: 1320px;
  padding: 28px max(20px, env(safe-area-inset-right)) 80px max(20px, env(safe-area-inset-left));
}

/* ---- header, filters ---- */

.top {
  align-items: flex-start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  font-size: 0.88rem;
  gap: 4px 18px;
  justify-content: flex-end;
}

.nav a {
  color: var(--ink-2);
  padding: 4px 0;
  text-decoration: none;
}

.nav a:hover {
  color: var(--ink);
}

.nav a[aria-current="page"] {
  border-bottom: 2px solid var(--ink);
  color: var(--ink);
}

@media (max-width: 719px) {
  .top {
    flex-direction: column-reverse;
    gap: 14px;
  }

  .nav {
    justify-content: flex-start;
  }

  .nav a {
    align-items: center;
    display: inline-flex;
    min-height: 36px;
  }
}

.sync {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.82rem;
  gap: 7px;
  margin: 6px 0 0;
}

.filters {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin: 22px 0 6px;
}

.field {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.85rem;
  gap: 8px;
}

select {
  appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238f8d86' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 32px;
  padding: 4px 30px 4px 10px;
}

.check {
  align-items: center;
  color: var(--ink-2);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.85rem;
  gap: 8px;
  min-height: 32px;
}

.check input {
  accent-color: var(--accent);
  height: 16px;
  margin: 0;
  width: 16px;
}

/* ---- sections ---- */

.block {
  margin-top: 30px;
}

.block-head {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: space-between;
  margin-bottom: 12px;
}

h2 {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.005em;
  margin: 0;
}

.count {
  color: var(--muted);
  font-weight: 400;
  margin-left: 4px;
}

h3 {
  font-size: 1rem;
  font-weight: 650;
  margin: 0;
  overflow-wrap: anywhere;
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  margin: 0;
  padding: 16px;
}

.note {
  color: var(--ink-2);
  font-size: 0.85rem;
  margin: 8px 0;
}

.muted {
  color: var(--muted);
}

/* segmented control */
.seg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
}

.seg button {
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  min-height: 28px;
  padding: 3px 10px;
  white-space: nowrap;
}

.seg button:hover {
  background: var(--hover);
  color: var(--ink);
}

.seg button[aria-pressed="true"] {
  background: var(--raised);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  color: var(--ink);
  font-weight: 600;
}

.btn {
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.82rem;
  min-height: 32px;
  padding: 4px 12px;
}

.btn:hover {
  background: #2c2c2a;
}

/* status: colored dot + text label, never color alone */
.badge {
  align-items: center;
  color: var(--ink-2);
  display: inline-flex;
  font-size: 0.8rem;
  gap: 6px;
  white-space: nowrap;
}

.dot {
  background: var(--muted);
  border-radius: 50%;
  display: inline-block;
  flex: none;
  height: 8px;
  width: 8px;
}

.dot.is-accent {
  background: var(--accent);
}

.dot.is-good {
  background: var(--good);
}

.dot.is-bad {
  background: var(--critical);
}

.dot.is-warn {
  background: var(--warning);
}

.dot.is-pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ---- GPU hosts ---- */

.hosts {
  display: grid;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.host-head {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: space-between;
}

.instance {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.gpu-model {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 2px 0 0;
}

.host-body {
  display: grid;
  gap: 16px 28px;
  margin-top: 14px;
}

/* many GPUs: table beside the charts; one or two: charts in a row under the table */
@media (min-width: 1000px) {
  .host-body.side {
    grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  }

  .host-body.side .metrics {
    grid-template-columns: minmax(0, 1fr);
  }
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  width: 100%;
}

th {
  color: var(--muted);
  font-weight: 500;
  text-align: left;
}

th,
td {
  border-bottom: 1px solid var(--grid);
  padding: 6px 10px 6px 0;
  vertical-align: middle;
  white-space: nowrap;
}

th.num,
td.num {
  text-align: right;
}

.gpu-table td:first-child {
  color: var(--muted);
}

.util {
  align-items: center;
  display: flex;
  gap: 8px;
}

.meter {
  background: var(--track);
  border-radius: 3px;
  flex: none;
  height: 6px;
  overflow: hidden;
  width: 84px;
}

.meter > span {
  background: var(--accent);
  display: block;
  height: 100%;
}

.metrics {
  display: grid;
  gap: 10px 20px;
}

@media (min-width: 700px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.metrics-grid {
  display: grid;
  gap: 12px 20px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.metric-title {
  align-items: baseline;
  display: flex;
  gap: 4px 10px;
  justify-content: space-between;
  margin: 0 0 2px;
}

.metric-title strong {
  font-size: 0.8rem;
  font-weight: 600;
}

.metric-title span {
  color: var(--ink-2);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.is-loading .chart {
  opacity: 0.45;
  transition: opacity 0.2s;
}

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

.chart {
  min-height: 48px;
  position: relative;
}

.chart svg {
  display: block;
  overflow: visible;
  touch-action: pan-y;
  width: 100%;
}

.chart svg:focus {
  outline: none;
}

.chart svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .axis {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .tick {
  fill: var(--muted);
  font-family: var(--sans);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.chart .end-label {
  fill: var(--ink-2);
  font-family: var(--sans);
  font-size: 11px;
}

.chart .line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.chart .band {
  fill-opacity: 0.14;
  stroke: none;
}

.chart .end,
.chart .focus {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart .cross {
  stroke: var(--ink-2);
  stroke-opacity: 0.45;
  stroke-width: 1;
}

.chart .wait {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 10px 0;
}

.line.s1 { stroke: var(--s1); }
.line.s2 { stroke: var(--s2); }
.line.s3 { stroke: var(--s3); }
.line.s4 { stroke: var(--s4); }
.line.s5 { stroke: var(--s5); }
.line.s6 { stroke: var(--s6); }
.line.s7 { stroke: var(--s7); }
.line.s8 { stroke: var(--s8); }
.band.s1, .end.s1, .focus.s1 { fill: var(--s1); }
.band.s2, .end.s2, .focus.s2 { fill: var(--s2); }
.band.s3, .end.s3, .focus.s3 { fill: var(--s3); }
.band.s4, .end.s4, .focus.s4 { fill: var(--s4); }
.band.s5, .end.s5, .focus.s5 { fill: var(--s5); }
.band.s6, .end.s6, .focus.s6 { fill: var(--s6); }
.band.s7, .end.s7, .focus.s7 { fill: var(--s7); }
.band.s8, .end.s8, .focus.s8 { fill: var(--s8); }
.key.s1 { background: var(--s1); }
.key.s2 { background: var(--s2); }
.key.s3 { background: var(--s3); }
.key.s4 { background: var(--s4); }
.key.s5 { background: var(--s5); }
.key.s6 { background: var(--s6); }
.key.s7 { background: var(--s7); }
.key.s8 { background: var(--s8); }

.legend {
  color: var(--ink-2);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.78rem;
  gap: 4px 14px;
  margin: 0 0 6px;
}

.legend > span {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.key {
  border-radius: 1px;
  display: inline-block;
  flex: none;
  height: 2px;
  width: 14px;
}

.tip {
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.78rem;
  max-width: 280px;
  padding: 7px 10px;
  pointer-events: none;
  position: absolute;
  top: 2px;
  z-index: 3;
}

.tip-head {
  color: var(--muted);
  margin-bottom: 3px;
  white-space: nowrap;
}

.tip-row {
  align-items: center;
  display: flex;
  gap: 7px;
  white-space: nowrap;
}

.tip-row strong {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.tip-row span {
  color: var(--ink-2);
}

.tip-extra {
  color: var(--ink-2);
  margin-top: 4px;
}

/* ---- runs table ---- */

.table-scroll {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: min(70vh, 760px);
  overflow: auto;
  overscroll-behavior: contain;
}

.runs-table th,
.runs-table td {
  padding: 7px 12px 7px 0;
}

.runs-table th:first-child,
.runs-table td:first-child,
.scores-table th:first-child,
.scores-table td:first-child {
  padding-left: 14px;
}

.runs-table thead th,
.scores-table thead th {
  background: var(--surface);
  border-bottom: 1px solid var(--axis);
  position: sticky;
  top: 0;
  z-index: 1;
}

.sort {
  align-items: center;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: inherit;
  font-weight: 500;
  gap: 4px;
  padding: 2px 0;
  white-space: nowrap;
}

th.num .sort {
  flex-direction: row-reverse;
}

.sort:hover,
th[aria-sort="ascending"] .sort,
th[aria-sort="descending"] .sort {
  color: var(--ink);
}

.sort i {
  color: var(--ink-2);
  font-style: normal;
  font-size: 0.7rem;
  min-width: 0.7em;
}

.runs-table tbody tr {
  cursor: pointer;
}

.runs-table tbody tr:hover,
.scores-table tbody tr:hover {
  background: var(--hover);
}

.runs-table tbody tr.is-open {
  background: #232a36;
}

.runs-table tbody tr:last-child td,
.scores-table tbody tr:last-child td {
  border-bottom: 0;
}

.run-link {
  background: none;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0;
  text-align: left;
}

.run-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.clip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.c-kind,
.c-box,
.c-host,
.c-stage,
.c-started,
.c-updated {
  color: var(--ink-2);
}

.prog {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: flex-end;
}

.bar {
  background: var(--grid);
  border-radius: 2px;
  display: inline-block;
  height: 4px;
  overflow: hidden;
  width: 56px;
}

.bar > span {
  background: var(--accent);
  display: block;
  height: 100%;
}

.m-dot,
.c-meta,
.sort-m {
  display: none;
}

.c-meta .bar {
  display: block;
  margin-top: 6px;
  width: 100%;
}

/* ---- scores ---- */

.scores-scroll {
  max-height: none;
  overflow-x: auto;
}

.scores-table td:first-child,
.scores-table th:first-child {
  background: var(--surface);
  left: 0;
  position: sticky;
  z-index: 1;
}

.scores-table thead th:first-child {
  z-index: 2;
}

.scores-table th {
  vertical-align: bottom;
  white-space: normal;
}

.scores-table th .sort {
  text-align: left;
  white-space: normal;
}

.scores-table th.num .sort {
  text-align: right;
}

.scores-table td.label {
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* ---- run panel ---- */

.backdrop {
  background: rgba(0, 0, 0, 0.55);
  inset: 0;
  position: fixed;
  z-index: 19;
}

.panel {
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  bottom: 0;
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  position: fixed;
  right: 0;
  top: 0;
  width: var(--panel-w);
  z-index: 20;
}

.panel-head {
  align-items: flex-start;
  border-bottom: 1px solid var(--grid);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 16px 20px 14px;
}

.panel-titles {
  min-width: 0;
}

.panel-kicker {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 4px;
}

.panel-head h2 {
  font-family: var(--mono);
  font-size: 0.98rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.panel-head h2:focus {
  outline: none;
}

.panel-body {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px 20px 40px;
}

.facts {
  display: grid;
  gap: 12px 18px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin: 0;
}

.facts div {
  min-width: 0;
}

.facts dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.facts dd {
  font-variant-numeric: tabular-nums;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.facts .wide {
  grid-column: 1 / -1;
}

.facts .bar {
  display: block;
  margin-top: 6px;
  width: 100%;
}

h4 {
  align-items: baseline;
  display: flex;
  font-size: 0.85rem;
  font-weight: 650;
  gap: 8px;
  justify-content: space-between;
  margin: 24px 0 8px;
}

h4 .muted {
  font-weight: 400;
}

.panel-block {
  border-top: 1px solid var(--grid);
  margin-top: 20px;
  padding-top: 4px;
}

.kv td {
  overflow-wrap: anywhere;
  white-space: normal;
}

.kv td:first-child {
  color: var(--muted);
  overflow-wrap: normal;
  padding-right: 16px;
  white-space: nowrap;
  width: 1%;
}

.log {
  background: var(--page);
  border: 1px solid var(--grid);
  border-radius: 8px;
  color: var(--ink-2);
  font: 12px/1.5 var(--mono);
  margin: 0;
  max-height: 440px;
  overflow: auto;
  overflow-wrap: anywhere;
  padding: 10px 12px;
  white-space: pre-wrap;
}

@media (min-width: 1500px) {
  .backdrop {
    display: none !important;
  }

  body.has-panel .shell {
    margin-right: calc(var(--panel-w) + 12px);
  }
}

/* ---- phone ---- */

@media (max-width: 719px) {
  .shell {
    padding: 18px max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left));
  }

  h1 {
    font-size: 1.5rem;
  }

  .filters {
    gap: 8px 12px;
  }

  .seg {
    width: 100%;
  }

  .seg button {
    flex: 1;
    padding: 3px 4px;
  }

  .card {
    padding: 14px;
  }

  .meter {
    width: 40px;
  }

  th,
  td {
    padding-right: 8px;
  }

  .sort-m {
    display: inline-flex;
  }

  .runs-table .table-scroll,
  .table-scroll.runs-scroll {
    max-height: none;
    overflow: visible;
  }

  .runs-table thead {
    display: none;
  }

  .runs-table,
  .runs-table tbody {
    display: block;
  }

  .runs-table tbody tr {
    border-bottom: 1px solid var(--grid);
    display: grid;
    gap: 3px 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 11px 14px;
  }

  .runs-table tbody tr:last-child {
    border-bottom: 0;
  }

  .runs-table td {
    border: 0;
    display: none;
    padding: 0;
  }

  .runs-table td:first-child {
    padding-left: 0;
  }

  .runs-table td.c-run {
    display: block;
    grid-column: 1;
    grid-row: 1;
    white-space: normal;
  }

  .runs-table td.c-progress {
    color: var(--ink-2);
    display: block;
    grid-column: 2;
    grid-row: 1;
    text-align: right;
  }

  .runs-table td.c-progress .bar {
    display: none;
  }

  .runs-table td.c-meta {
    color: var(--muted);
    display: block;
    font-size: 0.8rem;
    grid-column: 1 / -1;
    white-space: normal;
  }

  .m-dot {
    display: inline-block;
    margin-right: 8px;
    vertical-align: 1px;
  }

  .run-link {
    overflow-wrap: anywhere;
  }

  .panel-head {
    padding: 14px 16px 12px;
  }

  .panel-body {
    padding: 14px 16px 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dot.is-pulse {
    animation: none;
  }
}

/* ---- job queue ---- */

.queues {
  display: grid;
  gap: 14px;
}

.queue-actions {
  align-items: center;
  display: inline-flex;
  gap: 12px;
}

.tiles {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  margin-top: 12px;
}

.tile {
  background: var(--page);
  border: 1px solid var(--grid);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
}

.tile-value {
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.2;
}

.tile-label {
  color: var(--muted);
  font-size: 0.76rem;
}

.tile.is-bad {
  border-color: var(--critical);
}

.bar.wide {
  display: block;
  height: 6px;
  margin-top: 14px;
  width: 100%;
}

.queue-line {
  color: var(--ink-2);
  font-size: 0.82rem;
  margin: 6px 0 0;
}

.queue-lists {
  display: grid;
  gap: 10px 24px;
  margin-top: 12px;
}

@media (min-width: 720px) {
  .queue-lists {
    grid-template-columns: 2fr 1fr;
  }
}

.queue-label {
  color: var(--muted);
  font-size: 0.76rem;
  margin: 0 0 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 2px 10px;
}
