:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: rgba(18, 22, 28, 0.94);
  --panel-strong: #151920;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f7fa;
  --muted: #9aa4b2;
  --red: #e82127;
  --red-bright: #ff3a3f;
  --green: #2bd483;
  --amber: #f7b84b;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

header {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(180deg, rgba(9,11,15,.98), rgba(9,11,15,.75), transparent);
  pointer-events: none;
}
header > * { pointer-events: auto; }
.brand, .header-actions, .panel-heading, .battery-row { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  box-shadow: 0 8px 32px rgba(232, 33, 39, .35);
}
h1, h2, p { margin: 0; }
h1 { font-size: 16px; letter-spacing: .02em; }
.brand p, .muted { color: var(--muted); font-size: 12px; }
.header-actions { gap: 10px; }
.pill {
  padding: 7px 12px;
  border: 1px solid color-mix(in srgb, var(--green) 30%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 10%, transparent);
  color: var(--green);
  font-size: 12px;
  font-weight: 650;
}
.pill.dim { color: var(--muted); border-color: var(--line); background: rgba(0,0,0,.25); }
.pill.error { color: var(--amber); border-color: rgba(247,184,75,.3); }

main, #map { width: 100%; height: 100%; }
#map { background: #0c1016; }
.maplibregl-ctrl-bottom-right { margin: 0 12px 12px 0; }
.maplibregl-ctrl-group { border-radius: 10px !important; overflow: hidden; background: #171b22 !important; }
.maplibregl-ctrl button span { filter: invert(1); }
.maplibregl-popup-content {
  color: var(--text);
  background: #151920;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.maplibregl-popup-tip { border-top-color: #151920 !important; }

.panel {
  position: fixed;
  z-index: 10;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,.4);
  backdrop-filter: blur(18px);
}
.planner {
  top: 84px;
  left: 18px;
  width: min(410px, calc(100vw - 36px));
  max-height: calc(100vh - 104px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 20px;
}
.panel-heading { justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.panel-heading h2 { margin-top: 4px; font-size: 20px; line-height: 1.15; }
.eyebrow {
  color: var(--red-bright);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.stat {
  flex: none;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-size: 11px;
}
.map-pick-tip, .scope-note, .geocoder-attribution {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}
.geocoder-attribution { margin-top: -6px; }
.geocoder-attribution a { color: #c5ced9; }
label {
  display: grid;
  gap: 6px;
  color: #bac2ce;
  font-size: 11px;
  font-weight: 650;
}
input {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: rgba(0,0,0,.28);
  color: var(--text);
  padding: 0 11px;
}
input:focus { border-color: rgba(232,33,39,.8); box-shadow: 0 0 0 3px rgba(232,33,39,.12); }
input:disabled {
  cursor: not-allowed;
  opacity: .48;
}
#route-form { display: grid; gap: 14px; }
.location-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}
.location-grid > *, .two-columns > * { min-width: 0; }
.location-grid > input { font-size: 12px; }
.location-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}
.location-search-row .secondary { padding: 0 10px; }
.place-results {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #10141a;
}
.place-result {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 9px 11px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.place-result:last-child { border-bottom: 0; }
.place-result:hover, .place-result:focus { background: rgba(255,255,255,.08); outline: none; }
.place-result strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-result span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.place-results-empty {
  padding: 10px 11px;
  color: var(--muted);
  font-size: 11px;
}
.coordinate-details {
  color: var(--muted);
  font-size: 10px;
}
.coordinate-details summary {
  width: max-content;
  cursor: pointer;
  user-select: none;
}
.location-grid.live-location-active .coordinate-details {
  pointer-events: none;
  opacity: .45;
}
.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.coordinate-grid input { font-size: 12px; }
.waypoint-section {
  display: grid;
  gap: 9px;
  border-block: 1px solid var(--line);
  padding-block: 13px;
}
.waypoint-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.waypoint-heading > div { display: grid; gap: 2px; }
.waypoint-heading strong { color: #dce2ea; font-size: 12px; }
.waypoint-heading span, .waypoint-empty {
  color: var(--muted);
  font-size: 10px;
}
.waypoint-heading .secondary { min-height: 34px; }
#waypoint-list { display: grid; gap: 9px; }
.waypoint-card {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255,255,255,.035);
}
.waypoint-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.waypoint-order {
  color: var(--amber);
  font-size: 11px;
  font-weight: 750;
}
.waypoint-actions { display: flex; gap: 4px; }
.waypoint-actions button {
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  padding: 0;
}
.waypoint-actions .remove-waypoint { color: #ff8a8d; }
.waypoint-duration {
  grid-template-columns: 1fr 90px;
  align-items: center;
}
.waypoint-duration input { min-height: 34px; }
.waypoint-empty { line-height: 1.45; }
.waypoint-section:has(.waypoint-card) .waypoint-empty { display: none; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.time-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.datetime-24 { display: grid; gap: 5px; min-width: 0; }
.datetime-24 input, .datetime-24 select {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: rgba(0,0,0,.28);
  color: var(--text);
  padding-inline: 7px;
  font: inherit;
}
.datetime-24 input:focus, .datetime-24 select:focus {
  border-color: rgba(232,33,39,.8);
  box-shadow: 0 0 0 3px rgba(232,33,39,.12);
}
.clock-24 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 5px;
}
.clock-24 > span { color: var(--muted); text-align: center; }
.time-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  cursor: pointer;
}
.time-toggle input {
  width: 14px;
  min-height: 14px;
  accent-color: var(--red);
}
.time-field.time-disabled .datetime-24 :is(input, select) {
  cursor: not-allowed;
  opacity: .42;
}
.location-grid .use-vehicle-location {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-top: 2px;
}
.use-vehicle-location input {
  width: 15px;
  min-height: 15px;
  accent-color: var(--green);
}
.use-vehicle-location:has(input:disabled) { opacity: .45; }
.use-live-vehicle-data {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--green);
}
.use-live-vehicle-data input {
  width: 15px;
  min-height: 15px;
  accent-color: var(--green);
}
.use-live-vehicle-data:has(input:disabled) {
  color: var(--muted);
  opacity: .55;
}
.live-vehicle-value {
  border-color: rgba(43, 212, 131, .45);
  color: var(--green);
}
.unit-input { position: relative; }
.unit-input input { padding-right: 42px; }
.unit-input span {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 11px;
}
.toggles { display: flex; gap: 18px; }
.toggles label { display: flex; align-items: center; gap: 7px; }
.toggles input { width: 15px; min-height: 15px; accent-color: var(--red); }
.primary, .secondary, .icon-button {
  border: 0;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
}
.primary {
  min-height: 43px;
  background: linear-gradient(135deg, var(--red), #c10d14);
  box-shadow: 0 8px 22px rgba(232,33,39,.2);
}
.primary:hover { background: linear-gradient(135deg, var(--red-bright), var(--red)); }
.primary.stop-mode {
  background: linear-gradient(135deg, #f2a93b, #c76b14);
  color: #211304;
}
.primary.stop-mode:hover {
  background: linear-gradient(135deg, #ffc15c, #e17c17);
}
.primary:disabled, .secondary:disabled { cursor: wait; opacity: .55; }
.secondary { min-height: 40px; padding: 0 12px; background: rgba(255,255,255,.075); }
.secondary:hover { background: rgba(255,255,255,.12); }
.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,.08);
  font-size: 18px;
}
.vehicle { right: 18px; top: 84px; width: 310px; padding: 18px; }
.vehicle .panel-heading { margin-bottom: 12px; }
.battery-row { gap: 9px; }
.battery {
  position: relative;
  width: 78px;
  height: 25px;
  padding: 3px;
  border: 2px solid #747d89;
  border-radius: 6px;
}
.battery::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 6px;
  width: 4px;
  height: 9px;
  border-radius: 0 2px 2px 0;
  background: #747d89;
}
#battery-fill { width: 0; height: 100%; border-radius: 2px; background: var(--green); transition: width .3s; }
#range-label { color: var(--muted); font-size: 12px; }
#vehicle-detail { margin-top: 12px; line-height: 1.45; }
.vehicle-marker {
  position: relative;
  width: 38px;
  height: 38px;
  pointer-events: none;
  filter: drop-shadow(0 5px 10px rgba(0,0,0,.55));
}
.vehicle-marker-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--green);
  color: #07110c;
  font-size: 22px;
  line-height: 1;
  transform: rotate(var(--vehicle-heading, 0deg));
  transform-origin: center;
}
.vehicle-marker-label {
  position: absolute;
  top: 50%;
  left: 45px;
  transform: translateY(-50%);
  max-width: 180px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(12,16,22,.94);
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results {
  right: 18px;
  bottom: 18px;
  width: 390px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  padding: 18px;
}
.hidden { display: none !important; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.total {
  border-radius: 10px;
  background: rgba(255,255,255,.055);
  padding: 10px;
}
.total strong { display: block; font-size: 17px; }
.total span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
#stop-list { margin: 0 0 14px; padding: 0; list-style: none; }
#stop-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.stop-order {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--red);
  font-size: 10px;
}
.stop-order.break { background: var(--amber); color: #241704; }
.stop-meta { color: var(--muted); font-size: 10px; }
.stop-soc { color: var(--green); font-size: 11px; }
#warnings { color: var(--amber); font-size: 11px; line-height: 1.45; margin-bottom: 12px; }
.planning-status { display: flex; align-items: center; gap: 8px; }
.planning-status > span {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(242,169,59,.65);
  animation: planning-pulse 1.2s infinite;
}
@keyframes planning-pulse {
  70% { box-shadow: 0 0 0 7px rgba(242,169,59,0); }
  100% { box-shadow: 0 0 0 0 rgba(242,169,59,0); }
}
#send-navigation { width: 100%; }

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.75); backdrop-filter: blur(7px); }
.dialog-card {
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #11151b;
}
.setup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.setup-actions .primary { grid-column: span 2; }
pre {
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  margin: 0;
  border-radius: 10px;
  padding: 11px;
  background: #080a0e;
  color: #b8c2cf;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: #171b22;
  transition: .2s;
  font-size: 12px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.success { border-color: rgba(43,212,131,.55); }
#toast.warning { border-color: rgba(255,185,70,.65); }
#toast.error { border-color: rgba(232,33,39,.65); }

@media (max-width: 880px) {
  header { height: 64px; padding: 0 14px; }
  .brand p, #connection-pill { display: none; }
  .planner { top: 74px; left: 10px; max-height: calc(55vh - 74px); }
  .vehicle { top: auto; bottom: 10px; right: 10px; width: min(310px, calc(100vw - 20px)); }
  .results { top: 50%; bottom: 10px; right: 10px; width: calc(100vw - 20px); max-height: none; }
}
