:root {
  --bg: #ffffff;
  --bg-2: #f4f6f3;
  --ink: #15201a;
  --muted: #5f6b64;
  --line: #e2e7e3;
  --pri: #14532d;
  --pri-ink: #ffffff;
  --pri-soft: #e6f2ea;
  --leve: #22a35a;
  --considerable: #f08c00;
  --peligroso: #e03131;
  --reparado: #868e96;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(16, 32, 22, 0.16);
  --panel-w: 310px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { margin: 0; }

#app { position: fixed; inset: 0; display: flex; }

/* ---------- Panel lateral ---------- */
.panel {
  width: var(--panel-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line);
  z-index: 500;
}
.panel-head { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 22px;
  background: var(--pri);
}
.titulos { flex: 1; min-width: 0; }
.titulos h1 { font-size: 18px; letter-spacing: -0.01em; }
.titulos p { margin: 2px 0 0; font-size: 13px; }
.panel-body { flex: 1; overflow-y: auto; padding: 0 18px 18px; }
.resumen {
  background: var(--bg-2); border-radius: var(--radius); padding: 14px; margin-bottom: 18px;
  font-size: 15px;
}
.resumen strong { font-size: 22px; }
.resumen span { display: block; font-size: 13px; margin-top: 2px; }
section h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 8px;
}
section + section { margin-top: 18px; }
.filtros { display: flex; flex-direction: column; gap: 4px; }
.filtro {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: transparent; padding: 9px 10px; border-radius: 10px;
  cursor: pointer; text-align: left; font-size: 14px;
}
.filtro:hover { background: var(--bg-2); }
.filtro.activo { background: var(--ink); color: #fff; }
.filtro .n {
  margin-left: auto; min-width: 26px; text-align: center; font-size: 12px; font-weight: 600;
  background: var(--bg-2); color: var(--muted); border-radius: 99px; padding: 2px 8px;
}
.filtro.activo .n { background: rgba(255, 255, 255, 0.18); color: #fff; }
.punto { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.nota { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; line-height: 1.5; }
.nota p { margin: 0 0 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 999px; padding: 10px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform 0.08s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-pri { background: var(--pri); color: var(--pri-ink); }
.btn-pri:hover { background: #166534; }
.btn-sec { background: var(--bg); border-color: var(--line); color: var(--ink); }
.btn-sec:hover { background: var(--bg-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-wa { background: #25d366; color: #06371b; }
.btn-grande { padding: 14px 22px; font-size: 15px; box-shadow: var(--shadow); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--bg-2);
  cursor: pointer; font-size: 16px; flex: none;
}
.solo-movil { display: none; }

/* ---------- Mapa ---------- */
.mapa-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #e8ece6; }
#map.pick { cursor: crosshair; }
.acciones-mapa {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 450;
}
.hint {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 460;
  background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; text-align: center; width: max-content; max-width: calc(100% - 32px);
}
.hint p { margin: 0 0 10px; }
.fila { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.cargando {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 450;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13px;
}
.leaflet-container { font: inherit; }
.pin-temp {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--pri); border: 3px solid #fff; box-shadow: var(--shadow);
}

/* ---------- Detalle ---------- */
.sheet {
  position: absolute; z-index: 1100; background: var(--bg); box-shadow: var(--shadow);
  top: 16px; right: 16px; width: 360px; max-height: calc(100% - 32px); overflow-y: auto;
  border-radius: 18px;
}
.sheet .cerrar { position: absolute; top: 10px; right: 10px; z-index: 2; background: rgba(255,255,255,.9); }
.det-foto { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--bg-2); border-radius: 18px 18px 0 0; }
.det-sinfoto { padding: 26px; text-align: center; background: var(--bg-2); border-radius: 18px 18px 0 0; font-size: 34px; }
.det-cuerpo { padding: 16px 18px 18px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--bg-2);
}
.det-dir { font-size: 16px; font-weight: 650; margin: 0 0 4px; }
.det-desc { margin: 8px 0; line-height: 1.45; }
.det-meta { font-size: 13px; margin: 0 0 14px; }
.votos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.voto {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px;
  cursor: pointer; text-align: center; font-size: 13px; font-weight: 600;
}
.voto b { display: block; font-size: 20px; }
.voto.mio { border-color: var(--pri); background: var(--pri-soft); }
.det-acciones { display: flex; flex-direction: column; gap: 8px; }
.det-acciones .btn { width: 100%; }

/* ---------- Diálogo ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 20, 14, 0.45); }
dialog form { padding: 18px 20px 20px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.dlg-head h2 { font-size: 19px; }
.ubic { font-size: 13px; margin: 0 0 14px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend, .campo > span { font-weight: 600; font-size: 14px; margin-bottom: 6px; display: block; }
.gravedades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gravedades label { cursor: pointer; }
.gravedades input { position: absolute; opacity: 0; pointer-events: none; }
.gravedades span {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 4px; font-size: 18px; height: 100%;
}
.gravedades b { font-size: 13px; }
.gravedades small { font-size: 11px; color: var(--muted); }
.gravedades input:checked + span { border-color: var(--pri); background: var(--pri-soft); }
.gravedades input:focus-visible + span { outline: 2px solid var(--pri); outline-offset: 2px; }
.campo { display: block; margin-bottom: 12px; }
.campo input[type='text'], .campo textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg);
}
.campo input[type='file'] { width: 100%; font-size: 13px; }
.campo textarea { resize: vertical; }
.prev-foto { margin-top: 8px; width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; }
.error { color: var(--peligroso); background: #fff0f0; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.error .btn { margin-top: 8px; }
.dlg-pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 2000;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .panel { width: 100%; border-right: 0; border-bottom: 1px solid var(--line); max-height: 70%; }
  .panel-head { padding: 10px 16px; }
  .logo { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
  .titulos h1 { font-size: 16px; }
  .titulos p { font-size: 12px; }
  .solo-movil { display: block; }
  .panel-body { display: none; padding: 0 16px 16px; }
  .panel.abierto .panel-body { display: block; }
  .acciones-mapa { top: auto; bottom: calc(22px + env(safe-area-inset-bottom)); }
  .sheet {
    top: auto; right: 0; left: 0; bottom: 0; width: 100%; max-height: 78%;
    border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .gravedades span small { display: none; }
  .det-foto { aspect-ratio: auto; height: 32vh; }
}
