/* ============================================================
   Velo — Fleet Analytics
   Themes: light (default vars) + dark ([data-theme="dark"])
   ============================================================ */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --border: #e2e8f1;
  --border-strong: #cdd7e6;
  --text: #182238;
  --muted: #5d6b85;
  --accent: #0c9d68;
  --accent-2: #2f6fed;
  --accent-soft: rgba(12, 157, 104, 0.14);
  --ok: #0c9d68;
  --warn: #b97a08;
  --danger: #d64545;
  --chart-grid: rgba(24, 34, 56, 0.09);
  --chart-text: #5d6b85;
  --chart-guide: rgba(24, 34, 56, 0.30);
  --tooltip-bg: #182238;
  --tooltip-text: #f4f7fc;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 6px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0c111d;
  --surface: #141b2b;
  --surface-2: #1a2336;
  --border: #253049;
  --border-strong: #35436a;
  --text: #e8edf7;
  --muted: #8fa0bd;
  --accent: #3ddc97;
  --accent-2: #6ea8ff;
  --accent-soft: rgba(61, 220, 151, 0.16);
  --ok: #3ddc97;
  --warn: #f0b452;
  --danger: #f27d7d;
  --chart-grid: rgba(232, 237, 247, 0.08);
  --chart-text: #8fa0bd;
  --chart-guide: rgba(232, 237, 247, 0.32);
  --tooltip-bg: #e8edf7;
  --tooltip-text: #141b2b;
  --shadow: none;
  color-scheme: dark;
}

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

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

h1, h2, h3, p { margin: 0; }

::selection { background: var(--accent-soft); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}

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

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--bg);
  flex: none;
  box-shadow: var(--shadow);
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-text p {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.chip-soft {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible,
.stations-table th button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* theme icons: show sun in dark mode (click -> light), moon in light mode */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ---------- main layout ---------- */

main.wrap { padding-top: 22px; padding-bottom: 8px; }

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

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

.kpi {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.kpi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}

.kpi-icon svg { width: 20px; height: 20px; }

.kpi-body { min-width: 0; }

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.panel + .panel { margin-top: 16px; }

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

.panel-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding-top: 2px;
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

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

.chart-box { position: relative; width: 100%; }
.chart-box canvas { display: block; width: 100%; height: 100%; }

.chart-monthly { height: 300px; }
.chart-stations { height: 292px; }

.row-stations {
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 13fr);
  gap: 16px;
  margin-top: 16px;
}

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: 12px;
  line-height: 1.45;
  padding: 7px 11px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  max-width: 240px;
}

.tooltip.show { opacity: 1; transform: translateY(0); }

.tooltip .tt-title { font-weight: 700; margin-bottom: 1px; }
.tooltip .tt-value { font-variant-numeric: tabular-nums; }
.tooltip .tt-dim { opacity: 0.72; }

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

.table-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

.stations-table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 13.5px;
}

.stations-table th {
  padding: 8px 10px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: transparent;
  white-space: nowrap;
}

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

.stations-table th .th-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.stations-table th.num .th-btn { flex-direction: row-reverse; }

.stations-table th .th-btn:hover { color: var(--text); }

.sort-ind {
  font-size: 9px;
  line-height: 1;
  opacity: 0;
  transform: translateY(1px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.stations-table th.sorted { color: var(--text); }
.stations-table th.sorted .th-btn { color: var(--text); }
.stations-table th.sorted .sort-ind { opacity: 1; }
.stations-table th.sorted .sort-ind.desc { transform: translateY(-1px); }

.stations-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.stations-table tbody tr { transition: background-color 0.12s ease; }
.stations-table tbody tr:hover { background: var(--surface-2); }

.st-name { font-weight: 600; }

.st-faults.high { color: var(--danger); font-weight: 700; }

/* uptime cell: percent + mini bar */
.uptime-cell { display: flex; align-items: center; gap: 9px; min-width: 118px; }

.uptime-val { width: 52px; text-align: right; font-weight: 600; }

.uptime-bar {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.uptime-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.3s ease;
}

.uptime-bar.warn i { background: var(--warn); }
.uptime-bar.danger i { background: var(--danger); }

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

.footer {
  border-top: 1px solid var(--border);
  margin-top: 28px;
  padding: 18px 0 26px;
  color: var(--muted);
  font-size: 12.5px;
  transition: border-color 0.25s ease;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

@media (max-width: 1020px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-stations { grid-template-columns: 1fr; }
  .chart-stations { height: 260px; }
}

@media (max-width: 700px) {
  .wrap { padding: 0 16px; }
  .kpis { grid-template-columns: 1fr; }
  .chart-monthly { height: 250px; }
  .chart-stations { height: 240px; }
  .topbar-inner { flex-wrap: wrap; }
  .chip-soft { display: none; }
  .kpi-value { font-size: 24px; }
  .panel { padding: 16px 14px 14px; }
}
