:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #5d6882;
  --line: #e2e7f0;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- barra superior ---------- */
.topbar {
  background: var(--primary-dark);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .marca { font-weight: 700; font-size: 1.05rem; }
.topbar .marca span { opacity: .75; font-weight: 500; }
.topbar .espacio { flex: 1; }
.topbar .quien { font-size: .85rem; opacity: .9; text-align: right; }
.topbar button { background: rgba(255,255,255,.14); color: #fff; border: 0; }
.topbar button:hover { background: rgba(255,255,255,.24); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  overflow-x: auto;
  position: sticky;
  top: 52px;
  z-index: 19;
}
.tabs button {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.tabs button.activo { color: var(--primary); border-bottom-color: var(--primary); }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
main.estrecho { max-width: 640px; }

/* ---------- tarjetas ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card > h2 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.dos { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.dos { grid-template-columns: 3fr 2fr; } }

.kpi { padding: 14px 16px; margin: 0; }
.kpi .etq { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .valor { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: .85rem; }
.kpi.malo .valor { color: var(--bad); }

/* ---------- formularios ---------- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
input, select, button, textarea { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c9d1df;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.campo { margin-bottom: 12px; }
.fila { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.fila > * { flex: 1 1 160px; }
.fila > .auto { flex: 0 0 auto; }

button {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid #c9d1df;
  background: #fff;
  color: var(--text);
  padding: 9px 14px;
  font-weight: 600;
  min-height: 40px;
}
button:hover { background: #f1f4f9; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primario { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primario:hover { background: var(--primary-dark); }
button.peligro { color: var(--bad); border-color: #f0c4c4; }
button.peligro:hover { background: var(--bad-soft); }
button.grande { width: 100%; padding: 14px; font-size: 1.05rem; min-height: 52px; }
button.link { border: 0; background: none; color: var(--primary); padding: 4px 6px; min-height: 0; }

/* ---------- tablas ---------- */
.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8f9fc; }
td.der, th.der { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f6f8fd; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.malo { background: var(--bad-soft); color: var(--bad); }
.chip.pend { background: #eef1f6; color: var(--muted); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- barras ---------- */
.barras { display: flex; flex-direction: column; gap: 12px; }
.barra { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.barra .logo, .logo {
  width: 40px; height: 40px; border-radius: 8px; object-fit: contain; background: #f1f4f9; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); font-size: .8rem;
}
.barra .nombre { font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.barra .pista { height: 12px; background: #eef1f6; border-radius: 6px; overflow: hidden; }
.barra .relleno { height: 100%; background: var(--primary); border-radius: 6px; transition: width .5s; }
.barra:first-child .relleno { background: var(--ok); }
.barra .cifra { text-align: right; min-width: 90px; }
.barra .cifra b { display: block; font-size: 1.05rem; }
.progreso { height: 8px; background: #eef1f6; border-radius: 4px; overflow: hidden; min-width: 80px; }
.progreso > div { height: 100%; background: var(--primary); }

.vivo { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); font-weight: 500; }
.vivo::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulso 1.6s infinite; }
@keyframes pulso { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- modal ---------- */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto;
}
.modal { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.ancho { max-width: 900px; }
.modal .acciones { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,.25); font-weight: 500;
}
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

.aviso { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 500; }
.aviso.ok { background: var(--ok-soft); color: var(--ok); }
.aviso.malo { background: var(--bad-soft); color: var(--bad); }
.aviso.warn { background: var(--warn-soft); color: var(--warn); }
.aviso.info { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 400px; }
.login .cabeza { text-align: center; margin-bottom: 20px; }
.login .escudo {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 16px; background: var(--primary-dark); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
}

/* ---------- delegado ---------- */
.junta-info { background: var(--primary-soft); border-color: #cfdcff; }
.junta-info .titulo { font-size: 1.25rem; font-weight: 700; color: var(--primary-dark); }
.foto-acta { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; margin-top: 12px; }
.fila-voto {
  display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.fila-voto:last-child { border-bottom: 0; }
.fila-voto .logo { width: 48px; height: 48px; flex: 0 0 48px; }
.fila-voto .nombre { flex: 1; font-weight: 600; }
.fila-voto input { width: 110px; flex: 0 0 110px; text-align: right; font-size: 1.15rem; font-weight: 600; }
.fila-voto.total .nombre { color: var(--primary-dark); }
.barra-suma {
  position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); margin: 0 -16px; box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
.barra-suma .estado { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.pendiente-envio { position: sticky; top: 52px; z-index: 10; }

.foto-grande { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.acta-detalle { display: grid; gap: 16px; }
@media (min-width: 760px) { .acta-detalle { grid-template-columns: 1fr 1fr; } }

@media (max-width: 600px) {
  .topbar .quien { display: none; }
  main { padding: 12px; }
  .card { padding: 14px; }
  .kpi .valor { font-size: 1.4rem; }
  .ocultar-movil { display: none; }
}
