:root {
  --bg-oled: #03060c;
  --bg-card: #0b111e;
  --bg-card-elevated: #111a2e;
  --border-subtle: rgba(148, 163, 184, 0.16);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-ev: #10b981;
  --accent-hev: #3b82f6;
  --accent-iem: #a855f7;
  --accent-climb: #ef4444;
  --accent-regen: #06b6d4;
  --accent-warn: #f59e0b;
  --safe-top: env(safe-area-inset-top, 12px);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 24px);
  background-color: var(--bg-oled);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

/* Estilo Modo Oscuro OLED para los tiles de OpenStreetMap sin afectar polilíneas ni marcadores */
.leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(92%) contrast(90%);
}

body.cabin-oled-active {
  background-color: #000000;
}

body.cabin-oled-active .bg-card {
  background-color: #05080e;
  border-color: rgba(255, 255, 255, 0.14);
}

.app-container {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header & Top Status Bar */
.top-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #10b981, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
}

.brand-title h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-title p {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill-status {
  font-size: 0.73rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.pill-status.active-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.pill-status.active-warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.45);
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, background 0.15s ease;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: #10b981;
  color: #022c22;
  font-weight: 800;
  font-size: 0.96rem;
  padding: 13px 18px;
}

.btn-audio {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}

.btn-audio.unlocked {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #6ee7b7;
}

.btn-waze {
  background: linear-gradient(135deg, #06b6d4, #0284c7);
  border-color: #38bdf8;
  color: #fff;
  font-weight: 700;
}

.btn-gmaps {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #60a5fa;
  color: #fff;
  font-weight: 700;
}

/* Card Layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #cbd5e1;
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.input-row {
  display: flex;
  gap: 6px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: #060a12;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 11px 12px;
  border-radius: 11px;
  font-size: 0.92rem;
}

input[type="range"] {
  width: 100%;
  accent-color: #10b981;
  height: 26px;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chip {
  font-size: 0.74rem;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
  cursor: pointer;
}

.toggle-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #060a12;
  border: 1px solid var(--border-subtle);
  padding: 10px 12px;
  border-radius: 11px;
}

/* MODO CABINA OLED HUD */
.cabin-hud {
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.12), #030712 68%);
  border: 2px solid rgba(16, 185, 129, 0.45);
  border-radius: 22px;
  padding: 18px;
  position: relative;
}

.cabin-hud.mode-HEV {
  background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.15), #030712 68%);
  border-color: rgba(59, 130, 246, 0.55);
}

.cabin-hud.mode-iEM {
  background: radial-gradient(circle at top right, rgba(168, 85, 247, 0.15), #030712 68%);
  border-color: rgba(168, 85, 247, 0.55);
}

.cabin-hud.critical-climb-active {
  border-color: #ef4444;
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.25);
}

.hud-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.active-tramo-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

.geofence-countdown {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.geofence-countdown.imminent {
  background: rgba(239, 68, 68, 0.28);
  border-color: #ef4444;
  color: #fecaca;
  animation: pulse-alert 1s infinite alternate;
}

@keyframes pulse-alert {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}

.hud-main-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 680px) {
  .hud-main-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hud-main-grid .hud-tile:first-child {
    grid-column: span 2;
  }
}

.hud-tile {
  background: rgba(6, 10, 19, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}

.hud-tile-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.hud-tile-value {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hud-tile-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 3px;
}

.val-EV { color: var(--accent-ev); }
.val-HEV { color: #60a5fa; }
.val-iEM { color: #c084fc; }

/* Live Telemetry & Calibration Bar */
.hud-telemetry-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(2, 6, 14, 0.9);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  margin-bottom: 12px;
}

.telemetry-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.t-metric span {
  display: block;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.t-metric strong {
  font-size: 1.05rem;
  color: #f1f5f9;
}

.soc-calibration-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Simulator Dry-Run Box */
.simulator-box {
  background: rgba(15, 23, 42, 0.75);
  border: 1px dashed rgba(56, 189, 248, 0.4);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

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

.voice-banner {
  background: rgba(30, 41, 59, 0.7);
  border-left: 4px solid #38bdf8;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  color: #e2e8f0;
}

/* CarPlay Deep Link Launchers */
.carplay-launchers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 520px) {
  .carplay-launchers {
    grid-template-columns: 1fr;
  }
}

/* Map & Charts */
#route-map {
  width: 100%;
  height: 340px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: #060a12;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 290px;
}

/* Summary KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.kpi-box {
  background: #060a12;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 10px 12px;
}

.kpi-box small {
  display: block;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.kpi-box strong {
  font-size: 1.18rem;
  color: #f8fafc;
}

/* Tramos Timeline Table */
.tramos-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tramo-item {
  background: #060a12;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.tramo-item.active-tramo {
  border: 2px solid #10b981;
  background: rgba(16, 185, 129, 0.06);
}

.tramo-item-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tramo-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 0.73rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.badge-EV { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-HEV { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }
.badge-iEM { background: rgba(168, 85, 247, 0.22); color: #d8b4fe; }
.badge-critical { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
.badge-target { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }

.tramo-rationale {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

.hidden {
  display: none !important;
}
