/* ============================================================
   Velo — operations dashboard
   ============================================================ */

/* ---------- theme tokens ---------- */

:root[data-theme="dark"] {
  --bg:            #0b1015;
  --bg-tint-1:     rgba(53, 201, 148, 0.10);
  --bg-tint-2:     rgba(90, 140, 220, 0.08);
  --panel:         #121922;
  --panel-2:       #161f2a;
  --panel-hover:   #1a2531;
  --border:        #212d3a;
  --border-strong: #2e3d4d;
  --text:          #e9eff5;
  --text-soft:     #c3ced9;
  --muted:         #8b9aab;
  --accent:        #46e0a6;
  --accent-ink:    #06251a;
  --accent-soft:   rgba(70, 224, 166, 0.14);
  --warn:          #ffb648;
  --bad:           #ff7a7a;
  --shadow:        0 14px 34px rgba(0, 0, 0, 0.42);

  --c-grid:        rgba(226, 236, 245, 0.09);
  --c-grid-strong: rgba(226, 236, 245, 0.20);
  --c-axis:        #8b9aab;
  --c-line:        #46e0a6;
  --c-line-2:      #ffb648;
  --c-area-top:    rgba(70, 224, 166, 0.30);
  --c-area-bot:    rgba(70, 224, 166, 0.02);
  --c-bar:         #2fbf8a;
  --c-bar-hi:      #5cf0b6;
  --c-dot:         #121922;
  --c-guide:       rgba(226, 236, 245, 0.30);
  --tip-bg:        #1b2531;
  --tip-border:    #33424f;
}

:root[data-theme="light"] {
  --bg:            #f4f6f9;
  --bg-tint-1:     rgba(15, 143, 99, 0.10);
  --bg-tint-2:     rgba(40, 90, 170, 0.06);
  --panel:         #ffffff;
  --panel-2:       #f7f9fc;
  --panel-hover:   #eef2f7;
  --border:        #dfe5ec;
  --border-strong: #c6d0da;
  --text:          #14202c;
  --text-soft:     #33414f;
  --muted:         #5f6f80;
  --accent:        #0d8f63;
  --accent-ink:    #ffffff;
  --accent-soft:   rgba(13, 143, 99, 0.12);
  --warn:          #a8620a;
  --bad:           #b3261e;
  --shadow:        0 10px 26px rgba(20, 40, 60, 0.10);

  --c-grid:        rgba(20, 40, 60, 0.10);
  --c-grid-strong: rgba(20, 40, 60, 0.24);
  --c-axis:        #5f6f80;
  --c-line:        #0d8f63;
  --c-line-2:      #b06a10;
  --c-area-top:    rgba(13, 143, 99, 0.26);
  --c-area-bot:    rgba(13, 143, 99, 0.02);
  --c-bar:         #12996c;
  --c-bar-hi:      #0a7048;
  --c-dot:         #ffffff;
  --c-guide:       rgba(20, 40, 60, 0.30);
  --tip-bg:        #ffffff;
  --tip-border:    #c6d0da;
}

/* ---------- base ---------- */

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

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--bg-tint-1), transparent 62%),
    radial-gradient(900px 520px at 92% 4%, var(--bg-tint-2), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

h1, h2, p { margin: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .92em;
}

:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  padding: 6px;
  border-radius: 11px;
  background: var(--accent-soft);
  border: 1px solid var(--border-strong);
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }

.wordmark {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.wordmark::after { content: "."; color: var(--accent); }

.brand-sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .12s ease;
}

