: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, body {
  overflow-x: hidden;
  max-width: 100vw;
}
body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-main);
  line-height: 1.5;
  min-height: 100vh;
}

.site-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--color-border);
  background: linear-gradient(90deg, var(--color-surface), #0f0f1a);
}
.site-header h1 { font-size: 1.75rem; color: var(--color-primary); letter-spacing: -0.5px; }
.site-header .subtitle { color: var(--color-text-dim); font-size: 0.9rem; margin-top: 0.25rem; }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(10,10,15,0.95);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; transition: opacity 0.4s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.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;
}

.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); }

.site-footer { text-align: center; padding: 1.5rem; color: var(--color-text-dim); font-size: 0.75rem; border-top: 1px solid var(--color-border); }

/* ── 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; }

.node-panel {
  position: absolute; top: 12px; right: 12px; width: 320px; max-height: 90%;
  background: rgba(10,10,20,0.92); backdrop-filter: blur(8px);
  border: 1px solid var(--color-border); border-radius: 10px;
  padding: 1rem; overflow-y: auto; z-index: 50;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  transition: transform 0.3s, opacity 0.3s;
}
.node-panel.hidden { transform: translateX(20px); opacity: 0; pointer-events: none; }
.node-panel-close {
  position: absolute; top: 8px; right: 10px; background: transparent; border: none;
  color: var(--color-text-dim); font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.node-panel-close:hover { color: var(--color-text); }
.node-panel-content h3 { font-size: 1.1rem; color: var(--color-primary); margin-bottom: 0.25rem; }
.node-panel-content .sub { color: var(--color-text-dim); font-size: 0.8rem; margin-bottom: 0.75rem; }
.node-panel-content .stat-row { display: flex; justify-content: space-between; padding: 0.35rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.8rem; }
.node-panel-content .stat-row strong { color: var(--color-text); }
.node-panel-content .stat-row.negative strong { color: var(--color-critical); }
.node-panel-content .stat-row.positive strong { color: var(--color-success); }
.node-panel-content .mini-table { width: 100%; font-size: 0.75rem; margin-top: 0.75rem; }
.node-panel-content .mini-table th { text-align: left; padding: 0.3rem 0; color: var(--color-text-dim); border-bottom: 1px solid var(--color-border); }
.node-panel-content .mini-table td { padding: 0.25rem 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.node-panel-content h4 { font-size: 0.85rem; margin: 1rem 0 0.4rem; color: var(--color-text); }
.node-panel-content .conn-chip {
  display: inline-block; padding: 0.2rem 0.5rem; margin: 0.15rem;
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: 4px; font-size: 0.75rem; cursor: pointer;
}
.node-panel-content .conn-chip:hover { border-color: var(--color-primary); }
.node-panel-content .badge-inline { font-size: 0.65rem; padding: 0.1rem 0.35rem; border-radius: 3px; margin-left: 0.3rem; }

/* ── 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); }

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

@media (max-width: 900px) {
  .dashboard { grid-template-columns: 1fr; padding: 0.75rem; gap: 0.75rem; }
  .kpi-bar { grid-template-columns: repeat(2, 1fr); padding: 0.75rem; gap: 0.5rem; }
  .kpi { padding: 0.6rem; }
  .kpi-value { font-size: 1.1rem; }
  .site-header { padding: 1rem; }
  .site-header h1 { font-size: 1.3rem; }
  .tabs { gap: 0.15rem; }
  .tab-btn { padding: 0.4rem 0.6rem; font-size: 0.75rem; }
  .table-wrap { font-size: 0.7rem; }
  table { font-size: 0.7rem; }
  th, td { padding: 0.35rem 0.4rem; }
  .node-panel { width: calc(100% - 24px); top: auto; bottom: 12px; right: 12px; max-height: 55%; }
  .cd-panel { max-height: 92vh; width: 96vw; }
  .filters { order: -1; }
}

@media (max-width: 500px) {
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
  .dashboard { padding: 0.5rem; }
  .tab-btn { font-size: 0.7rem; padding: 0.35rem 0.5rem; }
}
