/* ══════════════════════════════════════════════════════════════════════
   BetBot 9000 Dashboard
   Dark-terminal monospace aesthetic. Fluid spacing + font sizes via
   utopia.fyi (320–1240 viewport). Color tokens stay fixed.
   ══════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────── */

:root {
  /* Fluid spacing — utopia.fyi scale, 320–1240 viewport */
  --spacing-4xs: clamp(0.125rem, 0.1033rem + 0.1087vw, 0.1875rem);
  --spacing-3xs: clamp(0.3125rem, 0.269rem + 0.2174vw, 0.4375rem);
  --spacing-2xs: clamp(0.5rem, 0.4348rem + 0.3261vw, 0.6875rem);
  --spacing-xs:  clamp(0.75rem, 0.6413rem + 0.5435vw, 1.0625rem);
  --spacing-s:   clamp(1rem, 0.8696rem + 0.6522vw, 1.375rem);
  --spacing-m:   clamp(1.5rem, 1.3043rem + 0.9783vw, 2.0625rem);
  --spacing-l:   clamp(2rem, 1.7391rem + 1.3043vw, 2.75rem);
  --spacing-xl:  clamp(3rem, 2.6087rem + 1.9565vw, 4.125rem);

  /* Fluid spacing pairs (one-up) */
  --spacing-2xs-xs: clamp(0.5rem, 0.3043rem + 0.9783vw, 1.0625rem);
  --spacing-xs-s:   clamp(0.75rem, 0.5326rem + 1.087vw, 1.375rem);
  --spacing-s-m:    clamp(1rem, 0.6304rem + 1.8478vw, 2.0625rem);
  --spacing-m-l:    clamp(1.5rem, 1.0652rem + 2.1739vw, 2.75rem);
  --spacing-l-xl:   clamp(2rem, 1.2609rem + 3.6957vw, 4.125rem);

  /* Fluid spacing pairs (two-up) */
  --spacing-3xs-xs: clamp(0.25rem, -0.0326rem + 1.413vw, 1.0625rem);
  --spacing-2xs-s:  clamp(0.5rem, 0.1957rem + 1.5217vw, 1.375rem);
  --spacing-xs-m:   clamp(0.75rem, 0.2935rem + 2.2826vw, 2.0625rem);
  --spacing-s-l:    clamp(1rem, 0.3913rem + 3.0435vw, 2.75rem);
  --spacing-m-xl:   clamp(1.5rem, 0.587rem + 4.5652vw, 4.125rem);

  /* Fluid font sizes */
  --text-2xs: clamp(0.5625rem, 0.5408rem + 0.1087vw, 0.625rem);
  --text-xs:  clamp(0.64rem, 0.6122rem + 0.1391vw, 0.72rem);
  --text-s:   clamp(0.8rem, 0.7652rem + 0.1739vw, 0.9rem);
  --text-m:   clamp(1rem, 0.9565rem + 0.2174vw, 1.125rem);
  --text-l:   clamp(1.25rem, 1.1957rem + 0.2717vw, 1.4063rem);
  --text-xl:  clamp(1.5625rem, 1.4946rem + 0.3397vw, 1.7578rem);

  /* Colours — light scheme.
   *
   * Three-tier hierarchy:
   *   --bg         page background (tinted, lets cards pop as white)
   *   --panel      card / table / panel background (white, elevated)
   *   --chart-bg   chart canvas only (dark, for line + gradient pop)
   *
   * Greens/reds are darker than the chart line variants below so they
   * keep AA contrast when used as body text. */
  --bg:        #f0f2f5;
  --panel:     #ffffff;
  --chart-bg:  #1a1d21;
  --chart-fg:  #e5e7eb;
  --chart-axis: #2a2f37;
  --border:    #e0e3e8;
  --fg:        #1f2328;
  --muted:     #6b7280;
  --green:     #15803d;
  --red:       #b91c1c;
  --yellow:    #b45309;
  --accent:    #2563eb;

  /* Mid-bright variants for chart polylines / fills where the value
   * isn't read as text. These are also what the JS chart hardcodes,
   * so the dashboard's HTML and canvas charts stay visually unified. */
  --green-line: #16a34a;
  --red-line:   #dc2626;

  /* Soft backgrounds used by panels, hover states, pills. Pulled out
   * so the rgba() literals in the rest of this file can be tokens. */
  --bg-hover:    rgba(0, 0, 0, 0.04);
  --bg-overlay:  rgba(0, 0, 0, 0.02);
  --bg-elev:     rgba(0, 0, 0, 0.015);
  --bg-pos-soft: rgba(21, 128, 61, 0.10);
  --bg-neg-soft: rgba(185, 28, 28, 0.10);
  --bg-warn-soft: rgba(180, 83, 9, 0.10);
  --bg-mute-soft: rgba(107, 114, 128, 0.12);
  --bg-accent-soft: rgba(21, 128, 61, 0.18);
}

