/* =====================================================================
   Geoportal Catastral — estilos (móvil primero)
   ===================================================================== */
:root {
  --verde: #1f4d3a;
  --verde-2: #2e6b52;
  --verde-claro: #e7f0eb;
  --ambar: #c98a12;
  --rojo: #b3402f;
  --tinta: #1c2421;
  --tinta-2: #55625c;
  --borde: #d9e0dc;
  --fondo: #f5f7f6;
  --blanco: #fff;
  --sombra: 0 6px 24px rgba(20, 35, 28, .18);
  --radio: 12px;
  --barra-h: 56px;
  --seg-top: env(safe-area-inset-top, 0px);
  --seg-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--tinta); background: var(--fondo);
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
.barra svg, .buscador svg, .ctrl svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ---------- Barra superior ---------- */
.barra {
  height: calc(var(--barra-h) + var(--seg-top)); padding: var(--seg-top) 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--verde); color: #fff; z-index: 1100; flex: none;
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.escudo {
  width: 36px; height: 36px; border-radius: 8px; flex: none;
  background: #fff; color: var(--verde); font-weight: 700; font-size: 12px;
  display: grid; place-items: center; letter-spacing: .5px;
}
.titulos { min-width: 0; }
.titulos h1 { font-size: 15px; margin: 0; font-weight: 700; line-height: 1.2; }
.titulos p { font-size: 12px; margin: 0; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-usuario {
  display: flex; align-items: center; gap: 6px; border: 1px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.1); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  max-width: 45vw;
}
.btn-usuario span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-usuario.activo { background: #fff; color: var(--verde); }

.aviso-demo {
  background: #fff6e0; color: #6b4a06; font-size: 12.5px; padding: 6px 12px;
  border-bottom: 1px solid #f0dca8; z-index: 1050; flex: none;
}

/* ---------- Mapa ---------- */
.contenedor { position: relative; flex: 1; min-height: 0; }
#mapa { position: absolute; inset: 0; background: #e9eeeb; }
.leaflet-container { font-family: inherit; }
.etiqueta-lote {
  background: none; border: none; box-shadow: none; padding: 0;
  font-size: 10.5px; font-weight: 600; color: #20302a; text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}
.etiqueta-lote::before { display: none; }
.etiqueta-mz { font-size: 13px; font-weight: 700; color: var(--verde); }

/* ---------- Buscador ---------- */
.buscador {
  position: absolute; top: 10px; left: 10px; right: 64px; z-index: 1000;
  display: flex; align-items: center; gap: 8px; background: #fff; border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 0 12px; height: 44px; max-width: 460px;
}
.buscador svg { color: var(--tinta-2); }
.buscador input { border: 0; outline: 0; flex: 1; font: inherit; font-size: 14px; min-width: 0; background: transparent; }
.resultados {
  position: absolute; top: 48px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: #fff; border-radius: var(--radio); box-shadow: var(--sombra); max-height: 50vh; overflow: auto;
}
.resultados li { padding: 9px 10px; border-radius: 8px; font-size: 13.5px; cursor: pointer; }
.resultados li small { display: block; color: var(--tinta-2); font-size: 12px; }
.resultados li:hover, .resultados li[aria-selected="true"] { background: var(--verde-claro); }
.resultados .vacio { color: var(--tinta-2); cursor: default; }

/* ---------- Controles ---------- */
.controles { position: absolute; top: 10px; right: 10px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.ctrl {
  width: 44px; height: 44px; border-radius: var(--radio); border: 0; background: #fff; color: var(--verde);
  box-shadow: var(--sombra); display: grid; place-items: center;
}
.ctrl[aria-pressed="true"] { background: var(--verde); color: #fff; }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution { font-size: 10px; }

.panel-capas {
  position: absolute; top: 62px; right: 10px; z-index: 1001; width: 250px;
  background: #fff; border-radius: var(--radio); box-shadow: var(--sombra); padding: 10px 14px 12px;
}
.panel-capas h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--tinta-2); margin: 10px 0 4px; }
.panel-capas h2:first-child { margin-top: 2px; }
.panel-capas label { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 4px 0; }
.panel-capas input { accent-color: var(--verde); width: 16px; height: 16px; }
.panel-capas label:has(input:disabled) { color: #9aa5a0; }

/* ---------- Leyenda ---------- */
.leyenda {
  position: absolute; left: 10px; bottom: calc(18px + var(--seg-bot)); z-index: 999;
  background: rgba(255,255,255,.95); border-radius: 10px; box-shadow: var(--sombra);
  padding: 8px 10px; font-size: 12px; max-width: 60vw;
}
.leyenda b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--tinta-2); margin-bottom: 4px; }
.leyenda span { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.leyenda i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.25); }

