:root {
  --primary: #1d4e89;
  --primary-dark: #163c6b;
  --primary-soft: #eaf1fa;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e6ebf2;
  --text: #1f2a3d;
  --muted: #6b7a90;
  --danger: #d64545;
  --danger-dark: #b53737;
  --ok: #1d9d5a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 30, 54, 0.04), 0 8px 24px rgba(16, 30, 54, 0.05);
  --sidebar-w: 232px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout (una sola columna) ---------- */
.app {
  min-height: 100vh;
}

.top {
  background: var(--primary);
  color: #fff;
  padding: 18px 16px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(16, 30, 54, 0.12);
}

.top h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.una-pagina {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.destacada {
  border: 2px solid var(--primary);
  background: #fbfcfe;
}

#mensaje-personalizado {
  font-size: 1.1rem;
  padding: 14px;
}

.sub-titulo {
  font-weight: 700;
  margin: 14px 0 2px;
}

.ayuda-grande {
  color: var(--muted);
  font-size: 1rem;
  margin: 8px 0 14px;
  line-height: 1.4;
}

.btn-bloque {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.btn-enorme {
  width: 100%;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 20px;
  margin-top: 14px;
  border-radius: 16px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
}

.brand-text {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#nav-principal {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-btn.activo {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Main ---------- */
main {
  flex: 1;
  min-width: 0;
  max-width: 1080px;
  padding: 32px clamp(16px, 4vw, 40px) 64px;
  display: flex;
  flex-direction: column;
}

.seccion {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: aparecer 0.25s ease;
}

@keyframes aparecer {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-head h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-head p {
  margin-top: 4px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.card h3 + .muted { margin-top: -4px; margin-bottom: 12px; }

/* ---------- Tipografía utilitaria ---------- */
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.oculto {
  display: none !important;
}

.badge {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 0.8rem;
  font-weight: 600;
}

code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.85em;
}

/* ---------- Estado WhatsApp ---------- */
.estado-dashboard,
#estado-contenido { display: flex; flex-direction: column; gap: 8px; }

.estado-conectado {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--ok);
}

.punto-verde {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.18);
}

.qr-contenedor {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-contenedor img {
  width: 240px;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}

/* ---------- Formularios ---------- */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

input[type="text"],
input[type="date"],
input[type="file"],
textarea {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

input[type="text"] {
  flex: 1;
  min-width: 160px;
  width: auto;
}

textarea {
  resize: vertical;
  margin-bottom: 12px;
}

input::placeholder,
textarea::placeholder { color: #9aa7b8; }

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- Botones ---------- */
.btn {
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-peligro {
  background: #fff;
  color: var(--danger);
  border-color: #f1cfcf;
}

.btn-peligro:hover { background: #fdf0f0; }

.btn-chico {
  padding: 6px 12px;
  font-size: 0.83rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Tablas ---------- */
.tabla-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 480px;
}

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--bg); }

td.acciones {
  white-space: nowrap;
  display: flex;
  gap: 6px;
}

/* ---------- Fotos / preview ---------- */
.fotos input[type="file"] {
  margin: 4px 0 12px;
}

.preview-fotos {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.foto-miniatura {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.caption-input { margin-bottom: 12px; }

/* ---------- Barra de progreso ---------- */
.barra-contenedor {
  width: 100%;
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 10px;
}

.barra-progreso {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* ---------- Inicio / bienvenida ---------- */
.inicio-head h1 { font-size: 2.1rem; }

.bienvenida {
  margin-top: 8px;
  font-size: 1.2rem;
  color: var(--muted);
}

/* ---------- Botones de acción grandes ---------- */
.acciones-grandes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.accion-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 28px 20px;
  border: none;
  border-radius: 20px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 8px 22px rgba(16, 30, 54, 0.14);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}

.accion-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(16, 30, 54, 0.2);
  filter: brightness(1.04);
}

.accion-card:active { transform: translateY(0); }

.accion-azul { background: linear-gradient(135deg, #2563eb, #1d4e89); }
.accion-verde { background: linear-gradient(135deg, #25b15f, #15803d); }
.accion-celeste { background: linear-gradient(135deg, #0ea5c4, #0f7e9b); }

.accion-emoji { font-size: 3rem; line-height: 1; }

.accion-texto {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.accion-sub {
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.92;
}

/* ---------- Dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  box-shadow: var(--shadow);
}

.stat-emoji { font-size: 1.9rem; line-height: 1; margin-bottom: 4px; }

.stat-valor {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}

.stat-titulo {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.dashboard-cumples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.lista-cumples {
  list-style: none;
  margin-top: 10px;
}

.lista-cumples li {
  padding: 12px 0;
  font-size: 1.08rem;
  border-bottom: 1px solid var(--border);
}

.lista-cumples li:last-child { border-bottom: none; }

.tag {
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 6px;
  white-space: nowrap;
}

.tag-ok { background: #e2f6ec; color: var(--ok); }
.tag-pendiente { background: #fdeed0; color: #9c6500; }

.mensaje-cumple {
  background: #fdf8ef;
  border-color: #f1e3c6;
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }

  .app { flex-direction: column; }

  /* Sidebar se convierte en barra de navegación inferior fija */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 16px rgba(16, 30, 54, 0.06);
    z-index: 50;
  }

  .brand { display: none; }

  #nav-principal {
    flex-direction: row;
    width: 100%;
    gap: 2px;
  }

  .nav-btn {
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 10px;
    justify-content: center;
    text-align: center;
  }

  .nav-btn svg { width: 26px; height: 26px; }

  main {
    padding: 22px 16px 104px;
  }

  .page-head h1 { font-size: 1.5rem; }
  .inicio-head h1 { font-size: 1.8rem; }
  .bienvenida { font-size: 1.1rem; }
}

/* ---------- Barra de importación CSV ---------- */
.importar-barra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.importar-barra p { margin: 4px 0 0; max-width: 60ch; }

/* ---------- Formulario de contacto (amigable) ---------- */
.card-sub { margin: -4px 0 16px; }

.form-contacto {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.campo {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.campo label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.campo .opcional {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
}

.campo input {
  font-size: 1.05rem;
  padding: 13px 14px;
}

.campo .ayuda {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.form-acciones {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.btn-grande {
  font-size: 1.02rem;
  padding: 14px 24px;
}

/* ---------- Buscador ---------- */
.buscar-input {
  width: 100%;
  margin-bottom: 16px;
  font-size: 1rem;
  padding: 12px 14px;
}

input[type="search"] {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- Resultado de importación ---------- */
.import-resultado {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  line-height: 1.6;
}

.import-resultado div + div { margin-top: 2px; }

.import-cargando { background: var(--bg); color: var(--muted); }
.import-ok { background: #e2f6ec; color: #15703f; border: 1px solid #bfe6cf; }
.import-error { background: #fdecec; color: var(--danger-dark); border: 1px solid #f3c9c9; }

/* ---------- Avisos flotantes (toast) ---------- */
#toast-cont {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: 92vw;
  pointer-events: none;
}

.toast {
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 6px 24px rgba(16, 30, 54, 0.22);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast-ok { background: #1d9d5a; }
.toast-error { background: var(--danger); }

/* ---------- Responsive: móvil ---------- */
@media (max-width: 560px) {
  .card { padding: 18px; }

  .importar-barra { flex-direction: column; align-items: stretch; }
  .importar-barra .btn { width: 100%; }

  .form-row { flex-direction: column; }

  .form-row input[type="text"],
  .form-row .btn { width: 100%; min-width: 0; }

  .form-acciones { flex-direction: column; }
  .form-acciones .btn { width: 100%; }

  .stat-valor { font-size: 1.7rem; }

  /* La lista de contactos se ve como tarjetas, no como tabla apretada */
  #tabla-votantes,
  #tabla-votantes thead,
  #tabla-votantes tbody,
  #tabla-votantes tr,
  #tabla-votantes td { display: block; width: 100%; }

  #tabla-votantes { min-width: 0; }

  #tabla-votantes thead { display: none; }

  #tabla-votantes tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 12px;
  }

  #tabla-votantes td {
    border: none;
    padding: 4px 0;
  }

  #tabla-votantes td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--muted);
  }

  #tabla-votantes tr:hover td { background: transparent; }

  #tabla-votantes td.acciones {
    display: flex;
    gap: 8px;
    margin-top: 8px;
  }

  #tabla-votantes td.acciones::before { content: none; }
  #tabla-votantes td.acciones .btn { flex: 1; }

  /* Otras tablas siguen con scroll horizontal normal */
  td.acciones { flex-direction: column; }
  td.acciones .btn { width: 100%; }
}
