/* PrismaElectoral — Dashboards concejales (alfa). Sistema de diseño compartido,
   consolidado desde los mockups de análisis y simulación D'Hondt. */
:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e7eaf0;
  --text: #101828;
  --muted: #667085;
  --purple: #5b2bbd;
  --purple-2: #7b4ce6;
  --purple-soft: #f2ecff;
  --nav: #071d33;
  --green: #16a34a;
  --orange: #f97316;
  --yellow: #f8c14a;
  --red: #ef4444;
  --gray: #c9cbd1;
  --blue: #2563eb;
  --shadow: 0 12px 30px rgba(16, 24, 40, .06);
  --radius: 16px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --side-w: 288px;
  --side-w-collapsed: 78px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; }
a { color: inherit; }

.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; transition: grid-template-columns .18s ease; }
body.side-collapsed .app { grid-template-columns: var(--side-w-collapsed) 1fr; }

/* ── Sidebar (independiente: sticky, scroll propio) ──────────────────── */
.sidebar {
  background: linear-gradient(180deg, #061a2e 0%, #08233d 100%); color: #fff; padding: 24px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.brand-text { min-width: 0; flex: 1; }
.star {
  width: 42px; height: 42px; border-radius: 12px;
  background: conic-gradient(from 20deg, #f97316, #facc15, #22c55e, #06b6d4, #4338ca, #ef4444, #f97316);
  clip-path: polygon(50% 0%, 61% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 34%);
  flex: 0 0 auto;
}
.brand h1 { margin: 0; font-size: 24px; line-height: 1; white-space: nowrap; }
.brand p { margin: 4px 0 0; color: #d2d8e2; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Botón contraer / expandir */
.side-toggle {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
  color: #d8e0ea; display: grid; place-items: center; transition: .15s ease;
}
.side-toggle:hover { background: rgba(255,255,255,.16); color: #fff; }
.side-toggle svg { width: 18px; height: 18px; stroke-width: 2.2; transition: transform .18s ease; }

.nav { display: grid; gap: 8px; }
.nav a {
  color: #d8e0ea; text-decoration: none; display: flex; align-items: center; gap: 13px;
  padding: 13px 14px; border-radius: 12px; font-size: 14.5px; transition: .15s ease; white-space: nowrap;
}
.nav a.active { background: linear-gradient(90deg, var(--purple), var(--purple-2)); color: #fff; box-shadow: 0 8px 18px rgba(91, 43, 189, .3); }
.nav a:hover:not(.active) { background: rgba(255, 255, 255, .08); }
.nav a.disabled { opacity: .4; pointer-events: none; }
.nav svg { width: 22px; height: 22px; stroke-width: 1.9; flex: 0 0 auto; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }
.side-foot { margin-top: auto; padding-top: 18px; }
.side-foot small { color: #6b7c93; font-size: 11px; line-height: 1.5; display: block; }

/* ── Estado contraído (sólo iconos) ─────────────────────────────────── */
body.side-collapsed .sidebar { padding: 24px 12px; align-items: stretch; }
body.side-collapsed .brand { flex-direction: column; gap: 14px; margin-bottom: 28px; }
body.side-collapsed .brand-text { display: none; }
body.side-collapsed .nav-label { display: none; }
body.side-collapsed .nav a { justify-content: center; padding: 13px 0; }
body.side-collapsed .side-toggle svg { transform: rotate(180deg); }
body.side-collapsed .side-foot { display: none; }

/* ── Main / topbar ───────────────────────────────────── */
.main { padding: 22px 30px 28px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.title { min-width: 0; }
.title h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.session { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.userbox { text-align: right; }
.userbox b { display: block; font-size: 14px; }
.userbox span { font-size: 12px; color: var(--muted); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: linear-gradient(135deg, var(--purple), var(--purple-2)); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; text-transform: uppercase; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px 16px; font-weight: 700; color: #344054; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.btn:hover { background: #f8f9fc; }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.run { border-color: #d9ccff; color: var(--purple); background: #fff; }

/* ── Selectores ──────────────────────────────────────── */
.selectors, .controls { display: grid; gap: 18px; align-items: end; margin-bottom: 20px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: #344054; margin-bottom: 8px; }
.segmented, select {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; min-height: 48px; display: flex; overflow: hidden;
}
.segmented button { border: 0; background: transparent; padding: 0 22px; font-weight: 700; color: #344054; cursor: pointer; }
.segmented button.active { background: var(--purple); color: #fff; }
select { width: 100%; padding: 0 18px; font-size: 15px; color: #101828; }
input[type="number"] { width: 64px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; text-align: center; font-weight: 800; color: #101828; background: #fff; }
input[type="range"] { width: 100%; accent-color: var(--purple); }
.actions { display: flex; justify-content: flex-end; gap: 12px; align-items: end; flex-wrap: wrap; }

/* ── Cards / grids ───────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { margin: 0 0 6px; font-size: 18px; }
.card .sub, .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.span2 { grid-column: span 2; }

/* ── KPIs ────────────────────────────────────────────── */
.kpis { display: grid; gap: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-height: 132px; }
.kpi-top { display: flex; gap: 12px; align-items: flex-start; color: #344054; font-size: 13px; font-weight: 700; }
.icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple); flex: none; }
.kpi .value { font-size: 31px; font-weight: 850; margin: 12px 0 4px; letter-spacing: -.02em; text-align: center; }
.kpi small { color: var(--muted); display: block; text-align: center; }
.delta { color: var(--green); font-size: 12px; font-weight: 800; margin-top: 6px; text-align: center; }
.delta.down { color: var(--red); }
.progress { height: 7px; background: #eef0f4; border-radius: 999px; margin-top: 12px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 999px; background: var(--green); }
.progress.orange span { background: var(--orange); }

/* ── Pesos / ponderación ─────────────────────────────── */
.weights .row { display: grid; grid-template-columns: 150px 1fr 84px; gap: 12px; align-items: center; margin: 13px 0; font-size: 14px; }
.weights .row.disabled { opacity: .5; }
.pct { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-weight: 800; }
.tag-nd { font-size: 10px; font-weight: 800; color: #9a3412; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 6px; padding: 2px 6px; }
.total-ok { margin-top: 16px; background: var(--purple-soft); color: #43218e; border: 1px solid #e1d5ff; padding: 13px 14px; border-radius: 12px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 800; }
.total-ok.warn { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.note { margin-top: 16px; background: var(--purple-soft); color: #43218e; border: 1px solid #e1d5ff; padding: 14px; border-radius: 12px; display: flex; gap: 10px; font-size: 13px; align-items: center; }
.note.warn { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }

/* ── Tablas ──────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: #667085; font-size: 12px; font-weight: 800; }
.high { color: var(--green); font-weight: 800; }
.med { color: var(--orange); font-weight: 800; }
.low { color: var(--muted); }
.link { color: var(--purple); font-weight: 800; text-align: center; margin-top: 12px; cursor: pointer; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 10px; background: var(--purple); }
.mini-select { height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: #fff; min-width: 150px; font-size: 12px; }

/* ── Donut ───────────────────────────────────────────── */
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 14px; align-items: center; min-height: 210px; }
.donut { width: 140px; height: 140px; border-radius: 50%; position: relative; }
.donut:after { content: ""; position: absolute; inset: 36px; background: #fff; border-radius: 50%; }
.legend-list { font-size: 12px; color: #344054; display: grid; gap: 10px; }
.legend-list div { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.legend-list .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 7px; }

/* ── Barras ──────────────────────────────────────────── */
.chart { height: 230px; position: relative; padding: 16px 8px 4px 38px; }
.bars { height: 150px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: flex-end; gap: 14px; padding: 0 16px; position: relative; }
.bar { flex: 1; max-width: 40px; background: linear-gradient(180deg, var(--purple-2), var(--purple)); border-radius: 6px 6px 0 0; position: relative; }
.bar:after { content: attr(data-v); position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 800; color: #101828; white-space: nowrap; }
.bar.nd { background: repeating-linear-gradient(45deg, #e9ecf3, #e9ecf3 6px, #f4f6fa 6px, #f4f6fa 12px); }
.xlabels { display: flex; gap: 14px; margin-left: 40px; font-size: 11px; color: #475467; text-align: center; }
.xlabels span { flex: 1; }
.legend-line { display: flex; gap: 22px; font-size: 12px; margin: 8px 0; flex-wrap: wrap; }
.legend-line i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; }
.group { display: flex; align-items: flex-end; gap: 4px; flex: 1; height: 100%; }
.group .bar { max-width: 16px; }

/* ── Info adicional ──────────────────────────────────── */
.info-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; }
.info-item { padding: 14px; border-right: 1px solid var(--line); min-height: 92px; }
.info-item:last-child { border-right: 0; }
.info-item span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.info-item b { display: block; font-size: 23px; }
.info-item small { color: var(--muted); }

/* ── Estados ─────────────────────────────────────────── */
.loading { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.banner { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 12px; padding: 12px 16px; font-size: 13px; font-weight: 600; margin-bottom: 16px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid #d9ccff; border-top-color: var(--purple); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ───────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #061a2e, #1a0b40); }
.login-card { background: #fff; border-radius: 18px; padding: 36px; width: 360px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.login-card .btn.primary { width: 100%; justify-content: center; margin-top: 22px; padding: 13px; }
.login-err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1400px) { :root { --side-w: 250px; } }

@media (max-width: 1100px) {
  .selectors, .controls, .grid, .below, .bottom,
  .grid-main, .grid-below, .grid-sim { grid-template-columns: 1fr !important; }
  .span2 { grid-column: auto !important; }
  .session { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 760px) {
  :root { --side-w: var(--side-w-collapsed); }
  .main { padding: 16px 16px 22px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .session { justify-content: flex-start; }
}
