
:root {
  /* Base */
  --white:        #ffffff;
  --surface:      #fafafa;
  --surface-2:    #f4f4f5;
  --surface-3:    #ececed;

  /* Texto */
  --text-primary:   #5a5a5a;
  --text-secondary: #2f2f33;
  --text-tertiary:  #323438;

  /* Bordes */
  --border:        rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.12);

  /* Acento */
  --accent:        #3b5bdb;
  --accent-light:  #eef2ff;
  --accent-muted:  #4c6ef5;

  /* Semánticos */
  --success:       #30827d;
  --success-bg:    #ddfff4;
  --warning:       #e67700;
  --warning-bg:    #fff9db;
  --danger:        #c92a2a;
  --danger-bg:     #fff5f5;
  --neutral:       #495057;
  --neutral-bg:    #f1f3f5;

  /* Tipografía */
  --text-xs:   11px;
  --text-sm:   12px;
  --text-base: 13px;
  --text-md:   14px;
  --text-lg:   16px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;

  /* Layout */
  --sidebar-w:           220px;
  --sidebar-w-collapsed:  52px;
  --topbar-h:             56px;

  /* Easing */
  --ease:      cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out:  cubic-bezier(0, 0, 0.2, 1);
}

/* ── RESET ────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

html, body {
  background: var(--surface);
}

body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 200;
  transition: width 0.25s var(--ease);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

/* Header del sidebar */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo-wrap {
  display: flex;
  align-items: center;
  overflow: hidden;
  flex: 1;
}
.sidebar-logo {
  height: 30px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.2s, width 0.25s var(--ease);
}
.sidebar-logo:hover { opacity: 0.9; }
.sidebar.collapsed .sidebar-logo { opacity: 0; width: 0; }

.sidebar-toggle {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text-primary); }
.sidebar-toggle svg { width: 13px; height: 13px; transition: transform 0.25s var(--ease); }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* Label del sistema */
.sidebar-system-label {
  padding: 16px 16px 4px;
  overflow: hidden;
}
.sidebar-system-label span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
  display: block;
}
.sidebar.collapsed .sidebar-system-label span { opacity: 0; }

/* Navegación */
.sidebar-nav {
  flex: 1;
  padding: 6px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }

.nav-group { margin-bottom: 4px; }
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 0 10px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.2s;
}
.sidebar.collapsed .nav-group-label { opacity: 0; }

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-align: left;
  white-space: nowrap;
  position: relative;
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* Tooltip en modo colapsado */
.nav-item .nav-tooltip {
  position: absolute;
  left: calc(var(--sidebar-w-collapsed) + 4px);
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  background: var(--text-primary);
  color: var(--white);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 300;
}
.sidebar.collapsed .nav-item:hover .nav-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Icono del nav */
.nav-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  background: transparent;
  flex-shrink: 0;
  transition: background 0.15s;
}
.nav-icon svg { width: 15px; height: 15px; stroke-width: 1.8; }
.nav-item.active .nav-icon { background: var(--accent-light); }

/* Label y badge */
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; transition: opacity 0.2s; }
.sidebar.collapsed .nav-label { opacity: 0; }

.nav-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: 'Geist Mono', monospace;
  background: var(--neutral-bg);
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 99px;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
  border: 1px solid var(--border);
}
.nav-item.active .nav-badge {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent-light);
}
.sidebar.collapsed .nav-badge { opacity: 0; }

/* Footer del sidebar */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-footer-inner { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.footer-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.footer-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
  font-weight: 500;
}
.footer-year {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  font-family: 'Geist Mono', monospace;
  transition: opacity 0.2s;
}
.sidebar.collapsed .footer-text,
.sidebar.collapsed .footer-year { opacity: 0; }

/* Overlay mobile — se activa via CSS cuando el sidebar tiene .mobile-open */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 199;
  animation: overlayIn 0.2s var(--ease-out);
}
/* El sidebar y el overlay son hermanos adjacentes en el DOM */
.sidebar.mobile-open + .sidebar-overlay { display: block; }

/* ── MAIN WRAPPER ─────────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s var(--ease);
  background: var(--surface);
}
.main-wrapper.collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ── TOPBAR (solo mobile visible por defecto en desktop) ──── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: right;
  justify-content: space-between;
  padding: 0 20px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-logo {
  height: 38px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.topbar-menu-btn {
  display: none;
  width: 34px; height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.topbar-menu-btn:hover { background: var(--surface-2); }
.topbar-menu-btn svg { width: 16px; height: 16px; }

.topbar-section-label {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-right { display: flex; align-items: flex-end; }

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
}

.module-tabs {
  gap: 4px;
  display: flex;
  background: transparent;   /* ← quitar el fondo del contenedor */
  padding: 0;
  border-radius: 0;
}

