/* Synthesizer Monitor. Mobile-first: base rules target phones; wider layouts are added
   with min-width media queries. Colors are role tokens, redefined for dark mode. */

/* "Instrument navy": cool blue-gray neutrals and the navy of KA_Labs' own trityl graphs. */
:root {
  color-scheme: light;
  --page: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eaeef5;
  --ink: #111827;
  --ink-2: #4a5468;
  --ink-3: #687286;
  --grid: #e1e6ef;
  --axis: #c2cad8;
  --border: rgba(17, 24, 39, 0.11);
  --accent: #3557a8;          /* marks, fills, links and buttons */
  --accent-strong: #2c4a93;
  --on-accent: #ffffff;
  --accent-wash: rgba(53, 87, 168, 0.13);
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 12px;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Source Code Pro", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d1018;
    --surface: #161b26;
    --surface-2: #1f2534;
    --ink: #eef1f7;
    --ink-2: #b9c1d1;
    --ink-3: #8e97aa;
    --grid: #262d3d;
    --axis: #353d50;
    --border: rgba(238, 241, 247, 0.1);
    --accent: #7d9be6;
    --accent-strong: #8fa9ec;
    --on-accent: #0d1018;
    --accent-wash: rgba(125, 155, 230, 0.16);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

a { color: var(--accent-strong); }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px; border: 0; border-radius: 8px;
  background: var(--accent-strong); color: var(--on-accent);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
button.quiet {
  background: transparent; color: var(--ink-2); border: 1px solid var(--border);
}

.logo img { display: block; width: auto; height: 100%; }

/* ---------- Sign-in and error pages ---------- */

body.message {
  min-height: 100vh; padding: 16px;
  display: grid; grid-template-columns: minmax(0, 420px); place-content: center;
}
.message-card {
  padding: 28px 24px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.message-card .logo { display: block; height: 36px; margin-bottom: 24px; }
.message-card h1 { font-size: 1.35rem; margin-bottom: 8px; }
.message-card p { margin: 0 0 20px; color: var(--ink-2); }
.message-card .button { width: 100%; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand account" "tabs tabs";
  align-items: center; gap: 8px 12px;
  padding: 10px 16px 0; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  grid-area: brand; display: flex; align-items: center; gap: 10px; min-width: 0;
  color: inherit; text-decoration: none;
}
.brand .logo { height: 28px; flex: none; }
.brand-name {
  color: var(--ink-2); font-size: 0.9rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  padding-left: 10px; border-left: 1px solid var(--border);
}
@media (max-width: 400px) { .brand-name { display: none; } }
.account { grid-area: account; display: flex; align-items: center; gap: 10px; }
.account form { margin: 0; }
.signout {
  min-height: 36px; padding: 6px 12px; font-size: 0.875rem; font-weight: 500;
  background: transparent; color: var(--ink-2); border: 1px solid var(--border);
}
.conn { font-size: 0.8rem; color: var(--ink-3); display: inline-flex; align-items: center; gap: 6px; }
.conn::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--axis);
}
.conn[data-state="live"]::before { background: var(--good); }
.conn[data-state="reconnecting"]::before { background: var(--warning); }
.conn .conn-label { display: none; }
.conn[data-state="reconnecting"] .conn-label { display: inline; }

