:root {
  --color-bg: #0a0a0f;
  --color-surface: #11111a;
  --color-surface-2: #1a1a25;
  --color-border: #2a2a3a;
  --color-text: #e0e0e0;
  --color-text-dim: #8888a0;
  --color-primary: #4fc3f7;
  --color-critical: #e74c3c;
  --color-warning: #f39c12;
  --color-info: #3498db;
  --color-success: #2ecc71;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html { overflow-x: hidden; }
body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-main);
  line-height: 1.5;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
}

.site-header {
  padding: 1.25rem 2rem 0;
  border-bottom: 1px solid var(--color-border);
  background: linear-gradient(90deg, var(--color-surface), #0f0f1a);
  position: relative;
}
.disclaimer-bar {
  margin: 0.75rem -2rem 0;
  padding: 0.5rem 2rem;
  background: rgba(243, 156, 18, 0.08);
  border-top: 1px solid rgba(243, 156, 18, 0.15);
  font-size: 0.7rem;
  color: var(--color-text-dim);
  line-height: 1.5;
  text-align: center;
}
.disclaimer-bar a {
  color: var(--color-warning);
  text-decoration: underline;
  font-weight: 500;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
}
.site-header h1 { font-size: 1.5rem; color: var(--color-primary); letter-spacing: -0.5px; }
.site-header .subtitle { color: var(--color-text-dim); font-size: 0.85rem; margin-top: 0.15rem; }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(10,10,15,0.97);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; transition: opacity 0.5s;
  gap: 1rem;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-overlay p {
  color: var(--color-text);
  font-size: 1rem;
  font-family: var(--font-main);
  min-height: 1.5em;
  letter-spacing: 0.5px;
}
.typewriter-cursor {
  color: var(--color-primary);
  animation: blink 0.8s step-end infinite;
  font-weight: 700;
}
@keyframes blink { 50% { opacity: 0; } }
.progress-bar-wrap {
  width: 200px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-success));
  border-radius: 2px;
  transition: width 0.4s ease;
}
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--color-border);
  border-top-color: var(--color-primary); border-radius: 50%;
  animation: spin 1s linear infinite; margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.kpi-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem;
  padding: 1rem 2rem; background: var(--color-surface); border-bottom: 1px solid var(--color-border);
}
.kpi {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: 8px; padding: 1rem; text-align: center;
}
.kpi-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--color-primary); }
.kpi-label { display: block; font-size: 0.75rem; color: var(--color-text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem; }
.kpi.critical .kpi-value { color: var(--color-critical); }
.kpi.warning .kpi-value { color: var(--color-warning); }
.kpi.info .kpi-value { color: var(--color-info); }

.dashboard {
  display: grid; grid-template-columns: 220px 1fr; gap: 1rem;
  padding: 1rem 2rem 2rem; max-width: 1600px; margin: 0 auto;
  transition: opacity 0.5s;
}
.dashboard.no-filters {
  grid-template-columns: 1fr;
}
.dashboard.no-filters .filters {
  display: none;
}

.panel {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 1rem;
}

.filters h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--color-primary); }
.filters label { display: block; margin-bottom: 0.75rem; font-size: 0.8rem; color: var(--color-text-dim); }
.filters select {
  width: 100%; margin-top: 0.25rem; padding: 0.4rem 0.5rem;
  background: var(--color-surface-2); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: 6px; font-size: 0.85rem;
}
.filters button {
  width: 100%; margin-top: 0.5rem; padding: 0.5rem;
  background: var(--color-primary); color: #000; font-weight: 600;
  border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.filters button:hover { opacity: 0.9; }

.main-content { min-height: 70vh; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; }
.tab-btn {
  padding: 0.5rem 1rem; background: transparent; color: var(--color-text-dim);
  border: 1px solid transparent; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { background: var(--color-surface-2); color: var(--color-primary); border-color: var(--color-border); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-content h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.tab-content h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: var(--color-text-dim); }
.help-text { color: var(--color-text-dim); font-size: 0.8rem; margin-bottom: 1rem; }

.table-wrap { border: 1px solid var(--color-border); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; table-layout: auto; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--color-border); word-break: break-word; overflow-wrap: anywhere; }
th { background: var(--color-surface-2); color: var(--color-text-dim); font-weight: 600; position: sticky; top: 0; white-space: nowrap; }
tr:hover td { background: rgba(255,255,255,0.03); }
td { color: var(--color-text); }

.badge { display: inline-block; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; }
.badge-critical { background: rgba(231,76,60,0.15); color: var(--color-critical); border: 1px solid rgba(231,76,60,0.3); }
.badge-warning { background: rgba(243,156,18,0.15); color: var(--color-warning); border: 1px solid rgba(243,156,18,0.3); }
.badge-info { background: rgba(52,152,219,0.15); color: var(--color-info); border: 1px solid rgba(52,152,219,0.3); }

.alertas-controls { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.severity-filter {
  padding: 0.3rem 0.7rem; border: 1px solid var(--color-border); background: var(--color-surface-2);
  color: var(--color-text-dim); border-radius: 6px; cursor: pointer; font-size: 0.8rem;
}
.severity-filter.active { background: var(--color-primary); color: #000; border-color: var(--color-primary); }

/* ── Download Section ───────────────────────────────────────────────── */
.download-section {
  padding: 0 2rem 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}
.download-card {
  background: linear-gradient(135deg, var(--color-surface), var(--color-surface-2));
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
}
.download-card h3 {
  font-size: 1rem;
  color: var(--color-primary);
  margin-bottom: 0.35rem;
}
.download-card p {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  margin-bottom: 0.75rem;
}
.download-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  font-size: 0.8rem;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.download-btn:hover {
  border-color: var(--color-primary);
  background: rgba(79,195,247,0.08);
}
.download-btn span { font-size: 1rem; }

.site-footer { text-align: center; padding: 1.5rem; color: var(--color-text-dim); font-size: 0.75rem; border-top: 1px solid var(--color-border); }
.footer-brand {
  margin-bottom: 1rem;
}
.footer-banner {
  max-width: 600px;
  width: 100%;
  height: auto;
  opacity: 0.6;
  transition: opacity 0.3s;
}
.footer-banner:hover { opacity: 0.9; }
.github-link { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.github-link:hover { text-decoration: underline; }

/* ── Network UI ─────────────────────────────────────────────────────── */
.network-legend {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem;
  font-size: 0.75rem; flex-wrap: wrap;
}
.network-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.3rem; }

/* Scene control buttons */
.scene-controls {
  position: absolute; top: 8px; left: 12px;
  display: flex; gap: 4px; z-index: 10;
  background: rgba(10,10,20,0.7); backdrop-filter: blur(6px);
  border: 1px solid var(--color-border);
  border-radius: 8px; padding: 4px 6px;
  flex-wrap: wrap;
}
.sc-ctrl-btn {
  background: transparent; color: var(--color-text-dim);
  border: 1px solid transparent; border-radius: 5px;
  padding: 0.25rem 0.55rem; cursor: pointer;
  font-size: 0.8rem; line-height: 1;
  transition: all 0.15s;
}
.sc-ctrl-btn:hover { background: var(--color-surface-2); color: var(--color-primary); border-color: var(--color-border); }

/* Scene tooltip (rich hover card) */
.scene-tooltip {
  position: absolute; top: 0; left: 0;
  width: 210px;
  background: rgba(10,10,20,0.92); backdrop-filter: blur(10px);
  border: 1px solid var(--color-border);
  border-radius: 10px; padding: 0.75rem;
  z-index: 40; pointer-events: none;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  font-size: 0.75rem; line-height: 1.4;
}
.scene-tooltip .tt-header {
  font-size: 0.85rem; font-weight: 700; color: var(--color-primary);
  margin-bottom: 0.15rem; word-break: break-word;
}
.scene-tooltip .tt-party {
  color: var(--color-text-dim); font-size: 0.7rem;
  margin-bottom: 0.5rem;
}
.scene-tooltip .tt-stats { margin-bottom: 0.4rem; }
.scene-tooltip .tt-row {
  display: flex; justify-content: space-between;
  padding: 0.15rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.scene-tooltip .tt-row span:first-child { color: var(--color-text-dim); }
.scene-tooltip .tt-row span:last-child { font-weight: 600; color: var(--color-text); }
.scene-tooltip .tt-click-hint {
  font-size: 0.6rem; color: var(--color-text-dim);
  text-align: center; margin-top: 0.25rem;
  opacity: 0.7;
}



/* ── Candidate Detail Modal ─────────────────────────────────────────── */
.cd-modal { position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center; justify-content: center; }
.cd-modal.hidden { display: none; }
.cd-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.cd-panel {
  position: relative; width: 95vw; max-width: 1400px; max-height: 92vh;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 12px; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7); overflow: hidden;
}
.cd-close {
  position: absolute; top: 10px; right: 12px; background: transparent; border: none;
  color: var(--color-text-dim); font-size: 1.6rem; cursor: pointer; z-index: 10; line-height: 1;
}
.cd-close:hover { color: var(--color-text); }
.cd-header { padding: 1.2rem 1.5rem 0.8rem; border-bottom: 1px solid var(--color-border); }
.cd-name { font-size: 1.3rem; color: var(--color-primary); margin-bottom: 0.2rem; }
.cd-meta { color: var(--color-text-dim); font-size: 0.85rem; margin-bottom: 0.5rem; }
.cd-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.cd-tabs {
  display: flex; gap: 0.25rem; padding: 0.5rem 1.5rem 0;
  border-bottom: 1px solid var(--color-border); background: var(--color-surface-2);
}
.cd-tab-btn {
  padding: 0.4rem 0.9rem; background: transparent; color: var(--color-text-dim);
  border: 1px solid transparent; border-radius: 6px 6px 0 0; cursor: pointer; font-size: 0.8rem;
}
.cd-tab-btn:hover { color: var(--color-text); }
.cd-tab-btn.active { background: var(--color-surface); color: var(--color-primary); border-color: var(--color-border); border-bottom-color: var(--color-surface); }
.cd-body { flex: 1; overflow-y: auto; padding: 1rem 1.5rem 1.5rem; }
.cd-content { display: none; }
.cd-content.active { display: block; }

.cd-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem;
}
.cd-stat {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: 8px; padding: 0.75rem; text-align: center;
}
.cd-stat span { display: block; font-size: 0.7rem; color: var(--color-text-dim); text-transform: uppercase; margin-bottom: 0.2rem; }
.cd-stat strong { display: block; font-size: 1.1rem; color: var(--color-primary); }
.cd-stat.neg strong { color: var(--color-critical); }
.cd-stat.pos strong { color: var(--color-success); }

.cd-table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: 8px; margin-top: 0.5rem; }

/* Clickable table rows */
#tablaCandidatos tbody tr { cursor: pointer; }
#tablaCandidatos tbody tr:hover td { background: rgba(79,195,247,0.08) !important; }

/* Clickable alert badges */
#tablaCandidatos .badge { cursor: pointer; transition: transform 0.1s; }
#tablaCandidatos .badge:hover { transform: scale(1.15); }

/* ── Resumen Styles ────────────────────────────────────────────────── */
.resumen-section { margin-bottom: 1.25rem; }
.resumen-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.resumen-stat-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  transition: transform 0.15s, border-color 0.15s;
}
.resumen-stat-card:hover { transform: translateY(-2px); border-color: var(--color-primary); }
.resumen-stat-icon { font-size: 1.4rem; margin-bottom: 0.25rem; display: block; }
.resumen-stat-value { display: block; font-size: 1.25rem; font-weight: 700; color: var(--color-primary); line-height: 1.2; }
.resumen-stat-label { display: block; font-size: 0.7rem; color: var(--color-text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem; }
.resumen-stat-card.critical .resumen-stat-value { color: var(--color-critical); }
.resumen-stat-card.warning .resumen-stat-value { color: var(--color-warning); }
.resumen-stat-card.info .resumen-stat-value { color: var(--color-info); }
.resumen-stat-card.success .resumen-stat-value { color: var(--color-success); }

.resumen-row-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.resumen-chart-box {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.75rem;
}
.resumen-chart-title { font-size: 0.85rem; color: var(--color-text); margin-bottom: 0.5rem; font-weight: 600; }
.resumen-chart-wrap { position: relative; height: 280px; }

.resumen-table-wrap {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.75rem;
  overflow-x: auto;
}
.resumen-table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.resumen-table-wrap th, .resumen-table-wrap td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.resumen-table-wrap th { background: var(--color-surface); color: var(--color-text-dim); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.resumen-table-wrap tr:hover td { background: rgba(255,255,255,0.03); }
.resumen-table-wrap tr.clickable-row { cursor: pointer; }
.resumen-table-wrap tr.clickable-row:hover td { background: rgba(79,195,247,0.08); }

.resumen-cross-card {
  background: linear-gradient(135deg, var(--color-surface-2), var(--color-surface));
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-warning);
  border-radius: 10px;
  padding: 1rem;
}
.resumen-cross-title { font-size: 0.85rem; color: var(--color-warning); font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.5px; }
.resumen-cross-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.5rem; }
.resumen-cross-item { background: rgba(0,0,0,0.15); border: 1px solid var(--color-border); border-radius: 6px; padding: 0.5rem 0.75rem; }
.resumen-cross-item span { display: block; font-size: 0.7rem; color: var(--color-text-dim); text-transform: uppercase; }
.resumen-cross-item strong { display: block; font-size: 1rem; color: var(--color-text); }

