/* SOS Pereira — tema claro único, colores de estado validados (CVD):
   habitable #15803d · restringido #ca8a04 · insegura #dc2626 */

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* el atributo hidden SIEMPRE gana (el modal usa display:grid) */
html, body {
  margin: 0; height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1e293b; background: #f1f5f9;
}

#mapa { position: fixed; inset: 0; z-index: 1; background: #dbe4ea; }

/* ---------- panel lateral ---------- */
#panel {
  position: fixed; z-index: 1000; top: 12px; left: 12px; bottom: 12px;
  width: 330px; max-width: calc(100vw - 24px);
  background: #ffffff; border: 1px solid #e2e8f0; border-radius: 12px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, .16);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .2s ease;
}
#panel.plegado { transform: translateX(-360px); }

.panel-cab {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 16px 10px; border-bottom: 1px solid #eef2f7;
}
.panel-cab h1 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.panel-sub { margin: 2px 0 0; font-size: 12.5px; color: #64748b; }

.btn-icono {
  border: 1px solid #e2e8f0; background: #fff; color: #475569;
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer;
  font-size: 16px; line-height: 1;
}
.btn-icono:hover { background: #f8fafc; }
.btn-abrir {
  position: fixed; z-index: 1001; top: 18px; left: 12px;
  box-shadow: 0 4px 14px rgba(15,23,42,.18); width: 34px; height: 34px;
}

/* barra inferior táctil (solo móvil) */
.barra-movil {
  display: none;
  position: fixed; z-index: 1450; left: 0; right: 0; bottom: 0;
  background: #ffffff; border-top: 1px solid #e2e8f0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: 1fr 1.4fr 1fr; gap: 8px;
  box-shadow: 0 -6px 20px rgba(15,23,42,.12);
}
.bm-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; min-height: 52px; border-radius: 12px; cursor: pointer;
  border: 1px solid #e2e8f0; background: #f8fafc; color: #334155;
  font-size: 20px; line-height: 1.1;
}
.bm-btn small { font-size: 11px; font-weight: 600; }
.bm-btn.bm-pri { background: #0f766e; border-color: #0f766e; color: #fff; }
.bm-btn.bm-pri.activo { background: #b45309; border-color: #b45309; }

/* acciones principales: marcar + gps + buscar */
.acciones { padding: 10px 14px 2px; display: flex; flex-direction: column; gap: 8px; }
.btn.grande { font-size: 14px; padding: 11px 12px; font-weight: 700; }
.btn.pri.activo { background: #b45309; border-color: #b45309; }
.buscador { position: relative; }
.buscador input {
  width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 13px; background: #fff; color: #1e293b;
}
.buscar-res {
  position: absolute; z-index: 1200; top: 100%; left: 0; right: 0; margin: 4px 0 0;
  padding: 4px; list-style: none; background: #fff; border: 1px solid #e2e8f0;
  border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.2); max-height: 250px; overflow-y: auto;
}
.buscar-res li { padding: 8px 10px; border-radius: 7px; font-size: 12.5px; cursor: pointer; color: #334155; }
.buscar-res li:hover { background: #f1f5f9; }
.buscar-res li small { display: block; color: #94a3b8; }

.filtros { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 4px; align-items: center; }
.filtros select {
  border: 1px solid #e2e8f0; background: #f8fafc; color: #334155;
  border-radius: 999px; padding: 5px 8px; font-size: 12px; cursor: pointer;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #e2e8f0; background: #f8fafc; color: #334155;
  border-radius: 999px; padding: 5px 10px; font-size: 12.5px; cursor: pointer;
}
.chip b { font-weight: 600; color: #0f172a; }
.chip:not(.activo) { opacity: .38; }
.chip .punto { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.ayuda { font-size: 12px; color: #64748b; padding: 6px 16px 8px; margin: 0; border-bottom: 1px solid #eef2f7; }

/* lista de zonas */
.lista { list-style: none; margin: 0; padding: 6px 8px; overflow-y: auto; flex: 1; }
.lista li {
  display: flex; gap: 10px; align-items: center; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.lista li:hover { background: #f1f5f9; border-color: #e2e8f0; }
.lista .marca {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.lista .tit { font-size: 13.5px; font-weight: 600; color: #0f172a; margin: 0; }
.lista .det { font-size: 12px; color: #64748b; margin: 0; }
.lista .vacia { color: #94a3b8; font-size: 13px; text-align: center; padding: 24px 8px; cursor: default; }
.lista .vacia:hover { background: none; border-color: transparent; }

.panel-pie {
  display: flex; gap: 6px; padding: 10px 12px;
  border-top: 1px solid #eef2f7; background: #fbfcfe;
}

.btn {
  display: inline-block; text-align: center; text-decoration: none;
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; cursor: pointer;
  border: 1px solid #cbd5e1; background: #fff; color: #334155; flex: 1;
}
.btn:hover { background: #f8fafc; }
.btn.pri { background: #0f766e; border-color: #0f766e; color: #fff; font-weight: 600; }
.btn.pri:hover { background: #115e59; }
.btn.salir { flex: 0 0 auto; color: #b91c1c; }

/* ---------- login ---------- */
.login-fondo {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px);
  display: grid; place-items: center;
}
.login-caja {
  background: #fff; border-radius: 14px; padding: 28px 30px; width: 320px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35); text-align: center;
}
.login-caja h1 { margin: 0 0 4px; font-size: 24px; }
.login-sub { margin: 0 0 18px; color: #64748b; font-size: 13px; line-height: 1.45; }
.login-caja input {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14px; margin-bottom: 10px;
}
.login-caja button {
  width: 100%; padding: 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: #0f766e; color: #fff; font-size: 14px; font-weight: 600;
}
.login-caja button:hover { background: #115e59; }
.login-error { color: #dc2626; font-size: 13px; margin: 10px 0 0; }

/* ---------- ficha: cajón lateral derecho, NO bloquea mapa ni vista de calle ---------- */
.modal-fondo {
  position: fixed; z-index: 1600; top: 12px; right: 12px; bottom: 12px;
  width: 446px; max-width: calc(100vw - 24px);
  background: transparent; pointer-events: none;
}
.modal-caja {
  pointer-events: auto;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
  padding: 18px 20px; width: 100%; height: 100%; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(15,23,42,.35);
}
.modal-caja h2 { margin: 0 0 12px; font-size: 18px; }

.lbl { display: block; font-size: 12px; font-weight: 600; color: #475569; margin: 12px 0 4px; }
.modal-caja input[type=text], .modal-caja input[type=date],
.modal-caja input[type=number],
.modal-caja select, .modal-caja textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: #1e293b;
}
.modal-caja textarea { resize: vertical; }
.fila2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.niveles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.nivel-op {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 2px solid #e2e8f0; border-radius: 10px; padding: 10px 6px 8px;
  cursor: pointer; text-align: center; font-size: 12.5px; font-weight: 600; color: #334155;
}
.nivel-op small { display: block; font-weight: 400; color: #94a3b8; font-size: 11px; }
.nivel-op input { position: absolute; opacity: 0; }
.nivel-chip {
  width: 34px; height: 34px; border-radius: 10px; background: var(--c);
  color: #fff; font-size: 17px; font-weight: 800; display: grid; place-items: center;
}
.nivel-op:has(input:checked) { border-color: var(--sel, #0f766e); background: #f0fdfa; }
.nivel-op[data-nivel=habitable]:has(input:checked)  { --sel: #15803d; background: #f0fdf4; }
.nivel-op[data-nivel=restringido]:has(input:checked){ --sel: #ca8a04; background: #fefce8; }
.nivel-op[data-nivel=insegura]:has(input:checked)   { --sel: #dc2626; background: #fef2f2; }

.modal-botones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-botones .btn { flex: 0 0 auto; padding: 9px 18px; }
.fila3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* fotos del daño */
.fotos-lista { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.fotos-lista:empty { display: none; }
.foto-mini {
  position: relative; width: 86px; height: 86px; border-radius: 10px; overflow: hidden;
  border: 1px solid #e2e8f0; background: #f1f5f9;
}
.foto-mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto-mini.borrada img { opacity: .25; filter: grayscale(1); }
.foto-mini .foto-x {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px;
  border: 0; border-radius: 50%; background: rgba(15,23,42,.72); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer;
}
.foto-mini .foto-etq {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 9.5px; text-align: center;
  background: rgba(15,23,42,.62); color: #fff; padding: 1px 0;
}
#btn-foto { width: 100%; }

.pop-fotos { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.pop-fotos img {
  width: 60px; height: 60px; object-fit: cover; border-radius: 8px;
  border: 1px solid #e2e8f0; cursor: pointer;
}
.pop-fotos span {
  width: 60px; height: 60px; border-radius: 8px; display: grid; place-items: center;
  background: #f1f5f9; color: #64748b; font-size: 13px; font-weight: 700;
}

/* fila de coordenadas + fachada dentro de la ficha */
.coords-fila {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 6px 8px;
}
.coords { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; color: #334155; flex: 1; min-width: 150px; }
.btn.mini { flex: 0 0 auto; font-size: 11.5px; padding: 4px 8px; }
.niveles.error { outline: 2px solid #dc2626; outline-offset: 3px; border-radius: 10px; animation: sacudir .3s; }
@keyframes sacudir { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* modo marcación */
#mapa.marcando { cursor: crosshair; }
.cta-flotante {
  position: fixed; z-index: 1500; top: 20px; left: 50%; transform: translateX(-50%);
  background: #0f766e; color: #fff; border: 0; border-radius: 999px;
  font-size: 14px; font-weight: 700; padding: 11px 20px; cursor: pointer;
  box-shadow: 0 10px 30px rgba(15,23,42,.35);
}
.cta-flotante:hover { background: #115e59; }
.pin-fantasma { filter: hue-rotate(120deg) saturate(1.4); }

/* tarjeta de confirmación del punto */
.confirmar {
  position: fixed; z-index: 1500; left: 50%; bottom: 22px; transform: translateX(-50%);
  width: 410px; max-width: calc(100vw - 24px);
  background: #fff; border: 1px solid #e2e8f0; border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 14px 40px rgba(15,23,42,.3);
}
.conf-tit { margin: 0 0 2px; font-weight: 700; font-size: 14.5px; color: #0f172a; }
.conf-dir { margin: 0; font-size: 13px; color: #0f172a; min-height: 18px; }
.conf-coords { margin: 2px 0 0; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: #64748b; }
.conf-hint { margin: 6px 0 9px; font-size: 11.5px; color: #94a3b8; }
.conf-botones { display: flex; gap: 6px; }
.conf-botones .btn { flex: 1; padding: 8px 10px; font-size: 12.5px; }
.conf-botones .btn.pri { flex: 1.6; }

/* panel de vista de calle (Mapillary) — independiente y SIEMPRE accesible */
.fachada {
  position: fixed; z-index: 1700; right: 12px; top: 12px; width: 460px; max-width: calc(100vw - 24px);
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden;
  box-shadow: 0 14px 40px rgba(15,23,42,.3);
}
.fachada header {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid #eef2f7; font-size: 13px; background: #fbfcfe;
}
.fachada header b { flex: 0 0 auto; }
#fachada-info { flex: 1; color: #64748b; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fachada-visor { width: 100%; height: 340px; background: #0f172a; }
.fachada-msg { margin: 0; padding: 10px 12px; font-size: 12.5px; color: #64748b; background: #f8fafc; }
/* cuando la ficha (cajón derecho) está abierta, la vista de calle se corre a su lado */
@media (min-width: 1000px) {
  body.con-ficha .fachada { right: 470px; }
}

/* ---------- popups y leyenda ---------- */
.leaflet-popup-content { font-size: 13px; margin: 12px 14px; }
.pop-tit { font-weight: 700; font-size: 14px; margin: 0 0 2px; }
.pop-nivel {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600;
  font-size: 12px; padding: 2px 8px; border-radius: 999px; color: #fff; margin: 2px 0 6px;
}
.pop-estado {
  display: inline-block; font-size: 11px; font-weight: 600; color: #475569;
  border: 1px solid #cbd5e1; border-radius: 999px; padding: 1px 8px; margin-left: 4px;
}
.pop-det { margin: 2px 0; color: #475569; }
.pop-obs { margin: 6px 0 0; color: #334155; white-space: pre-wrap; }
.pop-botones { display: flex; gap: 6px; margin-top: 10px; }
.pop-botones button {
  flex: 1; font-size: 12px; padding: 5px 8px; cursor: pointer;
  border: 1px solid #cbd5e1; background: #fff; border-radius: 6px; color: #334155;
}
.pop-botones button:hover { background: #f8fafc; }
.pop-botones .rojo { color: #b91c1c; border-color: #fecaca; }

.leyenda {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 8px 12px; font-size: 12px; color: #334155;
  box-shadow: 0 4px 14px rgba(15,23,42,.15); line-height: 1.9;
}
.leyenda .fila { display: flex; align-items: center; gap: 8px; }
.leyenda .sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

.aviso {
  position: fixed; z-index: 4000; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; font-size: 13px; padding: 9px 16px;
  border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.3); opacity: 0;
  transition: opacity .25s; pointer-events: none;
}
.aviso.ver { opacity: 1; }

/* ============ MÓVIL (pantalla ≤ 640px): pensado para dedo y campo ============ */
@media (max-width: 640px) {
  .barra-movil { display: grid; }
  .btn-abrir { display: none; }               /* la barra inferior lo reemplaza */

  /* el panel se vuelve hoja deslizante sobre el mapa, cerrada por defecto */
  #panel {
    top: 8px; left: 8px; right: 8px; width: auto; max-width: none;
    bottom: calc(76px + env(safe-area-inset-bottom));
    transition: transform .25s ease;
  }
  #panel.plegado { transform: translateY(calc(100% + 100px)); }

  /* tamaños táctiles */
  .fila2, .fila3 { grid-template-columns: 1fr; }
  .niveles { grid-template-columns: 1fr; }
  .nivel-op { flex-direction: row; justify-content: flex-start; text-align: left; gap: 10px; padding: 12px 10px; }
  .lista li { padding: 13px 10px; }
  .chip { padding: 8px 12px; font-size: 13px; }
  .filtros select { padding: 8px 10px; font-size: 13px; }
  .btn { padding: 11px 12px; font-size: 13.5px; }
  .btn.mini { padding: 7px 10px; font-size: 12px; }
  .pop-botones button { padding: 10px 8px; font-size: 13px; }
  .conf-botones .btn { min-height: 46px; }

  /* 16px evita el auto-zoom de iOS al enfocar campos */
  input, select, textarea { font-size: 16px !important; }

  /* controles del mapa más grandes (zoom + herramientas de dibujo) */
  .leaflet-touch .leaflet-bar a,
  .leaflet-touch .leaflet-pm-toolbar .leaflet-buttons-control-button {
    width: 42px; height: 42px; line-height: 42px;
  }

  /* nada tapado por la barra inferior */
  .leaflet-bottom { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .aviso { bottom: calc(82px + env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); text-align: center; }
  .confirmar { bottom: calc(78px + env(safe-area-inset-bottom)); }
  .leyenda { font-size: 11px; line-height: 1.7; padding: 6px 9px; }

  /* vista de calle y ficha apiladas: fachada arriba, ficha como hoja inferior */
  .fachada { right: 8px; left: 8px; width: auto; top: 8px; }
  #fachada-visor { height: 235px; }
  .modal-fondo {
    top: auto; left: 8px; right: 8px; bottom: 8px; width: auto;
    height: min(64vh, calc(100vh - 120px));   /* altura FIJA: así la caja interna sí scrollea */
  }
  .modal-caja { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
