/* Layout Structure */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 1000;
    box-shadow: 0 2px 10px var(--shadow-light);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-medium);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background: var(--light-gray);
    color: var(--primary-blue);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-img {
    height: 35px;
    width: auto;
}

.logo-text {
    font-weight: 600;
    color: var(--text-medium);
    font-size: 1rem;
}

.topbar-center {
    flex: 1;
    max-width: 500px;
    margin: 0 2rem;
}

.search-box {
    position: relative;
    width: 100%;
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-lighter);
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--light-gray);
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-blue);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.wallet-balance {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary-blue-ultra-light);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    color: var(--primary-blue);
}

.wallet-balance i {
    font-size: 1rem;
}

.add-fund-btn {
    background: var(--primary-blue);
    color: var(--white);
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.add-fund-btn:hover {
    background: var(--primary-blue-dark);
    transform: scale(1.1);
}

.notifications {
    position: relative;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.notifications:hover {
    background: var(--light-gray);
}

.notifications i {
    font-size: 1.2rem;
    color: var(--text-medium);
}

.notification-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--danger-red);
    color: var(--white);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.notification-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--shadow-medium);
    display: none;
    z-index: 1001;
}

.notification-dropdown.show {
    display: block;
}

.notification-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.3s ease;
}

.notification-item:hover {
    background: var(--light-gray);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item i {
    font-size: 1.2rem;
}

.notification-item h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.notification-item p {
    font-size: 0.75rem;
    color: var(--text-light);
}

.profile-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    transition: background 0.3s ease;
}

.profile-dropdown:hover {
    background: var(--light-gray);
}

.profile-avatar {
    width: 35px;
    height: 35px;
    background: var(--gradient-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
}

.profile-name {
    font-weight: 600;
    color: var(--text-medium);
}

.profile-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--shadow-medium);
    display: none;
    z-index: 1001;
    padding: 0.5rem 0;
}

.profile-menu.show {
    display: block;
}

.profile-menu a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-medium);
    font-size: 0.875rem;
    transition: background 0.3s ease;
}

.profile-menu a:hover {
    background: var(--light-gray);
    color: var(--primary-blue);
}

.profile-menu hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0.5rem 0;
}

/* Sidebar - Desktop Default */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--white);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 999;
    transition: transform 0.3s ease;
    transform: translateX(0) !important; /* Default: visible on desktop */
}

/* Desktop collapsed state - Higher specificity */
body .sidebar.collapsed {
    transform: translateX(-100%) !important;
}

.sidebar-nav {
    padding: 1.5rem 0;
}

.nav-section {
    margin-bottom: 2rem;
}

.nav-section h3 {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-lighter);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
    padding: 0 1.5rem;
}

.nav-section ul {
    list-style: none;
}

.nav-section li {
    margin-bottom: 0.25rem;
}

.nav-section a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    color: var(--text-medium);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
}

.nav-section a:hover {
    background: var(--light-gray);
    color: var(--primary-blue);
}

.nav-section li.active a {
    background: var(--primary-blue-ultra-light);
    color: var(--primary-blue);
    font-weight: 600;
}

.nav-section li.active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-blue);
}

.badge {
    background: var(--primary-blue);
    color: var(--white);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    margin-left: auto;
}

.badge-danger {
    background: var(--danger-red);
}


.submenu {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
    background: var(--light-gray) !important;
}

.submenu.show {
    max-height: 300px !important;
}

/* Ensure submenu toggle icon rotates */
.submenu-toggle {
    margin-left: auto !important;
    transition: transform 0.3s ease !important;
}

/* High specificity rules to ensure submenu animations work */
.sidebar .sidebar-nav .submenu {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
    background: var(--light-gray) !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.sidebar .sidebar-nav .submenu.show {
    max-height: 300px !important;
}

.sidebar .sidebar-nav .submenu-toggle {
    margin-left: auto !important;
    transition: transform 0.3s ease !important;
    display: inline-block !important;
}

.submenu li a {
    padding-left: 3rem;
    font-size: 0.8rem;
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--light-gray);
}

.quick-store h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-medium);
    margin-bottom: 1rem;
}

.store-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.store-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--white);
    color: var(--text-medium);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.store-btn:hover {
    background: var(--primary-blue);
    color: var(--white);
    border-color: var(--primary-blue);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 2rem;
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.3s ease;
}

/* Desktop main content expanded state - Higher specificity */
body .main-content.expanded {
    margin-left: 0;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-header p {
    color: var(--text-light);
    font-size: 1rem;
    margin-bottom: 1rem;
}

.page-header .btn {
    margin-top: 1rem;
}

/* Legacy Client Area Wrapper Support */
.client-area {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.client-area .topbar {
    /* Override fixed positioning for old structure */
    position: relative;
    top: auto;
    left: auto;
    right: auto;
}

.client-area .sidebar {
    /* Override fixed positioning for old structure */
    position: relative;
    top: auto;
    left: auto;
    width: var(--sidebar-width);
    height: auto;
    min-height: calc(100vh - var(--topbar-height));
    float: left;
}

.client-area .main-content {
    /* Adjust for old structure */
    margin-left: var(--sidebar-width);
    margin-top: 0;
    padding: 2rem;
    min-height: calc(100vh - var(--topbar-height));
    overflow: hidden;
}

/* Legacy breadcrumb support */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

.breadcrumb i {
    font-size: 0.75rem;
    color: var(--text-lighter);
}

/* Legacy menu toggle support */
.menu-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-medium);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.menu-toggle:hover {
    background: var(--light-gray);
    color: var(--primary-blue);
}

/* Legacy user menu support */
.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    transition: background 0.3s ease;
}