.resumen-guide-card {
  background: linear-gradient(135deg, var(--color-surface-2), var(--color-surface));
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-success);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}
.resumen-guide-title { font-size: 1rem; color: var(--color-success); font-weight: 700; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.resumen-guide-body > p { font-size: 0.85rem; color: var(--color-text); line-height: 1.6; margin-bottom: 1rem; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.75rem; margin-bottom: 0.5rem; }
.guide-item { background: rgba(0,0,0,0.12); border: 1px solid var(--color-border); border-radius: 8px; padding: 0.75rem; font-size: 0.8rem; color: var(--color-text); line-height: 1.5; }
.guide-icon { display: block; font-size: 1.4rem; margin-bottom: 0.3rem; }
.guide-item strong { display: block; font-size: 0.85rem; color: var(--color-primary); margin-bottom: 0.25rem; }
.guide-item p { margin: 0; font-size: 0.78rem; color: var(--color-text-dim); }
.guide-footer { margin-top: 1rem; }

/* Resumen clickable rows */
.resumen-table-wrap tr.clickable-row,
#rs-alerts-table-wrap tr.clickable-row {
  cursor: pointer;
  transition: background 0.15s;
}
.resumen-table-wrap tr.clickable-row:hover td,
#rs-alerts-table-wrap tr.clickable-row:hover td {
  background: rgba(79,195,247,0.1) !important;
}
.resumen-table-wrap tr.clickable-row td:first-child::before,
#rs-alerts-table-wrap tr.clickable-row td:first-child::before {
  content: '▸ ';
  color: var(--color-primary);
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.resumen-table-wrap tr.clickable-row:hover td:first-child::before,
#rs-alerts-table-wrap tr.clickable-row:hover td:first-child::before {
  opacity: 1;
}