.top-tab {
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  padding: 5px 14px;
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all .16s var(--ease);
  font-family: inherit;
  letter-spacing: -0.01em;
}

.top-tab:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.top-tab.active {
  background: var(--accent-light);
  color: var(--success);
  font-weight: 600;
}

/* Desktop: topbar visible pero slim — solo muestra sección + logo */
@media (min-width: 769px) {
  .topbar {
    display: flex;
    height: 80px;
    padding: 0 28px;
    background: var(--white);
  }
  /* El botón hamburger no se necesita en desktop */
  .topbar-menu-btn { display: none; }

  /* Nombre de sección — estilo breadcrumb sutil */
  .topbar-section-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-tertiary);
    letter-spacing: 0.01em;
  }

  /* Logo JP — visible pero contenido */
  .topbar-logo {
    height: 60px;
    width: auto;
    transition: opacity 0.15s;
  }
  .topbar-logo:hover { opacity: 1; }
}

/* Desktop ancho: sidebar tipo rail + tabs superiores principales */
@media (min-width: 1180px) {
  .sidebar {
    width: 86px;
  }

  .main-wrapper {
    margin-left: 86px;
  }

  .sidebar-toggle,
  .sidebar-system-label,
  .nav-group-label,
  .nav-label,
  .nav-badge,
  .footer-text,
  .footer-year {
    display: none;
  }

  .sidebar-header {
    justify-content: center;
    padding: 0;
  }

  .sidebar-nav {
    padding: 10px 8px;
  }

  .nav-item {
    justify-content: center;
    padding: 8px;
  }

  .nav-item .nav-tooltip {
    left: 92px;
  }
}

/* ── CONTENT ──────────────────────────────────────────────── */
.content-section { display: none; flex: 1; }
.content-section.active { display: flex; flex-direction: column; }

.content-inner {
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── PAGE TITLE ───────────────────────────────────────────── */
.page-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.page-subtitle {
  font-size: var(--text-md);
  color: var(--text-tertiary);
  margin-top: 4px;
  font-weight: 400;
}

/* ── KPI CARDS ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transition: background 0.15s;
}
.stat-card:hover { background: var(--surface); }

.stat-card-inner {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

/* Fila superior: icono + badge opcional */
.stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-icon-wrap {
  width: 36px; height: 36px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-wrap svg { width: 18px; height: 18px; stroke: var(--text-secondary); }

/* Número principal */
.stat-number {
  font-family: 'Geist Mono', monospace;
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.1;
  display: block;
}

.stat-label-main {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
}
.stat-sub {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Anillos SVG ocultos — el JS los necesita en el DOM pero no deben verse */
.ring-wrap, .ring-svg, .ring-track, .ring-fill, .ring-center, .ring-value-hidden {
  display: none !important;
}

/* ── CHART SECTION ────────────────────────────────────────── */
.chart-section { display: block; }

.chart-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  overflow: hidden;
}
.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.chart-card-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.chart-card-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 3px;
}
.chart-canvas-wrap {
  position: relative;
  height: 280px;
}
.chart-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Insight debajo del gráfico */
.chart-insight {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 12px;
  min-height: 16px;
  line-height: 1.5;
}
.chart-insight strong { color: var(--text-secondary); font-weight: 600; }

/* Tag de filtro activo */
.chart-filter-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 12px;
  background: var(--accent-light);
  border: 1px solid rgba(59, 91, 219, 0.15);
  border-radius: 99px;
  width: fit-content;
  font-size: var(--text-sm);
  color: var(--accent);
  font-weight: 600;
}
.chart-filter-clear {
  width: 14px; height: 14px;
  border: none; background: transparent;
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  opacity: 0.6;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.chart-filter-clear:hover { opacity: 1; }
.chart-filter-clear svg { width: 10px; height: 10px; }

/* ── LIST SECTION ─────────────────────────────────────────── */
.list-section { display: flex; flex-direction: column; gap: 10px; }

.list-sticky-controls {
  position: sticky;
  top: 72px;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 0 10px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.list-header-left { display: flex; align-items: baseline; gap: 10px; }
.list-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.list-count {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  font-family: 'Geist Mono', monospace;
}
.list-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Search box */
.search-box { position: relative; width: 240px; }
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-tertiary); }
.search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* Filter pills */
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  padding: 5px 14px;
  border-radius: 99px;
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--white);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.filter-pill:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.filter-pill.active {
  background: var(--text-primary);
  color: var(--white);
  border-color: var(--text-primary);
}

