/* =========================================================
   BASE
   ========================================================= */

html {
    font-size: 16px;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    margin: 0;
    background: #f5f7fb;
    overflow-x: hidden;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

img {
    max-width: 100%;
    height: auto;
}


/* =========================================================
   COMMON UI
   ========================================================= */

.navbar-brand {
    letter-spacing: .3px;
}

.card {
    border: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

.stat {
    background: #fff;
    border-radius: .75rem;
    padding: 1.25rem;
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

    .stat span {
        display: block;
        color: #6c757d;
    }

    .stat strong {
        font-size: 1.8rem;
    }


/* =========================================================
   APPLICATION
   ========================================================= */

.app-wrapper {
    min-height: 100vh;
    display: flex;
}


/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
    width: 280px;
    min-height: 100vh;
    background: linear-gradient( 180deg, #1f2933 0%, #17212b 100% );
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: width .25s ease, transform .25s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,.08);
}


    .sidebar.collapsed {
        width: 76px;
    }


/* =========================================================
   SIDEBAR BRAND
   ========================================================= */

.sidebar-brand {
    height: 84px;
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    position: relative;
    flex-shrink: 0;
}


    .sidebar-brand img {
        width: 46px;
        height: 46px;
        object-fit: contain;
        flex-shrink: 0;
        border-radius: 8px;
    }


.sidebar-brand-text {
    margin-left: 12px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .15s ease;
}


.brand-title {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: .5px;
    line-height: 1.1;
}


.brand-subtitle {
    color: #f0ad32;
    font-weight: 700;
    font-size: .85rem;
    letter-spacing: 1px;
}


/* =========================================================
   DESKTOP SIDEBAR TOGGLE
   ========================================================= */

.sidebar-toggle {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #2469d8;
    color: white;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: -15px;
    top: 27px;
    box-shadow: 0 3px 10px rgba(0,0,0,.25);
    transition: background .2s ease, transform .2s ease;
}


    .sidebar-toggle:hover {
        background: #1d5fc4;
    }


/* =========================================================
   MOBILE CLOSE BUTTON
   ========================================================= */

.mobile-sidebar-close {
    display: none;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 8px;
    background: rgba(255,255,255,.08);
    color: white;
    font-size: 1.7rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}


    .mobile-sidebar-close:hover {
        background: rgba(255,255,255,.14);
    }


/* =========================================================
   SIDEBAR NAVIGATION
   ========================================================= */

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}


    .sidebar-nav:hover {
        scrollbar-color: #4b5563 transparent;
    }


    .sidebar-nav::-webkit-scrollbar {
        width: 5px;
    }


    .sidebar-nav::-webkit-scrollbar-track {
        background: transparent;
    }


    .sidebar-nav::-webkit-scrollbar-thumb {
        background: transparent;
        border-radius: 10px;
    }


    .sidebar-nav:hover::-webkit-scrollbar-thumb {
        background: #4b5563;
    }


    .sidebar-nav::-webkit-scrollbar-thumb:hover {
        background: #6b7280;
    }


.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #d9e0e7;
    text-decoration: none;
    padding: 11px 14px;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: color .15s ease, background .15s ease, transform .15s ease;
    font-size: .97rem;
    white-space: nowrap;
}


    .sidebar-link:hover {
        color: #fff;
        background: rgba(255,255,255,.08);
    }


    .sidebar-link.active {
        color: #fff;
        background: #2469d8;
        box-shadow: 0 4px 12px rgba(0,0,0,.18);
    }


.sidebar-icon {
    width: 24px;
    min-width: 24px;
    text-align: center;
    font-size: 1.05rem;
    display: inline-flex;
    justify-content: center;
}


.sidebar-link-text {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity .15s ease;
}


/* =========================================================
   COLLAPSED DESKTOP SIDEBAR
   ========================================================= */

.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .sidebar-link-text,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-logout-text {
    display: none;
}


.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}


.sidebar.collapsed .sidebar-icon {
    margin: 0;
    font-size: 1.25rem;
}


.sidebar.collapsed .sidebar-user {
    justify-content: center;
}


.sidebar.collapsed .sidebar-footer {
    padding-left: 10px;
    padding-right: 10px;
}


.sidebar-collapsed-icon {
    display: none;
}


.sidebar.collapsed
.sidebar-collapsed-icon {
    display: inline;
}


/* =========================================================
   SIDEBAR USER / FOOTER
   ========================================================= */

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.08);
    padding: 16px;
    flex-shrink: 0;
    background: rgba(0,0,0,.06);
}


.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}


.sidebar-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #e9ecef;
    color: #495057;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}


.sidebar-user-info {
    min-width: 0;
    flex: 1;
}


.sidebar-user-name {
    font-weight: 600;
    color: white;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.sidebar-user-role {
    color: #aeb8c2;
    font-size: .8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* =========================================================
   MAIN AREA
   ========================================================= */

.main-area {
    margin-left: 280px;
    width: calc(100% - 280px);
    min-width: 0;
    min-height: 100vh;
    transition: margin-left .25s ease, width .25s ease;
}


body.sidebar-collapsed
.main-area {
    margin-left: 76px;
    width: calc(100% - 76px);
}


/* =========================================================
   TOP BAR
   ========================================================= */

.topbar {
    min-height: 68px;
    background: white;
    border-bottom: 1px solid #e7eaf0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 28px;
    position: sticky;
    top: 0;
    z-index: 900;
}


.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}


.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}