/* Detail expansion rows in candidate modal */
.donor-detail.hidden, .conn-detail.hidden, .prov-conn-detail.hidden { display: none; }
.donor-row:hover, .conn-row:hover, .prov-conn-row:hover { background: rgba(79,195,247,0.06); }


@media (max-width: 1024px) {
  .site-header {
    padding: 0.5rem 0.75rem 0;
  }
  .site-header h1 { font-size: 1.05rem; }
  .site-header .subtitle { font-size: 0.68rem; }
  .header-brand { gap: 0.4rem; }
  .header-logo { width: 30px; height: 30px; }
  .disclaimer-bar {
    margin: 0.4rem -0.75rem 0;
    padding: 0.3rem 0.75rem;
    font-size: 0.6rem;
  }

  .global-search-bar {
    padding: 0.35rem 0.6rem;
  }
  .global-search-bar input {
    font-size: 0.78rem;
    padding: 0.45rem 0.6rem;
  }
  .search-results { left: 0.6rem; right: 0.6rem; max-height: 280px; }

  .kpi-bar {
    grid-template-columns: repeat(3, 1fr);
    padding: 0.5rem 0.6rem;
    gap: 0.35rem;
  }
  .kpi { padding: 0.4rem 0.35rem; border-radius: 6px; }
  .kpi-value { font-size: 0.9rem; }
  .kpi-label { font-size: 0.58rem; }

  .dashboard {
    grid-template-columns: 1fr;
    padding: 0.4rem;
    gap: 0.4rem;
  }

  /* Filters: collapsed by default on mobile */
  .filters {
    order: -1;
    max-height: 48px;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
  }
  .filters label, .filters button, .filters h2 { display: none; }
  .filters.expanded { max-height: none; padding: 0.75rem; }
  .filters.expanded label, .filters.expanded button, .filters.expanded h2 { display: block; }
  .filters.expanded h2 { font-size: 0.85rem; margin-bottom: 0.5rem; }
  .filters.expanded label { font-size: 0.7rem; margin-bottom: 0.35rem; }
  .filters.expanded select, .filters.expanded input {
    font-size: 0.75rem;
    padding: 0.35rem 0.4rem;
  }
  .filter-toggle {
    font-size: 0.75rem;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0;
    border-radius: 6px;
  }

  /* Tabs: wrap instead of scroll, show all */
  .tabs {
    gap: 2px;
    flex-wrap: wrap;
    overflow-x: visible;
    padding-bottom: 0.3rem;
  }
  .tab-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.68rem;
    white-space: nowrap;
    flex-shrink: 0;
    border-radius: 4px;
  }

  .tab-content h2 { font-size: 0.9rem; margin-bottom: 0.3rem; }
  .tab-content h3 { font-size: 0.8rem; }
  .help-text { font-size: 0.68rem; }

  /* Tables */
  .table-wrap { font-size: 0.65rem; border-radius: 6px; }
  table { font-size: 0.65rem; }
  th, td { padding: 0.3rem 0.35rem; }
  th { font-size: 0.6rem; }
  .table-search { font-size: 0.7rem; padding: 0.3rem 0.5rem; }

  .badge { font-size: 0.58rem; padding: 0.1rem 0.28rem; }
  .badge-basura { font-size: 0.52rem; }

  /* Charts */
  .resumen-row-2 { grid-template-columns: 1fr; }
  .resumen-chart-wrap { height: 200px; }
  .resumen-chart-title { font-size: 0.72rem; }
  .resumen-stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
  .resumen-stat-card { padding: 0.45rem; border-radius: 8px; }
  .resumen-stat-icon { font-size: 0.9rem; }
  .resumen-stat-value { font-size: 0.9rem; }
  .resumen-stat-label { font-size: 0.58rem; }
  .resumen-cross-grid { grid-template-columns: repeat(2, 1fr); }
  .guide-grid { grid-template-columns: 1fr; }

  /* Scene 3D: adaptive height */
  #three-container { height: 380px !important; }
  .scene-controls { top: 4px; left: 4px; padding: 2px 4px; gap: 2px; }
  .sc-ctrl-btn { font-size: 0.62rem; padding: 0.2rem 0.35rem; }
  .scene-tooltip { width: 170px; font-size: 0.62rem; padding: 0.45rem; }
  .network-legend { font-size: 0.62rem; gap: 0.4rem; }

  /* Modal: tighter */
  .cd-panel { max-height: 90vh; width: 98vw; border-radius: 8px; }
  .cd-header { padding: 0.7rem 0.8rem 0.4rem; }
  .cd-name { font-size: 1.05rem; }
  .cd-meta { font-size: 0.7rem; }
  .cd-tabs { padding: 0.25rem 0.4rem 0; overflow-x: auto; flex-wrap: nowrap; }
  .cd-tab-btn { padding: 0.25rem 0.45rem; font-size: 0.65rem; white-space: nowrap; flex-shrink: 0; }
  .cd-body { padding: 0.4rem 0.6rem 0.8rem; }
  .cd-stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.3rem; }
  .cd-stat { padding: 0.4rem; }
  .cd-stat strong { font-size: 0.8rem; }
  .cd-stat span { font-size: 0.55rem; }

  .download-section { padding: 0 0.4rem 0.6rem; }
  .download-card { padding: 0.6rem 0.8rem; }
  .download-card h3 { font-size: 0.8rem; }
  .download-btn { font-size: 0.68rem; padding: 0.35rem 0.5rem; }

  .site-footer { padding: 0.6rem; font-size: 0.6rem; }
  .footer-banner { max-width: 100%; }
}