/* ── Reset ──────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  padding: var(--spacing-s);
  max-width: 1400px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: var(--text-s);
  background: var(--bg);
  color: var(--fg);
}

/* ── Header ─────────────────────────────────────────────────────── */

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--spacing-2xs) 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--spacing-s);
}

header h1 {
  margin: 0;
  font-size: var(--text-m);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Tab nav ────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: var(--spacing-s);
  font-size: var(--text-s);
}

.tabs a {
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  padding: var(--spacing-3xs) 0;
  border-bottom: 1px solid transparent;
}

.tabs a:hover { color: var(--fg); }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--fg); }

header .status {
  color: var(--muted);
  font-size: var(--text-s);
}

header .status .live {
  color: var(--green);
}

/* ── Stat cards (old grid layout) ───────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: 1.5fr repeat(5, 1fr);
  gap: var(--spacing-s);
  padding: var(--spacing-xs) var(--spacing-s);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  margin-bottom: var(--spacing-s);
}

.stat {
  display: flex;
  flex-direction: column;
  position: relative;
}

.stat .label {
  color: var(--muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.stat .value {
  font-size: var(--text-l);
  font-weight: 600;
  margin-top: var(--spacing-4xs);
}

.stat .sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--spacing-4xs);
}

.stat.pos .value  { color: var(--green); }
.stat.neg .value  { color: var(--red); }
.stat .sub .pos   { color: var(--green); }
.stat .sub .neg   { color: var(--red); }
.stat .sub .warn  { color: var(--yellow); }

.stat.highlight .value {
  font-size: var(--text-xl);
}

/* Inline sparkline (small SVG, fixed height for crispness) */
.sparkline {
  margin-top: var(--spacing-3xs);
  width: 100%;
  height: 32px;
  display: block;
}

.sparkline polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
}

.sparkline .axis {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.muted {
  color: var(--muted);
  font-size: var(--text-s);
}

/* ── Service summary pill (overview) ───────────────────────────── */

.services {
  display: flex;
  align-items: center;
  margin-bottom: var(--spacing-xs);
}

.svc-summary {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-3xs);
  padding: var(--spacing-3xs) var(--spacing-xs);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: var(--text-s);
  text-decoration: none;
  color: var(--fg);
}

.svc-summary:hover { border-color: var(--fg); }
.svc-summary.green  { color: var(--green);  border-color: var(--bg-pos-soft); }
.svc-summary.yellow { color: var(--yellow); border-color: var(--bg-warn-soft); }
.svc-summary.red    { color: var(--red);    border-color: var(--bg-neg-soft); }

/* ── Services table (/services) ────────────────────────────────── */

/* Real CSS table. Column widths come from <colgroup>; the browser's
 * native table-layout algorithm aligns thead and tbody automatically.
 * No display:grid / display:block hacks (those fight table-layout
 * and were causing the header misalignment). */
.services-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--text-s);
}

.services-table th,
.services-table td {
  line-height: 1.6rem;
  vertical-align: middle;
  /* Fixed-layout column widths include padding (per spec). Keep
   * horizontal padding small so the column's usable content area
   * isn't eaten by the gutter. */
  padding: var(--spacing-3xs) var(--spacing-2xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
}

.services-table th {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  text-align: left;
}

.services-table tbody tr:last-child td { border-bottom: none; }

.services-table .col-status      { text-align: center; }
.services-table .col-status .dot { font-size: var(--text-s); color: var(--muted); }
.services-table tr[data-status="green"]  .col-status .dot { color: var(--green); }
.services-table tr[data-status="yellow"] .col-status .dot { color: var(--yellow); }
.services-table tr[data-status="red"]    .col-status .dot { color: var(--red); }

.services-table .col-name   { font-weight: 500; }
.services-table .col-uptime { font-variant-numeric: tabular-nums; color: var(--muted); }
.services-table .col-seen   { font-variant-numeric: tabular-nums; color: var(--muted); }
.services-table .col-spark .muted { font-size: var(--text-2xs); }
.services-table .col-note   { color: var(--muted); }

/* Inter-heartbeat-gap sparkline. Reference dashed line marks the
 * nominal 15s heartbeat. Polyline color follows the row status. */
.hb-spark {
  width: 120px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
}
.hb-spark polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linejoin: round;
}
.hb-spark .ref {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 2 2;
}
.services-table tr[data-status="green"]  .hb-spark { color: var(--green); }
.services-table tr[data-status="yellow"] .hb-spark { color: var(--yellow); }
.services-table tr[data-status="red"]    .hb-spark { color: var(--red); }

