:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #dbeafe;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

body.tv-dark {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.18);
  --success-soft: rgba(21, 128, 61, 0.25);
  --warning-soft: rgba(180, 83, 9, 0.25);
  --danger-soft: rgba(185, 28, 28, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* LOGIN */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%);
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 14px;
  padding: 2.2rem 2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.flag-bar {
  height: 6px;
  border-radius: 4px;
  margin-bottom: 1.25rem;
  background: linear-gradient(90deg, #facc15 0% 50%, #1d4ed8 50% 75%, #dc2626 75% 100%);
}

.login-title {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 800;
  color: #0f172a;
}

.login-sub {
  margin: 0 0 1.5rem;
  font-size: 0.92rem;
  color: #475569;
}

/* TOPBAR */
.topbar {
  background: #0f172a;
  color: #f8fafc;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 3px solid #2563eb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-badge {
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  padding: 0.35rem 0.6rem;
  border-radius: 7px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.brand h1 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.brand small {
  display: block;
  color: #94a3b8;
  font-size: 0.76rem;
}

.simulacro-pill {
  background: #f59e0b;
  color: #0f172a;
  font-weight: 800;
  font-size: 0.74rem;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
}

.nav-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border: 1px solid transparent;
  padding: 0.48rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  transition: all 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.nav-btn.active {
  background: #2563eb;
  color: #ffffff;
  border-color: #60a5fa;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.role-chip {
  background: #1e293b;
  border: 1px solid #334155;
  color: #93c5fd;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* LAYOUT & CARDS */
.container {
  max-width: 1460px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem 2.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.card-title {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
}

/* BOTONES Y CONTROLES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.52rem 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.btn:hover {
  filter: brightness(0.96);
}

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

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-warning {
  background: #d97706;
  border-color: #d97706;
  color: #ffffff;
}

.btn-sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.8rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.52rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.28rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
}

/* TARJETAS DE LAS 5 DIGNIDADES */
.dignidad-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

@media (max-width: 1100px) {
  .dignidad-strip {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  }
}

.dig-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.95rem;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}

.dig-card:hover {
  transform: translateY(-2px);
  border-color: #93c5fd;
}

.dig-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dig-card-title {
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.dig-card-meta {
  font-size: 0.79rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.kpi-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 800;
  margin: 0.15rem 0;
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* RANKING BARRAS CANDIDATOS */
.cand-row {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 0.65rem;
  background: var(--surface-alt);
}

.cand-row.leader {
  border-width: 2px;
}

.cand-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  flex-wrap: wrap;
}

.cand-identity {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.party-logo-box {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 3px;
  object-fit: contain;
  flex-shrink: 0;
}

.cand-photo-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  background: #e2e8f0;
  flex-shrink: 0;
}

.mini-logo-box {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 2px;
  object-fit: contain;
  flex-shrink: 0;
}

.mini-cand-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  flex-shrink: 0;
}

.media-upload-card {
  border: 1px dashed var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lista-badge {
  color: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.28rem 0.6rem;
  border-radius: 7px;
  min-width: 58px;
  text-align: center;
}

.cand-name {
  font-weight: 700;
  font-size: 1rem;
}

.cand-org {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cand-stats {
  text-align: right;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.cand-pct {
  font-size: 1.45rem;
  font-weight: 800;
}

.cand-votes {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
}

.cand-bar-track {
  height: 14px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.cand-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* WEBSTER CURULES Y TABLA */
.seats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.seat-card {
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  background: var(--surface-alt);
}

.seat-president {
  background: var(--warning-soft);
}

/* TABLAS */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td.win-cell {
  background: var(--success-soft);
  font-weight: 800;
  color: var(--success);
}

/* DIGITACIÓN */
.dig-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 980px) {
  .dig-layout {
    grid-template-columns: 1fr;
  }
}

.juntas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.5rem;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.junta-tile {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  background: var(--surface-alt);
  transition: all 0.12s;
}

.junta-tile:hover {
  border-color: #93c5fd;
}

.junta-tile.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.junta-code {
  font-weight: 800;
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
}

.mini-dots {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.mini-pill {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.st-PENDIENTE { background: #e2e8f0; color: #475569; }
.st-CUADRADA { background: #dcfce7; color: #166534; }
.st-VALIDADA { background: #15803d; color: #ffffff; }
.st-CON_NOVEDAD { background: #fee2e2; color: #991b1b; }
.st-IMPUGNADA { background: #1e293b; color: #f8fafc; }

.dignidad-selector-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.voto-input-row {
  display: grid;
  grid-template-columns: 74px 1fr 140px;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.45rem;
  background: var(--surface-alt);
}

.voto-input-row input {
  font-size: 1.18rem;
  font-weight: 800;
  text-align: right;
  padding: 0.45rem 0.65rem;
}

.cuadre-banner {
  padding: 0.8rem 1rem;
  border-radius: 9px;
  font-weight: 600;
  margin: 0.85rem 0;
  border: 1px solid var(--border);
}

.cuadre-ok {
  background: var(--success-soft);
  border-color: #86efac;
  color: #14532d;
}

.cuadre-err {
  background: var(--danger-soft);
  border-color: #fca5a5;
  color: #7f1d1d;
}

body.tv-dark .cuadre-ok { color: #bbf7d0; }
body.tv-dark .cuadre-err { color: #fecaca; }

/* DROPZONE CTRL+V WHATSAPP */
.paste-zone {
  border: 2px dashed #60a5fa;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
}

.paste-zone:hover {
  background: var(--primary-soft);
}

.preview-img {
  max-width: 100%;
  max-height: 290px;
  border-radius: 8px;
  margin-top: 0.6rem;
  border: 1px solid var(--border);
}

/* MODAL AUDITORÍA SPLIT-SCREEN */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-split {
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 1280px;
  max-height: 93vh;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45);
}

.modal-header {
  padding: 0.85rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body-split {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1rem;
  padding: 1rem 1.2rem;
  overflow-y: auto;
}

@media (max-width: 920px) {
  .modal-body-split {
    grid-template-columns: 1fr;
  }
}

.photo-viewer-stage {
  background: #0f172a;
  border-radius: 8px;
  min-height: 430px;
  max-height: 70vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.photo-viewer-stage img {
  max-width: 100%;
  transition: transform 0.2s ease;
  transform-origin: center center;
}

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  border-left: 5px solid #3b82f6;
}

.toast.ok { border-left-color: #22c55e; }
.toast.err { border-left-color: #ef4444; }

@media print {
  .topbar, .no-print {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .card {
    box-shadow: none !important;
    break-inside: avoid;
  }
}