/* ---------- Ficha del lote ---------- */
.ficha {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1002; background: #fff;
  border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(20,35,28,.2);
  max-height: 62%; display: flex; flex-direction: column; padding-bottom: var(--seg-bot);
}
.ficha-asa { width: 40px; height: 4px; border-radius: 4px; background: var(--borde); margin: 8px auto 0; }
.ficha-cab { display: flex; justify-content: space-between; align-items: flex-start; padding: 8px 16px 4px; gap: 8px; }
.ficha-kicker { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--tinta-2); }
.ficha-cab h2 { margin: 2px 0 0; font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.ficha-dir { margin: 2px 0 0; color: var(--tinta-2); font-size: 13.5px; }
.btn-cerrar { border: 0; background: var(--fondo); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--tinta-2); flex: none; }
.pestanas { display: flex; gap: 4px; padding: 6px 12px 0; overflow-x: auto; border-bottom: 1px solid var(--borde); flex: none; scrollbar-width: none; }
.pestanas button {
  border: 0; background: none; padding: 8px 10px; font-size: 13.5px; font-weight: 600; color: var(--tinta-2);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.pestanas button[aria-selected="true"] { color: var(--verde); border-bottom-color: var(--verde); }
.ficha-cuerpo { overflow: auto; padding: 12px 16px 16px; font-size: 14px; }
.datos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0; }
.datos div { min-width: 0; }
.datos dt { font-size: 11.5px; color: var(--tinta-2); }
.datos dd { margin: 1px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.datos .ancho { grid-column: 1 / -1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--borde); }
th { font-size: 11.5px; color: var(--tinta-2); font-weight: 600; }
td.num, th.num { text-align: right; }
.estado { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12.5px; padding: 2px 8px; border-radius: 999px; }
.estado::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.estado.APROBADO { color: #1d6b43; background: #e3f3e9; }
.estado.PENDIENTE { color: #8a5d00; background: #fff3d6; }
.estado.OBSERVADO { color: var(--rojo); background: #fbe6e2; }
.nota { font-size: 12.5px; color: var(--tinta-2); background: var(--fondo); border-radius: 8px; padding: 8px 10px; margin: 10px 0 0; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn-principal, .btn-secundario, .btn-peligro {
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; font-size: 14px;
}
.btn-principal { background: var(--verde); color: #fff; }
.btn-principal:disabled { opacity: .6; cursor: wait; }
.btn-secundario { background: var(--verde-claro); color: var(--verde); }
.btn-peligro { background: #fbe6e2; color: var(--rojo); }
.btn-deshabilitado { background: var(--fondo); color: #8b9691; border: 1px dashed var(--borde); cursor: not-allowed; }
textarea { width: 100%; font: inherit; font-size: 14px; border: 1px solid var(--borde); border-radius: 10px; padding: 8px 10px; min-height: 70px; resize: vertical; }

/* ---------- Modales ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000; background: rgba(15, 25, 20, .5);
  display: grid; place-items: center; padding: 16px;
}
.caja {
  position: relative; width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 22px 20px 18px; box-shadow: var(--sombra);
}
.caja h2 { margin: 0 32px 4px 0; font-size: 18px; }
.caja .sub { margin: 0 0 14px; color: var(--tinta-2); font-size: 13.5px; }
.caja .btn-cerrar { position: absolute; top: 12px; right: 12px; }
.campo { display: block; font-size: 12.5px; font-weight: 600; color: var(--tinta-2); margin-bottom: 12px; }
.campo input, .campo select {
  display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 15px; color: var(--tinta);
  border: 1px solid var(--borde); border-radius: 10px; padding: 10px 12px; background: #fff;
}
.campo input:focus, .campo select:focus, textarea:focus { outline: 2px solid var(--verde-2); outline-offset: 1px; }
.enlace { border: 0; background: none; color: var(--verde-2); font-size: 13px; padding: 0; margin: -4px 0 12px; text-decoration: underline; }
.caja .btn-principal { width: 100%; margin-top: 4px; }
.caja .btn-secundario { width: 100%; margin-top: 16px; }
.error { color: var(--rojo); background: #fbe6e2; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0 0 10px; }
.pie { font-size: 12px; color: var(--tinta-2); margin: 12px 0 0; text-align: center; }
.chip { display: inline-block; background: var(--verde-claro); color: var(--verde); font-weight: 600; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; }
.resumen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.resumen div { background: var(--fondo); border-radius: 10px; padding: 8px; text-align: center; }
.resumen strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.resumen small { font-size: 11px; color: var(--tinta-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--seg-bot)); transform: translateX(-50%); z-index: 3000;
  background: var(--tinta); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--sombra);
  max-width: calc(100% - 32px);
}

/* ---------- Formulario de ficha ---------- */
.modal-ficha { padding: 0; display: flex; align-items: stretch; justify-content: center; }
.hoja {
  background: #fff; width: 100%; height: 100%; max-height: 100%; min-height: 0; display: flex; flex-direction: column;
  padding-top: var(--seg-top);
}
.hoja-cuerpo { min-height: 0; }
.hoja-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 14px 16px 6px; border-bottom: 1px solid var(--borde); }
.hoja-cab h2 { margin: 2px 0 0; font-size: 18px; font-variant-numeric: tabular-nums; }
.hoja-aviso { margin: 10px 16px 0; }
.hoja-cuerpo { flex: 1; overflow: auto; padding: 8px 16px 24px; }
.hoja-pie { border-top: 1px solid var(--borde); padding: 10px 16px calc(10px + var(--seg-bot)); background: #fff; }
.hoja-pie .acciones { margin-top: 0; justify-content: flex-end; }
.hoja-pie .error { max-height: 90px; overflow: auto; }
.sec { border: 1px solid var(--borde); border-radius: 12px; margin-top: 10px; background: #fff; }
.sec > summary {
  list-style: none; cursor: pointer; padding: 13px 14px; font-weight: 700; font-size: 15px; color: var(--verde);
  display: flex; align-items: center; gap: 8px;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: "▾"; margin-left: auto; color: var(--tinta-2); transition: transform .15s; }
.sec[open] > summary::after { transform: rotate(180deg); }
.sec-cuerpo { padding: 0 14px 14px; }
.cuenta { background: var(--verde-claro); color: var(--verde); border-radius: 999px; font-size: 12px; padding: 1px 8px; }
.rejilla { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.rejilla .ancho, .rejilla > .ancho { grid-column: 1 / -1; }
.rejilla .campo { margin-bottom: 10px; min-width: 0; }
.rejilla .campo select, .rejilla .campo input { font-size: 14px; padding: 9px 10px; }
.rejilla .campo textarea { margin-top: 5px; }
.rejilla.cats { grid-template-columns: repeat(2, 1fr); }
.campo .invalido, .invalido { border-color: var(--rojo) !important; background: #fff7f5; }
.tarjeta { border: 1px dashed var(--borde); border-radius: 10px; padding: 10px 10px 4px; margin-top: 10px; background: #fbfcfb; }
.tarjeta h4 { margin: 0 0 8px; font-size: 13.5px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }
.check input { accent-color: var(--verde); width: 18px; height: 18px; }
.mini { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--tinta-2); margin: 2px 0 6px; }
.btn-agregar { margin-top: 10px; width: 100%; border: 1px dashed var(--verde-2); background: var(--verde-claro); color: var(--verde); border-radius: 10px; padding: 10px; font-weight: 600; }
.btn-quitar { border: 0; background: none; color: var(--rojo); font-size: 13px; padding: 2px 0 8px; text-decoration: underline; }
@media (min-width: 900px) {
  .modal-ficha { padding: 24px; align-items: center; }
  .hoja { max-width: 760px; height: min(92vh, 1000px); border-radius: 16px; box-shadow: var(--sombra); }
  .rejilla { grid-template-columns: repeat(4, 1fr); }
  .rejilla.cats { grid-template-columns: repeat(4, 1fr); }
  .rejilla .campo:not(.ancho) { grid-column: span 2; }
  .tarjeta .rejilla .campo:not(.ancho) { grid-column: span 2; }
}

.buscar-usuarios { margin-top: 12px; }
.buscar-usuarios input { width: 100%; font: inherit; font-size: 14px; border: 1px solid var(--borde); border-radius: 10px; padding: 10px 12px; }
.usuario .usr-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.usuario .usr-cab small { color: var(--tinta-2); overflow-wrap: anywhere; }
.usuario .usr-meta { text-transform: none; letter-spacing: 0; font-weight: 500; margin: 0; }
.usuario .acciones { margin: 8px 0 8px; }

[hidden] { display: none !important; }

/* ---------- Escritorio ---------- */
@media (min-width: 900px) {
  .titulos h1 { font-size: 17px; }
  .titulos p { font-size: 13px; }
  .ficha {
    top: 10px; right: 10px; left: auto; bottom: 10px; width: 400px; max-height: none;
    border-radius: 16px; box-shadow: var(--sombra);
  }
  .ficha-asa { display: none; }
  .ficha:not([hidden]) ~ .controles, body.ficha-abierta .controles { right: 420px; }
  body.ficha-abierta .panel-capas { right: 420px; }
  .leyenda { max-width: 260px; }
}