.services-table tr.empty td {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: var(--spacing-2xs);
  white-space: normal;
}

/* ── Grid / panel layout ────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-s);
}

.grid.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--spacing-xs) var(--spacing-s);
  min-height: 200px;
  max-height: 450px;
  overflow-y: auto;
}

.panel h2 {
  margin: 0 0 var(--spacing-2xs);
  font-size: var(--text-s);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 500;
}

/* ── Row (generic data row) ─────────────────────────────────────── */

.row {
  display: grid;
  gap: var(--spacing-2xs);
  padding: var(--spacing-3xs) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-s);
}

.row:last-child {
  border-bottom: none;
}

/* Column templates — keep px so column alignment is stable */
.fire   { grid-template-columns: 70px 80px 80px 50px 70px 50px; }
.place  { grid-template-columns: 70px 80px 100px 1fr 70px; }
.settle { grid-template-columns: 85px 80px 100px 100px 60px; }
.active { grid-template-columns: 70px 1fr 70px 20px; }

.fire .dir,
.settle .outcome {
  font-weight: 600;
}

.settle.up .outcome   { color: var(--green); }
.settle.down .outcome { color: var(--red); }

.active.fired .fired {
  color: var(--green);
  font-weight: 600;
}

.active.pending .fired { color: var(--muted); }
.active .rem            { color: var(--yellow); }

.time,
.lat {
  color: var(--muted);
}

.bot {
  color: var(--accent);
}

.empty {
  color: var(--muted);
  font-style: italic;
  padding: var(--spacing-2xs) 0;
}

/* ── Stat cards (new style — individual bordered cards) ─────────── */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--spacing-2xs);
  margin-bottom: var(--spacing-xs);
}

.stat-cards .stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--spacing-2xs) var(--spacing-xs);
}

/* Kill-signal cards: same shape as stat cards but with room for a
   small inline sparkline between the value and the sub-line. The
   sparkline is the actual signal — the value is just a checkpoint. */
.kill-cards {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kill-card .kill-spark {
  margin-top: var(--spacing-3xs);
}

.kill-card .kill-spark .bot-spark {
  width: 100%;
  height: 32px;
  display: block;
}

.kill-card .kill-spark polyline {
  fill: none;
  stroke-width: 1.25;
}

.kill-card .kill-spark .spark-empty {
  display: block;
  height: 32px;
  color: var(--muted);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
}

/* ── Range picker ───────────────────────────────────────────────── */

.range-picker {
  display: flex;
  gap: var(--spacing-3xs);
}

.range-btn {
  padding: var(--spacing-3xs) var(--spacing-2xs);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
}

.range-btn:hover  { color: var(--fg); border-color: var(--fg); }
.range-btn.active { color: var(--fg); background: var(--bg); border-color: var(--fg); }

/* ── Bots panel ─────────────────────────────────────────────────── */

.bots-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-s);
  margin-bottom: var(--spacing-s);
}

.bots {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--spacing-xs) var(--spacing-s);
}

/* Cap the panel height only when no row is expanded so a long fleet
   stays scrollable in the closed state; expanding a row should grow
   the panel to fit its detail content rather than clip + double-scroll. */
.bots:not(:has(details[open])) {
  max-height: 600px;
  overflow-y: auto;
}

.bots-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--spacing-2xs);
}

.bots-header h2 {
  margin: 0;
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.bots-total {
  font-size: var(--text-s);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.bots-total.pos { color: var(--green); }
.bots-total.neg { color: var(--red); }
.bots-count {
  color: var(--muted);
  font-size: var(--text-xs);
}

.bots-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2xs);
}

/* ── Bot row (details/summary accordion) ────────────────────────── */

.bot-row-details {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  overflow: hidden;
}

