/* ==========================================================================
   /public_html/assets/css/mapa.css — MA Ayacucho (Producción)
   Propósito:
   - Vista de mapa limpia tipo inDrive (mobile-first).
   - Pantalla completa fiable (vh + svh/dvh), controles “glass” y leyenda.
   - Chips de estado (Disponible/Ocupado), FAB de centrar y sheet inferior.
   - Modo oscuro, safe-area (notch) y CSP estricta (sin inline).
   ========================================================================== */

/* --------- Variables de tema (usa tokens globales si existen) --------- */
:root{
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;           /* gris muy claro */
  --text: #0f172a;                /* slate-900 */
  --muted: #64748b;               /* slate-500 */
  --border: #e2e8f0;              /* slate-200 */
  --brand: #0ea5e9;               /* cyan-500 */

  --ok: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;

  /* Tokens compartidos por defecto (main.css puede sobreescribirlos) */
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.12);

  /* Capas de z-index (coherentes con mapa.html) */
  --z-map: 0;
  --z-controls: 10;
  --z-sheet: 20;
  --z-toast: 30;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg: #0b1220;
    --surface: #0f172a;
    --surface-2: #0b1220;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --brand: #22d3ee;            /* cyan-400 */
    --shadow: 0 12px 30px rgba(0,0,0,.35);
  }
}

/* --------- Accesibilidad / resets mínimos --------- */
*{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body{ height: 100%; }
html{ color-scheme: light dark; }
body{
  margin: 0;
  font: 400 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* el mapa ocupa toda la vista */
}
a{ color: var(--brand); text-underline-offset: 2px; }
:focus-visible{ outline: 2px solid var(--brand); outline-offset: 2px; }

/* Utilidades de accesibilidad */
.hidden{ display:none !important; }
.sr-only{
  position:absolute; width:1px; height:1px; padding:0; margin:-1px;
  overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0;
}

/* --------- Utilidades de capa --------- */
.z-map{ z-index: var(--z-map); }
.z-controls{ z-index: var(--z-controls); }
.z-sheet{ z-index: var(--z-sheet); }
.z-toast{ z-index: var(--z-toast); }

/* --------- Layout del mapa: pantalla completa fiable --------- */
#map{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;   /* fallback universal */
  background: var(--surface-2);
}
@supports (height: 100svh){ #map{ height: 100svh; } }
@supports (height: 100dvh){ #map{ height: 100dvh; } }

/* --------- MapLibre: look limpio y controles “glass” --------- */
.maplibregl-ctrl, .maplibregl-ctrl-group{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,.90);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.maplibregl-ctrl-group > button{
  width: 36px; height: 36px;
  border-bottom: 1px solid var(--border);
}
.maplibregl-ctrl-group > button:last-child{ border-bottom: 0; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-scale{
  font-size: 11px; padding: 4px 8px; border-radius: 10px;
  background: rgba(255,255,255,.85);
  border: 1px solid var(--border);
}
@media (prefers-color-scheme: dark){
  .maplibregl-ctrl, .maplibregl-ctrl-group{ background: rgba(17,24,39,.85); }
  .maplibregl-ctrl-attrib, .maplibregl-ctrl-scale{ background: rgba(17,24,39,.80); }
}

/* Evitar estirar íconos/tiles/SVG del mapa por reglas globales */
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile,
.leaflet-pane > svg,
.maplibregl-canvas{
  max-width: none !important;
  max-height: none !important;
  object-fit: contain;
}

/* --------- Panel superior de estado (GPS/red) --------- */
.status-panel{
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  max-width: min(720px, 94vw);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex; gap: 12px; align-items: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.status-panel[hidden]{ display: none !important; }
.status-panel__title{ font-weight: 700; font-size: 15px; }
.status-panel__meta{ color: var(--muted); font-size: 13px; }

/* --------- FAB grande (CTA global se inyecta en la leyenda) --------- */
.fab{
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: var(--z-controls);
}

/* --------- FAB mini: centrar ubicación --------- */
.fab-mini{
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: var(--z-controls);
}
.fab-mini button{
  width:44px; height:44px; border-radius:12px;
  display:grid; place-items:center;
  border:1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* --------- Leyenda y tarjetas utilitarias en el mapa --------- */
.map-legend, .control-card{
  position: fixed;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 86vw;
  background: rgba(255,255,255,.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.map-legend h4{ margin: 0 0 6px; font-size: 14px; }
.map-legend ul{ margin: 0; padding-left: 16px; font-size: 13px; color: var(--muted); }
@media (prefers-color-scheme: dark){
  .map-legend, .control-card{ background: rgba(17,24,39,.85); }
}

/* Chips del estado de conductores (usados en la leyenda) */
.chip-legend{
  display:inline-flex; align-items:center; gap:6px;
  font-size: 12px; line-height: 1;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text);
}
.chip-legend::before{
  content: ""; width: 10px; height: 10px; border-radius: 9999px; display:inline-block;
}
.chip-legend--disponible::before{ background: var(--ok); }
.chip-legend--ocupado::before{ background: var(--warn); }

/* Distancia al más cercano (control-card generado por JS) */
#distCard strong{ font-size: 13px; }
#nearestText{ font-weight: 700; }

/* Selector de estilo inyectado en la leyenda */
#styleSel{
  width: 100%;
  appearance: none;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
  font: inherit;
  color: inherit;
}

/* --------- Bottom sheet (panel inferior) --------- */
.bottom-sheet{
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,.96);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  max-height: 70vh;               /* fallback universal */
  overflow: auto;
  backdrop-filter: blur(6px);
}
@supports (height: 100svh){ .bottom-sheet{ max-height: 70svh; } }
@supports (height: 100dvh){ .bottom-sheet{ max-height: 70dvh; } }

.bottom-sheet[hidden]{ display: none !important; }
.bottom-sheet__grabber{
  width: 44px; height: 4px; border-radius: 9999px;
  background: var(--border); margin: 6px auto 10px;
}

/* --------- Toast del mapa --------- */
.toast{
  position: fixed;
  left: 50%; transform: translateX(-50%) translateY(8px);
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text); font-weight: 500;
  opacity: 0; transition: opacity .2s ease, transform .2s ease;
  z-index: var(--z-toast);
}
.toast[hidden]{ display: none !important; }
.toast.is-visible{ opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------- Banner offline --------- */
.offline-banner{
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--danger); color: #fff;
  text-align: center; font-size: 13px; padding: 8px 10px;
  z-index: var(--z-toast);
}
.offline-banner[hidden]{ display: none !important; }

/* --------- Estados y utilidades menores --------- */
body.is-loading{ cursor: progress; }
.spinner{
  width: 18px; height: 18px; border:2px solid currentColor;
  border-bottom-color: transparent; border-radius: 50%;
  display:inline-block; vertical-align: middle;
  animation: spin 1s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

/* --------- Compatibilidad iOS (notch / barras) --------- */
.safe-top{ padding-top: env(safe-area-inset-top); }
.safe-right{ padding-right: env(safe-area-inset-right); }
.safe-bottom{ padding-bottom: env(safe-area-inset-bottom); }
.safe-left{ padding-left: env(safe-area-inset-left); }

/* --------- Utilidades pequeñas usadas por el HTML --------- */
.text-center{ text-align:center; }

/* (Opcional) Pin central si lo habilitas luego desde el JS/HTML
.center-pin{
  position: fixed; left: 50%; top: 50%;
  width: 28px; height: 28px; transform: translate(-50%,-100%);
  z-index: var(--z-controls); pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.18));
}
*/
