/* Hyundai Kona dashboard — the pieces base.css does not carry.
 *
 * Loaded AFTER base.css, which owns the PärKit house palette (--bg, --pink,
 * --text, --border …), the reset, the noise overlay and the gradient accent
 * bar. Nothing here redefines one of those: the tokens below are ADDITIVE
 * aliases and extras, so a change to the canonical theme still reaches this
 * dashboard. base.css is a byte-exact copy of common/static/css/base.css and
 * must never be edited here — scripts/check_shared_assets.py is the referee.
 *
 * Shape borrowed from services/bmw's dashboard (battery hero, metric strip,
 * card grid, history panels, AI-feed rows) so the two cars read the same;
 * repainted onto the house palette, and with the CarData-only furniture
 * (descriptor table, MQTT event timeline, Leaflet trail) left out.
 */

:root {
  --surface: var(--card);
  --elevated: var(--card-hover);
  --border-vis: #ffffff1a;
  --text-2: #b6b6c6;
  --text-3: var(--dim);
  --text-4: var(--dimmer);
  --green: var(--success);
  --yellow: var(--warning);
  --red: var(--danger);
  --blue: #6bb8ff;
  /* System mono — no webfont, no CDN. Telemetry wants tabular digits, not a
     network round-trip on every cold load. */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.hdr {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; background: var(--bg-deep);
}
.hdr-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hdr h1 {
  font-size: 0.95rem; font-weight: 700; color: var(--pink);
  letter-spacing: -0.01em;
}
.hdr-right {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-3);
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--text-4); transition: background .3s, box-shadow .3s;
}
.dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.stale { background: var(--yellow); }
.dot.off { background: var(--text-4); }

.hdr-switch {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border-vis);
}
.nav-app-switch {
  font: 500 0.7rem var(--mono); letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); text-decoration: none; padding: 4px 8px;
  border-radius: 6px; transition: all .15s;
}
.nav-app-switch:hover { color: var(--pink); background: var(--pink-dim); text-decoration: none; }
.nav-app-infra { opacity: .6; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  background: var(--elevated); color: var(--text-2);
  border: 1px solid var(--border-vis); border-radius: 8px; padding: 6px 10px;
  font: 500 0.7rem var(--mono); letter-spacing: .05em; text-transform: uppercase;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--pink-dim); color: var(--pink); border-color: var(--pink); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.ok { color: var(--green); border-color: var(--green); }
.btn.err { color: var(--red); border-color: var(--red); }
.btn.warn { color: var(--yellow); border-color: var(--yellow); }
/* A forced poll wakes the car over cellular and spends a rationed daily slot —
   it should not look like the free one sitting next to it. */
.btn.wake { border-style: dashed; }