.bot-row-details[open] {
  border-color: var(--bg-pos-soft);
  background: var(--bg-overlay);
}

.bot-row {
  display: grid;
  grid-template-columns: 14px minmax(180px, max-content) minmax(0, 1fr);
  align-items: center;
  gap: var(--spacing-s);
  padding: var(--spacing-xs) var(--spacing-s);
  cursor: pointer;
  list-style: none;
}

.bot-row::-webkit-details-marker { display: none; }
.bot-row:hover { background: var(--bg-hover); }

/* ── Bot caret (triangle icon) ──────────────────────────────────── */

.bot-caret {
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  color: var(--muted);
  transition: transform 120ms;
}

.bot-caret::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.bot-row-details[open] .bot-caret {
  transform: rotate(90deg);
}

/* ── Bot metadata ───────────────────────────────────────────────── */

.bot-meta {
  display: flex;
  align-items: center;
  gap: var(--spacing-2xs);
  min-width: 0;
}

.bot-meta-text {
  min-width: 0;
}

.bot-name {
  font-size: var(--text-m);
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--spacing-4xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Bot performance group (sparkline + price — same metric) ────── */

.bot-performance {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--spacing-2xs);
  min-width: 0;
}

/* ── Bot mid (sparkline / range picker) ─────────────────────────── */

.bot-mid {
  display: flex;
  align-items: center;
  min-width: 0;
  width: clamp(200px, 25vw, 320px);
}

.bot-row-details[open] .bot-spark-cell { display: none; }
.bot-row-details:not([open]) .bot-picker-row { display: none; }

.bot-spark-cell {
    min-width: 0;
    width: 100%;
}

/* Picker strip — full-width row that appears only when the bot detail
   is open. Sits between <summary> and the detail body. Buttons centered
   on narrow screens, naturally horizontal because the row has the full
   width available — no fighting the figures for the summary's right
   edge. */
.bot-picker-row {
  display: flex;
  justify-content: center;
  padding: var(--spacing-2xs) var(--spacing-s);
  border-top: 1px solid var(--border);
  background: var(--bg-overlay);
}

/* ── Bot figures (PnL + ROI pill) ───────────────────────────────── */

.bot-figures {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--spacing-3xs);
}

.bot-pnl {
  font-size: var(--text-m);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bot-pnl.pos { color: var(--green); }
.bot-pnl.neg { color: var(--red); }

.bot-pill {
  display: inline-block;
  padding: var(--spacing-4xs) var(--spacing-2xs);
  border-radius: 0.25rem;
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--bg-mute-soft);
  color: var(--muted);
}

.bot-pill.pos { background: var(--bg-pos-soft); color: var(--green); }
.bot-pill.neg { background: var(--bg-neg-soft); color: var(--red); }

/* ── Heartbeat dot ──────────────────────────────────────────────── */

.hb-dot {
  font-size: var(--text-xs);
  display: inline;
  vertical-align: middle;
  line-height: 1;
}

.hb-dot.hb-up      { color: var(--green); }
.hb-dot.hb-lagging { color: var(--yellow); }
.hb-dot.hb-down    { color: var(--red); }

/* ── Bot sparkline SVG ──────────────────────────────────────────── */

.bot-spark {
  width: 100%;
  height: 36px;
  display: block;
}

.bot-spark polyline {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.spark-empty {
  color: var(--muted);
  font-size: var(--text-xs);
}

/* ── Range picker (detail) ──────────────────────────────────────── */

.range-picker-detail {
  display: flex;
  gap: var(--spacing-3xs);
  flex-wrap: wrap;
}

.range-picker-detail .range-btn {
  padding: var(--spacing-4xs) var(--spacing-2xs);
  font-size: var(--text-xs);
}

/* ── Bot detail (expanded panel) ────────────────────────────────── */

.detail-body {
  border-top: 1px solid var(--border);
  background: var(--bg-overlay);
  padding: var(--spacing-s) var(--spacing-s) var(--spacing-xs);
}

.detail-chart {
  /* Explicit fluid height — uPlot (and the old SVG fallback) takes the
   * container's pixel size. Floor 140px keeps the chart readable on
   * phone widths; ceiling 240px stops it from dominating the detail
   * body on desktop. */
  height: clamp(140px, 28vw, 240px);
  margin-bottom: var(--spacing-2xs);
}
.bot-detail-chart { width: 100%; height: 100%; }
.detail-chart .uplot { width: 100% !important; }

.detail-chart-empty {
  color: var(--muted);
  font-size: var(--text-s);
  padding: var(--spacing-s);
  text-align: center;
}

.detail-signal {
  font-size: var(--text-s);
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--spacing-xs);
}

