:root {
  --primary:      #0d2240;
  --primary-light:#1a3a6b;
  --accent:       #006847;
  --accent-bg:    #e8f5ee;
  --bg:           #f0f2f5;
  --white:        #ffffff;
  --text:         #1a1a2e;
  --muted:        #6b7280;
  --border:       #e2e8f0;
  --success:      #16a34a;
  --danger:       #dc2626;
  --warning:      #d97706;
  --info:         #2563eb;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius:       8px;
  --nav-h:        56px;
}

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

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Navegacion ─────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.3px;
  flex-shrink: 0;
}

.nav-brand-flag {
  display: flex;
  height: 20px;
  width: 30px;
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.nav-brand-flag span {
  flex: 1;
}
.flag-green  { background: #006847; }
.flag-white  { background: #ffffff; }
.flag-red    { background: #ce1126; }

.nav-links {
  display: flex;
  gap: .25rem;
  list-style: none;
}

.nav-links a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  padding: .4rem .75rem;
  border-radius: 6px;
  font-size: .9rem;
  transition: background .15s, color .15s;
}

.nav-links a:hover,
.nav-links a.active {
  background: rgba(255,255,255,.15);
  color: var(--white);
}

/* ── Contenedor ─────────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* ── Cabecera de pagina ─────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}
.page-header p {
  color: var(--muted);
  font-size: .92rem;
  margin-top: .2rem;
}

/* ── Tarjetas ───────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* ── Contadores del dashboard ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  border-left: 4px solid var(--accent);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: .82rem;
  color: var(--muted);
  margin-top: .35rem;
}

/* ── Grid de dos columnas ───────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ── Tablas ─────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

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

thead th {
  background: var(--bg);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .65rem .9rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}

tbody td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: #f8faff;
}

.td-name a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.td-name a:hover { text-decoration: underline; color: var(--accent); }

.td-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--primary);
}

.td-muted {
  color: var(--muted);
  font-size: .85rem;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-presente    { background: #dcfce7; color: #15803d; }
.badge-ausente     { background: #fee2e2; color: #b91c1c; }
.badge-justificado { background: #fef9c3; color: #92400e; }
.badge-comision    { background: #dbeafe; color: #1e40af; }
.badge-licencia    { background: #f3e8ff; color: #6b21a8; }
.badge-concluida   { background: #f1f5f9; color: #475569; }
.badge-encurso     { background: #d1fae5; color: #065f46; }
.badge-programada  { background: #e0f2fe; color: #075985; }
.badge-diputados   { background: #e0f2fe; color: #075985; }
.badge-senado      { background: #ede9fe; color: #5b21b6; }
.badge-default     { background: var(--bg); color: var(--muted); }

/* ── Partido chip ───────────────────────────────────────────────────────── */
.partido-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 600;
}
.partido-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Filtros ────────────────────────────────────────────────────────────── */
.filters {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: 140px;
}

.filter-group label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.filter-group input,
.filter-group select {
  height: 36px;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .88rem;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .15s;
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,104,71,.12);
}

.filter-group.wide input {
  min-width: 200px;
}

/* ── Botones ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
  height: 36px;
}
.btn-primary:hover { background: #005238; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  height: 36px;
}
.btn-ghost:hover { background: var(--bg); }

/* ── Paginacion ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 0 0;
  font-size: .85rem;
  color: var(--muted);
}

.pagination-controls {
  display: flex;
  gap: .5rem;
}

.page-btn {
  padding: .3rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s;
}
.page-btn:hover:not(:disabled) { background: var(--bg); }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-btn.active  { background: var(--primary); color: var(--white); border-color: var(--primary); }

/* ── Grafica de barras CSS ──────────────────────────────────────────────── */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 46px;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
}

.bar-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  height: 14px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
}

.bar-pct {
  font-size: .78rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.pct-high { color: var(--success); }
.pct-mid  { color: var(--warning); }
.pct-low  { color: var(--danger);  }

/* ── Perfil de legislador ───────────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

.profile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .4rem;
}

.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.profile-stat {
  background: var(--bg);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  text-align: center;
}

.profile-stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.profile-stat-lbl {
  font-size: .75rem;
  color: var(--muted);
  margin-top: .2rem;
}

/* ── Seccion con titulo ─────────────────────────────────────────────────── */
.section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}

/* ── Estados de carga y error ───────────────────────────────────────────── */
.loading, .empty-state {
  padding: 2.5rem;
  text-align: center;
  color: var(--muted);
  font-size: .92rem;
}

.loading::before {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto .75rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  padding: 1rem 1.25rem;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: var(--radius);
  font-size: .88rem;
}

/* ── Back link ──────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  margin-bottom: 1rem;
  transition: color .15s;
}
.back-link:hover { color: var(--accent); }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .container { padding: 1rem .75rem 2rem; }
  .nav { padding: 0 .75rem; gap: 1rem; }
  .nav-links { display: none; }
  .filters { flex-direction: column; }
  .filter-group { min-width: unset; width: 100%; }
  .two-col { grid-template-columns: 1fr; }
}