/* ── Extra-small screens (phones <500px portrait) ─────────────────── */
@media (max-width: 500px) {
  .site-header {
    padding: 0.4rem 0.5rem 0;
  }
  .site-header h1 { font-size: 0.9rem; }
  .header-logo { width: 24px; height: 24px; }
  .header-brand { gap: 0.3rem; }
  .disclaimer-bar {
    margin: 0.3rem -0.5rem 0;
    padding: 0.25rem 0.5rem;
    font-size: 0.55rem;
  }

  .global-search-bar {
    padding: 0.25rem 0.4rem;
  }
  .global-search-bar input { font-size: 0.7rem; padding: 0.35rem 0.5rem; }
  .search-results { left: 0.4rem; right: 0.4rem; max-height: 220px; font-size: 0.7rem; }
  .search-result-item { padding: 0.4rem 0.6rem; font-size: 0.72rem; }

  /* KPI: 2 columns, abbreviate long amounts */
  .kpi-bar {
    grid-template-columns: repeat(2, 1fr);
    padding: 0.35rem 0.4rem;
    gap: 0.25rem;
  }
  .kpi { padding: 0.3rem 0.25rem; }
  .kpi-value { font-size: 0.78rem; }
  .kpi-label { font-size: 0.5rem; }

  .dashboard { padding: 0.25rem; gap: 0.3rem; }
  .panel { padding: 0.5rem 0.4rem; border-radius: 8px; }

  /* Filters toggle: full width, prominent */
  .filters { max-height: 44px; padding: 0.3rem 0.4rem; }
  .filters.expanded { max-height: none; padding: 0.5rem; }
  .filters.expanded label { font-size: 0.65rem; margin-bottom: 0.3rem; }
  .filters.expanded select, .filters.expanded input { font-size: 0.7rem; padding: 0.3rem 0.35rem; }
  .filter-toggle { font-size: 0.7rem; padding: 0.35rem 0.45rem; }

  /* Tabs: wrap, very compact */
  .tabs {
    gap: 1px;
    padding-bottom: 0.25rem;
  }
  .tab-btn {
    font-size: 0.6rem;
    padding: 0.22rem 0.35rem;
    border-radius: 3px;
  }

  .resumen-stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.25rem; }
  .resumen-stat-card { padding: 0.35rem; }
  .resumen-stat-value { font-size: 0.8rem; }
  .resumen-stat-label { font-size: 0.52rem; }
  .resumen-chart-wrap { height: 170px; }
  .resumen-guide-title { font-size: 0.85rem; }

  .cd-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .cd-tab-btn { font-size: 0.6rem; padding: 0.2rem 0.35rem; }
  .cd-stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.25rem; }

  .table-wrap {
    font-size: 0.58rem;
    border-radius: 5px;
  }
  table { font-size: 0.58rem; }
  th, td { padding: 0.18rem 0.22rem; }
  th { font-size: 0.5rem; }

  /* Scene 3D: smaller for phone portrait */
  #three-container { height: 300px !important; }
  .scene-tooltip { width: 140px; font-size: 0.58rem; }

  .alertas-controls { gap: 0.25rem; }
  .severity-filter { font-size: 0.62rem; padding: 0.22rem 0.4rem; }

  .badge { font-size: 0.5rem; padding: 0.08rem 0.2rem; }
  .badge-basura { font-size: 0.48rem; }
}