/* ── Battery hero ──────────────────────────────────────────────────────── */
.bat-hero { padding: 20px 0 12px; }
.bat-row { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.bat-pct {
  font-size: 2.3rem; font-weight: 800; min-width: 92px; line-height: 1;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.bat-track {
  flex: 1; height: 28px; border-radius: 14px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
}
.bat-fill {
  height: 100%; border-radius: 13px; width: 0;
  transition: width 1s cubic-bezier(.4, 0, .2, 1), background .5s;
  position: relative;
}
.bat-fill.charging::after {
  content: ''; position: absolute; inset: 0; border-radius: 13px;
  background: linear-gradient(90deg, transparent, #ffffff26 50%, transparent);
  background-size: 200% 100%; animation: shimmer 2s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.bat-range {
  min-width: 84px; text-align: right; font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums; line-height: 1.25;
}
.bat-range small { display: block; font-size: 0.7rem; font-weight: 400; color: var(--text-3); }
.bat-sub {
  display: none; align-items: center; gap: 8px;
  padding-left: 108px; font-size: 0.78rem; color: var(--text-3);
}
.bat-sub.active { display: flex; }
.bat-sub .bolt { color: var(--green); animation: bolt 2s ease-in-out infinite; }
@keyframes bolt { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ── Metric strip ──────────────────────────────────────────────────────── */
.metrics {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  margin-bottom: 18px; background: var(--surface);
}
.m-cell { padding: 13px 14px; border-right: 1px solid var(--border); text-align: center; }
.m-cell:last-child { border-right: none; }
.m-cell .lbl {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); margin-bottom: 4px; font-weight: 600;
}
.m-cell .val {
  font-family: var(--mono); font-size: 0.85rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Clocks — three of them, never conflated ───────────────────────────── */
.clocks {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 18px;
}
.clock {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.clock .k {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); font-weight: 600; display: block; margin-bottom: 4px;
}
.clock .v {
  font-family: var(--mono); font-size: 0.85rem; font-weight: 600;
  font-variant-numeric: tabular-nums; display: block;
}
.clock .age { font-size: 0.68rem; color: var(--text-4); font-family: var(--mono); }
.clock.car { border-left: 2px solid var(--pink); }
.clock.fix { border-left: 2px solid var(--blue); }
.clock.poll { border-left: 2px solid var(--text-4); }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 17px; transition: border-color .15s;
}
.card:hover { border-color: var(--border-vis); }
.card h2 {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); margin-bottom: 10px; font-weight: 700;
}
.row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 5px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row .lbl { font-size: 0.8rem; color: var(--text-2); }
.row .val {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 600;
  font-variant-numeric: tabular-nums; text-align: right;
  overflow-wrap: anywhere;
}
.val.g { color: var(--green); }
.val.y { color: var(--yellow); }
.val.r { color: var(--red); }
.val.b { color: var(--blue); }
.val.dim { color: var(--text-4); }
.card a { word-break: break-word; }

.pill {
  display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 20px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; border: 1px solid;
}
.pill.ok { color: var(--green); border-color: #6bffa840; background: #6bffa812; }
.pill.warn { color: var(--yellow); border-color: #ffb86b40; background: #ffb86b12; }
.pill.dim { color: var(--text-3); border-color: var(--border-vis); }

/* ── Panels + history lists ────────────────────────────────────────────── */
.panel { margin-bottom: 18px; }
.panel h2 {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); font-weight: 700; margin-bottom: 8px;
}
.panel-list { list-style: none; max-height: 320px; overflow-y: auto; }
.panel-list::-webkit-scrollbar { width: 3px; }
.panel-list::-webkit-scrollbar-thumb { background: var(--text-4); border-radius: 2px; }

.hi {
  display: grid; grid-template-columns: 92px 1fr auto; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 0.78rem; align-items: baseline;
}
.hi:last-child { border-bottom: none; }
.hi .dt { color: var(--text-3); font-family: var(--mono); font-size: 0.7rem; }
.hi .det { color: var(--text-2); }
.hi .sub { display: block; color: var(--text-4); font-size: 0.68rem; }
.hi .st {
  font-family: var(--mono); font-weight: 600; text-align: right;
  font-variant-numeric: tabular-nums; font-size: 0.72rem; white-space: nowrap;
}
.eff-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
}
.eff-dot.good { background: var(--green); }
.eff-dot.ok { background: var(--blue); }
.eff-dot.mid { background: var(--yellow); }
.eff-dot.bad { background: var(--red); }
.tag {
  font-size: 0.6rem; padding: 1px 6px; border-radius: 10px; font-weight: 700;
  letter-spacing: .03em; margin-left: 6px; white-space: nowrap;
}
.tag.approx { color: var(--yellow); background: #ffb86b14; border: 1px solid #ffb86b2e; }
.tag.live { color: var(--green); background: #6bffa814; border: 1px solid #6bffa82e; }

/* ── Daily energy table (Kona-specific) ────────────────────────────────── */
.energy-wrap { overflow-x: auto; }
.energy {
  width: 100%; border-collapse: collapse; font-size: 0.74rem;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.energy th, .energy td {
  padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.energy th {
  color: var(--text-4); font-weight: 600; font-size: 0.62rem;
  text-transform: uppercase; letter-spacing: .05em;
}
.energy td:first-child, .energy th:first-child { text-align: left; color: var(--text-3); }
.energy tbody tr:hover { background: #ffffff05; }
.energy .strong { color: var(--text); font-weight: 700; }
.energy .regen { color: var(--green); }

/* ── AI feeds ──────────────────────────────────────────────────────────── */
.feeds {
  margin-top: 18px; padding: 14px 17px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
}
.feeds h2 {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); font-weight: 700; margin-bottom: 10px;
}
.feed-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.feed-row:last-child { border-bottom: none; }
.feed-desc { flex: 1; font-size: 0.76rem; color: var(--text-2); }
.feed-desc strong { color: var(--text); font-weight: 700; }
.feed-copy {
  padding: 4px 10px; border-radius: 6px; font: 500 0.7rem var(--mono);
  background: var(--pink-dim); color: var(--pink);
  border: 1px solid var(--tag-border); cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.feed-copy:hover { background: var(--pink-glow); }
.feed-copy.ok { background: #6bffa814; color: var(--green); border-color: #6bffa82e; }
.feed-copy.err { background: #ff555514; color: var(--red); border-color: #ff55552e; }
.feeds .note { margin-top: 10px; font-size: 0.68rem; color: var(--text-4); }

/* ── Footer ────────────────────────────────────────────────────────────── */
.foot {
  margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 0.68rem; color: var(--text-4); font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--text-4); }
.hidden { display: none !important; }

@media (max-width: 640px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .m-cell:nth-child(2) { border-right: none; }
  .m-cell:nth-child(3), .m-cell:nth-child(4) { border-top: 1px solid var(--border); }
  .clocks { grid-template-columns: 1fr; }
  .bat-pct { font-size: 1.8rem; min-width: 72px; }
  .bat-sub { padding-left: 88px; }
  .hdr { padding: 10px 14px; }
  .hi { grid-template-columns: 78px 1fr; }
  .hi .st { grid-column: 2; text-align: left; }
}

/* ── Map ───────────────────────────────────────────────────────────────────
 * bmw's map furniture, repainted onto the house palette. Same structure, same
 * control positions, same Leaflet overrides — this is a carry, not a redesign.
 */
#map-container {
  margin-bottom: 18px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); position: relative;
}
#map { height: 300px; background: var(--surface); }

.map-overlay {
  position: absolute; bottom: 10px; left: 10px; z-index: 1000;
  background: #12121fd9; backdrop-filter: blur(8px);
  border-radius: 8px; padding: 6px 10px; border: 1px solid var(--border);
  display: flex; gap: 12px; font-size: 0.68rem; color: var(--text-2);
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.map-overlay span { white-space: nowrap; }
.map-overlay .lbl { color: var(--text-4); margin-right: 3px; }

.map-actions { position: absolute; top: 10px; right: 10px; z-index: 1000; display: flex; gap: 6px; }
.map-actions a {
  padding: 5px 10px; border-radius: 6px; font-size: 0.68rem; font-weight: 600;
  text-decoration: none; color: var(--pink); background: #12121fd9;
  backdrop-filter: blur(8px); border: 1px solid var(--tag-border); transition: all .15s;
}
.map-actions a:hover { background: var(--pink-dim); text-decoration: none; }

.map-range, .map-layers {
  position: absolute; top: 10px; z-index: 1000; display: flex; gap: 3px;
  padding: 3px; border-radius: 999px; background: #12121fe0;
  backdrop-filter: blur(10px); border: 1px solid var(--border);
  box-shadow: 0 10px 24px #00000038;
}
.map-range { left: 10px; }
.map-layers { left: 196px; }
.map-range button, .map-layers button {
  appearance: none; border: none; outline: none; background: transparent;
  padding: 6px 10px; border-radius: 999px; color: var(--text-3); cursor: pointer;
  transition: all .15s; font: 500 0.62rem var(--mono);
  letter-spacing: .04em; text-transform: uppercase;
}
.map-range button { min-width: 38px; }
.map-range button:hover, .map-layers button:hover { color: var(--text-2); background: #ffffff0a; }
.map-range button.active { color: var(--text); background: var(--pink-dim); box-shadow: inset 0 0 0 1px var(--tag-border); }
.map-layers button.active { color: var(--text); background: #ffffff10; box-shadow: inset 0 0 0 1px #ffffff14; }

.map-meta {
  position: absolute; top: 46px; left: 10px; z-index: 1000;
  background: #12121fd9; backdrop-filter: blur(8px); border-radius: 8px;
  padding: 6px 10px; border: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.62rem; color: var(--text-2);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.map-meta .legend { display: flex; align-items: center; gap: 6px; color: var(--text-3); }
.map-meta .stat .lbl { color: var(--text-4); margin-right: 4px; }
.map-meta .status {
  display: flex; align-items: center; gap: 6px; padding: 2px 7px;
  border-radius: 999px; border: 1px solid #ffffff0f; background: #ffffff08;
}
.map-meta .status.loading { color: var(--text); border-color: var(--tag-border); background: var(--pink-dim); }
.map-meta .status.error { color: var(--red); border-color: #ff55553a; background: #ff55551a; }
.map-meta .spinner-dot {
  width: 8px; height: 8px; border-radius: 50%; display: none;
  border: 1.5px solid #ffffff2e; border-top-color: var(--pink);
  animation: spin .8s linear infinite;
}
.map-meta .status.loading .spinner-dot { display: block; }
.map-meta .swatch {
  width: 24px; height: 2px; border-radius: 999px;
  background: linear-gradient(90deg, #6bffa8 0%, #ffb86b 50%, #ff5555 100%);
}

/* Markers */
.car-pulse {
  width: 14px; height: 14px; border-radius: 50%; background: var(--pink);
  border: 2px solid #fff; box-shadow: 0 0 8px var(--pink);
}
.charge-marker {
  width: 8px; height: 8px; border-radius: 50%;
  background: #6bffa84d; border: 1.5px solid var(--green);
}
.history-anchor {
  width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font: 700 0.56rem var(--mono); color: #12121f;
  border: 1px solid #ffffff2e; box-shadow: 0 8px 18px #00000047;
}
.history-anchor.start { background: #6bffa8ea; }
.history-anchor.end { background: #ff6b9dea; color: #fff; }
.parked-cluster {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font: 700 0.56rem var(--mono);
  color: var(--text); background: #6bb8ffea;
  border: 1px solid #ffffff2e; box-shadow: 0 8px 18px #00000047;
}

/* Leaflet chrome, dressed to match */
.leaflet-control-attribution {
  font-size: 9px !important; background: #12121fb3 !important; color: var(--text-4) !important;
}
.leaflet-control-attribution a { color: var(--text-3) !important; }
.leaflet-control-zoom a {
  background: var(--surface) !important; color: var(--text-2) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--elevated) !important; }
.map-tip {
  background: #12121fe6 !important; color: var(--text) !important;
  border: 1px solid var(--border) !important; border-radius: 6px !important;
  font-family: var(--mono) !important; font-size: 0.68rem !important;
  padding: 3px 8px !important; box-shadow: none !important;
}
.map-tip::before { border-top-color: #12121fe6 !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #12121ff5 !important; color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-popup-content {
  margin: 10px 12px !important; font-family: var(--mono) !important; font-size: 0.68rem !important;
}
.map-popup-links { display: flex; gap: 8px; margin-top: 8px; }
.map-popup-links a {
  color: var(--pink); text-decoration: none; padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--tag-border); background: var(--pink-dim);
}
.map-popup-links a:hover { background: var(--pink-glow); text-decoration: none; }

@media (max-width: 640px) {
  #map { height: 230px; }
  .map-range, .map-layers { gap: 2px; padding: 2px; }
  .map-range button, .map-layers button { padding: 5px 8px; }
  .map-range button { min-width: 34px; }
  .map-layers { top: 46px; left: 10px; max-width: calc(100% - 20px); flex-wrap: wrap; }
  .map-meta { top: 82px; max-width: calc(100% - 20px); }
}

/* Dark basemap without a tile API key: invert OSM's standard tiles and put the hues back.
   Applied to the tile pane only (className on the tileLayer), so markers and lines keep
   their real colours. */
.map-tiles-dark { filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%) saturate(60%); }
