body {
    background-color: #f0f4f8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: #2c3e50;
    padding-top: 56px; /* Compensar navbar fijo */
    font-size: 12px;
    overflow: auto !important; /* Nunca bloquear scroll */
    padding-right: 0 !important; /* No ajustar por scrollbar */
}

/* Prevenir que modales bloqueen el body */
body.modal-open {
    overflow: auto !important;
    padding-right: 0 !important;
}

/* Asegurar que no queden backdrops huérfanos */
.modal-backdrop {
    display: none !important;
}

#sidebar {
    position: fixed !important;
    top: 56px !important; /* Altura del navbar */
    bottom: 0 !important;
    left: 0 !important;
    z-index: 999;
    padding: 0 !important;
    background: linear-gradient(180deg, #a8d5e2 0%, #a8d5e2 100%) !important;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.15);
    min-height: calc(100vh - 56px) !important;
    width: 60px !important; /* Ancho para mostrar solo iconos */
    max-width: 60px !important;
    overflow-y: auto;
    overflow-x: hidden;
    height: calc(100vh - 56px) !important;
    transition: width 0.3s ease, max-width 0.3s ease;
    white-space: nowrap;
}

/* Estado expandido del sidebar al hacer hover */
#sidebar:hover {
    width: 250px !important;
    max-width: 250px !important;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
}

/* Ocultar texto del menú por defecto */
.menu-text {
    display: inline-block;
    width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: width 0.3s ease, opacity 0.3s ease;
}

/* Mostrar texto al hacer hover en el sidebar */
#sidebar:hover .menu-text {
    width: auto;
    opacity: 1;
}

@media (min-width: 768px) {
    #sidebar {
        display: block !important;
    }
}

.sidebar {
    height: 100%;
}

.sidebar .position-sticky {
    position: relative !important;
    padding-top: 1rem;
    height: 100%;
}

.sidebar .nav-link {
    font-weight: 500;
    color: #1e3a5f !important;
    padding: 0.5rem 0;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
    text-decoration: none;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

#sidebar:not(:hover) .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.3) !important;
    color: #0d2540 !important;
    border-left-color: #1e3a5f;
}

.sidebar .nav-link.active {
    color: #0d2540 !important;
    background-color: rgba(255, 255, 255, 0.5) !important;
    border-left: 3px solid #1e3a5f;
    font-weight: 600;
}

.sidebar .nav-link i {
    width: 18px;
    text-align: center;
    opacity: 0.9;
    font-size: 0.95rem;
    margin-right: 0;
    transition: margin-right 0.3s ease;
}

#sidebar:hover .nav-link i {
    margin-right: 0.5rem;
}

/* Animación de flecha en submenús */
.submenu-arrow {
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 0.75rem;
    opacity: 0;
}

#sidebar:hover .submenu-arrow {
    opacity: 1;
}

a[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

/* Ocultar submenús cuando el sidebar está colapsado */
#sidebar:not(:hover) .collapse {
    display: none !important;
}

/* Estilos para submenús colapsables */
.sidebar .collapse {
    transition: all 0.3s ease-in-out;
}

.sidebar .collapse .nav-link {
    font-size: 0.8rem; /* Más pequeño para submenús */
    padding: 0.5rem 0.75rem;
    padding-left: 2rem; /* Menos indentación */
}

.sidebar .collapse .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.4) !important;
    padding-left: 2.25rem;
}

.sidebar .collapse .nav-link.active {
    background-color: rgba(255, 255, 255, 0.6) !important;
    border-left: 3px solid #0d2540;
}

/* Efecto de hover en menús con submenús */
.sidebar .nav-link[data-bs-toggle="collapse"] {
    cursor: pointer;
}

.sidebar .nav-link[data-bs-toggle="collapse"]:hover {
    background-color: rgba(255, 255, 255, 0.3) !important;
}

.navbar-custom {
    background: linear-gradient(90deg, #a8d5e2 0%, #7ab8d4 100%) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
    z-index: 1050 !important; /* Por encima del sidebar (999) y del backdrop (1040) */
}

.navbar-custom .navbar-brand,
.navbar-custom .nav-link {
    color: #1e3a5f !important;
    font-weight: 500;
}

.navbar-custom .nav-link:hover {
    color: #0d2540 !important;
}

.navbar-custom .navbar-toggler {
    border-color: rgba(30, 58, 95, 0.5);
}

.navbar-custom .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2830, 58, 95, 0.8%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Botón toggle del sidebar */
#sidebarToggle {
    border-color: rgba(30, 58, 95, 0.5);
    color: #1e3a5f;
    transition: all 0.3s ease;
}

#sidebarToggle:hover {
    background-color: rgba(30, 58, 95, 0.1);
    border-color: #1e3a5f;
    color: #0d2540;
}

#sidebarToggle:focus {
    box-shadow: 0 0 0 0.2rem rgba(30, 58, 95, 0.25);
}

main {
    padding: 6px 8px;
    margin-left: 60px !important; /* Espacio para sidebar compacto */
    margin-right: auto !important;
    max-width: calc(100% - 60px);
    transition: margin-left 0.3s ease;
    min-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

main > * {
    width: 100%;
    max-width: 1400px; /* Ancho máximo del contenido centrado */
}

/* Responsive: ocultar margen en pantallas pequeñas */
@media (max-width: 767.98px) {
    main {
        margin-left: 0 !important;
    }
    
    #sidebar {
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease;
        width: 200px !important;
        max-width: 200px !important;
    }
    
    #sidebar.show {
        transform: translateX(0) !important;
    }
}

.navbar-dark {
    background: linear-gradient(90deg, #a8d5e2 0%, #7ab8d4 100%) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}

.navbar-dark .navbar-brand,
.navbar-dark .nav-link {
    color: #1e3a5f !important;
}

.navbar-dark .nav-link:hover {
    color: #0d2540 !important;
}

.card {
    border: none;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, #7ab8d4 0%, #5a9fb8 100%);
    border: none;
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5a9fb8 0%, #4a8ca0 100%);
    color: white;
}

.table {
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
}

.table thead {
    background: linear-gradient(135deg, #a8d5e2 0%, #7ab8d4 100%);
    border-bottom: 2px solid #5a9fb8;
    color: #1e3a5f;
}

.border-bottom {
    border-color: #a8d5e2 !important;
}

.text-primary {
    color: #5a9fb8 !important;
}

.bg-primary {
    background: linear-gradient(135deg, #a8d5e2 0%, #7ab8d4 100%) !important;
    color: #1e3a5f !important;
}

.badge.bg-info {
    background-color: #7ab8d4 !important;
}

/* Asegurar que todos los elementos tengan fuente de 11px */
.table, .btn, .form-control, .form-select, .card-body, .modal-body, .alert {
    font-size: 12px;
}

/* Títulos y headers ligeramente más grandes */
h1, h2, h3, h4, h5, h6 {
    font-size: 1.2em;
}

.card-title {
    font-size: 13px;
}

.navbar-brand {
    font-size: 14px;
}