.user-menu:hover {
    background: var(--light-gray);
}

.user-avatar {
    width: 35px;
    height: 35px;
    background: var(--gradient-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
}

.user-name {
    font-weight: 600;
    color: var(--text-medium);
}

/* Legacy sidebar header support */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--light-gray);
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header .logo img {
    height: 40px;
    width: auto;
}

/* Fix for old structure sidebar nav */
.client-area .sidebar-nav {
    padding: 1.5rem 0;
}

.client-area .sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.client-area .sidebar-nav li {
    margin-bottom: 0.25rem;
}

.client-area .sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    color: var(--text-medium);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
}

.client-area .sidebar-nav a:hover {
    background: var(--light-gray);
    color: var(--primary-blue);
}

.client-area .sidebar-nav li.active a {
    background: var(--primary-blue-ultra-light);
    color: var(--primary-blue);
    font-weight: 600;
}

.client-area .sidebar-nav li.active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-blue);
}

.client-area .sidebar-nav .has-submenu .submenu-toggle {
    margin-left: auto;
    transition: transform 0.3s ease;
}

.client-area .sidebar-nav .submenu {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
    background: var(--light-gray) !important;
}

.client-area .sidebar-nav .submenu.show {
    max-height: 300px !important;
}

/* Ensure client-area submenu toggle icon rotates */
.client-area .sidebar-nav .submenu-toggle {
    margin-left: auto !important;
    transition: transform 0.3s ease !important;
}

.client-area .sidebar-nav .submenu li a {
    padding-left: 3rem;
    font-size: 0.8rem;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* Responsive Design */
@media (max-width: 1024px) {
    .topbar-center {
        max-width: 300px;
        margin: 0 1rem;
    }
    
    .topbar-right {
        gap: 1rem;
    }
}

@media (min-width: 769px) {
    /* Desktop sidebar behavior - Force proper styles */
    body .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--topbar-height));
        transform: translateX(0) !important;
        padding-top: 0;
        box-shadow: none;
        transition: transform 0.3s ease;
    }
    
    body .sidebar.collapsed {
        transform: translateX(-100%) !important;
    }
    
    body .sidebar.show {
        /* Ensure show class doesn't interfere on desktop */
        transform: translateX(0) !important;
    }
    
    body .main-content {
        margin-left: var(--sidebar-width);
        transition: margin-left 0.3s ease;
    }
    
    body .main-content.expanded {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    /* Hide search on mobile */
    .topbar-center {
        display: none;
    }
    
    /* Mobile topbar adjustments */
    .topbar {
        padding: 0 1rem;
    }
    
    .topbar-right {
        gap: 0.75rem;
    }
    
    .wallet-balance span:first-child {
        display: none;
    }
    
    .profile-name {
        display: none;
    }
    
    /* Mobile sidebar - Only override what's needed */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        padding-top: var(--topbar-height) !important;
        z-index: 1001 !important;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%) !important;
    }
    
    /* Main content adjustments */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
    }
    
    .main-content.expanded {
        margin-left: 0;
    }
    
    /* Mobile sidebar navigation */
    .sidebar-nav {
        padding: 1rem 0;
    }
    
    .nav-section h3 {
        padding: 0 1rem;
        font-size: 0.7rem;
    }
    
    .nav-section a {
        padding: 1rem 1rem;
        font-size: 0.875rem;
        min-height: 44px; /* Touch-friendly target size */
        display: flex;
        align-items: center;
    }
    
    .nav-section a:active {
        background: var(--light-gray);
    }
    
    .sidebar-nav .submenu-toggle {
        padding: 0.5rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .topbar {
        padding: 0 0.75rem;
    }
    
    .sidebar {
        width: 100vw;
    }
    
    .main-content {
        padding: 0.75rem;
    }
    
    .logo-text {
        display: none;
    }
    
    .wallet-balance {
        font-size: 0.875rem;
    }
    
    .notifications {
        font-size: 0.875rem;
    }
    
    /* Grid responsive */
    .grid {
        grid-gap: 0.75rem;
    }
    
    .grid-2, .grid-3, .grid-4, .grid-auto {
        grid-template-columns: 1fr;
    }
    
    /* Card adjustments */
    .card {
        margin-bottom: 1rem;
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }
}

/* Additional responsive grid fixes */
@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
    
    .dashboard-stats.grid-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 375px) {
    .dashboard-stats.grid-4 {
        grid-template-columns: 1fr;
    }
}