/* ── Chile Legislative Intelligence — Design System ── */

/* ── Custom Properties ── */
:root {
  --bg: #0a0f1e;
  --bg-secondary: #111827;
  --card-bg: #141d30;
  --card-border: rgba(255, 255, 255, 0.06);
  --text: #e8ecf4;
  --text-muted: #94a3b8;
  --brand: #f59e0b;
  --brand-light: #fbbf24;
  --accent: #3b82f6;
  --ok: #22c55e;
  --bad: #ef4444;
  --warning: #f59e0b;
  --line: #1e293b;

  /* Legacy aliases for backward compat */
  --bg2: var(--bg-secondary);
  --card: var(--card-bg);
  --text-color: var(--text);
  --muted: var(--text-muted);

  /* Typography */
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Transitions */
  --transition-fast: 0.12s ease;
  --transition-base: 0.15s ease;
  --transition-slow: 0.25s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.2;
  margin: 0 0 0.5em;
  color: var(--text);
}
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--brand-light); }

/* ── Layout Primitives ── */
.container, .wrap {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--space-md);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, var(--space-md));
}

.cluster, .row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cluster-gap, var(--space-sm));
  align-items: center;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-md); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-md); }
/* Legacy alias */
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }

.sidebar-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-lg);
}

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .sidebar-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4, .grid2 { grid-template-columns: 1fr; }
  .row, .cluster { flex-direction: column; align-items: stretch; }
}

/* ── Card (Glass-morphism) ── */
.card {
  background: rgba(20, 29, 48, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.card-header {
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-sm);
  border-bottom: 1px solid var(--line);
}
.card-body { padding: var(--space-xs) 0; }
.card-footer {
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
  border-top: 1px solid var(--line);
}

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.nav-brand {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text);
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}
.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}
.nav-link.active {
  color: var(--brand);
  background: rgba(245, 158, 11, 0.1);
}
.nav-auth {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Legacy .nav class compat */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 18px;
}
.nav a {
  color: var(--brand);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  background: rgba(17, 24, 39, 0.6);
  font-size: 0.85rem;
  transition: background var(--transition-base), color var(--transition-base), border-color var(--transition-base);
}
.nav a:hover:not(.active) {
  background: rgba(30, 41, 59, 0.8);
  border-color: var(--brand);
}
.nav a.active {
  background: var(--brand);
  color: var(--bg);
  border-color: var(--brand);
}
.nav a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4);
}

/* ── Hamburger (mobile) ── */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}
@media (max-width: 768px) {
  .nav-hamburger { display: block; }
  .nav-links { display: none; }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--line);
    padding: var(--space-sm);
  }
}

/* ── Pills / Badges ── */
.pill, .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}
.pill-success, .badge-success { background: rgba(34, 197, 94, 0.15); color: var(--ok); }
.pill-warning, .badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.pill-error, .badge-error { background: rgba(239, 68, 68, 0.15); color: var(--bad); }
.pill-info, .badge-info { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.pill-neutral, .badge-neutral { background: rgba(148, 163, 184, 0.12); color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg-secondary);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}
.btn:hover { background: rgba(30, 41, 59, 0.8); border-color: rgba(255, 255, 255, 0.1); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4); }

.btn-primary {
  background: var(--brand);
  color: var(--bg);
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-light); border-color: var(--brand-light); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

/* Legacy button compat */
button {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 9px 10px;
  background: linear-gradient(180deg, #1e293b, #111827);
  color: var(--text);
  cursor: pointer;
  transition: filter var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}
button:hover { filter: brightness(1.1); }
button:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25); }

/* ── Form Controls ── */
.input, .select,
input, select, textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 9px 12px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.input:focus, .select:focus,
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

/* ── Data Tables ── */
.table-wrap { overflow-x: auto; margin: 0 -2px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--card-bg);
}
.data-table tbody tr {
  transition: background var(--transition-fast);
}
.data-table tbody tr:hover {
  background: rgba(245, 158, 11, 0.04);
}
.data-table td {
  color: var(--text);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table .empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 18px;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--brand); }
th .sort-arrow {
  display: inline-block;
  width: 14px;
  text-align: center;
  margin-left: 2px;
  font-size: 0.7rem;
  opacity: 0.35;
}
th.sorted-asc .sort-arrow::after { content: "\25B2"; opacity: 1; }
th.sorted-desc .sort-arrow::after { content: "\25BC"; opacity: 1; }

/* ── Pager ── */
.pager {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-xs);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.pager button {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}
.pager button:disabled { opacity: 0.35; cursor: default; }
.pager select { font-size: 0.78rem; padding: 3px 6px; }
.pager .pager-info { margin-right: auto; }
.pg-num { min-width: 60px; text-align: center; }

/* ── KPI Boxes ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-sm);
  margin: var(--space-sm) 0;
}
.kpi {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  transition: border-color var(--transition-base);
}
.kpi:hover { border-color: rgba(255, 255, 255, 0.1); }
.kpi .label { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: var(--space-xs); font-family: var(--font-display); }
@media (max-width: 1024px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .kpi-grid { grid-template-columns: 1fr; } }

/* ── Key-Value Grid ── */
.kv {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 10px;
}
.kv .k { color: var(--text-muted); }
@media (max-width: 768px) { .kv { grid-template-columns: 1fr; } }