/* ── MUNICIPALITY LIST ────────────────────────────────────── */
.municipality-list {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Animación de entrada */
@keyframes rowEnter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.muni-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  opacity: 0;
  animation: rowEnter 0.3s var(--ease-out) both;
}
.muni-row:last-child { border-bottom: none; }
.muni-row:hover { background: var(--surface); }

/* Avatar inicial */
.muni-row::before {
  content: '';
  display: none; /* reservado — avatar requiere JS para la letra */
}

/* Nombre + etapa */
.muni-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 170px;
  flex: 0 0 190px;
}
.muni-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.muni-stage {
  font-size: 10px;
  font-weight: 500;
  color: #4b5563;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

/* Barra de progreso */
.muni-progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.muni-bar-track {
  height: 4px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
}
.muni-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.muni-bar-fill.none     { background: var(--surface-3); }
.muni-bar-fill.low      { background: var(--warning); }
.muni-bar-fill.medium   { background: var(--warning); }
.muni-bar-fill.high     { background: var(--accent); }
.muni-bar-fill.complete { background: var(--success); }

.muni-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-tertiary);
  font-family: 'Geist Mono', monospace;
}

/* Porcentaje */
.muni-badge { flex-shrink: 0; }
.badge-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'Geist Mono', monospace;
}
.badge-pill.none     { color: var(--text-tertiary); background: var(--neutral-bg); }
.badge-pill.low      { color: var(--warning);        background: var(--warning-bg); }
.badge-pill.medium   { color: var(--warning);        background: var(--warning-bg); }
.badge-pill.high     { color: var(--accent);         background: var(--accent-light); }
.badge-pill.complete { color: var(--success);        background: var(--accent-light); }

/* Hint de edición */
.muni-edit-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.muni-row:hover .muni-edit-hint { opacity: 1; }
.muni-edit-hint svg { width: 11px; height: 11px; }

/* ── LOADING / EMPTY ──────────────────────────────────────── */
.loading-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--text-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.loading-dots { display: flex; gap: 6px; }
.loading-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--surface-3);
  animation: bounce-dot 1.3s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce-dot {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--text-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.empty-icon { opacity: 0.3; }
.empty-icon svg { width: 36px; height: 36px; }

/* ── FOOTER ───────────────────────────────────────────────── */
.main-footer {
  margin-top: auto;
  background: var(--text-primary);
  border-top: 1px solid var(--border);
  padding: 14px 32px;
  font-size: var(--text-xs);
  color: white;
  font-weight: 400;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.footer-logo {
  height: 200px;
  width: auto;
  object-fit: contain;
  opacity: 0.8;
  flex-shrink: 0;
}

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.open {
  display: flex;
  animation: overlayIn 0.2s var(--ease-out);
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal-container {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  animation: modalIn 0.2s var(--ease-out);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Barra de progreso modal (2px, full width, acento) */
.modal-progress-bar { height: 2px; background: var(--surface-3); flex-shrink: 0; }
.modal-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.55s var(--ease);
}

/* Header del modal */
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.modal-header-left { display: flex; align-items: center; gap: 10px; }

.modal-tag {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.pot-tag { background: var(--accent-light); color: var(--accent); }
.mit-tag { background: var(--accent-light); color: var(--accent); }

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.modal-pct-counter {
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: 'Geist Mono', monospace;
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.3s;
}
.modal-pct-counter.none     { background: var(--neutral-bg);  color: var(--neutral); }
.modal-pct-counter.low      { background: var(--warning-bg);  color: var(--warning); }
.modal-pct-counter.medium   { background: var(--warning-bg);  color: var(--warning); }
.modal-pct-counter.high     { background: var(--accent-light); color: var(--accent); }
.modal-pct-counter.complete { background: var(--success-bg);  color: var(--success); }

.modal-close {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.modal-close svg { width: 14px; height: 14px; }
.modal-close:hover { background: var(--surface-2); color: var(--text-primary); }

/* Body del modal */
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }

/* Footer del modal */
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* ── FASE SECTIONS (dentro del modal) ─────────────────────── */
.phase-section { margin-bottom: 24px; }
.phase-section:last-child { margin-bottom: 0; }
.phase-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.phase-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  flex: 1;
}
.phase-weight {
  font-size: var(--text-xs);
  font-family: 'Geist Mono', monospace;
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 99px;
}

.phase-control-row {
  margin-bottom: 10px;
}

/* Checkboxes */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 4px;
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.checkbox-field:hover { background: var(--surface-2); border-color: var(--border); }

.checkbox-field.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-2);
  border-color: var(--border);
}

.checkbox-field.checkbox-field--review {
  border-color: var(--border);
  background: #fff7ed;
}

.checkbox-field.checkbox-field--review.is-active {
  border-color: #fb923c;
  background: #ffedd5;
}
.checkbox-field input { position: absolute; opacity: 0; pointer-events: none; }

.checkbox-box {
  width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
}
.checkbox-field:hover .checkbox-box { border-color: var(--text-secondary); }
.checkbox-field input:checked + .checkbox-box {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-box::after {
  content: '';
  width: 4px; height: 7px;
  border-bottom: 1.5px solid white;
  border-left: 1.5px solid white;
  border-top: none; border-right: none;
  transform: rotate(-45deg) scale(0);
  transition: transform 0.12s var(--ease);
  position: absolute;
  top: 0px;
}
.checkbox-field input:checked + .checkbox-box::after { transform: rotate(-45deg) scale(1); }

@keyframes checkPulse {
  0%   { box-shadow: 0 0 0 0   rgba(59, 91, 219, 0.3); }
  60%  { box-shadow: 0 0 0 6px rgba(59, 91, 219, 0); }
  100% { box-shadow: 0 0 0 0   rgba(59, 91, 219, 0); }
}
.checkbox-box.pulse { animation: checkPulse 0.4s var(--ease); }

.checkbox-label {
  font-size: var(--text-base);
  color: var(--text-primary);
  font-weight: 400;
  line-height: 1.3;
}

/* Date & Notes */
.date-field-wrap { margin-top: 8px; }
.date-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
}
.date-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: var(--text-md);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}
.date-input:focus { border-color: var(--accent); }

