/* =====================================================================
   Pirámides Poblacionales · Venezuela — Diseño del sistema (moderno)
   Tema claro / oscuro vía CSS variables. Sin dependencias.
   ===================================================================== */

/* ----------------------------- Tokens ------------------------------ */
:root {
  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --bg: #eef1f7;
  --bg-grad-a: #e8edf8;
  --bg-grad-b: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f9;
  --border: #e3e8f0;
  --border-strong: #cdd6e4;

  --text: #1c2536;
  --text-2: #52607a;
  --text-3: #7a879b;

  --accent: #3b5bfd;
  --accent-2: #22b3e6;
  --accent-grad: linear-gradient(135deg, #3b5bfd, #22b3e6);
  --accent-soft: rgba(59, 91, 253, 0.12);

  --h: #2b6cb0;      /* hombres */
  --m: #FF69B4;      /* mujeres (rosado) */
  --c2001: #00ff40;  /* censo 2001 (ámbar, como el PDF) */
  --c2011: #002060;  /* censo 2011 (azul oscuro, como el PDF) */
  --c2024: #ff8a00;  /* censo 2024 (naranja) */

  --ok: #0f9d6e;
  --warn: #d97706;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(28, 37, 54, 0.06), 0 1px 3px rgba(28, 37, 54, 0.06);
  --shadow-lg: 0 16px 44px rgba(28, 37, 54, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
  --bg: #0c1220;
  --bg-grad-a: #0e1526;
  --bg-grad-b: #111a2c;
  --surface: #151d2f;
  --surface-2: #1a2338;
  --surface-3: #202b44;
  --border: #232f4a;
  --border-strong: #31405f;

  --text: #e8edf7;
  --text-2: #aab6cc;
  --text-3: #7d8aa3;

  --accent: #6f8bff;
  --accent-2: #4cd2ff;
  --accent-soft: rgba(111, 139, 255, 0.16);

  --h: #4d9de0;
  --m: #ff85c8;  /* mujeres (rosado claro) */
  --c2001: #ffc940;
  --c2011: #7fa4ff;
  --c2024: #ffbf80;

  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.5);
}

/* ----------------------------- Base -------------------------------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--bg-grad-a), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, var(--bg-grad-b), transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.4s var(--ease), color 0.4s var(--ease);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
select { font-family: inherit; }

::selection { background: var(--accent-soft); }

/* Scrollbar */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }

/* ----------------------------- Topbar ------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.page-banner-wrap {
  width: 100%;
  margin: 0;
  padding: 0;
  background: #f5f1e8;
  border-bottom: 1px solid var(--border);
}

.page-banner {
  display: block;
  width: 100%;
  height: auto;
  max-height: 130px;
  min-height: 78px;
  object-fit: cover;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: #f5f1e8;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-logo {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  font-size: 24px;
  border-radius: 13px;
  background: var(--accent-grad);
  box-shadow: 0 6px 18px rgba(59, 91, 253, 0.35);
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(16px, 2vw, 21px);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.brand-text p { margin: 1px 0 0; font-size: 12.5px; color: var(--text-3); }

.topbar-actions { display: flex; gap: 10px; flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease),
              border-color 0.2s, background 0.2s, color 0.2s;
}
.btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}
.btn-primary {
  border-color: transparent;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 5px 16px rgba(59, 91, 253, 0.25);
}
.btn-primary:hover { color: #fff; border-color: transparent; }
.btn-excel {
  border-color: rgba(30, 124, 79, 0.28);
  background: linear-gradient(135deg, #dff7e8 0%, #b3e7c7 35%, #7ad3a4 100%);
  color: #0d5b3a;
  box-shadow: 0 10px 20px rgba(79, 186, 120, 0.25);
}
.btn-excel:hover {
  border-color: rgba(25, 105, 67, 0.4);
  background: linear-gradient(135deg, #d5f7e4 0%, #9fe4b4 35%, #5dc88e 100%);
  color: #083d26;
  box-shadow: 0 12px 24px rgba(70, 163, 106, 0.28);
}
.btn:active { transform: translateY(0); }

/* ----------------------------- Layout ------------------------------ */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  padding: 24px clamp(16px, 3vw, 40px) 48px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}


/* ----------------------------- Sidebar ----------------------------- */
.sidebar {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field { border: none; padding: 0; margin: 0; }
.field legend {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

.selects { display: flex; flex-direction: column; gap: 10px; }

.select-wrap { display: flex; flex-direction: column; gap: 5px; }
.select-label { font-size: 12px; font-weight: 600; color: var(--text-2); }

select {
  width: 100%;
  appearance: none;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a879b' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 38px 10px 12px;
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
select:hover { border-color: var(--border-strong); }
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Segmented control */
.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-3);
  border-radius: 12px;
  padding: 4px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
  padding: 8px 6px;
  border-radius: 9px;
  transition: background 0.22s var(--ease), color 0.22s, box-shadow 0.22s;
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Switch */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  cursor: pointer;
}
.switch-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background 0.25s var(--ease);
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s var(--ease);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 3px var(--accent-soft); }

.sidebar-foot { font-size: 11.5px; color: var(--text-3); text-align: center; padding: 2px; }