/* ── Responsive Table Column Hiding ─────────────────────────────────── */

/* Small screens (≤600px): hide secondary columns */
@media (max-width: 600px) {
  /* Candidatos: hide Posición(3), Provincia(4), Balance(7) */
  #tablaCandidatos th:nth-child(3),
  #tablaCandidatos td:nth-child(3),
  #tablaCandidatos th:nth-child(4),
  #tablaCandidatos td:nth-child(4),
  #tablaCandidatos th:nth-child(7),
  #tablaCandidatos td:nth-child(7) { display: none; }

  /* Ingresos: hide Efectivo(6), Cheque(7), Especie(8), Propios(9) */
  #tablaIngresos th:nth-child(6),
  #tablaIngresos td:nth-child(6),
  #tablaIngresos th:nth-child(7),
  #tablaIngresos td:nth-child(7),
  #tablaIngresos th:nth-child(8),
  #tablaIngresos td:nth-child(8),
  #tablaIngresos th:nth-child(9),
  #tablaIngresos td:nth-child(9) { display: none; }

  /* Egresos: hide Fecha(1), Partido(3), Categoría(6) */
  #tablaEgresos th:nth-child(1),
  #tablaEgresos td:nth-child(1),
  #tablaEgresos th:nth-child(3),
  #tablaEgresos td:nth-child(3),
  #tablaEgresos th:nth-child(6),
  #tablaEgresos td:nth-child(6) { display: none; }

  /* Alertas: hide Tipo(2), Partido(4) */
  #tablaAlertas th:nth-child(2),
  #tablaAlertas td:nth-child(2),
  #tablaAlertas th:nth-child(4),
  #tablaAlertas td:nth-child(4) { display: none; }

  /* Donantes Cruzados: hide #Donaciones(4) */
  #tablaDonantesCruzados th:nth-child(4),
  #tablaDonantesCruzados td:nth-child(4) { display: none; }

  /* Proveedores Cruzados: hide #Facturas(4) */
  #tablaProveedoresCruzados th:nth-child(4),
  #tablaProveedoresCruzados td:nth-child(4) { display: none; }

  /* RUCs Cruzados: hide Donante-nombre(2), Proveedor-nombre(3) */
  #tablaRucsCruzados th:nth-child(2),
  #tablaRucsCruzados td:nth-child(2),
  #tablaRucsCruzados th:nth-child(3),
  #tablaRucsCruzados td:nth-child(3) { display: none; }
}