.topbar-title {
    color: #6c757d;
    font-size: .92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.topbar-user-name {
    font-weight: 600;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.language-form {
    margin: 0;
}


.language-select {
    min-width: 135px;
}


/* =========================================================
   MOBILE MENU BUTTON
   ========================================================= */

.mobile-menu-button {
    display: none;
    width: 42px;
    height: 42px;
    border: 1px solid #dee2e6;
    border-radius: 9px;
    background: white;
    padding: 9px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}


    .mobile-menu-button span {
        display: block;
        width: 20px;
        height: 2px;
        border-radius: 10px;
        background: #343a40;
    }


/* =========================================================
   PAGE CONTENT
   ========================================================= */

.page-content {
    width: 100%;
    min-width: 0;
    padding: 28px;
}


    /* Prevent Bootstrap grid children from forcing page width. */

    .page-content .row > * {
        min-width: 0;
    }


    /* Forms should never exceed container width. */

    .page-content input,
    .page-content select,
    .page-content textarea {
        max-width: 100%;
    }


    /* Responsive images inside application pages. */

    .page-content img {
        max-width: 100%;
        height: auto;
    }


/* =========================================================
   SIDEBAR OVERLAY
   ========================================================= */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(1px);
    z-index: 1040;
    opacity: 0;
    transition: opacity .2s ease;
}


    .sidebar-overlay.show {
        opacity: 1;
    }


/* =========================================================
   TABLE BASELINE
   ========================================================= */

/*
    Existing tables should eventually be reviewed page by page.

    If a page already uses .table-responsive, this guarantees
    smooth horizontal scrolling on smaller screens.
*/

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}


/* =========================================================
   TABLET + MOBILE
   ========================================================= */

@media (max-width: 991.98px) {

    body.mobile-sidebar-open {
        overflow: hidden;
    }


    /* Sidebar becomes an off-canvas drawer. */

    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        box-shadow: 12px 0 32px rgba(0,0,0,.22);
    }


        .sidebar.mobile-open {
            transform: translateX(0);
        }


        /* Always show sidebar labels inside mobile drawer. */

        .sidebar .sidebar-brand-text,
        .sidebar .sidebar-link-text,
        .sidebar .sidebar-user-info,
        .sidebar .sidebar-logout-text {
            display: block;
        }


        .sidebar .sidebar-collapsed-icon {
            display: none;
        }


        .sidebar .sidebar-link {
            justify-content: flex-start;
            padding: 11px 14px;
        }


        .sidebar .sidebar-user {
            justify-content: flex-start;
        }


    .sidebar-toggle {
        display: none;
    }


    .mobile-sidebar-close {
        display: flex;
    }


    .sidebar-overlay.show {
        display: block;
    }


    /* Content gets the full device width. */

    .main-area,
    body.sidebar-collapsed
    .main-area {
        margin-left: 0;
        width: 100%;
    }


    .mobile-menu-button {
        display: flex;
    }


    .topbar {
        padding: 9px 18px;
        min-height: 64px;
    }


    .page-content {
        padding: 20px;
    }
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 767.98px) {

    html {
        font-size: 15px;
    }


    .topbar {
        padding: 8px 12px;
        gap: 10px;
    }


    .topbar-right {
        gap: 8px;
    }


    .topbar-title {
        display: none;
    }


    .topbar-user-name {
        display: none;
    }


    .language-select {
        min-width: 110px;
        width: 110px;
    }


    .page-content {
        padding: 16px 12px;
    }


        /* Page headers should wrap instead of overflowing. */

        .page-content h1,
        .page-content h2,
        .page-content h3 {
            overflow-wrap: anywhere;
        }


        /*
        Common Bootstrap action rows can wrap safely.
        Individual complex screens will still be reviewed.
    */

        .page-content
        .d-flex {
            min-width: 0;
        }


        .page-content
        .btn {
            white-space: normal;
        }


    .card {
        border-radius: .75rem;
    }


    .stat {
        padding: 1rem;
    }


        .stat strong {
            font-size: 1.5rem;
        }
}


/* =========================================================
   VERY SMALL PHONES
   ========================================================= */

@media (max-width: 420px) {

    .sidebar {
        width: min(86vw, 300px);
    }


    .language-select {
        min-width: 100px;
        width: 100px;
        font-size: .82rem;
    }


    .mobile-menu-button {
        width: 40px;
        height: 40px;
    }


    .page-content {
        padding: 14px 10px;
    }
}


/* =========================================================
   PRINT
   ========================================================= */

@media print {

    .no-print,
    .navbar,
    .sidebar,
    .topbar,
    .sidebar-overlay {
        display: none !important;
    }


    body {
        background: #fff;
    }


        .main-area,
        body.sidebar-collapsed
        .main-area {
            margin-left: 0;
            width: 100%;
        }


    .page-content {
        padding: 0;
    }


    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
