/* ==========================================================================
   Smart Vote — Design System
   Paleta institucional neutral: azul confianza · cian progreso · ámbar
   pendientes · rojo suave alertas · grises fondo. Sin dependencia de build.
   ========================================================================== */
:root {
  --brand:      #0B2A4A;   /* azul profundo — confianza */
  --brand-600:  #123A63;
  --brand-500:  #1B4E86;
  --accent:     #0FB8A6;   /* cian/verde — progreso */
  --accent-600: #0B9A8B;
  --warn:       #F5A524;   /* ámbar — pendientes */
  --danger:     #EF5350;   /* rojo suave — alertas */
  --ok:         #16A34A;
  --info:       #2563EB;

  --bg:      #F4F6FA;
  --surface: #FFFFFF;
  --line:    #E5E9F0;
  --line-2:  #EEF1F6;
  --ink:     #10203A;
  --ink-2:   #4A5A72;
  --ink-3:   #5F6A7C;   /* darkened for WCAG AA (4.5:1 on white) */

  --radius:   14px;
  --radius-sm:10px;
  --shadow:   0 1px 2px rgba(16,32,58,.04), 0 6px 20px rgba(16,32,58,.06);
  --shadow-lg:0 10px 40px rgba(16,32,58,.14);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
[x-cloak] { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd6e4; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }

/* ------------------------------- App shell ------------------------------ */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--brand) 0%, #08213B 100%);
  color: #C7D4E5; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px 18px;
}
.sidebar__logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #12CBB6);
  display: grid; place-items: center; color: #04241F; flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(15,184,166,.4);
}
.sidebar__logo-img {
  height: 44px; width: auto; flex-shrink: 0;
  filter: drop-shadow(0 3px 8px rgba(15,184,166,.45));
}
.sidebar__name { color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -.3px; line-height: 1.1; }
.sidebar__tag  { font-size: 10.5px; color: #7E93AD; letter-spacing: .2px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 12px; overflow-y: auto; }
.nav__section { font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: #5E738F; padding: 16px 10px 6px; }
.nav__link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  color: #B4C3D8; transition: background .12s, color .12s;
}
.nav__link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav__link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav__link.active { background: linear-gradient(90deg, rgba(15,184,166,.24), rgba(15,184,166,.05)); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav__link.active svg { opacity: 1; color: var(--accent); }
.sidebar__user {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
}

/* ------------------------------- Main area ------------------------------ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 15px 26px; background: rgba(255,255,255,.86); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 0 rgba(16,32,58,.02), 0 6px 18px -12px rgba(16,32,58,.18);
}
.topbar h1 { font-size: 18px; font-weight: 750; letter-spacing: -.4px; margin: 0; }
.topbar__sub { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; }
.content { padding: 24px 26px 40px; }

/* ------------------------------- Avatar --------------------------------- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--brand-500));
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  flex-shrink: 0; overflow: hidden; box-shadow: 0 0 0 2px rgba(255,255,255,.6), 0 1px 3px rgba(16,32,58,.15);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar--xs { width: 22px; height: 22px; font-size: 9px; }
.avatar--sm { width: 28px; height: 28px; font-size: 10.5px; }
.avatar--lg { width: 44px; height: 44px; font-size: 15px; }
.avatar--xl { width: 52px; height: 52px; font-size: 18px; }

/* ------------------------------- Cards ---------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__head { padding: 16px 20px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card__title { font-size: 14.5px; font-weight: 700; margin: 0; }
.card__body { padding: 18px 20px; }
.card__foot { padding: 12px 20px; border-top: 1px solid var(--line-2); }

/* KPI grid */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { background: linear-gradient(180deg, #fff, #FCFDFF); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 19px; box-shadow: var(--shadow); position: relative; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
.kpi::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(180deg, var(--accent), var(--brand-500)); opacity: .0; transition: opacity .2s; }
.kpi:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(16,32,58,.11); }
.kpi:hover::after { opacity: .9; }
.kpi__icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 12px; transition: transform .2s ease; }
.kpi:hover .kpi__icon { transform: scale(1.06); }
.kpi__val { font-size: 27px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.kpi__label { font-size: 12.5px; color: var(--ink-2); margin-top: 5px; font-weight: 500; }
.kpi__delta { font-size: 11.5px; font-weight: 600; margin-top: 8px; display: inline-flex; align-items: center; gap: 4px; }
.tint-brand  { background: rgba(27,78,134,.12);  color: var(--brand-500); }
.tint-accent { background: rgba(15,184,166,.14);  color: var(--accent-600); }
.tint-warn   { background: rgba(245,165,36,.16);  color: #B9791A; }
.tint-danger { background: rgba(239,83,80,.14);   color: var(--danger); }
.tint-info   { background: rgba(37,99,235,.12);   color: var(--info); }
.tint-ok     { background: rgba(22,163,74,.13);   color: var(--ok); }

/* ------------------------------- Grid utils ----------------------------- */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mt-0{margin-top:0} .mb-0{margin-bottom:0} .ml-auto{margin-left:auto}
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* ------------------------------- Badges --------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  white-space: nowrap; line-height: 1.6;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-new     { background: #EEF2F7; color: #566379; }
.b-pending { background: rgba(245,165,36,.15); color: #8A5D0D; }
.b-valid   { background: rgba(37,99,235,.12); color: #1D4ED8; }
.b-confirm { background: rgba(22,163,74,.13); color: #157A38; }
.b-inactive{ background: #F0F1F4; color: #5F6A7C; }
.b-dup     { background: rgba(239,83,80,.12); color: #B23531; }
.b-dnc     { background: #2B2F36; color: #E4E6EA; }
.b-ok      { background: rgba(15,184,166,.15); color: #0A6E63; }
.b-off     { background: #EEF2F7; color: #5A6472; }
.b-danger  { background: rgba(239,83,80,.13); color: #B23531; }
.b-warn    { background: rgba(245,165,36,.15); color: #8A5D0D; }
.b-info    { background: rgba(37,99,235,.12); color: #1D4ED8; }
.role-badge{ background: rgba(11,42,74,.08); color: var(--brand-500); font-weight: 700; }

/* ------------------------------- Tables --------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-3); padding: 11px 14px;
  border-bottom: 1px solid var(--line); background: #FAFBFD; white-space: nowrap;
}
table.data tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:hover { background: #FAFBFE; }
table.data tbody tr:last-child td { border-bottom: none; }
.cell-strong { font-weight: 650; }
.cell-mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; font-size: 12.5px; color: var(--ink-2); }

/* ------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 600; padding: 9px 15px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; transition: all .13s; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(11,42,74,.24); }
.btn-primary:hover { background: var(--brand-600); }
.btn-accent { background: var(--accent); color: #04322C; }
.btn-accent:hover { background: var(--accent-600); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { border-color: #cdd6e4; color: var(--ink); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-danger { background: rgba(239,83,80,.1); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 9px; }

/* ------------------------------- Forms ---------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--ink);
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  transition: border .13s, box-shadow .13s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(27,78,134,.1);
}
textarea { resize: vertical; min-height: 80px; }
.hint { font-size: 11.5px; color: var(--ink-3); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }

/* Filter bar */
.filterbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filterbar .field { margin: 0; min-width: 140px; flex: 1; }
.filterbar select, .filterbar input { padding: 8px 11px; font-size: 13px; }

/* ------------------------------- Alerts --------------------------------- */
.alert { padding: 11px 15px; border-radius: 11px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.alert-success { background: rgba(22,163,74,.1); color: #146c31; }
.alert-error   { background: rgba(239,83,80,.11); color: #b23430; }
.alert-info    { background: rgba(37,99,235,.09); color: #1e429f; }
.alert-warn    { background: rgba(245,165,36,.13); color: #97640f; }
.notice {
  background: linear-gradient(90deg, rgba(15,184,166,.08), rgba(27,78,134,.05));
  border: 1px solid rgba(15,184,166,.25); border-radius: 12px; padding: 14px 16px;
  font-size: 12.5px; color: var(--ink-2); display: flex; gap: 11px; align-items: flex-start;
}

/* ------------------------------- Misc ----------------------------------- */
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 4px 0 12px; }
.empty { text-align: center; padding: 46px 20px; color: var(--ink-3); }
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 12px; }
.divider { height: 1px; background: var(--line-2); margin: 16px 0; }
.pill-tab { display: inline-flex; gap: 4px; background: #EEF1F6; padding: 4px; border-radius: 11px; }
.pill-tab a { padding: 6px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.pill-tab a.active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

/* progress bar */
.prog { height: 7px; background: #EAEEF4; border-radius: 999px; overflow: hidden; }
.prog > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #16C9B7); }

/* meta list on profile */
.meta { display: grid; grid-template-columns: 130px 1fr; gap: 9px 14px; font-size: 13px; }
.meta dt { color: var(--ink-3); font-weight: 500; }
.meta dd { margin: 0; font-weight: 550; }

/* timeline */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2.5px solid var(--accent); }
.tl-item:last-child { padding-bottom: 0; }

/* chart canvas sizing */
.chart-box { position: relative; height: 240px; }
.chart-box--sm { height: 180px; }

/* map */
#map { height: 620px; border-radius: var(--radius); }
/* Custom branded pin para centros (evita el bug del marker por defecto de Leaflet). */
.sv-pin { width: 30px; height: 30px; position: relative; }
.sv-pin > span {
  position: absolute; inset: 0; margin: auto; width: 30px; height: 30px;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: linear-gradient(135deg, var(--brand-500), var(--brand));
  border: 2px solid #fff; box-shadow: 0 3px 9px rgba(11,42,74,.45);
  display: grid; place-items: center;
}
.sv-pin > span::after {
  content: attr(data-c); transform: rotate(45deg); color: #fff; font-size: 10.5px; font-weight: 700;
}
/* Popups Leaflet más pulidos. */
.leaflet-popup-content-wrapper { border-radius: 12px; box-shadow: 0 8px 28px rgba(16,32,58,.18); }
.leaflet-popup-content { font-family: var(--sans); font-size: 12.5px; line-height: 1.55; margin: 11px 14px; color: var(--ink); }
.leaflet-popup-content b { font-size: 13px; }
.leaflet-popup-content a { color: var(--brand-500); font-weight: 600; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 3px 0; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }

/* login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-aside {
  background: linear-gradient(150deg, var(--brand) 0%, #06192E 55%, #071E38 100%);
  color: #fff; padding: 52px 56px; display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.login-aside::after {
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px;
  background: radial-gradient(circle, rgba(15,184,166,.35), transparent 70%); border-radius: 50%;
}
.login-form-side { display: grid; place-items: center; padding: 40px; }
.login-card { width: 100%; max-width: 380px; }
.demo-creds { background: #F7F9FC; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 12px; }
.demo-creds__row { display: flex; justify-content: space-between; padding: 4px 0; cursor: pointer; border-radius: 6px; }
.demo-creds__row:hover { background: #EEF2F8; }

/* ------------------------- Accessibility & polish ----------------------- */
/* Visible keyboard focus on every interactive element (was inputs-only). */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible,
select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(27,78,134,.55); outline-offset: 2px; border-radius: 8px;
}
.btn-primary:focus-visible, .btn-accent:focus-visible { outline-color: rgba(15,184,166,.7); }
.nav__link:focus-visible { outline: 2px solid rgba(15,184,166,.85); outline-offset: -2px; }
.sidebar__user a:focus-visible { outline-color: rgba(255,255,255,.6); }
.demo-creds__row:focus-visible { outline: 3px solid rgba(27,78,134,.5); outline-offset: 1px; }

/* Tabular figures so KPI/data digits don't shift. */
.kpi__val, .cell-mono, table.data td { font-variant-numeric: tabular-nums; }

/* Larger comfortable hit area for small icon buttons (visual stays compact). */
.icon-btn { position: relative; }
.icon-btn::after { content: ""; position: absolute; inset: -6px; }

select { cursor: pointer; }

/* Mobile drawer toggle — hidden on desktop. */
.menu-btn, .drawer-backdrop { display: none; }

/* Premium micro-interactions (respetan reduced-motion). */
.card { transition: box-shadow .2s ease, transform .2s ease; }
.content .card:hover { box-shadow: 0 10px 30px rgba(16,32,58,.09); }
table.data tbody tr { transition: background .12s ease; }
.btn { transition: transform .12s ease, background .13s ease, box-shadow .13s ease, border-color .13s ease; }
.btn:active { transform: translateY(1px); }
.nav__link { transition: background .14s ease, color .14s ease, padding-left .14s ease; }
.nav__link:hover { padding-left: 14px; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* Sin transform: no rompe el posicionamiento de mapas Leaflet dentro del contenedor. */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: no-preference) {
  .kpis .kpi { animation: fadeUp .5s cubic-bezier(.22,1,.36,1) both; }
  .kpis .kpi:nth-child(1) { animation-delay: .02s; }
  .kpis .kpi:nth-child(2) { animation-delay: .08s; }
  .kpis .kpi:nth-child(3) { animation-delay: .14s; }
  .kpis .kpi:nth-child(4) { animation-delay: .20s; }
  .content > .grid, .content > .card, .content > .stack { animation: fadeIn .45s ease both; animation-delay: .1s; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ------------------------------- Responsive ----------------------------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .g-2, .g-3, .g-2-1, .form-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-aside { display: none; }

  /* Sidebar becomes an off-canvas drawer instead of disappearing. */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100dvh; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(8,21,40,.5);
  }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 13px 16px; }
  .content { padding: 18px 16px 40px; }
  #map { height: 460px; }
}

@media (max-width: 620px) {
  .kpis { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 16px; }
  .grid[style*="280px"] { grid-template-columns: 1fr !important; }
}
