:root {
  --ink: #0F1519;
  --panel: #16202700;
  --surface: #172027;
  --surface-2: #1D2A32;
  --line: #2A3A44;
  --text: #E3EDF2;
  --muted: #8AA1AF;
  --volt: #6FE39B;
  --volt-dim: #2F6B4B;
  --amber: #E9B24C;
  --coral: #E87A64;
  --radius: 14px;
  --gap: 14px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2 { font-weight: 600; letter-spacing: -0.01em; }

button, input, select { font: inherit; color: inherit; }

/* Atribút `hidden` musí prebiť akékoľvek `display` nižšie. Bez tohto pravidla
   ho `.gate { display: grid }` (autorský štýl vyhráva nad štýlom prehliadača)
   ignoruje a prihlasovacia obrazovka ostane trvalo cez celý dashboard. */
[hidden] { display: none !important; }

/* ------------------------------------------------------------------- gate */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.gate-mark { width: 44px; height: 44px; color: var(--volt); margin-bottom: 18px; }

.gate h1 { margin: 0 0 4px; font-size: 1.5rem; }

.gate-hint { margin: 0 0 26px; color: var(--muted); font-size: 0.92rem; }

.code-field { margin-bottom: 14px; }

#code {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  outline: none;
}

#code:focus-visible { border-color: var(--volt); }
#code::placeholder { color: #3C4C57; }

