/* ==========================================================================
   /public_html/assets/css/mapa.css — MA Ayacucho (Producción)
   Propósito:
   - Estilos de la vista de mapa (mobile-first) sin romper Leaflet.
   - Pantalla completa fiable (vh + svh/dvh) y controles flotantes claros.
   - Modo oscuro, safe-area (notch) y CSP estricta (sin inline).
   Decisiones:
   - No duplicar botones/toasts de componentes.css; aquí solo lo específico del mapa.
   ========================================================================== */

/* --------- 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;
  --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; }

/* Evitar estirar íconos/tiles de Leaflet con reglas globales */
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile,
.leaflet-pane > svg {
  max-width: none !important;
  max-height: none !important;
  object-fit: contain;
}

/* 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 (coinciden con clases z-* del HTML) --------- */
.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);
}
/* Mejora en navegadores con unidades modernas */
@supports (height: 100svh){ #map{ height: 100svh; } }
@supports (height: 100dvh){ #map{ height: 100dvh; } }

/* --------- Leaflet: look limpio y controles con sombra --------- */
.leaflet-container{
  background: var(--surface-2);
  font: inherit; /* tipografía consistente */
}
.leaflet-control{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.leaflet-top  .leaflet-control { margin-top: 12px; }
.leaflet-bottom .leaflet-control { margin-bottom: 12px; }
.leaflet-left .leaflet-control { margin-left: 12px; }
.leaflet-right .leaflet-control { margin-right: 12px; }

@media (prefers-color-scheme: dark){
  .leaflet-control{ background: rgba(17,24,39,.85); }
}

.leaflet-bar a,
.leaflet-bar a:hover{
  width: 36px; height: 36px; line-height: 36px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.leaflet-bar a:last-child{ border-bottom: 0; }
.leaflet-touch .leaflet-control-attribution,
.leaflet-control-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){
  .leaflet-touch .leaflet-control-attribution,
  .leaflet-control-scale{ background: rgba(17,24,39,.8); }
}
/* Evitar que controles Leaflet queden debajo de overlays propios */
.leaflet-top, .leaflet-bottom{ z-index: var(--z-controls); }

/* --------- Panel superior de estado (del ride) ---------
   HTML: <div id="statusPanel"><strong id="statusTitulo">...</strong><span id="statusMeta">...</span></div>
   JS alterna [hidden]; por eso aquí el panel es visible por defecto
   y se oculta solo con [hidden].
   ------------------------------------------------------ */
.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 (usado por ui-rides.js para “Pedir MA”) --------- */
.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 ---------
   (mapa.js crea .control-card; mapa.html trae .map-legend)
   ------------------------------------------------------------- */
.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); }
}

/* --------- Bottom sheet (panel inferior) ---------
   Visible cuando NO tiene [hidden] (lo controla el JS).
   Con fallback a vh y sobreescritura con svh/dvh para evitar falsos
   errores de linters antiguos y mejorar en móviles.
   -------------------------------------------------- */
.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 ---------
   Se muestra con: element.hidden=false; + .is-visible (transición).
   ---------------------------------- */
.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); }