/* Extra-small (≤450px): hide even more columns */
@media (max-width: 450px) {
  /* Candidatos: also hide Partido(2) */
  #tablaCandidatos th:nth-child(2),
  #tablaCandidatos td:nth-child(2) { display: none; }

  /* Ingresos: also hide Fecha(1), Partido(3) */
  #tablaIngresos th:nth-child(1),
  #tablaIngresos td:nth-child(1),
  #tablaIngresos th:nth-child(3),
  #tablaIngresos td:nth-child(3) { display: none; }

  /* Egresos: also hide Detalle(7), Factura(8) */
  #tablaEgresos th:nth-child(7),
  #tablaEgresos td:nth-child(7),
  #tablaEgresos th:nth-child(8),
  #tablaEgresos td:nth-child(8) { display: none; }

  /* Donantes Cruzados: hide Candidatos list(6) */
  #tablaDonantesCruzados th:nth-child(6),
  #tablaDonantesCruzados td:nth-child(6) { display: none; }

  /* Proveedores Cruzados: hide Candidatos list(6) */
  #tablaProveedoresCruzados th:nth-child(6),
  #tablaProveedoresCruzados td:nth-child(6) { display: none; }

  /* RUCs Cruzados: hide Candidatos list(7) */
  #tablaRucsCruzados th:nth-child(7),
  #tablaRucsCruzados td:nth-child(7) { display: none; }
}

