:root {
  --fondo: #f4f3ef;
  --superficie: #ffffff;
  --borde: #dedbd2;
  --texto: #1f2328;
  --sutil: #6a6f76;
  --primario: #1f5f8b;
  --primario-oscuro: #174a6d;
  --peligro: #c0392b;
  --ok: #2f9e5b;

  --c-sin_ubicar: #d64545;
  --c-fuera: #8e44ad;
  --c-dudoso: #e39b2d;
  --c-auto: #3b78d8;
  --c-confirmado: #2f9e5b;

  --radio: 8px;
  --sombra: 0 6px 24px rgba(20, 24, 30, .14), 0 1px 3px rgba(20, 24, 30, .1);
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--fuente); color: var(--texto); background: var(--fondo); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
code, kbd { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
kbd { border: 1px solid var(--borde); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fafafa; color: var(--sutil); }
.sutil { color: var(--sutil); }
[hidden] { display: none !important; }

/* ---------- botones y formularios ---------- */
.boton {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--borde); background: var(--superficie); color: var(--texto);
  padding: 7px 12px; border-radius: 6px; font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.boton:hover { border-color: #b9b5a9; }
.boton:disabled { opacity: .5; cursor: default; }
.boton-primario { background: var(--primario); border-color: var(--primario); color: #fff; font-weight: 600; }
.boton-primario:hover { background: var(--primario-oscuro); }
.boton-primario kbd { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.3); color: #fff; }
.boton-quieto { background: transparent; }
.boton-chico { padding: 4px 10px; font-size: 13px; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primario) 40%, transparent); border-color: var(--primario); }

/* ---------- páginas simples (login / instalación) ---------- */
.pagina-simple { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.caja { background: var(--superficie); border: 1px solid var(--borde); border-radius: 12px; padding: 28px; width: 100%; max-width: 420px; box-shadow: var(--sombra); }
.formulario { display: grid; gap: 14px; margin-top: 16px; }
.formulario label { display: grid; gap: 4px; font-weight: 600; }
.aviso { padding: 10px 12px; border-radius: 6px; margin: 12px 0; }
.aviso-error { background: #fbeaea; color: #8a1f1f; }
.aviso-ok { background: #e6f4ec; color: #1d6b3d; }
.pasos { padding-left: 20px; margin: 8px 0; }
.pasos li { margin: 4px 0; }

/* ---------- app ---------- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.barra {
  display: flex; align-items: center; gap: 20px; padding: 10px 16px;
  background: var(--superficie); border-bottom: 1px solid var(--borde); flex-wrap: wrap;
}
.barra-titulo { display: flex; flex-direction: column; }
.barra-titulo strong { font-size: 16px; }
.barra-titulo .sutil { font-size: 12px; }
.progreso { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 10px; }
.progreso-barra { flex: 1; max-width: 280px; height: 8px; background: #ebe8df; border-radius: 4px; overflow: hidden; }
.progreso-barra span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s; }
#progreso-texto { font-size: 13px; color: var(--sutil); white-space: nowrap; }
.barra-acciones { display: flex; gap: 8px; }

.cuerpo { flex: 1; display: flex; min-height: 0; }
.lateral {
  width: 340px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--superficie); border-right: 1px solid var(--borde); min-height: 0;
}
.filtros { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--borde); background: #fff; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip b { font-weight: 600; color: var(--sutil); margin-left: 2px; }
.chip.activo { background: var(--texto); color: #fff; border-color: var(--texto); }
.chip.activo b { color: #fff; }

.lista { list-style: none; margin: 0 -12px; padding: 0; overflow-y: auto; flex: 1; }
.lista li {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; cursor: pointer; border-left: 3px solid transparent;
}
.lista li:hover { background: #f7f6f2; }
.lista li.sel { background: #eef4f9; border-left-color: var(--primario); }
.lista li > div { flex: 1; min-width: 0; }
.lista li small { display: block; color: var(--sutil); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista li .deleg { color: var(--texto); }
.lista li .punto { margin-top: 4px; }
.lista .cuenta { font-size: 11px; background: #ebe8df; border-radius: 999px; padding: 1px 7px; color: var(--sutil); }
.lista .vacio { color: var(--sutil); cursor: default; padding: 24px 12px; }

.punto { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.punto.sin_ubicar { background: var(--c-sin_ubicar); }
.punto.fuera { background: var(--c-fuera); }
.punto.dudoso { background: var(--c-dudoso); }
.punto.auto { background: var(--c-auto); }
.punto.confirmado { background: var(--c-confirmado); }

.mapa-envoltorio { flex: 1; position: relative; min-width: 0; }
#mapa { position: absolute; inset: 0; background: #e5e3dc; }

.leyenda {
  position: absolute; left: 12px; bottom: 22px; z-index: 500;
  background: rgba(255,255,255,.95); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 8px 12px; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px;
}
.leyenda span { display: inline-flex; align-items: center; gap: 5px; }

/* ficha del edificio seleccionado */
.ficha {
  position: absolute; top: 12px; right: 12px; z-index: 1001; width: 370px; max-height: calc(100% - 24px); overflow-y: auto;
  background: var(--superficie); border-radius: 12px; box-shadow: var(--sombra); padding: 16px 18px;
}
.ficha .cerrar, .dialogo .cerrar {
  position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--sutil);
}
.ficha h2 { font-size: 19px; margin: 6px 0 2px; padding-right: 20px; }
.ficha .ayuda { margin: 10px 0; font-size: 13px; color: var(--sutil); }
.ficha .original { font-size: 12px; color: var(--sutil); margin-bottom: 8px; }
.etiqueta { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; color: #fff; }
.etiqueta.sin_ubicar { background: var(--c-sin_ubicar); }
.etiqueta.fuera { background: var(--c-fuera); }
.etiqueta.dudoso { background: var(--c-dudoso); }
.etiqueta.auto { background: var(--c-auto); }
.etiqueta.confirmado { background: var(--c-confirmado); }
.escuelas { list-style: none; padding: 8px 10px; margin: 0 0 12px; background: #f7f6f2; border-radius: 6px; }
.escuelas li { padding: 2px 0; }
.escuelas .sutil { font-size: 12px; }
.buscar-otra { display: flex; gap: 6px; margin-bottom: 12px; }
.buscar-otra input { padding: 5px 8px; font-size: 13px; }
.fila-botones { display: flex; gap: 8px; flex-wrap: wrap; }
.acciones-ficha .boton-primario { flex: 1; }
.fila-links { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; }
.fila-links a { color: var(--primario); }
.sin-guardar { margin: 10px 0 0; font-size: 12px; color: #9a5b00; }
.cercanos { background: #fff6e5; border: 1px solid #f0d9a8; border-radius: 6px; padding: 10px; margin-bottom: 12px; font-size: 13px; }
.cercanos p { margin: 0 0 8px; }
.cercanos p:not(:first-child) { margin-top: 10px; }

/* marcadores del mapa */
.pin span {
  position: absolute; left: 3px; top: 0; width: 24px; height: 24px; border-radius: 50% 50% 50% 0;
  background: var(--texto); transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.pin span::after { content: ""; position: absolute; inset: 6px; background: #fff; border-radius: 50%; }
.candidato {
  display: grid !important; place-items: center; border-radius: 50%; background: #fff; border: 2px solid var(--c-dudoso);
  font-weight: 700; font-size: 12px; color: var(--texto); box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer;
}
.candidato.google { border-color: #4285f4; color: #1a56c4; }
.candidato:hover { transform: scale(1.15); }
.nombre-deleg span {
  display: inline-block; transform: translate(-50%, -50%); white-space: nowrap; font-weight: 700; font-size: 12px;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; pointer-events: none; opacity: .85;
}

/* avisos */
.avisos { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 2000; display: grid; gap: 8px; }
.aviso-flotante { background: var(--texto); color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: var(--sombra); transition: opacity .4s; }
.aviso-flotante.ok { background: #1d6b3d; }
.aviso-flotante.error { background: #8a1f1f; }
.aviso-flotante.saliendo { opacity: 0; }

/* diálogo de referencias */
.dialogo { border: 0; border-radius: 12px; box-shadow: var(--sombra); padding: 24px 28px; max-width: 620px; width: calc(100% - 32px); }
.dialogo::backdrop { background: rgba(20, 24, 30, .4); }
.dialogo h3 { margin-top: 20px; font-size: 15px; }
.referencias { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.referencias dt { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.referencias dd { margin: 0; color: var(--sutil); }

@media (max-width: 860px) {
  .cuerpo { flex-direction: column-reverse; }
  .lateral { width: auto; height: 38vh; border-right: 0; border-top: 1px solid var(--borde); }
  .ficha { left: 12px; right: 12px; width: auto; max-height: 60%; }
  .leyenda { display: none; }
  .referencias { grid-template-columns: 1fr; }
}