/* ── List Controls ── */
.list-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 var(--space-sm);
  align-items: center;
}
.list-controls input,
.list-controls select {
  font-size: 0.8rem;
  padding: 5px 8px;
}
@media (max-width: 640px) {
  .list-controls { flex-direction: column; align-items: stretch; }
  .list-controls input, .list-controls select { width: 100%; }
}

/* ── Code / Pre ── */
pre {
  background: rgba(10, 15, 30, 0.8);
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: var(--radius-lg);
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.85rem;
}

/* ── Utility Classes ── */
.text-muted, .muted { color: var(--text-muted); }
.text-brand { color: var(--brand); }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.transition-colors { transition: color var(--transition-base), background-color var(--transition-base), border-color var(--transition-base); }
.transition-opacity { transition: opacity var(--transition-base); }
.transition-transform { transition: transform var(--transition-base); }

/* ── Politician Profile — Magazine Portrait Layout ── */
.profile-hero-card {
  padding: 0 !important;
  overflow: hidden;
}
.profile-hero {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 330px;
}
.profile-portrait {
  width: 200px;
  height: 100%;
  min-height: 330px;
  object-fit: cover;
  object-position: top;
  display: block;
}
.profile-portrait-fallback {
  width: 200px;
  min-height: 330px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  color: var(--text-muted);
}
.profile-hero-content {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.profile-hero-content h1 {
  font-size: 2rem;
  margin-bottom: 0;
}
.profile-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.profile-bio {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-top: var(--space-xs);
}
.profile-bio.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.profile-bio-toggle {
  background: none !important;
  border: none !important;
  color: var(--brand);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 0;
  font-weight: 500;
  align-self: flex-start;
}
.profile-bio-toggle:hover {
  color: var(--brand-light);
}

/* Stat badges */
.profile-stats {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: var(--space-sm);
}
.profile-stat {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-width: 72px;
  text-align: center;
}
.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--font-display);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}

.social-links {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: var(--space-sm);
}
.social-links a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-decoration: none;
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}
.social-links a:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: rgba(245, 158, 11, 0.06);
}

/* ── Politician Grid — Circle Avatar Cards ── */
.pol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-md);
}
.pol-card-link {
  text-decoration: none;
  color: inherit;
}
.pol-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-md) var(--space-sm) var(--space-sm) !important;
  cursor: pointer;
  height: 100%;
  gap: 8px;
}
.pol-card-avatar-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
}
.pol-card-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  display: block;
  transition: border-color var(--transition-base);
}
.pol-card:hover .pol-card-avatar {
  border-color: var(--brand);
}
.pol-card-avatar-fallback {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: var(--text-muted);
}
.pol-card-loyalty-ring {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  border: 2px solid;
  background: var(--card);
  line-height: 1.3;
  white-space: nowrap;
}
.pol-card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 4px;
  min-width: 0;
  width: 100%;
}
.pol-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.pol-card-meta {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.pol-card-meta .pill { font-size: 0.65rem; }
.pol-card-party {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
  min-width: 0;
}
.pol-card-votes {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: auto;
}
@media (max-width: 480px) {
  .pol-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-sm); }
  .pol-card-avatar-wrap, .pol-card-avatar, .pol-card-avatar-fallback { width: 72px; height: 72px; }
  .pol-card-name { font-size: 0.8rem; }
}

/* ── Tabs ── */
.profile-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--line);
  margin-bottom: var(--space-lg);
  overflow-x: auto;
}
.profile-tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 18px;
  margin-bottom: -2px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  border-radius: 0;
}
.profile-tabs button:hover {
  color: var(--text);
}
.profile-tabs button.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* ── Timeline ── */
.timeline {
  position: relative;
  padding-left: 24px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--line);
}
.timeline-item {
  position: relative;
  padding-bottom: var(--space-md);
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--bg);
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item .tl-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.timeline-item .tl-date {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Grid card photo */
.card-photo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  flex-shrink: 0;
}
.card-photo-fallback {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Profile portrait responsive */
@media (max-width: 768px) {
  .profile-hero { grid-template-columns: 160px 1fr; }
  .profile-portrait, .profile-portrait-fallback { width: 160px; }
  .profile-stats { gap: 6px; }
  .profile-stat { padding: 6px 10px; min-width: 60px; }
  .stat-value { font-size: 1.1rem; }
}
@media (max-width: 480px) {
  .profile-hero {
    grid-template-columns: 1fr;
  }
  .profile-portrait, .profile-portrait-fallback {
    width: 100%;
    min-height: 200px;
    max-height: 280px;
  }
  .profile-hero-content { text-align: center; }
  .profile-hero-content h1 { font-size: 1.5rem; }
  .profile-meta { justify-content: center; }
  .profile-bio-toggle { align-self: center; }
  .profile-stats { justify-content: center; }
  .social-links { justify-content: center; }
}
