/* 
 * MaxOne Accounts - Main Layout Stylesheet
 * Integrates light/dark CSS custom properties, sidebar mechanics, fixed footer, and animations.
 */

:root {
    --transition-speed: 0.25s;
    --sidebar-width: 270px;
    --sidebar-collapsed-width: 80px;
    --top-navbar-height: 70px;
    --footer-height: 50px;
    
    /* Primary brand colors */
    --brand-primary: #4f46e5;      /* Indigo */
    --brand-primary-rgb: 79, 70, 229;
    --brand-success: #10b981;      /* Emerald */
    --brand-warning: #f59e0b;      /* Amber */
    --brand-danger: #ef4444;       /* Rose */
}

/* Light Theme Variables */
[data-bs-theme="light"] {
    --bg-body: #f3f4f6;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-navbar: rgba(255, 255, 255, 0.85);
    
    --border-color: #e5e7eb;
    --border-navbar: rgba(229, 231, 235, 0.6);
    
    --text-main: #1f2937;
    --text-muted: #6b7280;
    
    --sidebar-text: #4b5563;
    --sidebar-hover-bg: #f3f4f6;
    --sidebar-hover-text: #4f46e5;
    --sidebar-active-bg: #e0e7ff;
    --sidebar-active-text: #4f46e5;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    
    --glass-blur: blur(12px);
}

/* Dark Theme Variables */
[data-bs-theme="dark"] {
    --bg-body: #0b0f19;
    --bg-sidebar: #111827;
    --bg-card: #1f2937;
    --bg-navbar: rgba(17, 24, 39, 0.85);
    
    --border-color: #374151;
    --border-navbar: rgba(55, 65, 81, 0.6);
    
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    
    --sidebar-text: #9ca3af;
    --sidebar-hover-bg: #1f2937;
    --sidebar-hover-text: #ffffff;
    --sidebar-active-bg: #1e1b4b;
    --sidebar-active-text: #818cf8;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    
    --glass-blur: blur(12px);
}

/* Global Reset & Transition Styles */
body {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.3);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.6);
}

/* App Wrapper Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* SIDEBAR LAYOUT */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), 
                transform var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1),
                background-color var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    height: var(--top-navbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--brand-primary);
    font-weight: 700;
    font-size: 1.25rem;
    transition: transform 0.2s ease;
}
.sidebar-logo:hover {
    transform: scale(1.02);
}

.sidebar-menu-wrapper {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.25rem 0.75rem;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.75rem 0.75rem 0.25rem 0.75rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.925rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sidebar-link-content {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1.05rem;
    transition: transform 0.2s ease;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-text);
}
.sidebar-link:hover i {
    transform: scale(1.15);
}

.sidebar-item.active .sidebar-link {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}
.sidebar-item.active .sidebar-link i {
    color: var(--brand-primary);
}

/* Sidebar Dropdown Accordion */
.sidebar-submenu {
    list-style: none;
    padding-left: 2.75rem;
    margin-top: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    overflow: hidden;
    transition: height var(--transition-speed) ease;
}

.sidebar-submenu-link {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.sidebar-submenu-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-text);
    padding-left: 1rem;
}

.sidebar-submenu-item.active .sidebar-submenu-link {
    color: var(--brand-primary);
    font-weight: 600;
}

.dropdown-arrow {
    font-size: 0.75rem !important;
    transition: transform var(--transition-speed) ease;
}

.sidebar-link[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(90deg);
}

/* MAIN CONTENT CONTAINER */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1),
                width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
}

/* TOP NAVBAR */
.top-navbar {
    height: var(--top-navbar-height);
    background-color: var(--bg-navbar);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-navbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: background-color var(--transition-speed) ease, border-bottom var(--transition-speed) ease;
}

.navbar-toggle-btn {
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 1.25rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}
.navbar-toggle-btn:hover {
    background-color: var(--sidebar-hover-bg);
}

/* Page Frame Content */
.content-body {
    flex-grow: 1;
    padding: 2rem 1.5rem calc(var(--footer-height) + 2rem) 1.5rem;
}

/* FIXED FOOTER */
.fixed-footer {
    height: var(--footer-height);
    background-color: var(--bg-sidebar);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: fixed;
    bottom: 0;
    right: 0;
    width: calc(100% - var(--sidebar-width));
    z-index: 998;
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1),
                background-color var(--transition-speed) ease,
                border-top var(--transition-speed) ease;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* FLOATING BACK TO TOP BUTTON */
.back-to-top {
    position: fixed;
    bottom: calc(var(--footer-height) + 20px);
    right: 25px;
    z-index: 1030;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: var(--brand-primary);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background-color: #4338ca;
    box-shadow: 0 6px 15px rgba(79, 70, 229, 0.6);
    transform: translateY(-3px);
}