.notes-wrap { margin-top: 8px; }
.notes-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: var(--text-md);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--white);
  outline: none;
  resize: vertical;
  min-height: 72px;
  transition: border-color 0.15s;
}
.notes-input:focus { border-color: var(--accent); }

/* Mitigación activity list */
.mit-activity-list { display: flex; flex-direction: column; gap: 2px; }
.mit-activity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.mit-activity-row:hover { background: var(--surface-2); border-color: var(--border); }
.mit-activity-row input { position: absolute; opacity: 0; pointer-events: none; }
.mit-activity-row input:checked ~ .mit-activity-label { color: var(--text-primary); font-weight: 500; }
.mit-activity-label {
  flex: 1;
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: 1.4;
  transition: color 0.12s;
}
.mit-activity-weight {
  font-size: var(--text-xs);
  font-family: 'Geist Mono', monospace;
  color: var(--text-tertiary);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 99px;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
  transition: all 0.15s;
}
.mit-activity-row input:checked ~ .mit-activity-weight {
  background: var(--success-bg);
  color: var(--success);
}

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: var(--text-base);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: background 0.15s, box-shadow 0.15s;
  letter-spacing: -0.01em;
}
.btn svg { width: 14px; height: 14px; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--text-primary);
  color: var(--white);
}
.btn-primary:hover { background: #1a1a1e; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }

@keyframes spin { to { transform: rotate(360deg); } }
.btn-spinner {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

/* ── TOAST ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 16px; right: 16px;
  background: var(--text-primary);
  color: var(--white);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: var(--text-base);
  font-weight: 400;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
  z-index: 2000;
  pointer-events: none;
  white-space: nowrap;
  max-width: 320px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── DONUT SECTION ────────────────────────────────────────── */
.modal-donut-section {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: 10px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  min-height: 126px;
}
.modal-donut-section canvas { flex-shrink: 0; }
.modal-donut-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.donut-legend-item { display: flex; align-items: center; gap: 8px; }
.donut-legend-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.donut-legend-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  flex: 1;
  line-height: 1.3;
}
.donut-legend-value {
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: 'Geist Mono', monospace;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ── MAP (para compatibilidad) ────────────────────────────── */
.map-container { position: relative; min-height: 180px; border-radius: 10px; overflow: hidden; }
.map-container svg { width: 100%; height: auto; display: block; }
.map-container path {
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
  stroke: rgba(255,255,255,0.55);
  stroke-width: 0.6;
}
.map-container path:hover { filter: brightness(0.82); }
.muni-row.map-highlight { background: var(--accent-light); }

/* Mapa municipal + stats superpuestas */
.map-outline {
    background: var(--surface);
    border: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 16px 16px;
    gap: 16px;
    min-height: 200px;
}

.map-svg-wrap {
    width: 100%;
    max-width: 820px;
    background: #f8fafc; /* Gris muy tenue solicitado */
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
}

.pr-muni-svg {
    width: 100%;
    height: auto;
    display: block;
}

.map-stack {

    position: relative;

    width: 100%;

    max-width: 820px;

    aspect-ratio: 2480 / 875;

    background: #f8fafc;

    border: 1px solid var(--border);

    border-radius: 10px;

    overflow: hidden;

}

.map-base-visual {

    position: absolute;

    inset: 10px;

    width: calc(100% - 20px);

    height: calc(100% - 20px);

    object-fit: contain;

    object-position: center;

    pointer-events: none;

    user-select: none;

    opacity: 0.3;

    filter: grayscale(1) contrast(0.92) brightness(1.02);

}

.map-svg-overlay {

    position: absolute;

    inset: 10px;

    width: auto;

    max-width: none;

    height: auto;

    background: transparent;

    border: 0;

    border-radius: 0;

    padding: 0;

    display: flex;

    align-items: center;

    justify-content: center;

}

.map-svg-overlay .pr-muni-svg {

    width: 100%;

    height: 100%;

}

.map-svg-overlay .muni-path {

    fill-opacity: 1;

}

#map-container .muni-path {
    cursor: pointer;
    transition: fill 0.25s var(--ease), opacity 0.2s, stroke 0.2s, filter 0.2s;
    stroke: #ffffff;
    stroke-width: 0.5px;
    vector-effect: non-scaling-stroke;
    paint-order: stroke fill;
}

#map-container .muni-path:hover {
    stroke: #3b82f6; /* Azul vibrante */
    stroke-width: 1.5px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.12));
}