.theme-toggle:hover { background: var(--panel-hover); color: var(--text); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ico {
  width: 16px; height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ico-sun { display: none; }
:root[data-theme="light"] .ico-moon { display: none; }
:root[data-theme="light"] .ico-sun { display: block; }

/* ---------- layout shell ---------- */

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-head h2 {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: .01em;
}

.sub { margin-top: 3px; font-size: 12.5px; color: var(--muted); }

.row-count {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- KPI tiles ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi {
  position: relative;
  overflow: hidden;
  padding: 16px 18px 15px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 88%);
  opacity: .85;
}

.kpi-label {
  display: block;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-value {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  line-height: 1.1;
}

.kpi-value .unit {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
  letter-spacing: 0;
}

.kpi-note {
  display: block;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.kpi-note b { color: var(--text-soft); font-weight: 650; }

.kpi-chip {
  display: inline-block;
  margin-top: 9px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 999px;
}

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

.charts {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 20px;
}

.chart-panel { display: flex; flex-direction: column; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; }

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}

.swatch { width: 18px; height: 0; border-radius: 2px; }
.swatch-line { border-top: 2.5px solid var(--c-line); }
.swatch-dash { border-top: 2px dashed var(--c-line-2); }

.chart-wrap {
  position: relative;
  width: 100%;
  height: 322px;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  cursor: crosshair;
}

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

.tooltip {
  position: absolute;
  z-index: 5;
  min-width: 132px;
  padding: 9px 11px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  pointer-events: none;
  transform: translate(-50%, -100%);
  transition: opacity .12s ease;
}

.tooltip.below { transform: translate(-50%, 0); }

.tip-title {
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 5px;
  letter-spacing: .01em;
}

.tip-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}

.tip-row + .tip-row { margin-top: 2px; }
.tip-row b { color: var(--text); font-weight: 650; }
.tip-row .k { color: var(--muted); font-size: 11.5px; }
.tip-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

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

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

table.stations {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.stations thead th {
  position: sticky;
  top: 0;
  padding: 0;
  text-align: left;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border-strong);
}

.stations thead th:first-child { border-top-left-radius: 9px; }
.stations thead th:last-child  { border-top-right-radius: 9px; }

.th-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease;
}

th.num .th-btn { justify-content: flex-end; }

.th-btn:hover { color: var(--text); background: var(--panel-hover); }
.th-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.th-btn::after {
  content: "↕";
  font-size: 11px;
  letter-spacing: 0;
  opacity: .35;
  transform: translateY(-1px);
}

th[aria-sort="ascending"]  .th-btn::after { content: "▲"; font-size: 10px; opacity: 1; }
th[aria-sort="descending"] .th-btn::after { content: "▼"; font-size: 10px; opacity: 1; }

/* .stations thead th sets a background, so these need higher specificity */
.stations thead th[aria-sort="ascending"],
.stations thead th[aria-sort="descending"] { background: var(--accent-soft); }
.stations thead th[aria-sort="ascending"] .th-btn,
.stations thead th[aria-sort="descending"] .th-btn { color: var(--accent); }

.stations tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
}

.stations tbody tr { transition: background-color .14s ease; }
.stations tbody tr:hover { background: var(--panel-hover); }
.stations tbody tr:last-child td { border-bottom: 0; }

td.num { text-align: right; }

td.station-name {
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
}

td.rides { color: var(--text); font-weight: 600; }

.badge {
  display: inline-block;
  min-width: 26px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 650;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
}

.badge.ok  { color: var(--warn); border-color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.bad { color: var(--bad);  border-color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 45%, transparent);  background: color-mix(in srgb, var(--bad) 12%, transparent); }

.uptime { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.uptime-val { font-weight: 600; color: var(--text); }
.uptime-bar {
  width: 74px; height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.uptime-bar i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.uptime.ok  .uptime-bar i { background: var(--warn); }
.uptime.bad .uptime-bar i { background: var(--bad); }
.uptime.bad .uptime-val { color: var(--bad); }

/* ---------- footer ---------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px 20px;
  padding-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.foot-hint { color: var(--muted); color: color-mix(in srgb, var(--muted) 75%, transparent); }

/* ---------- responsive ---------- */

@media (max-width: 1040px) {
  .charts { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .topbar { padding: 12px 16px; }
  .shell { padding: 16px 14px 30px; gap: 16px; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: 26px; }
  .chart-wrap { height: 268px; }
  .panel { padding: 15px 14px 16px; }
  .panel-head { flex-direction: column; gap: 8px; }
  .brand-sub { font-size: 11.5px; }
  .theme-toggle { padding: 7px 11px; }
  .foot { flex-direction: column; }
}

/* stack the table into cards on narrow screens */
@media (max-width: 640px) {
  .table-scroll { overflow: visible; }
  table.stations { min-width: 0; }
  .stations thead { display: none; }
  .stations, .stations tbody { display: block; }
  .stations tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
  }
  .stations tbody tr:last-child { border-bottom: 0; }
  .stations tbody td {
    padding: 0;
    border: 0;
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
  }
  .stations tbody td::before {
    content: attr(data-label);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .stations tbody td.num { align-items: flex-start; text-align: left; }
  .stations tbody td:first-child { grid-column: 1 / -1; }
  .stations tbody td:first-child::before { content: none; }
  .uptime { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; }
}