/* ── Global Search Bar ────────────────────────────────────────────────── */
.global-search-bar {
  padding: 0.5rem 2rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}
.global-search-bar input {
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.global-search-bar input:focus {
  outline: none;
  border-color: var(--color-primary);
}
.search-results {
  position: absolute;
  top: 100%;
  left: 2rem;
  right: 2rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-primary);
  border-radius: 0 0 8px 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.search-result-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-result-item:hover { background: rgba(79,195,247,0.08); }
.search-result-item .sr-name { font-weight: 600; }
.search-result-item .sr-type { font-size: 0.7rem; color: var(--color-text-dim); }
.search-result-item .sr-badge { font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 3px; }

/* ── Data Quality Badges ──────────────────────────────────────────────── */
.badge-basura { background: rgba(231,76,60,0.12); color: #e74c3c; border: 1px solid rgba(231,76,60,0.3); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; display: inline-block; }
.data-basura-row { opacity: 0.5; background: rgba(231,76,60,0.04) !important; }
.data-basura-row:hover { opacity: 0.8; }

.highlight-match { background: rgba(79,195,247,0.15) !important; animation: highlightPulse 2s ease-in-out; }
.highlight-match td { border-bottom-color: rgba(79,195,247,0.3) !important; }
@keyframes highlightPulse {
  0% { background: rgba(79,195,247,0.35); }
  100% { background: rgba(79,195,247,0.12); }
}

.rare-chip {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  font-size: 0.72rem;
  color: var(--color-text-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.rare-chip:hover { background: var(--color-surface) !important; border-color: var(--color-primary) !important; color: var(--color-primary); }

/* ── Sortable Table Headers ───────────────────────────────────────────── */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--color-primary); }
th.sortable::after { content: ' ↕'; opacity: 0.3; font-size: 0.7rem; }
th.sortable.asc::after { content: ' ▲'; opacity: 1; }
th.sortable.desc::after { content: ' ▼'; opacity: 1; }

/* ── Collapsible Filters ──────────────────────────────────────────────── */
.filters { transition: max-height 0.3s ease; overflow: hidden; }
.filters.collapsed { max-height: 50px; }
.filters.collapsed label, .filters.collapsed button { display: none; }
.filters.collapsed h2 { display: none; }
.filter-toggle {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.filter-toggle:hover { border-color: var(--color-primary); }

/* ── Per-Table Search Inputs ──────────────────────────────────────────── */
.table-search {
  width: 100%;
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.75rem;
}
.table-search:focus { outline: none; border-color: var(--color-primary); }

/* ── Autocomplete Dropdown ────────────────────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  background: var(--color-surface-2);
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  width: calc(100% - 2rem);
  margin-left: 1rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.autocomplete-item {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--color-border);
}
.autocomplete-item:hover { background: rgba(79,195,247,0.1); }

/* ── Portrait mode override (covers any portrait-oriented device) ─── */
/* Must come AFTER all width-based media queries to take precedence */
@media (orientation: portrait) {
  .dashboard {
    grid-template-columns: 1fr !important;
  }
  .filters { order: -1; }
}