.detail-signal .pos   { color: var(--green);  font-weight: 600; }
.detail-signal .neg   { color: var(--red);    font-weight: 600; }
.detail-signal .warn  { color: var(--yellow); font-weight: 600; }
.detail-signal .muted { color: var(--muted);  margin-right: var(--spacing-3xs); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-s);
}

.section-label {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
  margin-bottom: var(--spacing-3xs);
}

/* ── Tile grid (perf + config) ──────────────────────────────────── */

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-2xs);
}

.tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: var(--spacing-2xs);
  display: flex;
  flex-direction: column;
}

.tile-label {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tile-value {
  font-size: var(--text-m);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: var(--spacing-4xs);
}

.tile-value.pos { color: var(--green); }
.tile-value.neg { color: var(--red); }

.tile-sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--spacing-4xs);
}

.tile-progress {
  margin-top: var(--spacing-4xs);
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.tile-progress-bar {
  display: block;
  height: 100%;
  background: var(--muted);
  transition: width 0.3s ease;
}

.tile-progress-bar.pos { background: var(--green); }

/* ── Chart panel (page hero) ────────────────────────────────────── */

.chart-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--spacing-s);
  margin-bottom: var(--spacing-xs);
}

.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--spacing-3xs);
}

/* Match the table-header typography: uppercase label, muted, tracked.
 * Same treatment as <th> across .feed / .bets / .services-table so
 * every panel reads with the same heading rhythm. */
.chart-title .title-label {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.chart-title .title-range {
  margin-left: var(--spacing-2xs);
  color: var(--muted);
  font-size: var(--text-2xs);
}

.chart-headline {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin: var(--spacing-3xs) 0;
}

.chart-headline.pos { color: var(--green); }
.chart-headline.neg { color: var(--red); }

.chart-headline-range {
  font-size: var(--text-s);
  color: var(--muted);
  font-weight: 500;
  margin-left: var(--spacing-3xs);
}

/* Persistent uPlot host. Subtle elevation off the white card so the
 * chart reads as its own surface — same lift as the bot-row details. */
#pnl-chart {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  margin: var(--spacing-3xs) 0;
  overflow: hidden;
}

.chart-area {
  width: 100%;
  height: 140px;
}

.sparkline-large {
  width: 100%;
  height: 100%;
  display: block;
}

.sparkline-large .axis {
  stroke: var(--chart-axis);
  stroke-width: 1;
  stroke-dasharray: 2 2;
}

.sparkline-large polyline {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.chart-footnote {
  color: var(--muted);
  font-size: var(--text-s);
  margin-top: var(--spacing-3xs);
}

.chart-footnote.pos { color: var(--green); }
.chart-footnote.neg { color: var(--red); }


/* ── Unified feed ──────────────────────────────────────────────── */

.feed-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  margin-bottom: var(--spacing-s);
  overflow: hidden;
}

.feed-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-2xs);
  padding: var(--spacing-2xs) var(--spacing-s);
  border-bottom: 1px solid var(--border);
  background: var(--bg-overlay);
}

.feed-header-label {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-right: var(--spacing-2xs);
}

.feed-select {
  padding: var(--spacing-4xs) var(--spacing-2xs);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--text-xs);
  font-family: inherit;
  cursor: pointer;
}

/* Table shell. Fixed widths on the metadata columns keep the variable
 * `Detail` column flex-sized; tabular-nums on numeric cells keeps
 * digits aligned. The `<tbody id="feed-rows">` is the SSE patch
 * target — Datastar prepends new <tr>s into it. */
/* Real CSS table. Widths from <colgroup>; native table-layout aligns
 * columns automatically. Sticky header works because <thead><th> stays
 * a real table-header-cell — no display overrides. */
.feed {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--text-s);
}

/* Same line-height (absolute) on both <th> and <td> so the header row
 * matches body row height — without this, the smaller header font
 * gets a smaller line-box and the row reads taller/shorter than body
 * rows. */
