/* ============================================================================
 * MovilityPark · styles.css
 * ----------------------------------------------------------------------------
 * Mobile-first, MODO OSCURO por defecto. Variables CSS con paleta accesible
 * (contraste AA). Safe-areas iOS, objetivos táctiles >=44px, modales
 * accesibles, foco visible. Estilos de marcador/cluster para Leaflet.
 * El modo claro se activa con .light en <html> (toggle del perfil).
 * ========================================================================== */

/* --- Variables: tema oscuro (por defecto) -------------------------------- */
:root {
  --bg:            #0b1220;
  --bg-elev:       #131c2e;
  --bg-elev-2:     #1c2740;
  --surface:       #182236;
  --border:        #2a3a57;
  --text:          #eef2fb;   /* AA sobre --bg */
  --text-muted:    #aab6cf;   /* AA sobre --bg */
  --primary:       #4f9cff;
  --primary-ink:   #07101f;   /* texto sobre --primary */
  --primary-hover: #6db0ff;
  --danger:        #ff5a5a;
  --danger-ink:    #1a0606;
  --success:       #16a34a;
  --warning:       #d97706;
  --focus:         #ffd166;   /* anillo de foco muy visible */
  --shadow:        0 10px 30px rgba(0,0,0,.45);

  --radius:        14px;
  --radius-sm:     10px;
  --tap:           44px;      /* objetivo táctil mínimo */

  /* Safe-areas iOS (notch / barra inferior) */
  --sa-top:    env(safe-area-inset-top, 0px);
  --sa-right:  env(safe-area-inset-right, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left:   env(safe-area-inset-left, 0px);

  --z-map: 1;
  --z-fabs: 600;
  --z-topbar: 700;
  --z-modal: 1000;
  --z-toast: 1100;
}

/* --- Modo claro (.light) -------------------------------------------------- */
html.light {
  --bg:            #f4f6fb;
  --bg-elev:       #ffffff;
  --bg-elev-2:     #eef1f8;
  --surface:       #ffffff;
  --border:        #cfd7e6;
  --text:          #10192b;
  --text-muted:    #4a566b;
  --primary:       #1e6fe0;
  --primary-ink:   #ffffff;
  --primary-hover: #155bc0;
  --danger:        #c81e1e;
  --danger-ink:    #ffffff;
  --success:       #157f3a;   /* AA (>=4.5:1) como texto sobre blanco */
  --focus:         #b8540a;
  --shadow:        0 10px 30px rgba(16,25,43,.18);
}

/* --- Reset ligero --------------------------------------------------------- */
* { box-sizing: border-box; }
/* El atributo [hidden] debe ocultar SIEMPRE, aunque la regla del elemento use
   display:flex/grid (que si no, gana al display:none del navegador). Arregla,
   p. ej., el banner "Toca el mapa para elegir la ubicación" que no se ocultaba. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
p { margin: 0 0 .6em; }
img { max-width: 100%; display: block; }
a { color: var(--primary); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }

/* --- Foco visible global -------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ========================================================================== */
/* Barra superior + buscador                                                  */
/* ========================================================================== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--sa-top)) calc(10px + var(--sa-right)) 8px calc(10px + var(--sa-left));
  background: linear-gradient(to bottom, var(--bg-elev), color-mix(in srgb, var(--bg-elev) 88%, transparent));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.topbar__logo { width: 28px; height: 28px; }
.topbar__title { margin: 0; font-weight: 700; font-size: 1.05rem; line-height: 1.2; white-space: nowrap; }
/* En móvil el título de marca se oculta VISUALMENTE pero sigue en el árbol de
   accesibilidad (es el único <h1> de la página): técnica visually-hidden, no display:none. */
@media (max-width: 420px) {
  .topbar__title {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    clip: rect(0 0 0 0); clip-path: inset(50%);
    overflow: hidden; white-space: nowrap;
  }
}

.search { position: relative; flex: 1 1 auto; display: flex; gap: 6px; }
.search__input {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 0 12px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.search__input::placeholder { color: var(--text-muted); }
.search__btn {
  flex: 0 0 auto;
  min-width: var(--tap); min-height: var(--tap);
  font-size: 1.1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.search__results {
  position: absolute;
  top: calc(var(--tap) + 6px);
  left: 0; right: 0;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 50vh; overflow-y: auto;
}
.search__results li {
  padding: 10px 12px;
  min-height: var(--tap);
  display: flex; align-items: center;
  border-radius: 8px;
  cursor: pointer;
}
.search__results li:hover,
.search__results li:focus,
.search__results li.is-active,
.search__results li[aria-selected="true"] { background: var(--bg-elev); }

/* ========================================================================== */
/* Mapa                                                                       */
/* ========================================================================== */
.map-wrap { position: absolute; inset: 0; z-index: var(--z-map); }
.map { position: absolute; inset: 0; background: var(--bg-elev); }
/* Compensar barra superior para que los controles de Leaflet no queden tapados */
.leaflet-top { margin-top: calc(58px + var(--sa-top)); }

/* ========================================================================== */
/* Botones flotantes (FAB)                                                    */
/* ========================================================================== */
.fabs {
  position: fixed;
  right: calc(12px + var(--sa-right));
  bottom: calc(16px + var(--sa-bottom));
  z-index: var(--z-fabs);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fab {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 1.35rem;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.fab:active { transform: scale(.94); }
.fab--primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
  width: 60px; height: 60px;
  font-size: 1.8rem;
}
.fab--primary:hover { background: var(--primary-hover); }

/* Banner del modo "elegir ubicación" */
.pick-banner {
  position: fixed;
  top: calc(64px + var(--sa-top));
  left: 50%; transform: translateX(-50%);
  z-index: var(--z-fabs);
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.pick-banner__text { font-size: .92rem; font-weight: 600; }

/* ========================================================================== */
/* Botones                                                                    */
/* ========================================================================== */
.btn {
  min-height: var(--tap);
  padding: 0 16px;
  font-size: 1rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-elev-2);
  color: var(--text);
}
.btn--sm { min-height: var(--tap); padding: 0 10px; font-size: .85rem; }
.btn--primary { background: var(--primary); color: var(--primary-ink); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--bg-elev); }
.btn--danger { background: var(--danger); color: var(--danger-ink); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn--active { outline: 2px solid var(--primary); }

/* ========================================================================== */
/* Formularios                                                                */
/* ========================================================================== */
.field { margin-bottom: 14px; }
.field__label { display: block; margin-bottom: 5px; font-weight: 600; font-size: .92rem; }
.field__input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field__input--num { max-width: 120px; }
.field__input--file { padding: 9px; }
textarea.field__input { resize: vertical; min-height: 64px; }
.field--half { flex: 1 1 0; min-width: 0; }

/* Selector de idioma del perfil: hereda .field__input (alto >=44px, colores
 * del tema, foco visible global). Aspecto nativo de <select> consistente. */
select.field__input {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  /* Flecha dibujada con un degradado (sin imágenes externas, respeta la CSP). */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 0 0 14px; }
.field-group__legend { padding: 0 6px; font-weight: 700; font-size: .9rem; }

.row { display: flex; gap: 12px; }
.row--wrap { flex-wrap: wrap; }

.loc-status { font-size: .9rem; color: var(--text-muted); margin: 0 0 8px; }
.loc-status.is-set { color: var(--success); font-weight: 600; }

/* Checkboxes de características como "chips" táctiles */
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.check:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 18%, var(--surface)); }

.photo-preview { margin-top: 10px; }
.photo-preview img { max-height: 180px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 8px; }

/* ========================================================================== */
/* Modales                                                                    */
/* ========================================================================== */
.modal {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(2, 6, 16, .62);
  backdrop-filter: blur(2px);
}
.modal__panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  padding-bottom: var(--sa-bottom);
  animation: sheet-up .18s ease-out;
}
.modal__panel--centered { align-self: center; border-radius: var(--radius); }
@keyframes sheet-up { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal__panel { border-radius: var(--radius); max-height: calc(100dvh - 48px); }
}

.modal__header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal__title { font-size: 1.15rem; }
.modal__close {
  min-width: var(--tap); min-height: var(--tap);
  font-size: 1.1rem; line-height: 1;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal__body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal__footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 16px calc(12px + var(--sa-bottom));
  border-top: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
  .modal__panel { animation: none; }
  * { scroll-behavior: auto; }
}

/* ========================================================================== */
/* Miniaturas (.thumb) + lightbox                                             */
/* ========================================================================== */
/* Botón-miniatura del detalle: objetivo táctil amplio, foto recortada y un
 * sutil indicador "ampliar". Hereda el foco visible global (:focus-visible). */
.thumb {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  min-height: var(--tap);
}
.thumb:hover { border-color: var(--primary); }
.thumb__img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
}
/* Pista visual de que la miniatura se puede ampliar. */
.thumb--detail::after {
  content: "🔍";
  position: absolute;
  right: 8px; bottom: 8px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  font-size: 1rem;
  background: rgba(2, 6, 16, .6);
  color: #fff;
  border-radius: 50%;
  pointer-events: none;
}