/* ----------------------------- Content ----------------------------- */
.content { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.analysis-layout { align-items: start; }
.analysis-layout {
  grid-template-columns: 260px minmax(0, 1fr);
  max-width: 1800px;
  gap: 18px;
  padding-left: 24px;
  padding-right: 24px;
}
.analysis-layout .panel { padding: 16px; gap: 15px; }
.analysis-layout .sidebar { top: 82px; }
.analysis-intro { padding-bottom: 2px; border-bottom: 1px solid var(--border); }
.analysis-intro h2, .analysis-heading h2 {
  margin: 3px 0 5px;
  font-size: clamp(20px, 2.5vw, 30px);
  letter-spacing: -0.03em;
}
.analysis-intro p, .analysis-heading p { margin: 0; color: var(--text-2); font-size: 13px; }
.analysis-eyebrow, .analysis-card-kicker {
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.analysis-tip {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-2);
  font-size: 12px;
}
.analysis-tip span:first-child { color: var(--accent); font-size: 16px; line-height: 1; }
.analysis-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  padding: 4px 4px 3px;
}
.analysis-status {
  white-space: nowrap;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 650;
}
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 14%, transparent);
}
.analysis-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.analysis-kpi {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1px;
  animation: rise 0.45s var(--ease) both;
}
.analysis-kpi strong { font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.analysis-kpi > span:last-child { color: var(--text-3); font-size: 11px; }
.analysis-kpi-year { color: var(--text-2); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.analysis-card { min-width: 0; padding: 13px 13px 10px; overflow: hidden; animation: rise 0.55s var(--ease) both; }
.analysis-card.poblacion-total {
  grid-column: 2;
  align-self: start;
  min-height: 100%;
}
.analysis-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 5px 5px; }
.analysis-card h3 { margin: 2px 0 0; font-size: 18px; }
.analysis-card-kicker { font-size: 9.5px; }
.censo-badge { padding: 5px 8px; border-radius: 999px; color: var(--text); background: var(--surface-3); font-size: 10px; font-weight: 750; white-space: nowrap; }
.censo-1990 .analysis-kpi-year, .censo-badge.censo-1990 { color: #9c5d00; }
.censo-2001 .analysis-kpi-year, .censo-badge.censo-2001 { color: #087b2a; }
.censo-2011 .analysis-kpi-year, .censo-badge.censo-2011 { color: var(--c2011); }
.analysis-chart-body { width: 100%; overflow: hidden; }
.analysis-chart-body svg { display: block; width: 100%; height: auto; }

.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
  padding: 2px 4px;
}
.breadcrumb .sep { opacity: 0.5; }
.breadcrumb .current { color: var(--text-2); font-weight: 650; }

/* KPI cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
  animation: rise 0.5s var(--ease) both;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent-grad);
}
.kpi.kpi-h::before { background: var(--h); }
.kpi.kpi-m::before { background: var(--m); }
.kpi.kpi-idx::before { background: linear-gradient(135deg, var(--h), var(--m)); }

.kpi-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.kpi-value {
  font-size: clamp(20px, 2.6vw, 27px);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 12px; color: var(--text-3); }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Card / chart */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chart-card { padding: 20px; }

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.chart-title {
  font-size: clamp(15px, 2vw, 19px);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; }
.chart-legend .lg { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.chart-legend .dot { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }

.chart-body { width: 100%; overflow-x: auto; }
.chart-body svg { display: block; width: 100%; height: auto; }
.chart-body svg rect.barra-h, .chart-body svg rect.barra-m { transition: x 0.6s var(--ease), width 0.6s var(--ease), y 0.4s var(--ease), height 0.4s var(--ease); animation: entraBarra 0.7s var(--ease) backwards; transform-origin: center bottom; }
.chart-body svg .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart-body svg text { font-family: var(--font); }
@keyframes entraBarra {
  from { opacity: 0; transform: scaleY(0.55); }
  to { opacity: 1; transform: scaleY(1); }
}

.aviso {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}

/* Tabla */
.tabla-card { overflow: hidden; }
.tabla-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  list-style: none;
  transition: background 0.2s;
}
.tabla-summary::-webkit-details-marker { display: none; }
.tabla-summary:hover { background: var(--surface-2); }
.tabla-summary .chevron { transition: transform 0.25s var(--ease); color: var(--text-3); }
.tabla-card[open] .chevron { transform: rotate(180deg); }

.table-wrap { overflow-x: auto; border-top: 1px solid var(--border); }
.tabla { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tabla th, .tabla td {
  padding: 10px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tabla th {
  background: var(--surface-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 700;
}
.tabla tbody tr { transition: background 0.15s; }
.tabla tbody tr:hover { background: var(--surface-2); }
.tabla tbody tr:last-child td { border-bottom: none; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla tbody td:first-child { color: var(--text); font-weight: 600; }
.tabla .tot { font-weight: 750; background: color-mix(in srgb, var(--surface-3) 60%, transparent); }

/* ----------------------------- Responsive -------------------------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .analysis-layout { padding-left: 16px; padding-right: 16px; }
  .analysis-grid { grid-template-columns: 1fr; }
  .analysis-card { padding-left: 20px; padding-right: 20px; }
  .page-banner {
    max-height: 110px;
    min-height: 68px;
  }
}

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .brand-text p { display: none; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .chart-head { flex-direction: column; align-items: flex-start; }
  .analysis-heading { align-items: flex-start; flex-direction: column; }
  .analysis-kpis { grid-template-columns: 1fr; }
  .analysis-status { align-self: flex-start; }
  .page-banner {
    max-height: 82px;
    min-height: 58px;
  }
}

@media (min-width: 961px) and (max-width: 1150px) {
  .analysis-grid { grid-template-columns: 1fr; }
}

/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
