/* FenixRed GPS v1 — tema oscuro, acentos naranja/rojo */
:root {
  --bg: #121216;
  --bg2: #1a1a20;
  --bg3: #232329;
  --text: #f2f2f5;
  --muted: #9a9aa5;
  --accent: #ff5a1f;
  --accent2: #ff8c42;
  --red: #e5383b;
  --green: #2ec4b6;
  --border: #2e2e38;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

/* --- Encabezado --- */
header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}
header img.logo { width: 38px; height: 38px; border-radius: 8px; }
header .title { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
header .title span { color: var(--accent); }
header .subtitle { font-size: 11px; color: var(--muted); margin-left: auto; text-align: right; }

/* --- Mapa --- */
#map { flex: 1; width: 100%; z-index: 1; background: #0b0b0e; }
.maplibregl-map { font-family: inherit; }
/* Mapa oscuro con tiles libres de OSM (CARTO exige API key desde 2026) */
.maplibregl-canvas {
  filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}
/* Controles de MapLibre en tema oscuro */
.maplibregl-ctrl-group {
  background: var(--bg3) !important;
  box-shadow: 0 0 0 1px var(--border) !important;
}
.maplibregl-ctrl-group button { background-color: transparent; }
.maplibregl-ctrl-group button:not(:disabled):hover { background-color: rgba(255,255,255,.08); }
.maplibregl-ctrl-group .maplibregl-ctrl-icon { filter: invert(.85); }
.maplibregl-ctrl-attrib {
  background: rgba(18,18,22,.7);
  font-size: 10px;
}
.maplibregl-ctrl-attrib a { color: var(--muted); }

/* Velocímetro flotante */
#speedo {
  position: absolute; right: 12px; bottom: 170px; z-index: 500;
  background: rgba(18,18,22,.88); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 14px; text-align: center;
  min-width: 96px; backdrop-filter: blur(4px);
}
#speedo .val { font-size: 30px; font-weight: 800; color: var(--accent2); line-height: 1; }
#speedo .unit { font-size: 11px; color: var(--muted); }
#speedo .mph { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Botón centrar */
#btn-center {
  position: absolute; right: 12px; bottom: 108px; z-index: 500;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); font-size: 22px; cursor: pointer;
}

/* Botón modo "de frente" (heading-up) */
#btn-heading {
  position: absolute; right: 68px; bottom: 108px; z-index: 500;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); font-size: 22px; cursor: pointer;
}
#btn-heading.active {
  border-color: var(--accent); color: var(--accent2);
  box-shadow: 0 0 10px rgba(255,90,31,.5);
}

/* --- Panel inferior --- */
#panel {
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  z-index: 1000; max-height: 42dvh; overflow-y: auto;
}

#dest-row { display: flex; gap: 8px; }
#dest-input {
  flex: 1; padding: 11px 12px; font-size: 15px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
#dest-input:focus { border-color: var(--accent); }
button.go {
  padding: 0 18px; font-size: 15px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--red));
  color: #fff; border: none; border-radius: 10px; cursor: pointer;
}
button.go:active { transform: scale(.97); }
button.ghost {
  padding: 10px 14px; font-size: 14px; font-weight: 600;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}

#share-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 30px;
  background: var(--bg3); border: 1px solid var(--border);
  transition: .2s; cursor: pointer;
}
.slider:before {
  content: ""; position: absolute; width: 22px; height: 22px;
  left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s;
}
.switch input:checked + .slider { background: rgba(46,196,182,.25); border-color: var(--green); }
.switch input:checked + .slider:before { transform: translateX(22px); background: var(--green); }
#share-label { font-size: 14px; }
#share-label small { display: block; color: var(--muted); font-size: 11px; }
#share-status { margin-left: auto; font-size: 12px; color: var(--muted); }
#share-status.on { color: var(--green); }

#status { font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 16px; }
#status.error { color: var(--red); }

/* Instrucciones de ruta */
#route-info { display: none; margin-top: 10px; }
#route-info.show { display: block; }
#route-summary {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; font-weight: 700; margin-bottom: 8px;
}
#route-summary .meta { color: var(--muted); font-weight: 400; font-size: 12px; }
#steps { list-style: none; margin: 0; padding: 0; max-height: 150px; overflow-y: auto; }
#steps li {
  font-size: 13px; padding: 7px 4px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: baseline;
}
#steps li .d { color: var(--muted); margin-left: auto; white-space: nowrap; font-size: 12px; }
#steps li.next { color: var(--accent2); font-weight: 700; }

/* Sugerencias de destino */
#suggestions {
  display: none; margin-top: 6px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
#suggestions.show { display: block; }
#suggestions button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 10px 12px; font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
#suggestions button:last-child { border-bottom: none; }
#suggestions button small { display: block; color: var(--muted); font-size: 11px; }