#map-container .muni-path.active {
    stroke: #2563eb;
    stroke-width: 2px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
}

.map-island-img {
    width: 100%;
    max-width: 620px;
    max-height: 240px;
    height: auto;
    display: block;
    filter: brightness(0) saturate(100%) invert(60%) sepia(20%) saturate(300%) hue-rotate(120deg) brightness(90%);
    opacity: 0.18;
    object-fit: contain;
}
.map-overlay-stats {
    display: flex;
    align-items: center;
    background: var(--white);
    border: 1px solid rgba(0,0,0,0.07);
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
    padding: 14px 4px;
    width: fit-content;
}
.map-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 0 20px;
}
.map-stat-value {
    font-size: 22px;
    font-weight: 900;
    font-family: 'Geist Mono', monospace;
    color: var(--text-primary);
    letter-spacing: -0.06em;
    line-height: 1;
}
.map-stat-label {
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.map-stat-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
    flex-shrink: 0;
}

.map-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; padding: 32px 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px; background: var(--surface);
  text-align: center;
}
.map-placeholder-text { font-size: var(--text-sm); color: var(--text-tertiary); line-height: 1.6; }
.map-placeholder-text code {
  font-family: 'Geist Mono', monospace; font-size: 11px;
  background: var(--surface-2); padding: 1px 5px; border-radius: 3px;
}
.map-legend { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.map-legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); color: var(--text-secondary);
}
.map-legend-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ── TOOLTIP DEL MAPA — Glassmorphism 2026 ──────────────────── */
.map-tooltip {
  position: fixed;
  z-index: 2500;
  min-width: 200px;
  max-width: 260px;

  /* Glassmorphism core */
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);

  /* Borde luminoso sutil */
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.13),
    0 1px 4px  rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  padding: 12px 14px;
  pointer-events: none;

  /* Aparición suave */
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transition:
    opacity 0.18s var(--ease-out),
    transform 0.18s var(--ease-out);
}
.map-tooltip.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Nombre del municipio */
.map-tooltip-name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

/* Etapa actual */
.map-tooltip-stage {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Barra de progreso */
.map-tooltip-track {
  width: 100%;
  height: 5px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
}
.map-tooltip-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  transition: width 0.3s var(--ease-out);
}