.gate-error { min-height: 1.4em; margin: 14px 0 0; color: var(--coral); font-size: 0.88rem; }

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(15, 21, 25, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-id { display: flex; flex-direction: column; min-width: 0; }
.car-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.car-plate { font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.budget {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.budget.low { color: var(--amber); border-color: #4A3B1E; }
.budget.out { color: var(--coral); border-color: #4A2620; }
.budget-slash { opacity: 0.45; margin: 0 1px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  background: none;
  transition: background-color .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--volt); color: #07120C; font-weight: 600; }
.btn-primary:hover:not([disabled]) { background: #85EAAB; }

.btn-outline { border-color: var(--line); color: var(--text); }
.btn-outline:hover:not([disabled]) { background: var(--surface-2); }

.btn-ghost { color: var(--muted); border-color: var(--line); padding: 7px 12px; font-size: 0.86rem; }
.btn-ghost:hover:not([disabled]) { color: var(--text); background: var(--surface); }

.btn-icon { display: grid; place-items: center; width: 34px; padding: 0; height: 32px; }
.btn-wide { width: 100%; padding: 13px; }

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

#main { max-width: 940px; margin: 0 auto; padding: 18px 16px 48px; }

.banner {
  border: 1px solid #4A3B1E;
  background: #241C0E;
  color: var(--amber);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 0.88rem;
  margin-bottom: var(--gap);
}
.banner.bad { border-color: #4A2620; background: #251512; color: var(--coral); }

/* ------------------------------------------------------------------- hero */

.hero {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 6px 0 22px;
}

.gauge-wrap { position: relative; width: 186px; height: 186px; flex-shrink: 0; }
.gauge { width: 100%; height: 100%; transform: rotate(-90deg); }

.gauge-track { fill: none; stroke: #22303A; stroke-width: 12; }
.gauge-fill {
  fill: none;
  stroke: var(--volt);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 540.35;
  stroke-dashoffset: 540.35;
  transition: stroke-dashoffset .6s cubic-bezier(.22,.61,.36,1), stroke .3s;
}
.gauge-target {
  fill: none;
  stroke: var(--muted);
  stroke-width: 12;
  stroke-dasharray: 2 538.35;
  stroke-dashoffset: 0;
  opacity: 0.7;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.soc {
  font-size: 3.1rem;
  font-weight: 300;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.soc-unit { font-size: 1.2rem; margin-left: 2px; color: var(--muted); }
.soc-sub { color: var(--muted); font-size: 0.95rem; margin-top: 6px; font-variant-numeric: tabular-nums; }

.hero-side { flex: 1; min-width: 190px; }

.chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  color: var(--muted);
}
.chip-lg { font-size: 0.92rem; padding: 7px 15px; }
.chip.live { color: var(--volt); border-color: var(--volt-dim); background: #12241B; }
.chip.warn { color: var(--amber); border-color: #4A3B1E; }

.mini-facts { margin: 16px 0 0; display: grid; gap: 9px; }

/* ------------------------------------------------------------------ panel */

.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .panel-wide { grid-column: 1 / -1; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h2 { margin: 0 0 12px; font-size: 0.98rem; }

.panel[hidden] { display: none; }

.facts, .mini-facts { font-size: 0.9rem; }
.facts { margin: 0 0 12px; display: grid; gap: 9px; }

.facts > div, .mini-facts > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid #202D36;
  padding-bottom: 8px;
}
.facts > div:last-child, .mini-facts > div:last-child { border-bottom: none; padding-bottom: 0; }

.facts dt, .mini-facts dt { color: var(--muted); }
.facts dd, .mini-facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.v-live { color: var(--volt); }
.v-warn { color: var(--amber); }
.v-bad { color: var(--coral); }

.settings-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.controls .btn { flex: 1 1 auto; min-width: 130px; }

.note { color: var(--muted); font-size: 0.78rem; margin: 12px 0 0; }

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

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }

.tile {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px;
  border-left: 3px solid var(--line);
}
.tile.ok { border-left-color: var(--volt-dim); }
.tile.alert { border-left-color: var(--amber); }
.tile-k { display: block; color: var(--muted); font-size: 0.72rem; }
.tile-v { display: block; margin-top: 3px; font-size: 0.88rem; }

/* --------------------------------------------------------------- controls */

.temp-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
  font-size: 0.86rem;
}
.temp-row label { color: var(--muted); }
#temp-out { font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }

input[type=range] { accent-color: var(--volt); width: 100%; }

.check { display: flex; align-items: center; gap: 9px; font-size: 0.86rem; color: var(--muted); }
.check input { accent-color: var(--volt); width: 16px; height: 16px; }

.aux-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px 10px;
  font-size: 0.86rem;
  margin-bottom: 4px;
}
.aux-row label { color: var(--muted); }

#spin, #aux-dur {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
#spin { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }
#spin:focus-visible, #aux-dur:focus-visible { border-color: var(--volt); }

.maplink { color: var(--volt); font-size: 0.88rem; text-decoration: none; border-bottom: 1px solid var(--volt-dim); }

/* --------------------------------------------------------------- profiles */

.profile {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}
.profile summary {
  cursor: pointer;
  padding: 11px 13px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  list-style: none;
}
.profile summary::-webkit-details-marker { display: none; }
.profile summary:focus-visible { outline: 2px solid var(--volt); outline-offset: -2px; }
.profile[open] summary { border-bottom: 1px solid var(--line); background: var(--surface-2); }
.profile-body { padding: 13px; font-size: 0.85rem; }
.profile-body .facts { margin-bottom: 12px; }
.profile-here { color: var(--volt); font-size: 0.78rem; }

.timeline { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.timeline li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.timeline li.on { color: var(--text); }

.sub-h { color: var(--muted); font-size: 0.76rem; margin: 14px 0 7px; }

/* ----------------------------------------------------------------- errors */

.errlist { margin: 0; padding: 0; list-style: none; display: grid; gap: 9px; font-size: 0.85rem; }
.errlist li { display: flex; gap: 10px; align-items: baseline; }
.errlist code {
  color: var(--muted);
  font-size: 0.76rem;
  flex-shrink: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------------------------------------------------------------------- foot */

.foot {
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.8;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.87rem;
  max-width: min(92vw, 420px);
  z-index: 40;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.toast.ok { border-color: var(--volt-dim); }
.toast.bad { border-color: #4A2620; color: var(--coral); }

/* --------------------------------------------------------------- heatmap */

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

#heatmap-range {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  outline: none;
  font-size: 0.82rem;
}
#heatmap-range:focus-visible { border-color: var(--volt); }

.heatmap-map { height: 340px; border-radius: var(--radius); overflow: hidden; }
@media (min-width: 720px) { .heatmap-map { height: 440px; } }

/* Leaflet defaultne svetlá dlaždicová mapa — tmavý filter na dlaždice, ovládacie
   prvky (zoom, atribúcia) prefarbené manuálne, keďže filter beží len na tile pane. */
.leaflet-container { background: var(--surface-2); font-family: inherit; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
.leaflet-control-attribution { background: var(--surface-2); color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bar a { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface); }

.heatmap-legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.78rem; color: var(--muted); }
.heatmap-legend-bar {
  flex: 1; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--volt), var(--amber), var(--coral));
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
