/* ========================================
   BENJA STOCK - LAYOUT SYSTEM
   Premium Apple-Style Navigation
   Mobile-First Responsive Design
   ======================================== */

/* ==========================================
   1. LAYOUT WRAPPER
   ========================================== */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--stock-bg);
}

/* ==========================================
   2. SIDEBAR - Desktop
   Premium glass morphism effect
   ========================================== */
.sidebar {
    width: 280px;
    background: var(--stock-card-bg);
    border-right: 1px solid var(--stock-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        box-shadow 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--luxury-gold);
    border-radius: 2px;
}

.sidebar-header {
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--stock-border);
}

.sidebar-header img {
    max-height: 48px;
    width: auto;
    transition: transform 0.3s ease;
}

.sidebar-header img:hover {
    transform: scale(1.05);
}

.sidebar-nav {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 0.5rem;
}

/* ==========================================
   3. NAVIGATION ITEMS
   ========================================== */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.8rem 1.1rem;
    border-radius: 12px;
    color: var(--stock-text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.25s ease;
}

.nav-item:hover {
    background: var(--luxury-gold-glow);
    color: var(--luxury-gold);
}

.nav-item.active {
    background: var(--stock-card-bg);
    color: var(--luxury-gold-dark);
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .nav-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--luxury-gold-light);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 24px;
    background: var(--gradient-gold);
    border-radius: 0 4px 4px 0;
}

/* Logout Button */
.nav-item.logout-btn {
    margin-top: auto !important;
    color: var(--stock-text-secondary);
    border: 1px solid var(--stock-border);
    justify-content: center;
    background: transparent;
}

.nav-item.logout-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    color: var(--accent-ruby);
    border-color: var(--accent-ruby);
}

/* ==========================================
   4. MAIN CONTENT
   ========================================== */
.main-content {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    background: var(--stock-bg);
    min-height: 100vh;
    transition: margin-left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ==========================================
   5. TOP BAR
   Glass morphism sticky header
   ========================================== */
.topbar {
    height: 72px;
    position: sticky;
    top: 0;
    z-index: 900;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    border-bottom: 1px solid var(--stock-border);
    transition: all 0.3s ease;
}

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

.topbar-left h2 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--stock-text);
    letter-spacing: -0.01em;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Mobile Menu Button */
.toggle-sidebar-btn,
#toggleSidebar {
    display: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--stock-border);
    background: var(--stock-card-bg);
    color: var(--stock-text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.toggle-sidebar-btn:hover,
#toggleSidebar:hover {
    background: rgba(212, 175, 55, 0.1);
    border-color: var(--luxury-gold);
    color: var(--luxury-gold);
}

/* ==========================================
   6. DASHBOARD CONTAINER
   ========================================== */
.dashboard-container {
    padding: 2rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ==========================================
   7. GRID SYSTEM
   12-column responsive grid
   ========================================== */
.grid-container {
    display: grid;
    gap: 1.5rem;
}

.grid-cols-12 {
    grid-template-columns: repeat(12, 1fr);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* Column Spans - Mobile First (Default = 12) */
.col-span-12 {
    grid-column: span 12;
}

.col-span-8 {
    grid-column: span 12;
}

.col-span-6 {
    grid-column: span 12;
}

.col-span-4 {
    grid-column: span 12;
}

.col-span-3 {
    grid-column: span 12;
}

/* ==========================================
   8. MOBILE RESPONSIVE (up to 768px)
   ========================================== */
@media (max-width: 768px) {

    /* Hide sidebar on mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 85%;
        max-width: 320px;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 60px rgba(0, 0, 0, 0.3);
    }

    /* Show mobile menu button */
    .toggle-sidebar-btn,
    #toggleSidebar {
        display: flex !important;
    }

    /* Remove margin from main content */
    .main-content {
        margin-left: 0;
    }

    /* Adjust topbar */
    .topbar {
        height: 64px;
        padding: 0 1rem;
    }

    .topbar-left h2 {
        font-size: 1.125rem;
    }

    /* Adjust dashboard padding */
    .dashboard-container {
        padding: 1rem;
    }

    /* Mobile overlay for sidebar */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ==========================================
   9. TABLET RESPONSIVE (768px - 1024px)
   ========================================== */
@media (min-width: 768px) {
    .col-span-md-6 {
        grid-column: span 6;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }

    .main-content {
        margin-left: 240px;
    }

    .sidebar-header img {
        max-height: 40px;
    }

    .nav-item {
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }

    .dashboard-container {
        padding: 1.5rem;
    }
}

/* ==========================================
   10. DESKTOP RESPONSIVE (1024px+)
   ========================================== */
@media (min-width: 1024px) {
    .col-span-lg-3 {
        grid-column: span 3;
    }

    .col-span-lg-4 {
        grid-column: span 4;
    }

    .col-span-lg-6 {
        grid-column: span 6;
    }

    .col-span-lg-8 {
        grid-column: span 8;
    }
}

/* ==========================================
   11. LARGE DESKTOP (1200px+)
   ========================================== */
@media (min-width: 1200px) {
    .dashboard-container {
        padding: 2.5rem;
    }
}

/* ==========================================
   12. SIDEBAR ANIMATIONS
   ========================================== */
@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.sidebar.animate-in {
    animation: slideInLeft 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* ==========================================
   13. RTL SUPPORT
   ========================================== */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--stock-border);
}

[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: 280px;
}

[dir="rtl"] .topbar-left {
    flex-direction: row-reverse;
}

[dir="rtl"] .topbar-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .nav-item {
    flex-direction: row;
    /* Keep icon-text order but allow container padding to handle it or use gap */
    gap: 0.875rem;
}

[dir="rtl"] .nav-item.active::before {
    left: auto;
    right: 0;
    border-radius: 4px 0 0 4px;
}

[dir="rtl"] .kpi-content {
    text-align: right;
}

[dir="rtl"] .chart-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .text-right {
    text-align: left !important;
}

[dir="rtl"] .modal-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .modal-footer {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

/* Mobile RTL */
@media (max-width: 768px) {
    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    [dir="rtl"] .sidebar.open {
        transform: translateX(0);
        box-shadow: -20px 0 60px rgba(0, 0, 0, 0.3);
    }

    [dir="rtl"] .main-content {
        margin-right: 0;
        margin-left: 0;
    }

    [dir="rtl"] .topbar {
        flex-direction: row;
        /* keep button on left if icon-btn is first */
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    [dir="rtl"] .main-content {
        margin-right: 240px;
        margin-left: 0;
    }
}

/* RTL Helpers */
.rtl-mode .ms-auto {
    margin-right: auto !important;
    margin-left: 0 !important;
}

.rtl-mode .me-auto {
    margin-left: auto !important;
    margin-right: 0 !important;
}

.rtl-mode .text-start {
    text-align: right !important;
}

.rtl-mode .text-end {
    text-align: left !important;
}

/* ==========================================
   14. DARK THEME SIDEBAR
   ========================================== */
[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, var(--midnight-800) 0%, var(--midnight-900) 100%);
    border-color: rgba(212, 175, 55, 0.1);
}

[data-theme="dark"] .topbar {
    background: rgba(10, 10, 15, 0.85);
    border-color: rgba(212, 175, 55, 0.1);
}

[data-theme="dark"] .nav-item.active {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.2) 0%, rgba(212, 175, 55, 0.08) 100%);
}