/* ═══════════════════════════════════════════
   YBT · Estadísticas Poblacionales
   Design: data-dense refined dark dashboard
   Fonts: Syne (display) + DM Mono (data)
═══════════════════════════════════════════ */

/* ── TOKENS ─────────────────────────────── */
:root {
  /* Palette */
  --bg:          #080c12;
  --bg-2:        #0c1118;
  --bg-3:        #101720;
  --surface:     #121a26;
  --surface-2:   #162030;
  --surface-3:   #1c2a3e;
  --border:      rgba(99, 135, 200, 0.10);
  --border-2:    rgba(99, 135, 200, 0.18);

  --text:        #dde8f8;
  --text-2:      #8ea5c4;
  --text-3:      #5a7090;

  /* Accents */
  --blue:        #4f8cff;
  --blue-dim:    rgba(79, 140, 255, 0.12);
  --green:       #3dd68c;
  --green-dim:   rgba(61, 214, 140, 0.10);
  --amber:       #f59e0b;
  --amber-dim:   rgba(245, 158, 11, 0.10);
  --red:         #ff5f6d;
  --red-dim:     rgba(255, 95, 109, 0.10);
  --orange:      #ff9f43;
  --orange-dim:  rgba(255, 159, 67, 0.10);
  --purple:      #a78bfa;
  --teal:        #2dd4bf;

  /* Chart palette (cohesive) */
  --c1: #4f8cff;
  --c2: #3dd68c;
  --c3: #f59e0b;
  --c4: #ff5f6d;
  --c5: #a78bfa;
  --c6: #2dd4bf;

  /* UI */
  --radius:    14px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow:    0 8px 32px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.03) inset;
  --shadow-sm: 0 2px 12px rgba(0,0,0,.3);
  --font-display: 'Syne', system-ui, sans-serif;
  --font-mono:    'DM Mono', 'Fira Mono', monospace;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

/* ── RESET ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* ── BASE ────────────────────────────────── */
.body-style {
  background:
    radial-gradient(ellipse 900px 500px at 5% -5%, rgba(79,140,255,.06) 0%, transparent 60%),
    radial-gradient(ellipse 700px 500px at 95% 5%, rgba(61,214,140,.04) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── MAIN CONTAINER ──────────────────────── */
.dash-main {
  margin: 0 auto;
  padding: 24px 24px 64px;
  position: relative;
}

/* ── PAGE HEADER ─────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.page-header__eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 6px;
  opacity: .85;
}
.page-header__title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.4px;
  line-height: 1.1;
  color: var(--text);
}
.page-header__sub {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: .01em;
}

/* ── BUTTONS ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  border: none;
}
.btn--sm { padding: 8px 14px; }
.btn--primary {
  background: var(--blue);
  color: #05090f;
  font-weight: 600;
}
.btn--primary:hover { background: #6fa3ff; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,140,255,.3); }
.btn--ghost {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-2);
}
.btn--ghost:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }

/* ── FILTER BAR ──────────────────────────── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-bar__inner {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filter-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
}
.filter-divider {
  width: 1px;
  height: 36px;
  background: var(--border-2);
}
.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.filter-bar__status {
  display: flex;
  align-items: center;
  gap: 7px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background .3s;
}
.status-dot.active { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.loading { background: var(--amber); animation: pulse 1s infinite; }
.status-dot.error { background: var(--red); }
.status-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  padding: 5px 12px;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  border: none;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}
.seg-btn.active {
  background: var(--blue);
  color: #05090f;
  font-weight: 600;
}
.seg-btn:hover:not(.active) { color: var(--text); background: var(--surface-3); }

/* Range inputs */
.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}
.num-input {
  width: 72px;
  padding: 6px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}
.num-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(79,140,255,.15); }
.num-input::placeholder { color: var(--text-3); }
.range-sep { color: var(--text-3); font-size: 14px; }

/* ── KPI ROW ─────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
  cursor: default;
}
.kpi-card:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
}
.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.018) 0%, transparent 60%);
  pointer-events: none;
}
.kpi-card--alert { border-color: rgba(255, 95, 109, .18); }
.kpi-card--warn { border-color: rgba(245, 158, 11, .15); }

.kpi-card__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-2);
  margin-top: 2px;
}
.kpi-card__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.kpi-card__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-card__value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.01em;
}
.kpi-card__sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  margin-top: 2px;
}
.kpi-card__bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--bar-color, var(--blue));
  opacity: .55;
}

/* ── CHARTS GRID ─────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition);
  position: relative;
  overflow: hidden;
}
.chart-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
}
.chart-card:hover { border-color: var(--border-2); }

/* column spans */
.chart-card[data-col="4"]  { grid-column: span 4; }
.chart-card[data-col="6"]  { grid-column: span 6; }
.chart-card[data-col="8"]  { grid-column: span 8; }
.chart-card[data-col="12"] { grid-column: span 12; }

