/* Palette per dataviz skill reference (references/palette.md), dark mode only —
   this dashboard is dark-themed by design, matching the rene-kreher.de reference. */
:root {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);

  /* categorical, fixed order — never cycled/reassigned per series identity */
  --series-1: #3987e5; /* blue   */
  --series-2: #d95926; /* orange */
  --series-3: #199e70; /* aqua   */
  --series-4: #c98500; /* yellow */
  --accent:   #d55181; /* magenta — brand accent for the hero SoC series/tiles */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
}

* { box-sizing: border-box; }

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

.viz-root {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

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

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.app-header__title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  display: inline-block;
}

.app-header__subtitle {
  margin-left: 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.conn-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.conn-status.is-live .conn-status__dot { background: var(--status-good); }
.conn-status.is-down .conn-status__dot { background: var(--status-critical); }

/* ---------- vehicle card ---------- */

.vehicle-card {
  background: radial-gradient(ellipse at 50% 30%, color-mix(in srgb, var(--accent) 10%, var(--surface-1)), var(--surface-1));
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}

/* Fixed aspect-ratio container so the Three.js canvas has a stable size to
   render into and percentage-based overlay positions (glow, cable) stay
   accurate at any card width. */
.vehicle-card__photo {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.vehicle-card__canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
.vehicle-card__canvas:active {
  cursor: grabbing;
}

/* Soft top/bottom fade so the photo blends into the dark card instead of
   ending on a hard edge. */
.vehicle-card__photo::before,
.vehicle-card__photo::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 2;
}
.vehicle-card__photo::before {
  top: 0;
  height: 22%;
  background: linear-gradient(to bottom, var(--surface-1), transparent);
}
.vehicle-card__photo::after {
  bottom: 0;
  height: 30%;
  background: linear-gradient(to top, var(--surface-1), transparent);
}

/* Procedural charging cable overlaid on the photo, docking at the front
   bumper. Hidden by default; app.js toggles is-visible while charging. */
.vehicle-card__cable {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.vehicle-card__cable.is-visible { opacity: 1; }
.vehicle-card__cable-wire {
  fill: none;
  stroke: #1a1a1a;
  stroke-width: 0.9;
  stroke-linecap: round;
}
.vehicle-card__cable-plug {
  fill: var(--accent);
  filter: drop-shadow(0 0 3px var(--accent));
}

.vehicle-card__hint {
  margin: 0;
  padding: 8px 14px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

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

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
}

.stat-tile__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.stat-tile__icon {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--text-muted);
}

.stat-tile__value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text-primary);
  overflow-wrap: break-word;
}

.stat-tile__value .unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 3px;
}

.stat-tile__badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 100px;
}
.stat-tile__badge--warning  { background: color-mix(in srgb, var(--status-warning) 22%, transparent); color: var(--status-warning); }
.stat-tile__badge--critical { background: color-mix(in srgb, var(--status-critical) 22%, transparent); color: var(--status-critical); }

.meter { margin-top: 8px; }
.meter__track {
  height: 5px;
  border-radius: 100px;
  background: color-mix(in srgb, var(--accent) 20%, var(--surface-1));
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: 100px;
  background: var(--accent);
  transition: width 0.4s ease;
}
.meter__fill--warning { background: var(--status-warning); }
.meter__fill--critical { background: var(--status-critical); }

.stat-tile--accent { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.stat-tile--accent .stat-tile__value { color: var(--accent); }

.stat-tile--stale .stat-tile__value,
.stat-tile--stale .stat-tile__label { color: var(--text-muted); }

/* ---------- filter row ---------- */

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-row__label {
  font-size: 13px;
  color: var(--text-secondary);
}

.filter-row__presets {
  display: flex;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.filter-row__presets button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.filter-row__presets button:hover { background: rgba(255,255,255,0.06); }
.filter-row__presets button.is-selected {
  background: var(--accent);
  color: #ffffff;
}

/* ---------- chart cards ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 6px;
}

.chart-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chart-card__title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.chart-card__legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.chart-card__legend .key {
  display: inline-block;
  width: 12px;
  height: 2px;
  margin-right: 5px;
  vertical-align: middle;
  border-radius: 1px;
}

.chart-card__empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}

/* ---------- uPlot overrides to match theme ---------- */

.u-wrap { margin-top: 4px; }
.uplot, .u-wrap { background: transparent; }
.u-legend { display: none; } /* we render our own legend above the plot */

/* hover marker: highlights the data point under the cursor */
.u-cursor-pt {
  box-shadow: 0 0 6px 2px rgba(255, 255, 255, 0.55);
}

/* custom tooltip */
.u-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: #000000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
  display: none;
}
.u-tooltip__time { color: var(--text-muted); margin-bottom: 3px; }
.u-tooltip__row { display: flex; align-items: center; gap: 6px; }
.u-tooltip__row .key { width: 10px; height: 2px; display: inline-block; border-radius: 1px; }
.u-tooltip__row .val { font-weight: 600; color: var(--text-primary); }
.u-tooltip__row .name { color: var(--text-secondary); }

.app-footer {
  margin-top: 28px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 480px) {
  .stat-tile__value { font-size: 20px; }
}
