:root {
  --bg-page: #f9fafb;
  --bg-card: #ffffff;
  --bg-soft: #f3f4f6;

  --border-subtle: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;

  /* Colores de marca (verde) */
  --brand-1: #1f442a;            /* principal */
  --brand-2: #2f6b3a;            /* medio */
  --brand-3: #8dcf6a;            /* acento claro */

  --accent: var(--brand-2);
  --accent-soft: rgba(31, 68, 42, 0.18);

  --radius-lg: 16px;
  --radius-md: 12px;

  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.06);
  --shadow-header: 0 10px 30px rgba(15, 23, 42, 0.04);
}

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

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* =================== ANIMACIONES =================== */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =================== TOPBAR =================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: rgba(249, 250, 251, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.9);
  box-shadow: var(--shadow-header);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(31, 68, 42, 0.08);
  color: var(--brand-1);
  border: 1px solid rgba(31, 68, 42, 0.35);
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.page-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
}

/* Selects tipo pill */

.field select {
  min-width: 150px;
  height: 36px;
  padding: 0 34px 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background-color: #ffffff;
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  appearance: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease, transform 0.08s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%239ca3af' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px 6px;
}

.field select:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

/* Input archivo (no lo usas ahora, pero no molesta) */
.field input[type="file"] {
  font-size: 11px;
  max-width: 210px;
}

/* Botón principal */

.btn {
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  padding: 0 18px;
  height: 36px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, box-shadow 0.15s ease,
    transform 0.08s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn.primary {
  background: linear-gradient(135deg, var(--brand-2), var(--brand-3));
  color: #ffffff;
  box-shadow: 0 14px 30px var(--accent-soft);
}

.btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 42px var(--accent-soft);
}

/* =================== LAYOUT GENERAL =================== */

.wrap {
  max-width: 1200px;
  margin: 22px auto 72px;
  padding: 0 16px;
}

/* =================== KPIs =================== */

.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  padding: 12px 14px 12px;
  cursor: pointer;
  display: grid;
  grid-template-rows: auto auto auto;
  align-items: start;
  gap: 6px;
  min-height: 120px;
  text-align: left;
  transition: box-shadow 0.15s ease, transform 0.08s ease,
    border-color 0.15s, background 0.15s ease;
  animation: fadeUp 0.4s ease-out both;
}

.kpis .kpi:nth-child(2) {
  animation-delay: 0.05s;
}
.kpis .kpi:nth-child(3) {
  animation-delay: 0.1s;
}
.kpis .kpi:nth-child(4) {
  animation-delay: 0.15s;
}
.kpis .kpi:nth-child(5) {
  animation-delay: 0.2s;
}
.kpis .kpi:nth-child(6) {
  animation-delay: 0.25s;
}

.kpi-top {
  display: flex;
  justify-content: left;
  align-items: left;
  gap: 6px;
}

.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  display: none;
}

/* Pill métrica */
.kpi-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand-2);
  background: rgba(31, 68, 42, 0.06);
  border-radius: 999px;
  padding: 2px 6px;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-sub {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}

.kpi:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.kpi.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow-soft);
  background: #f3faf5;
}

/* =================== CARDS & GRID =================== */

.layout {
  display: grid;
  grid-template-columns: 2fr 1.3fr;
  gap: 16px;
}

.layout-demografia {
  margin-top: 24px;
}

.layout-detalle {
  margin-top: 24px;
}

.card {
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeUp 0.45s ease-out both;
}

.card-large {
  grid-column: 1 / -1;
}

.card-wide {
  grid-column: 1 / -1;
}

.card-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.card-header p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.card-body {
  padding: 12px 14px 14px;
}

.chart-body {
  height: 280px;
}

.table-body {
  padding-top: 8px;
}

/* ========== MAPA BOLIVIA + BARRAS ========== */

.chart-body--map {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  height: auto;
}

.map-bo {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.map-bo__img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.chart-bo {
  width: 100%;
  height: 260px;
}

/* Canvases */
#chLine,
#chBar,
#chPieAll,
#chDeptosBo,
#chPais,
#chEdadGenero,
#chPages {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Tabla */

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.tbl th,
.tbl td {
  padding: 8px 10px;
  white-space: nowrap;
  border-bottom: 1px solid #f3f4f6;
}

.tbl th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 1;
  font-weight: 600;
  color: var(--text-muted);
}

.tbl tr:nth-child(even) td {
  background: #fcfcfd;
}

/* Layout split (si lo usas) */
.chart-body--split {
  display: flex;
  gap: 16px;
  align-items: stretch;
  height: 340px;
}

.chart-body--split .map-bo {
  position: relative;
  width: 55%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-body--split .map-bo__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.chart-body--split .chart-bo {
  flex: 1;
  min-width: 0;
}

/* =================== RESPONSIVE =================== */

@media (max-width: 980px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .card-large,
  .card-wide {
    grid-column: auto;
  }

  .chart-body--split {
    flex-direction: column;
    height: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field select {
    min-width: 130px;
  }

  .chart-body {
    height: 240px;
  }
}
