/* ==========================================
MOBILE LOCK (< 768px)
========================================== */
@media (max-width: 767px) {
    .desktop-sidebar, .desktop-header, .desktop-dashboard { display: none !important; }
    .app-header, .segmented-nav, .action-bar { display: flex; } /* Ensure mobile elements visible */
    .app-main { padding-bottom: 108px; }
}

/* ==========================================
TABLET (768px - 1023px)
========================================== */
@media (min-width: 768px) and (max-width: 1023px) {
    .header-inner { gap: 24px; }
    .app-brand { display: block; }
    .segmented-nav { max-width: 360px; margin: 0; }
    .app-main { padding: 24px; padding-bottom: 90px; }
    
    /* Two column layout for new bill on tablet */
    #page-new-bill.active { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
    #page-new-bill > .invoice-header, #page-new-bill > .card:nth-child(2), #page-new-bill > .card:nth-child(3) { grid-column: 1; }
    #page-new-bill > .totals-card, #page-new-bill > .card:last-child { grid-column: 2; grid-row: 1 / span 3; position: sticky; top: 74px; }
    
    .action-bar { justify-content: center; padding-left: 24px; padding-right: 24px; }
    .action-bar .btn { max-width: 160px; flex: none; }
    .action-bar .btn-primary { max-width: 200px; flex: none; }
    
    .modal-overlay { align-items: center; }
    .modal { border-radius: var(--radius-lg); max-height: 82vh; }
}

/* ==========================================
DESKTOP ENTERPRISE SHELL (>= 1024px)
========================================== */
@media (min-width: 1024px) {
    /* Hide Mobile Chrome */
    .app-header, .segmented-nav, .action-bar { display: none !important; }
    
    /* Show Desktop Chrome */
    .desktop-sidebar {
        display: flex; flex-direction: column;
        position: fixed; left: 0; top: 0; bottom: 0;
        width: 240px; background: var(--navy-dark);
        padding: 20px 0; z-index: 100;
        box-shadow: 2px 0 12px rgba(17,45,96,0.15);
    }
    .sidebar-brand {
        color: #ffffff; font-size: 18px; font-weight: 700;
        padding: 0 20px 24px; border-bottom: 1px solid rgba(255,255,255,0.1);
        margin-bottom: 16px; letter-spacing: -0.3px;
    }
    .sidebar-brand span { color: #60a5fa; }
    .sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 0 12px; }
    .sidebar-btn {
        display: flex; align-items: center; gap: 12px;
        padding: 10px 14px; border-radius: 8px;
        color: rgba(255,255,255,0.7); font-size: 14px; font-weight: 500;
        background: transparent; border: none; cursor: pointer;
        transition: all 0.14s ease; text-align: left; width: 100%;
    }
    .sidebar-btn:hover { background: rgba(255,255,255,0.08); color: #ffffff; }
    .sidebar-btn.active { background: rgba(255,255,255,0.15); color: #ffffff; font-weight: 600; }
    .sidebar-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
    .sidebar-footer { padding: 16px 20px; font-size: 11px; color: rgba(255,255,255,0.4); border-top: 1px solid rgba(255,255,255,0.1); }

    .desktop-main-wrapper { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; }
    
    .desktop-header {
        background: var(--bg-card); border-bottom: 1px solid var(--border-color);
        padding: 16px 32px; display: flex; justify-content: space-between; align-items: center;
        position: sticky; top: 0; z-index: 90; box-shadow: var(--shadow-xs);
    }
    .page-title { margin: 0; font-size: 20px; font-weight: 700; color: var(--navy-dark); letter-spacing: -0.3px; }
    .header-date { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

    .app-main {
        padding: 24px 32px; max-width: 1400px; width: 100%; margin: 0 auto;
        padding-bottom: 40px; /* No bottom bar on desktop */
    }

    /* Desktop Dashboard */
    .desktop-dashboard { display: block; margin-bottom: 24px; }
    .analytics-grid { grid-template-columns: 2fr 1fr; }
    .chart-card.full-width { grid-column: 1 / -1; }
    
    /* Desktop New Bill Layout */
    #page-new-bill.active {
        display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start;
    }
    #page-new-bill > .invoice-header { grid-column: 1 / -1; }
    #page-new-bill > .card:nth-child(2), #page-new-bill > .card:nth-child(3) { grid-column: 1; }
    #page-new-bill > .totals-card, #page-new-bill > .card:last-child {
        grid-column: 2; grid-row: 2 / span 3;
        position: sticky; top: 80px;
    }
    #page-new-bill > .card:last-child { margin-top: 16px; }

    /* Desktop Saved Bills Layout */
    #page-saved-bills.active { display: block; }
    
    /* Desktop Products Layout */
    #page-products.active { display: block; }
    .product-row { padding: 12px 16px; }
}

@media (min-width: 1440px) {
    .app-main { max-width: 1500px; }
    .analytics-grid { grid-template-columns: 1.5fr 1fr; }
}