/* Porcentaje */
.map-tooltip-pct {
  margin-top: 7px;
  font-size: var(--text-xs);
  font-family: 'Geist Mono', monospace;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Resaltado en lista al seleccionar municipio desde el mapa */
.muni-row.map-highlight {
  background: var(--accent-light) !important;
  border-left: 3px solid var(--accent);
  padding-left: 11px; /* compensa el borde extra */
  transition: background 0.2s var(--ease), border-left-color 0.2s;
}

/* Animación de "flash" cuando el scroll llega al elemento */
@keyframes mapFlash {
  0%   { background: rgba(59, 91, 219, 0.22); }
  60%  { background: rgba(59, 91, 219, 0.10); }
  100% { background: var(--accent-light); }
}
.muni-row.map-flash {
  animation: mapFlash 0.55s var(--ease-out) both;
}

/* ── LOGIN PAGE ───────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--surface);
}
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 400px;
  padding: 24px 20px;
}
.login-card {
  width: 100%;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.login-card-icon-wrap { display: flex; justify-content: center; margin-bottom: 20px; }
.login-card-icon { max-height: 48px; width: auto; object-fit: contain; }
.login-header { text-align: center; margin-bottom: 24px; }
.login-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.login-subtitle { font-size: var(--text-base); color: var(--text-tertiary); margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: var(--text-md);
  font-family: inherit;
  color: var(--text-primary);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-tertiary); }
.login-btn {
  width: 100%;
  padding: 11px 18px;
  margin-top: 6px;
  background: var(--text-primary);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: var(--text-md);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: -0.01em;
}
.login-btn:hover:not(:disabled) { background: #1a1a1e; }
.login-btn:active:not(:disabled) { transform: scale(0.99); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.form-footer { margin-top: 16px; text-align: center; }
.forgot-link { font-size: var(--text-sm); color: var(--text-tertiary); text-decoration: none; transition: color 0.15s; }
.forgot-link:hover { color: var(--text-primary); }
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: var(--text-base);
  font-weight: 500;
  margin-bottom: 14px;
  line-height: 1.4;
}
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid rgba(201, 42, 42, 0.2); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(8, 127, 91, 0.2); }
.login-footer-text { font-size: var(--text-xs); color: var(--text-tertiary); text-align: center; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
  }
  .main-wrapper { margin-left: 0 !important; }
  .topbar { display: flex; }
  .topbar-menu-btn { display: flex; }
  .topbar-center { display: none; }
  .topbar-section-label::before { display: none; }
  .list-sticky-controls {
    position: static;
    border-bottom: none;
    padding: 0;
  }
  .content-inner { padding: 20px 16px 48px; gap: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .search-box { width: 100%; }
  .list-header { flex-direction: column; align-items: stretch; }
  .list-controls { flex-direction: column; align-items: stretch; }
  .modal-container { border-radius: 12px; }
  .muni-row { flex-wrap: wrap; gap: 10px; }
  .muni-name-wrap { flex: 0 0 calc(100% - 56px); }
  .muni-progress-wrap { flex: 1; order: 3; }
  .muni-badge { margin-left: auto; }
  .muni-edit-hint { display: none; }
  /* Avatar on mobile */
  .muni-avatar { align-self: flex-start; }
  .footer-inner { flex-direction: column; gap: 6px; }
  .footer-logo { height: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card-inner { padding: 16px 18px; }
  .login-card { padding: 28px 22px; }
}

/* ═══════════════════════════════════════════════════════════
   VISUAL ENHANCEMENTS 2026
   ═══════════════════════════════════════════════════════════ */

/* ── 1. KPI CARDS — colored top-border accent per position ── */
.stats-grid .stat-card:nth-child(1) { border-top: 2px solid var(--text-tertiary); }
.stats-grid .stat-card:nth-child(2) { border-top: 2px solid var(--success); }
.stats-grid .stat-card:nth-child(3) { border-top: 2px solid var(--accent); }
.stats-grid .stat-card:nth-child(4) { border-top: 2px solid var(--warning); }

/* Icono coloreado por card */
.stats-grid .stat-card:nth-child(1) .stat-icon-wrap { background: var(--neutral-bg); }
.stats-grid .stat-card:nth-child(1) .stat-icon-wrap svg { stroke: var(--neutral); }
.stats-grid .stat-card:nth-child(2) .stat-icon-wrap { background: var(--success-bg); }
.stats-grid .stat-card:nth-child(2) .stat-icon-wrap svg { stroke: var(--success); }
.stats-grid .stat-card:nth-child(3) .stat-icon-wrap { background: var(--accent-light); }
.stats-grid .stat-card:nth-child(3) .stat-icon-wrap svg { stroke: var(--accent); }
.stats-grid .stat-card:nth-child(4) .stat-icon-wrap { background: var(--warning-bg); }
.stats-grid .stat-card:nth-child(4) .stat-icon-wrap svg { stroke: var(--warning); }

/* Número con color según card tipo */
.stats-grid .stat-card:nth-child(2) .stat-number { color: var(--success); }
.stats-grid .stat-card:nth-child(3) .stat-number { color: var(--accent); }

/* ── 2. AVATAR DE MUNICIPIO ───────────────────────────────── */
.muni-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  font-family: 'Geist', sans-serif;
  letter-spacing: -0.01em;
  /* color e background se setean via JS inline style */
}