.feed th,
.feed td {
  line-height: 1.6rem;
  vertical-align: middle;
  padding: var(--spacing-3xs) var(--spacing-2xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
}

.feed th {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
  text-align: left;
}

.feed tbody tr:last-child td { border-bottom: none; }

.feed .col-icon              { text-align: center; color: var(--muted); }
.feed .col-icon.pos          { color: var(--green); }
.feed .col-icon.neg          { color: var(--red); }
.feed tr[data-type="order_placed"] .col-icon  { color: var(--green); }
.feed tr[data-type="order_rejected"] .col-icon { color: var(--red); }
.feed .col-market            { font-weight: 500; }
.feed .col-meta              { text-align: right; font-variant-numeric: tabular-nums; }
.feed .col-detail .pos       { color: var(--green); font-weight: 600; }
.feed .col-detail .neg       { color: var(--red); font-weight: 600; }
.feed .col-detail .rejected  { color: var(--red); }
.feed .col-meta.pos          { color: var(--green); font-weight: 600; }
.feed .col-meta.neg          { color: var(--red); font-weight: 600; }

.feed tr.empty td {
  color: var(--muted);
  font-style: italic;
  padding: var(--spacing-2xs);
  text-align: center;
  white-space: normal;
}

/* ── Bet cards (one row per bet lifecycle) ──────────────────────── */

.bets {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--text-s);
}