.back-to-top:active {
    transform: translateY(-1px);
}

/* COLLAPSED STATE MECHANICS (Desktop) */
@media (min-width: 992px) {
    .app-wrapper.collapsed .sidebar {
        width: var(--sidebar-collapsed-width);
    }
    
    .app-wrapper.collapsed .sidebar-brand {
        justify-content: center;
        padding: 0;
    }
    
    /* Hide only text labels, NOT icons */
    .app-wrapper.collapsed .sidebar-brand-text,
    .app-wrapper.collapsed .sidebar-link-content > span,
    .app-wrapper.collapsed .dropdown-arrow,
    .app-wrapper.collapsed .sidebar-submenu,
    .app-wrapper.collapsed .sidebar-header,
    .app-wrapper.collapsed .px-3.py-2.border-bottom {
        display: none !important;
    }

    /* Keep the icon wrapper visible and centered */
    .app-wrapper.collapsed .sidebar-link-content {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 0;
    }

    .app-wrapper.collapsed .sidebar-link {
        justify-content: center;
        padding: 0.75rem 0;
    }

    /* Ensure icons are visible, sized well, and centered */
    .app-wrapper.collapsed .sidebar-link i {
        width: 22px;
        font-size: 1.1rem;
        text-align: center;
        display: block;
    }

    /* Hide the logo text but keep the icon */
    .app-wrapper.collapsed .sidebar-logo span {
        display: none !important;
    }

    .app-wrapper.collapsed .main-content {
        margin-left: var(--sidebar-collapsed-width);
        width: calc(100% - var(--sidebar-collapsed-width));
    }
    
    .app-wrapper.collapsed .fixed-footer {
        width: calc(100% - var(--sidebar-collapsed-width));
    }
}

/* RESPONSIVE BREAKPOINTS (Mobile Drawer Navigation) */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    .fixed-footer {
        width: 100%;
    }
    
    .app-wrapper.mobile-open .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 25px rgba(0, 0, 0, 0.15);
    }
    
    /* Backdrop overlay when mobile menu is open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.4);
        z-index: 1039;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-speed) ease;
    }
    
    .app-wrapper.mobile-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }
}

/* PREMIUM UI COMPONENT DECORATORS */
.premium-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.premium-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stats-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Theme Switch Animations */
.theme-icon-container {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-icon-container i {
    position: absolute;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

[data-bs-theme="light"] .theme-icon-moon {
    transform: rotate(0) scale(1);
    opacity: 1;
}

[data-bs-theme="light"] .theme-icon-sun {
    transform: rotate(90deg) scale(0);
    opacity: 0;
}

[data-bs-theme="dark"] .theme-icon-moon {
    transform: rotate(-90deg) scale(0);
    opacity: 0;
}

[data-bs-theme="dark"] .theme-icon-sun {
    transform: rotate(0) scale(1);
    opacity: 1;
}

/* Quick Page Loader / Transitions */
.page-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================================
   MODAL FIXES — prevent page-disabled appearance
   ============================================================ */

/* 1. Properly theme the Bootstrap backdrop for dark/light mode */
.modal-backdrop {
    z-index: 1050 !important;
}

[data-bs-theme="dark"] .modal-backdrop {
    background-color: rgba(0, 0, 0, 0.75) !important;
}

[data-bs-theme="light"] .modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* 2. Ensure modals sit above all our layout elements */
.modal {
    z-index: 1055 !important;
}

/* 3. Hide the back-to-top button when any modal is open (prevents z-index overlap) */
body.modal-open .back-to-top {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none;
}

/* 4. Compensate for Bootstrap's body padding-right on modal open
      so the fixed sidebar/footer don't shift */
body.modal-open .sidebar,
body.modal-open .top-navbar,
body.modal-open .fixed-footer {
    padding-right: 0 !important;
}

/* 5. Ensure fixed-positioned elements don't create new stacking contexts
      that would interfere with the modal backdrop */
body:not(.modal-open) .sidebar {
    isolation: isolate;
}

/* 6. Modal content theming for dark mode */
[data-bs-theme="dark"] .modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
}

[data-bs-theme="dark"] .modal .form-control,
[data-bs-theme="dark"] .modal .form-select,
[data-bs-theme="dark"] .modal .input-group-text {
    background-color: var(--bg-body);
    border-color: var(--border-color);
    color: var(--text-main);
}

[data-bs-theme="dark"] .modal .form-control::placeholder {
    color: var(--text-muted);
}

[data-bs-theme="dark"] .modal .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