/* Ajustar el layout de la fila para acomodar el avatar */
.muni-row {
  gap: 14px;
}

/* ── 3. STAGE PILL — colores semánticos ───────────────────── */
.muni-stage {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 500;
  background: var(--neutral-bg);
  color: var(--neutral);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  letter-spacing: 0.01em;
  margin-top: 2px;
}

/* ════════════════════════════════
   BENTO GRID
════════════════════════════════ */
.bento-section { margin-bottom: 28px; }

.bento-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.bento-cell {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.bento-cell.span-2 { grid-column: span 2; }
.bento-cell.span-3 { grid-column: span 3; }

.bento-hero {
  background: #30827d;
  border: none;
  border-radius: 14px;
  padding: 18px;
}

.bento-lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-tertiary);
  margin-bottom: 5px;
}
.bento-lbl-w {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: rgba(255,255,255,.65);
  margin-bottom: 5px;
}
.bento-val {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text-primary);
}
.bento-val-w {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
  color: #fff;
}
.bento-delta      { font-size: 11px; margin-top: 4px; color: var(--text-tertiary); }
.bento-delta-w    { font-size: 11px; margin-top: 4px; color: rgba(255,255,255,.72); }
.bento-cell-title { font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 2px; }
.bento-cell-sub   { font-size: 11px; color: var(--text-tertiary); }

.bento-sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 36px;
  margin-top: 16px;
}
.bento-sparkline span {
  flex: 1;
  border-radius: 2px 2px 0 0;
  background: rgba(255,255,255,.28);
}

