:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --surface3: #2d3248;
  --border: #2d3248;
  --border-light: #3a3f58;
  --text: #e8eaed;
  --text2: #9aa0b4;
  --text3: #6b7394;
  --accent: #4fc3f7;
  --accent2: #81d4fa;
  --accent-dim: rgba(79,195,247,.12);
  --green: #66bb6a;
  --green-dim: rgba(102,187,106,.12);
  --red: #ef5350;
  --red-dim: rgba(239,83,80,.12);
  --yellow: #ffd54f;
  --orange: #ffa726;
  --purple: #ab47bc;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
  --transition: all .25s cubic-bezier(.4,0,.2,1);

  /* Party Colors */
  --p-pp: #0056A4;
  --p-psoe: #E30613;
  --p-vox: #63BE21;
  --p-sumar: #E51C55;
  --p-podemos: #672F6C;
  --p-salf: #800080;
  --p-erc: #FFB232;
  --p-junts: #00C3B2;
  --p-bildu: #00A59A;
  --p-pnv: #008000;
  --p-bng: #76B3DD;
  --p-cca: #FFD700;
  --p-upn: #003399;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

@media (max-width: 1080px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; top: 0; left: 0; width: 340px; height: 100vh; z-index: 1000; }
  .sidebar.open { display: block; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 999; }
  .sidebar-overlay.open { display: block; }
  .mobile-toggle { display: flex !important; }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-icon {
  font-size: 1.8rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(79,195,247,.3);
}

.sidebar-brand h2 {
  font-size: 1.05rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand .brand-sub {
  font-size: .72rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section h3 {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text3);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Study List */
.study-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.study-item {
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.study-item:hover {
  background: var(--surface3);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.study-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.study-name {
  font-size: .88rem;
  font-weight: 600;
}

.study-meta {
  font-size: .75rem;
  color: var(--text3);
}

.study-badge {
  font-size: .68rem;
  padding: 3px 7px;
  border-radius: 4px;
  font-weight: 600;
}

.badge-nacional {
  background: rgba(79, 195, 247, 0.15);
  color: var(--accent);
}

.badge-autonomica {
  background: rgba(255, 167, 38, 0.15);
  color: var(--orange);
}

/* Ficha Card */
.ficha-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: .8rem;
}

.ficha-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.ficha-row:last-child { border-bottom: none; }
.ficha-label { color: var(--text3); }
.ficha-val { font-weight: 600; text-align: right; }

/* Model Selector in Sidebar */
.model-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.model-option {
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .82rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-option:hover {
  background: var(--surface3);
}

.model-option.active {
  border-color: var(--green);
  background: var(--green-dim);
  font-weight: 600;
  color: #fff;
}

/* ── Main Content ── */
.main-content {
  padding: 28px 36px;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .main-content { padding: 18px 16px; }
}

.mobile-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 20px;
  cursor: pointer;
}

.main-header {
  margin-bottom: 24px;
}

.main-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -.5px;
}

.main-header p.description {
  color: var(--text2);
  font-size: .92rem;
  margin-bottom: 16px;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.nav-tab {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.nav-tab:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border-light);
}

.nav-tab.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(79, 195, 247, 0.3);
}

/* Metric Cards Top Row */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent);
}

.metric-card.card-danger::before { background: var(--red); }
.metric-card.card-success::before { background: var(--green); }
.metric-card.card-warning::before { background: var(--orange); }

.metric-title {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text3);
  margin-bottom: 8px;
}

.metric-val {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 4px;
}

.metric-sub {
  font-size: .78rem;
  color: var(--text2);
}

/* Panels */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Tables */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 24px;
}

.table-section h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
}

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

th {
  text-align: left;
  padding: 12px 14px;
  background: var(--surface2);
  color: var(--text2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

tr:hover td {
  background: rgba(255,255,255,.02);
}

.party-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.party-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.diff-positive {
  color: var(--green);
  font-weight: 700;
}

.diff-negative {
  color: var(--red);
  font-weight: 700;
}

/* Hemiciclo Congress Container */
.hemiciclo-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  text-align: center;
}

.hemiciclo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.hemiciclo-chart-wrap {
  width: 100%;
  max-width: 680px;
  margin: 0 auto 20px auto;
  position: relative;
}

/* Majority Bar */
.majority-bar-container {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.majority-bar-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: .88rem;
}

.majority-track {
  height: 28px;
  background: var(--surface3);
  border-radius: 14px;
  display: flex;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-light);
}

.majority-segment {
  height: 100%;
  transition: width .5s cubic-bezier(.4,0,.2,1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

.majority-threshold-line {
  position: absolute;
  top: 0; bottom: 0;
  left: 50.28%; /* 176 / 350 */
  width: 2px;
  background: #ffffff;
  z-index: 10;
  box-shadow: 0 0 8px rgba(255,255,255,.8);
}

.majority-threshold-label {
  position: absolute;
  top: -24px;
  left: 50.28%;
  transform: translateX(-50%);
  font-size: .7rem;
  font-weight: 800;
  color: var(--yellow);
  background: var(--surface3);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
}

/* Momentum Sliders */
.momentum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 14px;
}

.momentum-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.momentum-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: .88rem;
  font-weight: 600;
}

.momentum-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.momentum-scale {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: var(--text3);
  margin-top: 4px;
}

/* Audit Cards */
.audit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.audit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.audit-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.audit-list {
  list-style: none;
}

.audit-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
  display: flex;
  justify-content: space-between;
}

.audit-list li:last-child { border-bottom: none; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* Footer */
.footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text3);
  font-size: .8rem;
  text-align: center;
}

/* ── Help & Statistical Glossary (Nivel Bachillerato) ── */
.header-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.help-btn-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: .86rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.help-btn-header:hover {
  background: var(--accent);
  color: #000;
  transform: translateY(-1px);
}

.help-hero {
  background: linear-gradient(135deg, rgba(79,195,247,0.12), rgba(102,187,106,0.08));
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin-bottom: 24px;
}

.help-hero h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 10px;
  color: #fff;
}

.help-hero p {
  font-size: .92rem;
  color: var(--text2);
  line-height: 1.65;
}

.help-steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.help-step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 4px 10px;
  border-radius: 20px;
  width: fit-content;
}

.help-step-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

.help-step-card p, .help-step-card li {
  font-size: .87rem;
  color: var(--text2);
  line-height: 1.6;
}

.help-step-card ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.formula-box {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: 'Courier New', monospace;
  font-size: .84rem;
  color: #fff;
  margin: 6px 0;
  overflow-x: auto;
}

.example-callout {
  background: rgba(255, 213, 79, 0.08);
  border: 1px solid rgba(255, 213, 79, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .84rem;
  color: var(--text);
}

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

.glossary-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  transition: var(--transition);
}

.glossary-card:hover {
  border-color: var(--border-light);
}

.glossary-term {
  font-size: .96rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.glossary-tag {
  font-size: .68rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--surface3);
  color: var(--text2);
  font-weight: 600;
}

.glossary-def {
  font-size: .85rem;
  color: var(--text2);
  line-height: 1.6;
}

