:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1f21;
  --muted: #5f6368;
  --border: #d9d6cf;
  --accent: #1f5fa8;
  --accent-text: #ffffff;
  --si: #2e7d4f;
  --si-bg: #e3f2e8;
  --no: #b3402e;
  --no-bg: #f9e5e1;
  --pend: #c9c6be;
  --pend-bg: #efede7;
  --calle: #e4e1d9;
  --focus: #f0a400;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1f2226;
    --surface-2: #2a2e33;
    --text: #eceae4;
    --muted: #a6a39c;
    --border: #3a3e44;
    --accent: #6ea8ec;
    --accent-text: #0e1a29;
    --si: #5cc489;
    --si-bg: #1d3427;
    --no: #ef8a76;
    --no-bg: #3d231e;
    --pend: #4a4e55;
    --pend-bg: #2a2e33;
    --calle: #2b2f34;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.35rem; margin: 4px 0 2px; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 0.9rem; }
[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}

button, .boton {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button.primario, .boton.primario { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.peligro { color: var(--no); border-color: var(--no); }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .lote:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.ancho { width: 100%; }
.mayus { text-transform: uppercase; }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 0.95rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
.ayuda { font-weight: 400; color: var(--muted); font-size: 0.85rem; }

.error {
  background: var(--no-bg);
  color: var(--no);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
}

/* ---- Resumen ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 1.4rem; line-height: 1.1; }
.stat span { font-size: 0.8rem; color: var(--muted); }
.stat.si b { color: var(--si); }
.stat.no b { color: var(--no); }
.barra { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--pend-bg); margin: 10px 0 4px; }
.barra .si { background: var(--si); }
.barra .no { background: var(--no); }
.montos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.monto { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.monto b { display: block; font-size: 1.15rem; }
.monto span { display: block; font-size: 0.8rem; color: var(--muted); }

/* ---- Mapa ---- */
.mapa-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mapa { display: block; width: 100%; min-width: 320px; height: auto; user-select: none; }
.mapa .calle { fill: var(--calle); }
.mapa .calle-nombre { fill: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; }
.mapa .mz-nombre { fill: var(--muted); font-size: 11px; font-weight: 700; }
.mapa .lote { cursor: pointer; }
.mapa .lote rect { stroke: var(--surface); stroke-width: 1.5; }
.mapa .lote text { font-size: 9px; pointer-events: none; fill: var(--text); }
.mapa .lote.pendiente rect { fill: var(--pend); }
.mapa .lote.si rect { fill: var(--si); }
.mapa .lote.si text, .mapa .lote.no text { fill: #fff; font-weight: 600; }
.mapa .lote.no rect { fill: var(--no); }
.mapa .lote.tramite rect { stroke-dasharray: 3 2; stroke: var(--text); stroke-width: 1; }
.mapa .lote.elegido rect { stroke: var(--focus); stroke-width: 3; }
.mapa .lote.ajeno { cursor: default; }
.mapa .lote.propio rect { stroke: var(--accent); stroke-width: 3; }
.leyenda { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.leyenda i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

/* ---- Mis lotes ---- */
.mis-lotes { list-style: none; margin: 8px 0 0; padding: 0; }
.mis-lotes button { width: 100%; justify-content: space-between; text-align: left; margin-bottom: 6px; }

.chip { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip.si { background: var(--si-bg); color: var(--si); }
.chip.no { background: var(--no-bg); color: var(--no); }
.chip.pendiente { background: var(--pend-bg); color: var(--muted); }
.chip.al_dia { background: var(--si-bg); color: var(--si); }
.chip.parcial { background: #fbf0d9; color: #8a5a00; }
.chip.sin_pagos { background: var(--pend-bg); color: var(--muted); }

/* ---- Ficha (diálogo) ---- */
dialog {
  border: none;
  border-radius: 16px;
  padding: 18px;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.ficha dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 14px; }
.ficha dt { color: var(--muted); }
.ficha dd { margin: 0; font-weight: 600; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.acciones > * { flex: 1 1 140px; }

/* ---- Formulario ---- */
.decisiones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.decision {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  font-weight: 700;
  cursor: pointer;
  margin: 0;
  background: var(--surface);
}
.decision input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.decision:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.decision.si:has(input:checked) { border-color: var(--si); background: var(--si-bg); color: var(--si); }
.decision.no:has(input:checked) { border-color: var(--no); background: var(--no-bg); color: var(--no); }
.opciones { display: flex; gap: 16px; flex-wrap: wrap; }
.opciones label, .check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; margin: 6px 0; }
.opciones input, .check input { width: 22px; height: 22px; min-height: 0; flex: none; margin-top: 1px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.texto-obra { white-space: pre-line; font-size: 0.95rem; }

.firma-caja { position: relative; border: 2px dashed var(--border); border-radius: 12px; background: #fff; touch-action: none; }
.firma-caja canvas { display: block; width: 100%; height: 180px; border-radius: 10px; }
.firma-caja .guia { position: absolute; left: 16px; right: 16px; bottom: 36px; border-top: 1px solid #c8c8c8; pointer-events: none; }
.firma-caja .guia-texto { position: absolute; left: 16px; bottom: 14px; font-size: 0.8rem; color: #888; pointer-events: none; }

.ok-icono { font-size: 2.6rem; line-height: 1; }

@media (max-width: 420px) {
  .dos { grid-template-columns: 1fr; }
  .stats { gap: 6px; }
  .stat b { font-size: 1.2rem; }
}

/* ---- Panel del organizador ---- */
.barra-sup { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0 4px; padding-bottom: 4px; }
.tabs button { flex: none; min-height: 38px; padding: 6px 12px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; }
.filtros > * { flex: 1 1 160px; width: auto; }
.tabla-wrap { overflow-x: auto; }
.paginacion { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.clic { cursor: pointer; }
tr.clic:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
.firma-img { max-width: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.cuota { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.cuota input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; }
.cuota input[type="date"] { width: 150px; min-height: 36px; padding: 4px 6px; }
.avisos li { margin-bottom: 4px; }
.wide { max-width: 1100px; }