/* --- Panel del dispatcher --- */
#dash { display: flex; flex: 1; min-height: 0; position: relative; }
#dash #map { flex: 1; min-width: 0; }

#fleet {
  width: 320px; flex-shrink: 0;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 1000;
}
#fleet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
#fleet-head h2 { margin: 0; font-size: 16px; }
#fleet-head h2 span { color: var(--accent); }
#fleet-actions { display: flex; gap: 8px; }
#fleet-actions .ghost { padding: 7px 12px; font-size: 13px; }

#driver-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#driver-list li {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
#driver-list li:active { background: var(--bg3); }
#driver-list .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
#driver-list .dot.moving { background: var(--green); box-shadow: 0 0 8px rgba(46,196,182,.8); }
#driver-list .dot.stopped { background: var(--muted); }
#driver-list .dot.stale { background: var(--red); }
#driver-list .info { flex: 1; min-width: 0; }
#driver-list .name {
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#driver-list .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
#driver-list .st { font-weight: 700; }
#driver-list .st-moving { color: var(--green); }
#driver-list .st-stopped { color: var(--muted); }
#driver-list .st-stale { color: var(--red); }

#fleet-empty {
  display: none; padding: 24px 16px; text-align: center;
  color: var(--muted); font-size: 13px; line-height: 1.7;
}
#fleet-empty.show { display: block; }
#refresh-status {
  font-size: 11px; color: var(--muted);
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
#refresh-status.error { color: var(--red); }

/* Marcadores de vehículos en el mapa del dispatcher */
.fx-marker { background: none; border: none; }
.fx-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 3px solid #fff;
}
.fx-dot.moving { background: var(--green); box-shadow: 0 0 10px rgba(46,196,182,.9); }
.fx-dot.stopped { background: var(--muted); box-shadow: 0 0 8px rgba(154,154,165,.7); }
.fx-dot.stale { background: var(--red); opacity: .7; }

/* Popups oscuros (MapLibre) */
.maplibregl-popup-content {
  background: var(--bg2); color: var(--text);
  border-radius: 10px; border: 1px solid var(--border);
  padding: 10px 14px; font-size: 13px; line-height: 1.55;
}
.maplibregl-popup-tip { border-top-color: var(--bg2); }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; }
.fx-pop-name { font-weight: 800; font-size: 14px; }
.fx-pop-speed { color: var(--accent2); font-weight: 700; }
.fx-pop-age { color: var(--muted); font-size: 12px; }

/* Móvil: la lista pasa a hoja inferior */
@media (max-width: 700px) {
  #dash { flex-direction: column; }
  #fleet {
    width: 100%; border-left: none; border-top: 1px solid var(--border);
    max-height: 38dvh;
  }
}

/* --- Modo flota (app del chofer) --- */
#fleet-box { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
#fleet-box .fleet-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
#fleet-box .fleet-title small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
#fleet-form { display: flex; gap: 8px; }
#fleet-form input {
  flex: 1; min-width: 0; padding: 11px 12px; font-size: 15px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
#fleet-code { text-transform: uppercase; }
#fleet-form input:focus { border-color: var(--accent); }
#fleet-form .go { flex-shrink: 0; }
#fleet-on { display: none; align-items: center; gap: 10px; }
#fleet-on.show { display: flex; }
#fleet-off.hide { display: none; }
#fleet-label { font-size: 14px; flex: 1; }
#fleet-label b { color: var(--green); letter-spacing: 1px; }
#fleet-label small { display: block; color: var(--muted); font-size: 11px; }
#fleet-status { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 16px; }
#fleet-status.error { color: var(--red); }
#fleet-status.ok { color: var(--green); }

/* --- Código de ruta del día (dispatcher) --- */
#route-banner {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(255,90,31,.14), rgba(229,56,59,.08));
  text-align: center;
}
#route-banner .rb-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
}
#route-banner .rb-code {
  font-size: 30px; font-weight: 800; color: var(--accent2);
  letter-spacing: 2px; margin: 4px 0;
}
#route-banner .rb-hint { font-size: 11px; color: var(--muted); }

/* --- Historial por ruta (dispatcher) --- */
#route-history {
  display: flex; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
#route-history select {
  flex: 1; min-width: 0; padding: 8px 10px; font-size: 14px; font-weight: 700;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
#route-history .ghost { padding: 8px 12px; font-size: 13px; white-space: nowrap; flex-shrink: 0; }

.route-chip {
  display: inline-block; font-size: 10px; font-weight: 700;
  background: rgba(255,90,31,.18); color: var(--accent2);
  border: 1px solid rgba(255,90,31,.4); border-radius: 20px;
  padding: 1px 8px; margin-left: 4px; vertical-align: 1px;
}

/* (los tooltips de Leaflet ya no se usan; el historial usa popups de MapLibre) */
