/* Variables de Diseño Premium */
:root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary-blue: #3b82f6;
    --primary-hover: #2563eb;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-hover: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --radius-lg: 16px;
    --radius-md: 10px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.dashboard-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ================== SIDEBAR (PREMIUM UI) ================== */
.sidebar {
    width: 280px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.logo-area {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    font-size: 20px;
    background: linear-gradient(135deg, var(--primary-blue), #60a5fa);
    color: white;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
}

.logo-area h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-section {
    padding: 24px 24px 0;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 1.2px;
    margin-bottom: 14px;
    display: block;
    text-transform: uppercase;
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.menu-nav a {
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    /* Preparado para el estado activo */
}

.menu-nav a:hover {
    background-color: #f8fafc;
    color: var(--text-main);
}

.menu-nav a.active {
    background-color: #eff6ff;
    color: var(--primary-hover);
    font-weight: 600;
    border-left: 3px solid var(--primary-blue);
    /* Línea indicadora azul */
}

/* Caja de Filtros Destacada */
.filtros-container {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.filtro-grupo label {
    font-size: 11px;
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: "▼";
    font-size: 10px;
    color: var(--text-muted);
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.filtro-select {
    width: 100%;
    padding: 10px 30px 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-main);
    background-color: #ffffff;
    cursor: pointer;
    outline: none;
    appearance: none;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.filtro-select:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Botón Restablecer */
.btn-reset {
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    background: transparent;
    border: 1px dashed #94a3b8;
    color: #64748b;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-reset:hover {
    background: #ffffff;
    color: #334155;
    border-color: #64748b;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* MAIN CONTENT & CABECERA */
.main-content {
    flex: 1;
    padding: 32px 40px;
    overflow-y: auto;
    background: var(--bg-body);
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 36px;
}

.title-badge {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    padding: 8px 24px 8px 10px;
    border-radius: 12px;
    border: 1px solid #bfdbfe;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
}

.title-badge span {
    font-size: 22px;
    background: white;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

.header-titles h1 {
    font-size: 24px;
    font-weight: 700;
    color: #1e3a8a;
    margin: 0;
    letter-spacing: -0.5px;
}

.header-titles p {
    color: var(--text-muted);
    font-size: 14px;
    margin-left: 4px;
}

/* NUEVO BUSCADOR */
.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

.search-box {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    opacity: 0.6;
}

.search-box input {
    padding: 10px 16px 10px 38px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 13px;
    width: 280px;
    outline: none;
    transition: all 0.2s ease;
    background-color: white;
}

.search-box input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.btn-primary {
    padding: 10px 20px;
    background-color: var(--primary-blue);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

/* TARJETAS KPI */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

@media (max-width: 1300px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(226, 232, 240, 0.6);
    transition: all 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.kpi-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.kpi-info h2 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-main);
    margin: 8px 0;
    letter-spacing: -1px;
}

.kpi-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.blue-bg {
    background: #eff6ff;
    color: #3b82f6;
}

.purple-bg {
    background: #faf5ff;
    color: #a855f7;
}

.orange-bg {
    background: #fff7ed;
    color: #f97316;
}

.green-bg {
    background: #f0fdf4;
    color: #22c55e;
}

/* NUEVA GRILLA DE GRÁFICOS */
.charts-grid-top {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.charts-grid-bottom {
    margin-bottom: 30px;
}

.tables-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 30px;
}

@media (max-width: 1400px) {
    .charts-grid-top {
        grid-template-columns: 1fr 1fr;
    }

    .large-chart {
        grid-column: span 2;
    }
}

@media (max-width: 1024px) {

    .charts-grid-top,
    .tables-grid {
        grid-template-columns: 1fr;
    }

    .large-chart {
        grid-column: span 1;
    }
}

.chart-card,
.table-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(226, 232, 240, 0.6);
    transition: all 0.3s ease;
}

.chart-card:hover,
.table-card:hover {
    box-shadow: var(--shadow-hover);
}

.chart-header h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-main);
}

.chart-body { 
    position: relative; 
    height: 300px; 
    width: 100%; 
    min-height: 400px; /* <--- Agrega esto para darle más espacio vertical a los gráficos */
}

.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 14px 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 14px 12px;
    color: var(--text-main);
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
}

tr:hover td {
    background-color: #f8fafc;
}

tr:last-child td {
    border-bottom: none;
}

.text-right {
    text-align: right;
}

.badge {
    background: #eff6ff;
    color: #3b82f6;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

/* VISTA POR SEDES */
.sede-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(226, 232, 240, 0.6);
    transition: all 0.3s ease;
}

.sede-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-blue);
}

.sede-header {
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.sede-header h3 {
    font-size: 18px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.sede-metric {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-muted);
}

.sede-metric span:last-child {
    font-weight: 700;
    color: var(--text-main);
}

.sede-metric.destacado span:last-child {
    color: var(--primary-blue);
    background: #eff6ff;
    padding: 4px 10px;
    border-radius: 12px;
}

/* =========================================
   VISTA POR SEDES - MEJORADA (DIAGNÓSTICO)
========================================= */
.sedes-grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .sedes-grid-container {
        grid-template-columns: 1fr;
    }
}

.sede-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(226, 232, 240, 0.6);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Separación entre bloques internos */
}

.sede-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: #bfdbfe;
}

/* Cabecera y Métricas Principales */
.sede-header-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.sede-header-block h3 {
    font-size: 18px;
    color: var(--text-main);
    font-weight: 700;
}

.sede-main-stat {
    text-align: right;
}

.sede-main-stat span {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.sede-main-stat strong {
    font-size: 24px;
    color: var(--primary-blue);
    font-weight: 700;
}

/* Subtítulos internos */
.sede-section-title {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* Barras de Progreso de Programas */
.sede-programs-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sede-prog-item {
    width: 100%;
}

.sede-prog-header {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-main);
}

.sede-prog-bg {
    width: 100%;
    height: 6px;
    background-color: #f1f5f9;
    border-radius: 4px;
    overflow: hidden;
}

.sede-prog-fill {
    height: 100%;
    background-color: var(--primary-blue);
    border-radius: 4px;
}

/* Badges de Vigencia */
.sede-vigencia-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.v-badge {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    /* Para que ocupen el mismo ancho */
    justify-content: center;
}

.v-act {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.v-vig {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.v-his {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* =========================================
   VISTA POR TÍTULOS (DISEÑO PREMIUM)
========================================= */
#tabla-catalogo-completo th {
    background-color: #f8fafc;
    /* Fondo para el sticky header */
    padding: 16px 20px;
}

#tabla-catalogo-completo td {
    padding: 16px 20px;
    font-size: 13px;
    vertical-align: middle;
}

.title-row-flex {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.book-icon-cell {
    font-size: 18px;
    background: #f1f5f9;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
}

/* Semáforo de Vigencia (Puntitos) */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.dot-act {
    background-color: #10b981;
    box-shadow: 0 0 0 3px #d1fae5;
}

.dot-vig {
    background-color: #f59e0b;
    box-shadow: 0 0 0 3px #fef3c7;
}

.dot-his {
    background-color: #ef4444;
    box-shadow: 0 0 0 3px #fee2e2;
}

/* Empty State */
.empty-state-container {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.8;
}

.empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

/* =========================================
   SELECTOR DE MÓDULOS (APP MENU)
========================================= */
#btn-app-selector:hover {
    background-color: #f1f5f9;
    color: var(--text-main);
}

.app-selector-menu {
    position: absolute;
    top: 70px;
    right: -10px;
    width: 260px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.app-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.app-option:hover {
    background-color: #f8fafc;
}

.app-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.app-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.app-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}