/* ===================================================
   SISTEMA DE LAYOUT & SIDEBAR BS5
   =================================================== */

:root {
    --sidebar-width: 260px;
    --sidebar-bg: #006099;
    --sidebar-hover-bg: #0382ce;
    --sidebar-active-bg: #004d7a;
    --sidebar-text: #ffffff;
    --topbar-height: 60px;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: #f4f6f9;
    overflow-x: hidden;
}

/* Estructura Principal Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

/* ---------------------------------------------------
   SIDEBAR LATERAL FIJO (POSITION FIXED)
----------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1040;
    transition: transform 0.3s ease-in-out;
}

.sidebar-header {
    padding: 0 15px;
    background-color: rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header .logo-img {
    max-width: 100%;
    height: auto;
    max-height: 38px;
    object-fit: contain;
}

/* Navegación y Scroll Propio del Menú */
.sidebar-nav {
    padding: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1;
}

/* Enlaces del Menú */
.sidebar-nav .nav-link {
    color: rgba(255, 255, 255, 0.88);
    border-radius: 6px;
    margin-bottom: 2px;
    padding: 9px 12px;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    width: 100%;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Ícono del Menú Principal */
.sidebar-nav .nav-link .nav-icon {
    font-size: 1.15rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    margin-right: 10px;
}

/* Formateo del Texto para Evitar Desbordes */
.sidebar-nav .nav-text {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 5px;
}

.sidebar-nav .nav-link:hover {
    color: #ffffff;
    background-color: var(--sidebar-hover-bg);
}

.sidebar-nav .nav-link.active {
    color: #ffffff;
    background-color: var(--sidebar-active-bg);
    font-weight: 600;
}

/* Submenús Desplegables */
.sub-menu {
    padding-left: 15px;
    margin-top: 2px;
    margin-bottom: 6px;
}

.sub-menu .nav-link {
    font-size: 0.86rem;
    padding: 6px 10px;
    opacity: 0.9;
}

/* Flechas Dropdown */
.sidebar-nav .dropdown-toggle::after {
    display: inline-block;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-nav .dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

/* ---------------------------------------------------
   TOPBAR & CONTENEDOR PRINCIPAL
----------------------------------------------------- */
.main-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    transition: margin-left 0.3s ease-in-out, width 0.3s ease-in-out;
}

.app-topbar {
    height: var(--topbar-height);
}

/* Botón Toggle Personalizado */
.btn-sidebar-toggle {
    background-color: transparent;
    border: none !important;
    color: #495057;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.btn-sidebar-toggle:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: var(--sidebar-bg);
}

.btn-sidebar-toggle:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 96, 153, 0.2);
    outline: none;
}

.btn-sidebar-toggle:active {
    background-color: rgba(0, 0, 0, 0.12);
}

/* Avatar del Menú de Usuario */
.avatar-circle {
    width: 32px;
    height: 32px;
    background-color: var(--sidebar-bg);
    color: white;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
}

/* ---------------------------------------------------
   ESCRITORIO (>= 992px)
----------------------------------------------------- */
@media (min-width: 992px) {
    /* Estado Normal: Sidebar visible a la izquierda */
    .app-sidebar {
        transform: translateX(0);
    }

    /* El contenido principal se desplaza exactamente 260px a la derecha */
    .main-container {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }

    /* Estado Colapsado: Sidebar se esconde fuera de pantalla */
    .app-wrapper.sidebar-collapsed .app-sidebar {
        transform: translateX(-100%);
    }

    /* El contenido principal pasa a ocuparlo todo (margin-left: 0) */
    .app-wrapper.sidebar-collapsed .main-container {
        margin-left: 0;
        width: 100%;
    }
}

/* ---------------------------------------------------
   RESPONSIVE MÓVIL (< 992px)
----------------------------------------------------- */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1030;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .main-container {
        margin-left: 0;
        width: 100%;
    }
}

.no-transition,
.no-transition * {
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    transition: none !important;
}

