/* =========================================================================
   Red Solidaria — estilos complementarios a Tailwind CDN
   Mobile-first · alto contraste · legible bajo luz solar
   ========================================================================= */

:root {
  --c-alert: #dc2626;
  --c-ok:    #15803d;
  --c-warn:  #b45309;
  --c-ink:   #0b1220;
  --nav-h:   68px;
}

* { -webkit-tap-highlight-color: rgba(220, 38, 38, .15); }

html { scroll-behavior: smooth; }

body {
  /* Sin sombras suaves: contraste duro para pantallas al sol */
  font-synthesis-weight: none;
  overscroll-behavior-y: contain;
}

/* Áreas seguras para notch / gesture bar en iOS */
.safe-top    { padding-top: env(safe-area-inset-top, 0px); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* =========================== TIPOGRAFÍA / FORM =========================== */

.label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #334155;
  margin-bottom: 4px;
}

.input {
  width: 100%;
  background: #fff;
  border: 2px solid #1e293b;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;           /* evita el zoom automático en iOS */
  font-weight: 600;
  color: var(--c-ink);
}
.input::placeholder { color: #94a3b8; font-weight: 500; }
.input:focus {
  outline: 3px solid #2563eb;
  outline-offset: 1px;
  border-color: #2563eb;
}
.input[aria-invalid="true"], .input:user-invalid {
  border-color: var(--c-alert);
  background: #fef2f2;
}

/* ========================= SELECTOR DE HORARIO ========================= */

.label-sm {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #475569;
  margin-bottom: 3px;
}

/* Los <select> nativos abren la rueda del sistema en móvil: mucho más
   fiable que un desplegable propio con el pulgar y bajo estrés. */
select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230b1220' stroke-width='3' stroke-linecap='round'%3e%3cpath d='M6 9l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
  cursor: pointer;
}

/* Rango desactivado al marcar "24 horas": se atenúa, no se oculta, para que
   el usuario entienda por qué dejó de estar disponible. */
[data-rango].rango-off {
  opacity: .4;
  pointer-events: none;
  filter: grayscale(1);
}

.horario-resumen {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  background: #eff6ff;
  border-left: 4px solid #1d4ed8;
  color: #0b1220;
}
.horario-resumen.aviso {
  background: #fffbeb;
  border-left-color: #b45309;
}
.horario-resumen.error {
  background: #fef2f2;
  border-left-color: #dc2626;
  color: #991b1b;
}

/* =============================== BOTONES =============================== */

.btn-primary, .btn-alert, .btn-ok, .btn-dark, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  border-radius: 10px;
  padding: 11px 16px;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;                 /* objetivo táctil accesible */
  transition: transform .08s ease, filter .15s ease;
  line-height: 1.1;
}
.btn-primary:active, .btn-alert:active, .btn-ok:active,
.btn-dark:active, .btn-ghost:active { transform: scale(.97); }

