:root {
  color-scheme: light;

  /* chart chrome & ink (dataviz reference palette, light) */
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --surface-raised: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border-hairline: rgba(11, 11, 11, 0.1);

  /* status */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  /* categorical series, per user request: zwart=Huis, geel=Zon, rood=Net, blauw=Batterij.
     Yellow/red re-tuned from the reference palette's steps -- the original
     ΔE 6-8 pairing failed the normal-vision floor once EV's color left the
     leading validated sequence; re-run scripts/validate_palette.js before
     changing any of these four. */
  --series-grid: #e34948; /* rood */
  --series-solar: #b8940a; /* geel */
  --series-battery: #2a78d6; /* blauw */
  --series-home: #0b0b0b; /* zwart */
  --series-ev: #008300; /* groen (niet gespecificeerd; groen omdat rood al Net is) */

  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --surface-raised: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border-hairline: rgba(255, 255, 255, 0.1);

    --series-grid: #e66767; /* rood */
    --series-solar: #a8890c; /* geel */
    --series-battery: #3987e5; /* blauw */
    --series-home: #ffffff; /* zwart -> wit op donkere ondergrond, blijft de "neutrale" */
    --series-ev: #008300; /* groen */
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --surface-raised: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border-hairline: rgba(255, 255, 255, 0.1);

  --series-grid: #e66767; /* rood */
  --series-solar: #a8890c; /* geel */
  --series-battery: #3987e5; /* blauw */
  --series-home: #ffffff; /* zwart -> wit op donkere ondergrond */
  --series-ev: #008300; /* groen */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
}

a {
  color: inherit;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ---- header ---- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-hairline);
}

.app-header .brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.app-header .brand .mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--series-solar);
  transform: rotate(45deg);
}

.app-header h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}

.app-header .subtitle {
  color: var(--text-muted);
  font-size: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logout-btn {
  border: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.logout-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.fleet-name {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--page-plane);
  border: 1px solid var(--border-hairline);
  padding: 4px 10px;
  border-radius: 999px;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px;
}

/* ---- stat tiles ---- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-tile .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
}

.stat-tile .value.good {
  color: var(--status-good);
}
.stat-tile .value.critical {
  color: var(--status-critical);
}

/* ---- device list ---- */

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

.device-card {
  display: block;
  text-decoration: none;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-left: 3px solid var(--baseline);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 150ms ease, transform 150ms ease;
}

.device-card:hover {
  border-color: var(--series-grid);
  transform: translateY(-1px);
}

.device-card.is-online {
  border-left-color: var(--status-good);
}
.device-card.is-offline {
  border-left-color: var(--text-muted);
}

.device-card .top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.device-card .name {
  font-weight: 600;
  font-size: 15px;
}

.device-card .city {
  color: var(--text-secondary);
  font-size: 12px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
.status-dot.online {
  background: var(--status-good);
}
.status-dot.offline {
  background: var(--text-muted);
}

.status-text {
  font-size: 11px;
  color: var(--text-muted);
}

.device-card .converter {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.device-card .mini-stats {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  font-size: 12px;
}

.health-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 12%, transparent);
}

.device-card .mini-stats .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  margin-right: 4px;
}

/* ---- detail page ---- */

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
}
.back-link:hover {
  color: var(--text-primary);
}

.detail-header {
  margin-bottom: 20px;
}
.detail-header h2 {
  margin: 0 0 2px;
  font-size: 22px;
}
.detail-header .meta {
  color: var(--text-secondary);
  font-size: 13px;
}

.live-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.live-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-left: 3px solid var(--tile-color, var(--baseline));
  border-radius: var(--radius);
  padding: 12px 14px;
}

.live-tile .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.live-tile .value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
}

.live-row .stale-note {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-muted);
}

.health-card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.health-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.health-verdict {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.health-verdict::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-good);
}

.health-verdict.not-okay::before {
  background: var(--status-critical);
}

.health-reported-at {
  font-size: 11px;
  color: var(--text-muted);
}

.health-flag-list {
  margin: 6px 0 12px;
  padding-left: 18px;
  font-size: 12px;
  color: var(--text-secondary);
}

.health-scores {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 48px;
}

.health-score-bar {
  flex: 1;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}

.health-score-bar.good {
  background: var(--status-good);
}
.health-score-bar.warning {
  background: var(--status-warning);
}
.health-score-bar.critical {
  background: var(--status-critical);
}

.range-row {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.range-btn {
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.range-btn.active {
  border-color: var(--series-grid);
  color: var(--text-primary);
  font-weight: 600;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius);
  padding: 18px 20px 12px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.legend-item .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.resolution-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  padding-top: 6px;
}

.chart-zoom-toolbar {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
}

.zoom-hint {
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}

.zoom-reset-btn {
  border: 1px solid var(--border-hairline);
  background: var(--surface-raised);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
}
.zoom-reset-btn:hover {
  color: var(--text-primary);
  border-color: var(--series-grid);
}

.empty-state,
.error-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}
.error-state {
  color: var(--status-critical);
}