.bets th,
.bets td {
  line-height: 1.6rem;
  vertical-align: middle;
  padding: var(--spacing-3xs) var(--spacing-2xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
}

.bets th {
  font-size: var(--text-2xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
  text-align: left;
}

.bets tbody tr:last-child td { border-bottom: none; }

.bets .col-time    { color: var(--muted); }
.bets .col-market  { font-weight: 500; }
.bets .col-dir     { font-weight: 600; }
.bets .col-dir.pos { color: var(--green); }
.bets .col-dir.neg { color: var(--red); }
.bets .col-intent  { font-variant-numeric: tabular-nums; }
.bets .col-result .pos      { color: var(--green); font-weight: 600; }
.bets .col-result .neg      { color: var(--red); }
.bets .col-result .rejected { color: var(--red); }
.bets .col-result .muted    { color: var(--muted); }

/* Order-type badge: pill in front of the result. FAK = took liquidity
   (immediate match-or-cancel), Maker = posted resting order. Subtle
   border + tinted bg so the badge reads as metadata, not a status. */
.kind-badge {
  display: inline-block;
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0 var(--spacing-3xs);
  border-radius: 0.25rem;
  border: 1px solid var(--border);
  color: var(--muted);
  vertical-align: middle;
  margin-right: var(--spacing-3xs);
}
.kind-badge.kind-fak   { color: #2563eb; border-color: #93c5fd; background: #eff6ff; }
.kind-badge.kind-maker { color: #7c3aed; border-color: #c4b5fd; background: #f5f3ff; }
.bets .col-settle           { text-align: right; font-variant-numeric: tabular-nums; }
.bets .col-settle .pos      { color: var(--green); font-weight: 600; }
.bets .col-settle .neg      { color: var(--red); font-weight: 600; }
.bets .col-settle .muted    { color: var(--muted); }

.bets tr.empty td {
  color: var(--muted);
  font-style: italic;
  padding: var(--spacing-2xs);
  text-align: center;
  white-space: normal;
}

/* ── Alarm strip ─────────────────────────────────────────────────── */
.alarm-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-2xs);
  margin-bottom: var(--spacing-xs);
  min-height: 1.5rem;
  align-items: center;
}
.alarm-strip:empty { display: none; }
.alarm-empty {
  color: var(--muted);
  font-size: var(--text-2xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.alarm-pill {
  display: inline-flex;
  align-items: baseline;
  gap: var(--spacing-2xs);
  padding: var(--spacing-3xs) var(--spacing-xs);
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}
.alarm-pill .alarm-sev {
  font-weight: 700;
  font-size: var(--text-3xs, 0.625rem);
  letter-spacing: 0.06em;
}
.alarm-pill .alarm-name {
  font-weight: 600;
  color: var(--muted);
}
.alarm-pill .alarm-msg { color: var(--text); }
.alarm-pill.alarm-crit { background: var(--bg-neg-soft); border-color: var(--red-line); }
.alarm-pill.alarm-crit .alarm-sev { color: var(--red); }
.alarm-pill.alarm-warn { background: var(--bg-warn-soft); border-color: var(--yellow); }
.alarm-pill.alarm-warn .alarm-sev { color: var(--yellow); }
.alarm-pill.alarm-info { background: var(--panel); }
.alarm-pill.alarm-info .alarm-sev { color: var(--muted); }

/* ── Strategy page ───────────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-xs);
}
.page-head h2 { margin: 0; font-size: var(--text-lg); }
.range-pill {
  font-size: var(--text-2xs);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0 var(--spacing-2xs);
}
.range-picker {
  margin-left: auto;
  display: flex;
  gap: var(--spacing-3xs);
}
.range-picker a {
  font-size: var(--text-2xs);
  padding: var(--spacing-3xs) var(--spacing-2xs);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  text-decoration: none;
  color: var(--muted);
}
.range-picker a[aria-current="page"] {
  background: var(--panel);
  color: var(--text);
  border-color: var(--text);
}
.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--spacing-xs);
  align-items: start;
}
.strategy-grid .panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--spacing-xs);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2xs);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.panel-head .label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}
.panel-head .sub { font-size: var(--text-2xs); color: var(--muted); }
.panel-foot { font-size: var(--text-2xs); }

/* Header latency tile. Inline, single-line, lives in the page-head
   between the range pill and the range picker. */
.lat-inline {
  display: inline-flex;
  align-items: baseline;
  gap: var(--spacing-2xs);
  margin-left: var(--spacing-xs);
  font-size: var(--text-2xs);
}
.lat-inline .lat-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lat-inline .lat-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.lat-inline .lat-sub { color: var(--muted); font-variant-numeric: tabular-nums; }

.chart-hist {
  width: 100%;
  height: auto;
  display: block;
}
.chart-hist rect { fill: var(--green-line); opacity: 0.85; }
.chart-hist .ref { stroke: var(--muted); stroke-dasharray: 2 3; }
.chart-hist .axis-tick { font-size: 9px; fill: var(--muted); }

.chart-rel {
  width: 100%;
  height: auto;
  display: block;
}
.chart-rel .grid     { stroke: var(--border); stroke-width: 0.5; }
.chart-rel .identity { stroke: var(--muted); stroke-width: 1;   stroke-dasharray: 3 3; }
.chart-rel circle    { fill-opacity: 0.75; }
.chart-rel .rel-on    { fill: var(--muted); }
.chart-rel .rel-under { fill: var(--green-line); }
.chart-rel .rel-over  { fill: var(--red-line); }
.chart-rel .axis-tick { font-size: 9px; fill: var(--muted); }

/* ── Fluid responsive (no breakpoints) ───────────────────────────────
   The spacing + font tokens above already scale 320–1240 via clamp().
   The remaining gap on narrow viewports comes from non-fluid layout
   primitives — flex containers that don't wrap, grid tracks pinned at
   px minimums, and tables with fixed colgroups. Patched intrinsically
   so the layout adapts continuously, not at one or two breakpoints. */

/* Header chrome wraps so title + nav + status stack on narrow screens
   without overlapping. Tabs grow to fill the available row. */
header { flex-wrap: wrap; row-gap: var(--spacing-3xs); }
.tabs { flex-wrap: wrap; }

/* Strategy page head — title, range pill, latency tile, range picker.
   Wrapping keeps the picker on its own row when there isn't horizontal
   room without forcing it there at every width. */
.page-head { flex-wrap: wrap; }
.range-picker { flex-wrap: wrap; }
.lat-inline { flex-wrap: wrap; }

/* Bot-row had a 180px floor on the bot-meta column and the sparkline
   cell had clamp(200px, 25vw, 320px). Both forced the row past phone
   width. Drop the floors so the row fluidly shrinks; sparkline goes
   to 0 width on small screens (SVG preserveAspectRatio handles it).
   The picker now lives in its own .bot-picker-row below the summary
   (see above), so .bot-mid only ever holds the sparkline. */
.bot-row { grid-template-columns: 14px minmax(0, max-content) minmax(0, 1fr); }
.bot-mid { width: clamp(0px, 25vw, 320px); min-width: 0; }

/* Tables (services, feed) keep their colgroup widths because the
   table-layout algorithm depends on them. Wrapping them in a scroll
   container lets the inner table render at its natural width and the
   user pan horizontally only when the viewport actually is narrower
   than the table — fluid behavior, no breakpoint. */
.feed-panel, #services-detail, .bots-row .bots {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Stat-cards grid: minmax floor was 160px, fine on phones. Bots-row
   bot-row internal grid already uses minmax(0, 1fr) post-fix. */