.btn-primary { background: #1d4ed8; color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }

.btn-alert { background: var(--c-alert); color: #fff; }
.btn-alert:hover { filter: brightness(1.12); }

.btn-ok { background: var(--c-ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.12); }

.btn-dark { background: #0f172a; color: #fff; }
.btn-dark:hover { filter: brightness(1.4); }

.btn-ghost { background: #fff; color: var(--c-ink); border-color: #1e293b; }
.btn-ghost:hover { background: #e2e8f0; }

button:focus-visible, a:focus-visible, input:focus-visible, .chip:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

/* ================================ CHIPS ================================ */

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 2px solid #1e293b;
  color: var(--c-ink);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  min-height: 38px;
}
.chip-on {
  background: var(--c-ink);
  color: #fff;
  border-color: var(--c-ink);
}

/* Chips-radio dentro de formularios (tipo de ayuda, vehículo, etc.) */
.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
}
.opt input { width: 18px; height: 18px; accent-color: #1d4ed8; flex: 0 0 auto; }
.opt:has(input:checked) {
  border-color: #1d4ed8;
  background: #eff6ff;
  box-shadow: inset 0 0 0 1px #1d4ed8;
}
.opt:has(input:focus-visible) { outline: 3px solid #2563eb; outline-offset: 2px; }

/* ============================ NAV INFERIOR ============================ */

.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px 10px;
  min-height: var(--nav-h);
  font-size: 11px;
  font-weight: 800;
  color: #94a3b8;
  background: transparent;
  border: none;
  border-top: 4px solid transparent;
  cursor: pointer;
}
.nav-btn i { font-size: 19px; }
.nav-btn.nav-active {
  color: #fff;
  border-top-color: var(--c-alert);
  background: rgba(255, 255, 255, .06);
}

/* Con 5 pestañas, "Vehículos" es la etiqueta crítica: 55 px de texto y
   64 px de columna en un móvil de 320 px. Se reduce un punto para dejar aire. */
@media (max-width: 360px) {
  .nav-btn      { font-size: 10px; padding-left: 2px; padding-right: 2px; }
  .nav-btn i    { font-size: 17px; }
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: 22%;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--c-alert);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: grid;
  place-items: center;
  border: 2px solid var(--c-ink);
}

/* ================================ MAPAS ================================ */

.map-box {
  height: 240px;
  width: 100%;
  border-radius: 12px;
  border: 3px solid #0f172a;
  overflow: hidden;
  background: #e2e8f0;
  z-index: 0;                       /* evita que Leaflet tape los modales */
}
.map-box-lg { height: 380px; }
.map-box-sm { height: 190px; }

.leaflet-container { font: inherit; background: #e2e8f0; }
.leaflet-control-attribution { font-size: 9px; opacity: .8; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.45; }
.leaflet-popup-content b { font-weight: 800; }
.leaflet-bar a { font-weight: 800; }

/* Marcadores personalizados (divIcon) */
.pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45);
  display: grid;
  place-items: center;
}
.pin i {
  transform: rotate(45deg);
  color: #fff;
  font-size: 12px;
}
.pin-verde   { background: #15803d; }
.pin-amarillo{ background: #ca8a04; }
.pin-rojo    { background: #dc2626; }
.pin-sos     { background: #dc2626; animation: pinPulse 1.4s ease-out infinite; }
.pin-via     { background: #7c2d12; }
.pin-yo      { background: #1d4ed8; }

@keyframes pinPulse {
  0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, .75); }
  70%  { box-shadow: 0 0 0 16px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* =========================== PULSO BOTÓN SOS =========================== */

.pulse-sos { animation: sosPulse 2s cubic-bezier(.4, 0, .6, 1) infinite; }

@keyframes sosPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .7), 0 8px 22px rgba(0, 0, 0, .35); }
  50%      { box-shadow: 0 0 0 18px rgba(220, 38, 38, 0), 0 8px 22px rgba(0, 0, 0, .35); }
}

/* Tarjeta de alerta SOS activa */
.sos-card { animation: sosGlow 2.6s ease-in-out infinite; }
@keyframes sosGlow {
  0%, 100% { border-color: #dc2626; }
  50%      { border-color: #fca5a5; }
}

.blink-dot { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ============================== TARJETAS ============================== */

.card {
  background: #fff;
  border: 3px solid #0f172a;
  border-radius: 12px;
  padding: 14px;
}
.card-green  { border-color: #15803d; }
.card-yellow { border-color: #ca8a04; }
.card-red    { border-color: #dc2626; }

.bar-track {
  height: 16px;
  width: 100%;
  background: #e2e8f0;
  border: 2px solid #0f172a;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .5s ease;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, .22) 0 6px,
    transparent 6px 12px
  );
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  border: 2px solid currentColor;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: #475569;
  font-weight: 700;
  background: #fff;
  border: 3px dashed #94a3b8;
  border-radius: 12px;
}

/* =============================== MODALES =============================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 20px; }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .75);
  animation: fadeIn .18s ease;
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  border-radius: 18px 18px 0 0;
  overflow: hidden;
  animation: slideUp .22s cubic-bezier(.2, .9, .3, 1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .5);
}
@media (min-width: 640px) {
  .modal-panel { border-radius: 18px; animation: fadeIn .18s ease; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  flex: 0 0 auto;
}
.modal-x {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .18);
  color: inherit;
  border: none;
  cursor: pointer;
  font-size: 18px;
}
.modal-x:hover { background: rgba(255, 255, 255, .32); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

body.modal-open { overflow: hidden; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ================================ TOAST ================================ */

.toast {
  pointer-events: auto;
  max-width: 480px;
  width: 100%;
  background: #0f172a;
  color: #fff;
  border-left: 6px solid #38bdf8;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: toastIn .2s ease;
}
.toast-ok    { border-left-color: #22c55e; }
.toast-error { border-left-color: #ef4444; }
.toast-warn  { border-left-color: #f59e0b; }
.toast-out   { animation: toastOut .25s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px); } }

/* ========================= UTILIDADES / A11Y ========================= */

.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* Modo alto contraste extra (luz solar directa) */
@media (prefers-contrast: more) {
  .card  { border-width: 4px; }
  .input { border-width: 3px; }
}

/* Impresión: listados útiles para puestos de mando sin energía */
@media print {
  header, #bottomNav, #btnSOS, .map-box, .chip-row, .modal { display: none !important; }
  main { padding: 0 !important; }
  .card { break-inside: avoid; border-width: 1px; }
}
