/* Sidebar layout */
.app-wrapper {
    display: flex;
    min-height: calc(100vh - 56px);
}

.app-sidebar {
    width: 238px;
    min-width: 238px;
    background: #ffffff;
    color: #1f2937;
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s ease, width 0.3s ease;
    border-right: 1px solid #e5e7eb;
    border-radius: 0;
}

.app-sidebar .sidebar-nav {
    padding: 1rem 0;
}

.app-sidebar .nav-link {
    color: #4b5563;
    padding: 0.62rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 0;
    transition: all 0.2s ease;
    border-radius: 8px;
    margin: 0.18rem 0.55rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.app-sidebar .nav-link:hover {
    background: #f3f4f6;
    color: #111827;
}

.app-sidebar .nav-link.active {
    background: #e8f9ef;
    color: #16a34a;
    border-left-color: transparent;
    box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.16);
}

.app-sidebar .nav-link i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.app-sidebar .sidebar-section-title {
    padding: 0.55rem 1rem;
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
}

.app-sidebar .collapse .list-unstyled {
    padding-left: 0;
}

.app-sidebar .collapse .dropdown-item,
.app-sidebar .collapse .sidebar-subitem {
    color: #4b5563;
    padding: 0.48rem 1rem 0.48rem 2.2rem;
    font-size: 0.86rem;
    display: block;
    text-decoration: none;
    transition: all 0.2s;
    border-radius: 8px;
    margin: 0.12rem 0.55rem;
}

.app-sidebar .collapse .dropdown-item:hover,
.app-sidebar .collapse .sidebar-subitem:hover {
    background: #f3f4f6;
    color: #111827;
}

.app-sidebar .collapse .dropdown-divider {
    border-color: #e5e7eb;
    margin: 0.25rem 1rem;
}

.app-sidebar .collapse .dropdown-header {
    color: #9ca3af;
    font-size: 0.7rem;
    padding: 0.5rem 1rem 0.5rem 2.25rem;
}

.app-sidebar .nav-link[data-bs-toggle="collapse"]::after {
    margin-left: auto;
}

.app-content {
    flex: 1;
    margin-left: 238px;
    padding: 1rem 1.15rem;
    background: #f3f5f7;
    min-height: calc(100vh - 56px);
}

.app-content .content-inner {
    background: #f7f8fa;
    border-radius: 12px;
    padding: 1rem 1.05rem;
    border: 1px solid #e5e7eb;
    box-shadow: none;
}

/* Top header */
.app-header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.45rem 1rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header .header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: #2c3e50;
    font-weight: 600;
}

.app-header .header-brand i {
    font-size: 1.35rem;
    color: #16a34a;
}

.app-header .navbar-nav {
    flex-direction: row;
    gap: 0.5rem;
}

/* Mobile: sidebar toggle */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        width: min(86vw, 320px);
        min-width: min(86vw, 320px);
        transform: translateX(-100%);
        box-shadow: 0 0 0 rgba(0, 0, 0, 0);
    }

    .app-sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.35);
    }

    .app-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .app-sidebar .sidebar-overlay {
        display: none;
    }

    .app-header {
        padding: 0.5rem 0.75rem;
    }

    .app-header .header-brand span {
        display: none;
    }

    .app-content {
        padding: 1rem;
    }

    .app-content .content-inner {
        padding: 1rem;
        border-radius: 5%;
    }
}

@media (max-width: 767.98px) {
    .global-search-wrapper {
        display: none;
    }

    .app-header {
        gap: 0.5rem;
    }

    .app-header .btn {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .app-sidebar .nav-link {
        padding: 0.7rem 1rem;
    }

    .app-sidebar .sidebar-section-title {
        padding: 0.65rem 1rem;
    }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

body.sidebar-open {
    overflow: hidden;
}

/* Footer with sidebar */
body {
    padding-top: 56px;
}

.footer {
    margin-left: 238px;
}

@media (max-width: 991.98px) {
    .footer {
        margin-left: 0;
    }
}

/* Dark mode */
:root[data-theme="dark"] .app-header {
    background: #1f2937;
    border-bottom-color: #374151;
}

:root[data-theme="dark"] .app-header .header-brand {
    color: #e5e7eb;
}

:root[data-theme="dark"] .app-header .header-brand i {
    color: #22c55e;
}

:root[data-theme="dark"] .app-sidebar {
    background: #1f2937;
    color: #e5e7eb;
    border-right-color: #374151;
}

:root[data-theme="dark"] .app-sidebar .sidebar-section-title {
    color: #9ca3af;
}

:root[data-theme="dark"] .app-sidebar .nav-link {
    color: #d1d5db;
}

:root[data-theme="dark"] .app-sidebar .nav-link:hover {
    background: #374151;
    color: #f9fafb;
}

:root[data-theme="dark"] .app-sidebar .nav-link.active {
    background: rgba(34, 197, 94, 0.16);
    color: #86efac;
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.28);
}

:root[data-theme="dark"] .app-sidebar .collapse .dropdown-item,
:root[data-theme="dark"] .app-sidebar .collapse .sidebar-subitem {
    color: #d1d5db;
}

:root[data-theme="dark"] .app-sidebar .collapse .dropdown-item:hover,
:root[data-theme="dark"] .app-sidebar .collapse .sidebar-subitem:hover {
    background: #374151;
    color: #f9fafb;
}

:root[data-theme="dark"] .app-sidebar .collapse .dropdown-divider {
    border-color: #374151;
}

:root[data-theme="dark"] .app-sidebar .collapse .dropdown-header {
    color: #9ca3af;
}

:root[data-theme="dark"] .app-content {
    background: #111827;
}

:root[data-theme="dark"] .app-content .content-inner {
    background: #111827;
    border-color: #374151;
}

:root[data-theme="dark"] .footer {
    border-top-color: #374151 !important;
    color: #9ca3af !important;
    background: #111827;
}