.tabs { grid-area: tabs; display: flex; gap: 4px; margin: 0 -4px; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 12px 12px; min-height: 44px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

@media (min-width: 720px) {
  .topbar {
    grid-template-columns: auto 1fr auto; grid-template-areas: "brand tabs account";
    padding: 0 24px; gap: 24px;
  }
  .brand { padding: 12px 0; }
  .tabs { margin: 0; align-self: stretch; }
  .tabs a { flex: none; display: flex; align-items: center; padding: 0 12px; }
}

/* ---------- Page layout ---------- */

.view {
  max-width: 1120px; margin: 0 auto; padding: 16px 16px 48px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  outline: none;
}
@media (min-width: 720px) { .view { padding: 24px 24px 64px; } }

.loading, .empty { color: var(--ink-2); padding: 24px 0; }
.error-note { color: var(--ink); background: var(--surface-2); padding: 12px 16px; border-radius: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
@media (min-width: 720px) { .card { padding: 20px 24px; } }

.section-title {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-2); margin-bottom: 12px;
}

.inst-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.inst-head h1 { font-size: 1rem; font-weight: 600; color: var(--ink-2); }
.agent { font-size: 0.85rem; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }

.back { display: inline-flex; align-items: center; min-height: 44px; margin: -8px 0 4px; text-decoration: none; font-weight: 500; }

/* ---------- Status pill (icon + label; color never alone) ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600; color: var(--ink);
  background: color-mix(in srgb, var(--tone) 16%, transparent);
  white-space: nowrap;
}
.pill svg { width: 14px; height: 14px; flex: none; color: var(--tone); }
.tone-good { --tone: var(--good); }
.tone-warning { --tone: var(--warning); }
.tone-serious { --tone: var(--serious); }
.tone-critical { --tone: var(--critical); }
.tone-neutral { --tone: var(--ink-3); }

/* ---------- Run page ---------- */

.run { display: grid; gap: 16px; }
.run .side { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .run .side { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

/* Run status: the instrument's run as a whole, never one column's construct. */
.run-status { display: grid; gap: 14px; }
.status-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.status-top .sub { color: var(--ink-2); }
.cycle { display: grid; gap: 8px; }
.cycle h2 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.cycle h2 small { font-size: 1rem; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
@media (min-width: 720px) {
  .cycle { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 24px; }
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head .section-title { margin-bottom: 0; }
button.small { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; font-weight: 500; gap: 6px; }
button.small svg { width: 16px; height: 16px; }

.bar { height: 8px; border-radius: 999px; background: var(--accent-wash); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
@media (min-width: 720px) { .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.facts dt { font-size: 0.8rem; color: var(--ink-2); }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.facts dd span { display: block; font-weight: 400; font-size: 0.85rem; color: var(--ink-2); }

.notice {
  display: flex; gap: 10px; align-items: flex-start; margin: 0;
  padding: 12px 14px; border-radius: 8px;
  background: color-mix(in srgb, var(--tone) 12%, transparent);
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--tone); }

.activity { margin: 0; font-size: 0.875rem; color: var(--ink-2); overflow-wrap: anywhere; }
.activity code { font-family: var(--mono); font-size: 0.85em; color: var(--ink); }

/* Columns: one equal tile per column; 1 across on phones, 2 on tablets, 4 on desktops. */
.col-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 560px) { .col-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .col-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.col {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.col-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.col-id { font-weight: 700; font-size: 0.85rem; color: var(--ink-2); }
.col-name { font-size: 1.1rem; font-weight: 650; overflow-wrap: anywhere; }
.col-count {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--ink-2); font-size: 0.85rem; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.col-done {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 0.8rem;
}
.col-done svg { width: 12px; height: 12px; color: var(--good); }
.col.is-done .seq b { background: transparent; }
.seq {
  margin: 0; font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.06em;
  color: var(--ink-2); overflow-wrap: anywhere; word-break: break-all;
}
.seq b { color: var(--ink); background: var(--accent-wash); border-radius: 3px; font-weight: 700; }
.seq .none { font-family: inherit; letter-spacing: 0; }
/* Trityl figures sit at the bottom so they line up across a row of tiles. */
.col-trityl { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--grid); display: grid; gap: 6px; }
.trityl-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.trityl-stats dt { font-size: 0.75rem; color: var(--ink-2); }
.trityl-stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.trityl-none { margin: 0; font-size: 0.85rem; color: var(--ink-2); }
.trityl-val { margin: 0; font-size: 0.8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.trityl-val strong, .chart-readout strong, .chart-stats strong { color: var(--ink); }
.trityl-val .pct { display: none; }

.spark { display: block; width: 100%; height: 36px; overflow: visible; touch-action: pan-y; }
.spark * { vector-effect: non-scaling-stroke; }
.spark .ref { stroke: var(--grid); stroke-width: 1; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .end-ring { stroke: var(--surface); stroke-width: 10; stroke-linecap: round; }
.spark .end { stroke: var(--accent); stroke-width: 7; stroke-linecap: round; }
.spark .cursor { stroke: var(--axis); stroke-width: 1; }
.spark .hit, .chart .hit { fill: transparent; }
.chart-readout .pct { color: var(--ink-3); }

/* Trityl histograms, one per column, 0 to 100% as KA_Labs draws them. */
.chart-note { margin: -4px 0 16px; font-size: 0.85rem; color: var(--ink-2); }
.chart-grid { display: grid; gap: 20px 24px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .chart-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.chart { margin: 0; min-width: 0; }
.chart figcaption { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.chart-title { font-weight: 700; font-size: 0.85rem; color: var(--ink-2); }
.chart-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-stats { margin: 0 0 6px; font-size: 0.8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--accent); }
.chart .cursor { stroke: var(--ink-3); stroke-width: 1; }
.chart-readout { margin: 2px 0 0; font-size: 0.8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 12px;
  padding: 6px 0; border-top: 1px solid var(--grid);
}
.timeline li:first-child { border-top: 0; }
.timeline time { color: var(--ink-2); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

/* Details */
details.card > summary {
  cursor: pointer; font-weight: 600; min-height: 28px; list-style-position: outside;
}
details.card[open] > summary { margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; margin-top: 16px; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; min-width: 100%; }
table.data caption { text-align: left; font-weight: 600; padding-bottom: 8px; }
table.data th, table.data td { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th { color: var(--ink-2); font-weight: 600; }
table.data th:first-child, table.data td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.data tfoot th, table.data tfoot td { font-weight: 600; color: var(--ink); border-top: 2px solid var(--axis); border-bottom: 0; }

/* ---------- History ---------- */

.history-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.history-head h1 { font-size: 1.4rem; }
.history-head p { margin: 0; color: var(--ink-2); font-size: 0.875rem; }
.run-list { list-style: none; margin: 0; padding: 0; }
.run-row {
  display: grid; gap: 2px 12px; padding: 12px 16px; color: inherit; text-decoration: none;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name status" "when len";
  border-top: 1px solid var(--grid);
}
.run-list li:first-child .run-row { border-top: 0; }
.run-row:hover, .run-row:focus-visible { background: var(--surface-2); }
.run-row .name {
  grid-area: name; font-weight: 600; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.run-row .reps { color: var(--ink-2); font-weight: 400; }
mark { background: var(--accent-wash); color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: inset 0 -2px 0 var(--accent); }

.search { margin: 0 0 12px; }
.search input {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.run-row .status { grid-area: status; justify-self: end; }
.run-row .when { grid-area: when; color: var(--ink-2); font-size: 0.875rem; }
.run-row .len { grid-area: len; color: var(--ink-2); font-size: 0.875rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-list { padding: 0; overflow: hidden; }
@media (min-width: 720px) {
  .run-row {
    grid-template-columns: 11em minmax(0, 1fr) 9em 12em;
    grid-template-areas: "when name status len"; align-items: center; padding: 12px 24px;
  }
  .run-row .status { justify-self: start; }
}
.more-row { display: flex; justify-content: center; padding: 16px; }

@media (prefers-reduced-motion: no-preference) {
  .bar > span { transition: width 400ms ease; }
}