.bento-prog-list  { display: flex; flex-direction: column; gap: 9px; margin-top: 14px; }
.bento-prog-row   { display: flex; flex-direction: column; gap: 4px; }
.bento-prog-meta  { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-tertiary); }
.bento-prog-track { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bento-prog-fill  { height: 100%; border-radius: 3px; transition: width .5s ease; }

.bento-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.bento-leg-item { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--text-tertiary); }
.bento-leg-sq   { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.bento-chart-wrap { position: relative; height: 165px; margin-top: 12px; }
.bento-map-slot   { margin-top: 12px; min-height: 160px; }

.bento-up   { color: #30827d; }
.bento-down { color: #dc2626; }
.bento-neu  { color: #6b7280; }

@media (max-width: 768px) {
  .bento-grid { grid-template-columns: 1fr; }
  .bento-cell.span-2,
  .bento-cell.span-3 { grid-column: span 1; }
}

/* Colorizar la pill según texto de la etapa — heurístico por keywords */
.muni-row:has(.muni-bar-fill.complete) .muni-stage {
  background: var(--accent-light);
  color: var(--success);
}
.muni-row:has(.muni-bar-fill.high) .muni-stage {
  background: var(--accent-light);
  color: var(--accent);
}
.muni-row:has(.muni-bar-fill.medium) .muni-stage,
.muni-row:has(.muni-bar-fill.low) .muni-stage {
  background: var(--warning-bg);
  color: var(--warning);
}

/* ── 4. MUNICIPALITY LIST — mejoras de lista ─────────────── */
/* Container con bordes internos más sutiles */
.municipality-list {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Nombre más prominente */
.muni-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Barra de progreso más visible */
.muni-bar-track {
  height: 4px;
}

/* Labels 0%/100% visualmente integrados */
.muni-bar-labels {
  font-size: 9px;
  letter-spacing: 0.02em;
  opacity: 0.6;
}

/* Badge de porcentaje más compacto */
.badge-pill {
  font-size: 12px;
  font-weight: 700;
  min-width: 52px;
  padding: 4px 10px;
}

/* ── 5. PAGE TITLE — más impacto visual ──────────────────── */
.page-title {
  font-size: 40px;
  font-weight: 700;
}
.page-title-row {
  align-items: center;
}

.page-title-row .topbar-logo {
  height: 85px;
  opacity: 0.85;
}

/* ── 6. CHART CARD — separación de header y fondo del canvas */
.chart-canvas-wrap {
  background: var(--surface);
  border-radius: 8px;
  padding: 12px 8px 8px;
  height: 300px;
}

/* ── 7. TOPBAR — fix logo duplication: solo uno visible ────── */
/* El sidebar logo es suficiente — en topbar se ve solo el nombre */
.topbar-right .topbar-logo {
  height: 28px;
  opacity: 0.6;
}

/* Topbar section name — con separador visual */
.topbar-left {
  gap: 14px;
}
.topbar-section-label::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: middle;
  opacity: 0.7;
}

/* ── 8. LIST SECTION HEADER — más jerarquía ──────────────── */
.list-section {
  gap: 10px;
}
.list-header {
  padding-bottom: 2px;
}
.list-title {
  font-weight: 700;
}

/* ── 9. STAT NUMBER — más peso visual ────────────────────── */
.stat-number {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* ── 10. FILTER PILLS — separador visual del chart ───────── */
.filter-pills {
  padding-top: 2px;
}

/* ── 11. Layout sin sidebar: lista izquierda + dashboard derecha ─────────── */
.sidebar {
  display: none !important;
}

.main-wrapper,
.main-wrapper.collapsed {
  margin-left: 0 !important;
}

.topbar-menu-btn {
  display: none !important;
}

.section-layout {
  display: grid;
  grid-template-columns: minmax(420px, 44%) minmax(0, 56%);
  grid-template-areas:
    "title title"
    "list dashboard";
  gap: 18px;
  align-items: stretch;
}

.content-section .content-inner.section-layout {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 18px 20px 40px;
}

.section-layout > .page-title-row {
  grid-area: title;
}

.section-layout > .list-section {
  grid-area: list;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.section-layout > .bento-section {
  grid-area: dashboard;
  margin-bottom: 0;
  width: 100%;
}

.section-layout .list-sticky-controls {
  top: 0;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 0 10px;
}

.section-layout .municipality-list {
  flex: 1;
  min-height: 0px;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.page-btn {
  border: 1px solid var(--border-strong);
  background: var(--white);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-primary);
}

.page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-info {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-family: 'Geist Mono', monospace;
  white-space: nowrap;
}

@media (max-width: 1320px) {
  .section-layout {
    grid-template-columns: minmax(380px, 42%) minmax(0, 58%);
    gap: 14px;
  }

}

@media (max-width: 1024px) {
  .section-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "title"
      "dashboard"
      "list";
  }

  .section-layout > .list-section {
    position: static;
    padding: 12px;
  }

  .section-layout .municipality-list {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .topbar {
    padding: 0 10px;
    gap: 8px;
  }

  .topbar-section-label {
    display: none;
  }

  .topbar-center {
    display: flex !important;
  }

  .module-tabs {
    gap: 6px;
  }

  .top-tab {
    padding: 5px 10px;
    font-size: 11px;
  }
}
/* ── THEME SWITCH ─── */
.theme-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 99px;
    margin-left: 10px;
    transition: background 0.15s;
    user-select: none;
}
.theme-switch:hover { background: var(--surface-2); }

.switch-icon-sun,
.switch-icon-moon {
    width: 13px; height: 13px;
    flex-shrink: 0;
    transition: color 0.2s, opacity 0.2s;
}
.switch-icon-sun  { color: var(--warning); opacity: 1; }
.switch-icon-moon { color: var(--text-tertiary); opacity: 0.45; }

[data-theme="dark"] .switch-icon-sun  { color: var(--text-tertiary); opacity: 0.45; }
[data-theme="dark"] .switch-icon-moon { color: #818cf8; opacity: 1; }

.theme-switch-track {
    width: 36px; height: 20px;
    border-radius: 99px;
    background: var(--surface-3);
    border: 1.5px solid var(--border-strong);
    position: relative;
    flex-shrink: 0;
    transition: background 0.25s, border-color 0.25s;
}
[data-theme="dark"] .theme-switch-track {
    background: var(--accent);
    border-color: var(--accent);
}

.theme-switch-thumb {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--white);
    position: absolute;
    top: 50%;
    left: 2px;
    transform: translateY(-50%);
    transition: left 0.25s var(--ease);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
[data-theme="dark"] .theme-switch-thumb {
    left: calc(100% - 16px);
}


[data-theme="dark"] {
  --white:          #111113;
  --surface:        #18181b;
  --surface-2:      #27272a;
  --surface-3:      #3f3f46;

  --text-primary:   #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary:  #71717a;

  --border:         rgba(255, 255, 255, 0.08);
  --border-strong:  rgba(255, 255, 255, 0.14);

  --accent-light:   #1e2a4a;
  --neutral-bg:     #27272a;
  --success-bg:     #052e16;
  --warning-bg:     #2d1a04;
  --danger-bg:      #2d0a0a;
}

/* Ajuste del hero del bento en dark */
[data-theme="dark"] .bento-hero {
  background: #1a3a37;
}

/* Tooltip en dark */
[data-theme="dark"] .map-tooltip {
  background: rgba(24, 24, 27, 0.88);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .map-svg-wrap,
[data-theme="dark"] .map-stack {
    background: #000000;
}