/* Lightbox: superposición oscura, foto centrada que cabe en pantalla. */
.modal--lightbox { align-items: center; justify-content: center; padding: 16px; }
.modal--lightbox .modal__backdrop { background: rgba(2, 6, 16, .9); }
.lightbox__panel {
  position: relative;
  max-width: min(96vw, 1100px);
  max-height: calc(100dvh - 32px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox__img {
  max-width: 96vw;
  max-height: calc(100dvh - 32px);
  width: auto; height: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.lightbox__close {
  position: absolute;
  top: -6px; right: -6px;
  min-width: var(--tap); min-height: var(--tap);
  font-size: 1.2rem; line-height: 1;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* ========================================================================== */
/* Detalle de plaza                                                           */
/* ========================================================================== */
.detail__addr { color: var(--text-muted); margin-bottom: 10px; }
.detail__dist { font-weight: 600; }
.badge-occ {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-weight: 700; font-size: .9rem;
  color: var(--text);
  border: 1px solid var(--border);
}
/* Punto de color: comunica el estado por color SOLO como apoyo; el texto
 * de la etiqueta lo comunica siempre (no se usa color como único medio). */
.badge-occ__dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.3);
}
.detail__feats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.feat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .85rem;
}
.detail__section-title { font-size: .9rem; font-weight: 700; margin: 14px 0 8px; color: var(--text-muted); }
.occ-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.occ-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 12px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600;
}
.occ-btn[aria-pressed="true"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 16%, var(--surface)); }
.detail__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* ========================================================================== */
/* Lista cercana / pendientes                                                 */
/* ========================================================================== */
.nearby, .pending { list-style: none; margin: 0; padding: 0; }
.nearby li, .pending li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}
.nearby__btn {
  flex: 1 1 auto; text-align: left;
  background: transparent; border: 0; color: var(--text);
  min-height: var(--tap); cursor: pointer; padding: 0;
}
.nearby__name { font-weight: 600; }
.nearby__meta { font-size: .85rem; color: var(--text-muted); }
/* Miniatura redondeada de la plaza en la lista cercana. */
.nearby__thumb {
  width: 44px; height: 44px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.3); }
