/* Variables de Diseño - Temática Operativa (Índigo) */
:root {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary-blue: #4f46e5;
    --primary-hover: #4338ca;
    --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 */
.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), #818cf8);
    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(79, 70, 229, 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: 10px 16px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 13.5px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.menu-nav a:hover {
    background-color: #f8fafc;
    color: var(--text-main);
}

.menu-nav a.active {
    background-color: #eef2ff;
    color: var(--primary-hover);
    font-weight: 600;
    border-left: 3px solid var(--primary-blue);
}

/* CAJA DE FILTROS */
.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(79, 70, 229, 0.1);
}

.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 */
.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, #e0e7ff 0%, #c7d2fe 100%);
    padding: 8px 24px 8px 10px;
    border-radius: 12px;
    border: 1px solid #a5b4fc;
    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(79, 70, 229, 0.1);
}

.header-titles h1 {
    font-size: 24px;
    font-weight: 700;
    color: #312e81;
    margin: 0;
    letter-spacing: -0.5px;
}

.header-titles p {
    color: var(--text-muted);
    font-size: 14px;
    margin-left: 4px;
}

/* 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: 320px;
    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(79, 70, 229, 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(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

/* TARJETAS KPI ESTADOS */
.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;
}

/* Colores de los Estados */
.blue-bg {
    background: #e0f2fe;
    color: #0284c7;
}

/* Reserva */
.orange-bg {
    background: #ffedd5;
    color: #ea580c;
}

/* Préstamo */
.green-bg {
    background: #d1fae5;
    color: #059669;
}

/* Devolución */
.red-bg {
    background: #fee2e2;
    color: #dc2626;
}

/* Cancelado */

/* GRILLA DE GRÁFICOS */
.charts-grid-top {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.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%;
}

/* TABLAS GENERALES */
.table-container {
    width: 100%;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    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);
    line-height: 1.4;
}

tr:hover td {
    background-color: #f8fafc;
}

tr:last-child td {
    border-bottom: none;
}

.text-right {
    text-align: right;
}

.badge {
    background: #e0e7ff;
    color: #4f46e5;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

/* =========================================
   TARJETAS UNIVERSALES DE ANÁLISIS 
   (Usadas en Sedes, Programas, Ciclos, Periodos)
========================================= */
.analisis-grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .analisis-grid-container {
        grid-template-columns: 1fr;
    }
}

.analisis-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;
}

.analisis-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: #a5b4fc;
}

.an-header-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.an-header-block h3 {
    font-size: 18px;
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.3;
}

.an-main-stat {
    text-align: right;
}

.an-main-stat span {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.an-main-stat strong {
    font-size: 24px;
    color: var(--primary-blue);
    font-weight: 700;
}

.an-section-title {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* Barras de sub-métricas */
.an-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.an-item {
    width: 100%;
}

.an-item-header {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-main);
}

.an-item-bg {
    width: 100%;
    height: 6px;
    background-color: #f1f5f9;
    border-radius: 4px;
    overflow: hidden;
}

.an-item-fill {
    height: 100%;
    background-color: var(--primary-blue);
    border-radius: 4px;
}

/* Badges de Estado */
.an-estado-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.st-badge {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
}

.st-res {
    background-color: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.st-pre {
    background-color: #ffedd5;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

.st-dev {
    background-color: #d1fae5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.st-can {
    background-color: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* VISTA HISTORIAL (TABLA) */
#tabla-historial-completo th {
    background-color: #f8fafc;
    padding: 16px 20px;
}

#tabla-historial-completo td {
    padding: 16px 20px;
    font-size: 13px;
    vertical-align: middle;
}

.estado-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tag-reserva {
    background-color: #e0f2fe;
    color: #0284c7;
}

.tag-prestamo {
    background-color: #ffedd5;
    color: #ea580c;
}

.tag-devolucion {
    background-color: #d1fae5;
    color: #059669;
}

.tag-cancelado {
    background-color: #f1f5f9;
    color: #64748b;
}

.empty-state-container {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* =========================================
   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;
}