.chart-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chart-card__title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text-2);
}
.chart-card__badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 100px;
  background: var(--surface-3);
  color: var(--text-3);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.chart-card__badge--info   { background: var(--blue-dim);   color: var(--blue);   border-color: rgba(79,140,255,.2); }
.chart-card__badge--warn   { background: var(--amber-dim);  color: var(--amber);  border-color: rgba(245,158,11,.2); }
.chart-card__badge--danger { background: var(--red-dim);    color: var(--red);    border-color: rgba(255,95,109,.2); }
.chart-card__badge--ok     { background: var(--green-dim);  color: var(--green);  border-color: rgba(61,214,140,.2); }

.chart-card__body {
  flex: 1;
  min-height: 0;
}
.chart-card__body--center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-card__meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.5;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

canvas {
  display: block;
  width: 100% !important;
  height: 240px !important;
}
.chart-card[data-col="4"] canvas { height: 210px !important; }
#chartSexo { height: 180px !important; }

/* ── TABLE ───────────────────────────────── */
.chart-card--table { gap: 14px; }
.table-scroll { overflow-x: auto; }
#tablaStats {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
#tablaStats th {
  text-align: right;
  padding: 9px 10px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-2);
  white-space: nowrap;
}
#tablaStats th.col-name { text-align: left; }
#tablaStats td {
  text-align: right;
  padding: 8px 10px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}
#tablaStats td:first-child {
  text-align: left;
  color: var(--text);
  font-weight: 500;
}
#tablaStats tbody tr:hover td {
  background: var(--surface-2);
  color: var(--text);
}
#tablaStats tbody tr:last-child td { border-bottom: none; }

/* ── LOAD OVERLAY ────────────────────────── */
.load-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, .85);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 999;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-3);
  opacity: 1;
  transition: opacity .4s;
}
.load-overlay.hidden { opacity: 0; pointer-events: none; }
.load-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border-2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ── ANIMATIONS ──────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpi-card, .chart-card {
  animation: fadeUp .4s ease both;
}
.kpi-card:nth-child(1) { animation-delay: .05s; }
.kpi-card:nth-child(2) { animation-delay: .09s; }
.kpi-card:nth-child(3) { animation-delay: .13s; }
.kpi-card:nth-child(4) { animation-delay: .17s; }
.kpi-card:nth-child(5) { animation-delay: .21s; }
.kpi-card:nth-child(6) { animation-delay: .25s; }

/* ── RESPONSIVE ──────────────────────────── */
@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .chart-card[data-col="4"] { grid-column: span 6; }
  .chart-card[data-col="6"] { grid-column: span 6; }
}
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: repeat(6, 1fr); }
  .chart-card[data-col="4"],
  .chart-card[data-col="6"],
  .chart-card[data-col="8"]  { grid-column: span 6; }
  .chart-card[data-col="12"] { grid-column: span 6; }
}
@media (max-width: 640px) {
  .dash-main { padding: 16px 14px 48px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-bar { flex-direction: column; align-items: flex-start; }
  .filter-bar__inner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .filter-divider { display: none; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card[data-col] { grid-column: span 1; }
  .page-header__title { font-size: 22px; }
}

/* ── LIGHT THEME OVERRIDES ───────────────── */
.light-theme {
  --bg:          #f0f4fa;
  --bg-2:        #e8eef8;
  --bg-3:        #dde6f2;
  --surface:     #ffffff;
  --surface-2:   #f5f8ff;
  --surface-3:   #ebf0fb;
  --border:      rgba(79, 120, 200, 0.10);
  --border-2:    rgba(79, 120, 200, 0.20);
  --text:        #0d1929;
  --text-2:      #3a5278;
  --text-3:      #7a94b4;
  --blue-dim:    rgba(79, 140, 255, 0.08);
  --amber-dim:   rgba(245, 158, 11, 0.08);
  --red-dim:     rgba(255, 95, 109, 0.08);
  --green-dim:   rgba(61, 214, 140, 0.08);
  --shadow:      0 4px 20px rgba(0,0,0,.06), 0 1px 0 rgba(255,255,255,.9) inset;
}
.light-theme .body-style {
  background:
    radial-gradient(ellipse 900px 500px at 5% -5%, rgba(79,140,255,.04) 0%, transparent 60%),
    var(--bg);
}
.light-theme .load-overlay { background: rgba(240, 244, 250, .85); }
.light-theme #tablaStats td { color: var(--text-2); }
.light-theme #tablaStats tbody tr:hover td { background: var(--surface-2); color: var(--text); }
.light-theme .segmented { background: var(--bg-3); }
.light-theme .num-input { background: var(--bg-3); }

/* ── CHART.JS GLOBAL DEFAULTS (set via JS) ── */
/* Las opciones de Chart.js se pasan en el JS */