.empty { color: var(--text-muted); text-align: center; padding: 24px 8px; }

.pending__info { flex: 1 1 auto; min-width: 0; }
.pending__actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ========================================================================== */
/* Perfil                                                                     */
/* ========================================================================== */
.stats { display: flex; gap: 10px; margin: 14px 0; }
.stat {
  flex: 1 1 0; text-align: center;
  padding: 12px 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.stat__num { display: block; font-size: 1.4rem; font-weight: 800; }
.stat__lbl { font-size: .78rem; color: var(--text-muted); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge {
  padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--warning) 20%, var(--surface));
  border: 1px solid var(--warning); font-size: .82rem;
}
.profile-actions { margin: 12px 0; }

/* Pie legal del perfil: discreto pero con contraste AA y foco visible. */
.legal { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.legal__title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 4px; }
.legal__links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.legal__link {
  display: inline-flex; align-items: center;
  min-height: var(--tap);
  color: var(--text-muted);
  font-size: .9rem;
  text-decoration: underline;
}
.legal__link:hover { color: var(--text); }

.toggle-row { padding: 10px 0; border-top: 1px solid var(--border); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; min-height: var(--tap); }
.toggle__label { flex: 1 1 auto; font-weight: 600; }
.toggle__input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  position: relative; flex: 0 0 auto;
  width: 50px; height: 28px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  transition: background .15s ease;
}
.toggle__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text-muted); transition: transform .15s ease, background .15s ease;
}
.toggle__input:checked + .toggle__track { background: var(--primary); border-color: var(--primary); }
.toggle__input:checked + .toggle__track::after { transform: translateX(22px); background: #fff; }
.toggle__input:focus-visible + .toggle__track { outline: 3px solid var(--focus); outline-offset: 2px; }

.admin-gate { display: flex; flex-direction: column; gap: 8px; }

/* ========================================================================== */
/* Toasts                                                                     */
/* ========================================================================== */
.toasts {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(20px + var(--sa-bottom));
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 14px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--info    { border-left-color: var(--primary); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ========================================================================== */
/* Marcadores y clusters de Leaflet                                           */
/* ========================================================================== */
.mp-marker {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  display: grid; place-items: center;
}
.mp-marker__inner { transform: rotate(45deg); font-size: 12px; line-height: 1; }

.mp-user-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); border: 3px solid #fff;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 40%, transparent);
}

/* Cluster: hereda color del estado predominante vía variable inline de map.js */
.mp-cluster {
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff; font-weight: 800;
  border: 3px solid rgba(255,255,255,.85);
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
}
.mp-cluster--sm { width: 36px; height: 36px; font-size: .85rem; }
.mp-cluster--md { width: 44px; height: 44px; font-size: .95rem; }
.mp-cluster--lg { width: 54px; height: 54px; font-size: 1.05rem; }

/* Popups de Leaflet acordes al tema */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-elev); color: var(--text);
}
.leaflet-bar a {
  background: var(--bg-elev-2); color: var(--text); border-color: var(--border);
}
