/* ============================================
   RESPONSIVE.CSS – Mobile, Tablet & Desktop
   RULE: NO content hidden. Everything visible.
   ============================================ */

/* ── Mobile Cards — hidden by default on desktop ── */
.mobile-cards { display: none; }

/* ── SVG Icon Buttons — Global alignment for all devices ── */
.btn svg, .mc-action-btn svg, .pcc-actions svg, a.btn svg, button svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}
.btn { display: inline-flex; align-items: center; gap: 6px; }
.btn-ghost svg { opacity: 0.85; }
.btn-ghost:hover svg { opacity: 1; }

/* ── Missing Badge Classes ── */
.badge-active { background:#dcfce7; color:#15803d; padding:4px 10px; border-radius:20px; font-size:12px; font-weight:600; }
.badge-disabled { background:#fee2e2; color:#b91c1c; padding:4px 10px; border-radius:20px; font-size:12px; font-weight:600; }
.badge-draft { background:#f1f5f9; color:#64748b; padding:4px 10px; border-radius:20px; font-size:12px; font-weight:600; }
[data-theme="dark"] .badge-active { background:rgba(22,163,74,0.15); color:#4ade80; }
[data-theme="dark"] .badge-disabled { background:rgba(239,68,68,0.15); color:#f87171; }
[data-theme="dark"] .badge-draft { background:rgba(100,116,139,0.15); color:#94a3b8; }

/* ── Fix Enterprise Card Visibility ── */
.e-card { background:var(--bg-card) !important; border:1px solid var(--border-color); box-shadow:var(--shadow-sm); }
.g-card { background:var(--bg-card) !important; border:1px solid var(--border-color); box-shadow:0 2px 12px rgba(0,0,0,0.03); }

/* ══════════════════════════════════════════
   TABLET (768px - 1024px)
   ══════════════════════════════════════════ */
@media (max-width:1024px) {
    .stats-grid { grid-template-columns:repeat(2,1fr) !important; gap:12px !important; }
    .grid-3 { grid-template-columns:1fr !important; }
    .grid-2 { grid-template-columns:1fr !important; }
    .e-grid-3 { grid-template-columns:repeat(2,1fr) !important; }
    .e-grid-4 { grid-template-columns:repeat(2,1fr) !important; }
    .g-grid-3 { grid-template-columns:repeat(2,1fr) !important; }
    .hero-grid { grid-template-columns:repeat(2,1fr) !important; }
    .page-header { flex-direction:column !important; align-items:flex-start !important; gap:12px !important; }
    .page-header .btn { width:100%; justify-content:center; }
}

/* ══════════════════════════════════════════
   MOBILE (below 768px)
   ══════════════════════════════════════════ */
@media (max-width:768px) {

    /* ── CRITICAL MOBILE OVERFLOW PREVENTION ── */
    html, body { overflow-x: hidden !important; width: 100vw !important; max-width: 100vw !important; }
    .app-layout, .main-content, .page-content { width: 100% !important; max-width: 100vw !important; min-width: 0 !important; }

    /* ── SHOW EVERYTHING — Override any display:none ── */
    .page-subtitle { display:block !important; font-size:12px !important; }
    .user-row > span { display:flex !important; }

    /* ── Stats Grid — 2 columns that FIT ── */
    .stats-grid { 
        grid-template-columns: 1fr 1fr !important; 
        gap: 8px !important; 
        margin-bottom: 12px !important;
    }
    .stat-card { 
        display: flex !important;
        flex-direction: row !important; /* Horizontal layout */
        align-items: center !important; 
        padding: 8px 10px !important; 
        gap: 8px !important; 
        border-radius: 12px !important;
        background: var(--bg-card) !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
        min-height: 52px !important; /* Extremely compact */
    }
    .stat-icon { 
        width: 28px !important; 
        height: 28px !important; 
        font-size: 14px !important; 
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }
    .stat-info {
        display: flex !important;
        flex-direction: column !important;
        min-width: 0 !important;
        flex: 1 !important;
    }
    .stat-label { 
        font-size: 9px !important; 
        font-weight: 600 !important;
        color: var(--text-tertiary) !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .stat-value { 
        font-size: 14px !important; 
        font-weight: 800 !important;
        line-height: 1.2 !important;
        word-break: break-all !important; 
        margin-top: 1px !important;
    }

    /* ── Enterprise Dashboard Cards ── */
    .e-grid-3, .e-grid-2, .e-grid-4 { grid-template-columns:1fr !important; gap:16px !important; }
    .g-grid-3, .g-grid-2 { grid-template-columns:1fr !important; gap:16px !important; }
    .hero-grid { grid-template-columns:1fr !important; gap:14px !important; }
    .e-card { padding:20px !important; }
    .g-card { padding:18px !important; border-radius:16px !important; }
    .hero-card { padding:18px !important; border-radius:16px !important; }
    .hero-value { font-size:22px !important; }
    .hero-split-value { font-size:18px !important; }
    .hero-icon { width:40px !important; height:40px !important; font-size:18px !important; }
    .e-card-value { font-size:24px !important; }
    .e-card-title { font-size:15px !important; }
    .e-card-sub { font-size:12px !important; }
    .premium-list-card { border-radius:16px !important; }
    .smart-card, .compact-card { border-radius:16px !important; width:100% !important; max-width:100% !important; box-sizing:border-box !important; min-width: 0 !important; }
    .smart-card-body { overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; width: 100% !important; }
    
    /* ── Recent Invoices Table — Compact & Fitting Mobile ── */
    #recentInvoicesList table,
    #c_recentInvoices table {
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: separate !important;
        border-spacing: 0 4px !important;
        min-width: 0 !important;
        display: table !important;
    }
    #recentInvoicesList tbody,
    #c_recentInvoices tbody {
        display: table-row-group !important;
        width: 100% !important;
    }
    #recentInvoicesList tr,
    #c_recentInvoices tr {
        display: table-row !important;
        width: 100% !important;
        background: var(--bg-tertiary) !important;
    }
    #recentInvoicesList tr:first-child,
    #c_recentInvoices tr:first-child {
        display: table-row !important; /* Keep headers visible but very small */
    }
    #recentInvoicesList tr:first-child td,
    #c_recentInvoices tr:first-child td {
        font-size: 8px !important;
        padding: 4px 6px !important;
        color: var(--text-tertiary) !important;
        text-transform: uppercase !important;
        font-weight: 700 !important;
        letter-spacing: 0.5px !important;
        border: none !important;
        background: transparent !important;
    }
    #recentInvoicesList td,
    #c_recentInvoices td {
        display: table-cell !important;
        padding: 8px 6px !important; /* Tighter padding for mobile */
        vertical-align: middle !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    /* Specific Column Width Allocations */
    #recentInvoicesList td:nth-child(1),
    #c_recentInvoices td:nth-child(1) {
        width: 25% !important;
        text-align: left !important;
        border-radius: 8px 0 0 8px !important;
    }
    #recentInvoicesList td:nth-child(2),
    #c_recentInvoices td:nth-child(2) {
        width: 33% !important;
        text-align: left !important;
    }
    #recentInvoicesList td:nth-child(3),
    #c_recentInvoices td:nth-child(3) {
        width: 22% !important;
        text-align: right !important;
    }
    #recentInvoicesList td:nth-child(4),
    #c_recentInvoices td:nth-child(4) {
        width: 20% !important;
        text-align: center !important;
        border-radius: 0 8px 8px 0 !important;
    }

    /* Inner Row elements */
    #recentInvoicesList td:nth-child(1) div:first-child,
    #c_recentInvoices td:nth-child(1) div:first-child {
        font-size: 11px !important;
        font-weight: 800 !important;
        color: #6366f1 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #recentInvoicesList td:nth-child(1) div:last-child,
    #c_recentInvoices td:nth-child(1) div:last-child {
        font-size: 9px !important;
        color: var(--text-tertiary) !important;
        margin-top: 1px !important;
        font-weight: 500 !important;
    }
    #recentInvoicesList td:nth-child(2) div,
    #c_recentInvoices td:nth-child(2) div {
        font-weight: 700 !important;
        font-size: 11px !important;
        color: var(--text-primary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #recentInvoicesList td:nth-child(3) span,
    #c_recentInvoices td:nth-child(3) span {
        font-weight: 900 !important;
        font-size: 11px !important;
        color: var(--text-primary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #recentInvoicesList td:nth-child(4) span,
    #c_recentInvoices td:nth-child(4) span {
        font-size: 8px !important;
        font-weight: 700 !important;
        padding: 3px 6px !important;
        border-radius: 8px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.2px !important;
        display: inline-block !important;
        white-space: nowrap !important;
    }

    /* ── Customers List Table — Compact & Fitting Mobile ── */
    #customersListTable {
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: separate !important;
        border-spacing: 0 4px !important;
        min-width: 0 !important;
        display: table !important;
    }
    #customersListTable tbody { display: table-row-group !important; width: 100% !important; }
    #customersListTable tr { display: table-row !important; width: 100% !important; background: var(--bg-tertiary) !important; }
    #customersListTable tr:first-child { display: table-row !important; }
    #customersListTable th { display: table-cell !important; font-size: 8px !important; padding: 4px 6px !important; color: var(--text-tertiary) !important; text-transform: uppercase !important; font-weight: 700 !important; letter-spacing: 0.5px !important; border: none !important; background: transparent !important; }
    #customersListTable td { display: table-cell !important; padding: 8px 6px !important; vertical-align: middle !important; box-sizing: border-box !important; overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important; }
    
    #customersListTable td:nth-child(1), #customersListTable th:nth-child(1) { width: 40% !important; text-align: left !important; border-radius: 8px 0 0 8px !important; padding-left: 8px !important; }
    #customersListTable td:nth-child(2), #customersListTable th:nth-child(2) { display: none !important; } /* Hide contact on very small screens to save space */
    #customersListTable td:nth-child(3), #customersListTable th:nth-child(3) { width: 35% !important; text-align: right !important; }
    #customersListTable td:nth-child(4), #customersListTable th:nth-child(4) { width: 25% !important; text-align: right !important; padding-right: 8px !important; border-radius: 0 8px 8px 0 !important; }

    #customersListTable td:nth-child(1) > div > div:first-child { width: 28px !important; height: 28px !important; font-size: 11px !important; border-radius: 6px !important; }
    #customersListTable td:nth-child(1) > div > div:last-child > div:first-child { font-size: 11px !important; font-weight: 700 !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
    #customersListTable td:nth-child(1) > div > div:last-child > div:last-child { font-size: 9px !important; }
    #customersListTable td:nth-child(3) span { font-size: 10px !important; padding: 4px 8px !important; border-radius: 8px !important; }
    #customersListTable td:nth-child(4) > div { justify-content: flex-end !important; gap: 4px !important; }
    #customersListTable td:nth-child(4) .btn { padding: 5px 8px !important; font-size: 10px !important; }

    /* ── Page Headers — Standard Premium Responsive Layout ── */
    .page-header {
        position: relative !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 8px 4px !important;
        margin-bottom: 12px !important;
    }
    .page-header-left {
        flex: 1 1 auto !important;
        margin-right: 120px !important; /* Avoid overlap with absolute primary button */
    }
    .page-header h1 {
        display: block !important;
        font-size: 20px !important;
        font-weight: 800 !important;
        color: var(--text-primary) !important;
        margin: 0 !important;
        letter-spacing: -0.5px !important;
    }
    .page-header p {
        display: none !important; /* Hide description to save space on mobile */
    }
    
    /* Primary button: positioned at top-right next to title */
    .page-header .btn-primary {
        position: absolute !important;
        top: 6px !important;
        right: 4px !important;
        width: auto !important;
        padding: 8px 14px !important;
        font-size: 12px !important;
        font-weight: 700 !important;
        border-radius: 20px !important; /* Premium pill style */
        box-shadow: 0 4px 12px rgba(99,102,241,0.2) !important;
        white-space: nowrap !important;
        z-index: 10 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Buttons container: side-by-side secondary buttons below row 1 */
    .page-header > div:last-child {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        width: 100% !important;
        margin-top: 4px !important;
    }
    /* Hide button container if it doesn't contain any secondary buttons */
    .page-header > div:last-child:not(:has(.btn:not(.btn-primary))) {
        display: none !important;
    }
    /* Secondary buttons style */
    .page-header > div:last-child .btn:not(.btn-primary) {
        flex: 1 1 0% !important; /* Equal width side-by-side */
        width: 100% !important;
        padding: 8px 12px !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        justify-content: center !important;
        border-radius: 8px !important;
        white-space: nowrap !important;
    }

    /* ── Top Customers & Top Vendors Tables — Compact & Fitting Mobile ── */
    #topCustomers table,
    #topVendors table,
    #c_topCustomers table {
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: separate !important;
        border-spacing: 0 4px !important;
        min-width: 0 !important;
        display: table !important;
    }
    #topCustomers tbody,
    #topVendors tbody,
    #c_topCustomers tbody {
        display: table-row-group !important;
        width: 100% !important;
    }
    #topCustomers tr,
    #topVendors tr,
    #c_topCustomers tr {
        display: table-row !important;
        width: 100% !important;
        background: var(--bg-tertiary) !important;
    }
    #topCustomers tr:first-child,
    #topVendors tr:first-child,
    #c_topCustomers tr:first-child {
        display: table-row !important; /* Keep headers visible but very small */
    }
    #topCustomers tr:first-child td,
    #topVendors tr:first-child td,
    #c_topCustomers tr:first-child td {
        font-size: 8px !important;
        padding: 4px 6px !important;
        color: var(--text-tertiary) !important;
        text-transform: uppercase !important;
        font-weight: 700 !important;
        letter-spacing: 0.5px !important;
        border: none !important;
        background: transparent !important;
    }
    #topCustomers td,
    #topVendors td,
    #c_topCustomers td {
        display: table-cell !important;
        padding: 8px 6px !important; /* Tighter padding for mobile */
        vertical-align: middle !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    /* Column widths: # is 12%, Customer/Vendor is 53%, Revenue/Purchases is 35% */
    #topCustomers td:nth-child(1),
    #topVendors td:nth-child(1),
    #c_topCustomers td:nth-child(1) {
        width: 12% !important;
        text-align: left !important;
        border-radius: 8px 0 0 8px !important;
    }
    #topCustomers td:nth-child(2),
    #topVendors td:nth-child(2),
    #c_topCustomers td:nth-child(2) {
        width: 53% !important;
        text-align: left !important;
    }
    #topCustomers td:nth-child(3),
    #topVendors td:nth-child(3),
    #c_topCustomers td:nth-child(3) {
        width: 35% !important;
        text-align: right !important;
        border-radius: 0 8px 8px 0 !important;
    }

    /* Inner Row elements */
    #topCustomers td:nth-child(1) div,
    #topVendors td:nth-child(1) div,
    #c_topCustomers td:nth-child(1) div {
        width: 24px !important;
        height: 24px !important;
        font-size: 11px !important;
        font-weight: 800 !important;
        border-radius: 6px !important;
        margin: 0 !important;
    }
    #topCustomers td:nth-child(2) div,
    #topVendors td:nth-child(2) div,
    #c_topCustomers td:nth-child(2) div {
        font-weight: 700 !important;
        font-size: 11px !important;
        color: var(--text-primary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #topCustomers td:nth-child(3) span,
    #topVendors td:nth-child(3) span,
    #c_topCustomers td:nth-child(3) span {
        font-weight: 800 !important;
        font-size: 11px !important;
        padding: 3px 6px !important;
        border-radius: 8px !important;
        white-space: nowrap !important;
        display: inline-block !important;
    }

    /* ── P&L Snapshot Optimization ── */
    .pnl-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        padding: 12px !important;
    }
    .pnl-stat {
        padding: 10px 8px !important;
        gap: 8px !important;
        border-radius: 12px !important;
        align-items: center !important;
        min-width: 0 !important;
    }
    .pnl-stat > div {
        min-width: 0 !important;
        overflow: hidden !important;
    }
    .pnl-icon {
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
        flex-shrink: 0 !important;
    }
    .pnl-label {
        font-size: 9px !important;
        letter-spacing: 0.3px !important;
        text-transform: uppercase !important;
        color: var(--text-tertiary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .pnl-value {
        font-size: 14px !important;
        font-weight: 800 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* ── Chart Canvases — Fill cards naturally, no empty space ── */
    .e-card canvas, .g-card canvas { max-width: 100% !important; width: 100% !important; }

    /* ── Dashboard Tabs (Segmented Control Style) ── */
    .dash-tabs {
        width: fit-content !important;
        max-width: 90% !important;
        margin: 0 auto 16px auto !important;
        border-radius: 10px !important;
        padding: 3px !important;
        display: flex !important;
        box-sizing: border-box !important;
    }
    .dash-tab {
        padding: 6px 14px !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        flex: 1 !important;
        text-align: center;
        min-width: 0 !important;
        border-radius: 7px !important;
    }
    .dash-tab.active { background: var(--bg-card) !important; color: var(--primary) !important; box-shadow: 0 2px 6px rgba(0,0,0,0.06) !important; }

    /* ── Quick Access Hub Header Mobile ── */
    .ql-header { margin-bottom: 16px !important; }
    .ql-title { font-size: 18px !important; letter-spacing: -0.3px !important; }

    /* ── Dashboard Topbar — NO cutoff & Same Line Controls ── */
    .dash-topbar { 
        flex-direction: column !important; 
        align-items: stretch !important; 
        gap: 6px !important; 
        margin-bottom: 16px !important;
    }
    .dash-topbar-left {
        font-size: 11px !important;
        color: var(--text-tertiary) !important;
        text-align: left !important;
        margin-bottom: 2px !important;
    }
    .dash-topbar-right { 
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 6px !important; 
        width: 100% !important;
    }
    #periodSelect {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        width: auto !important;
        font-size: 11px !important;
        padding: 6px 18px 6px 6px !important;
        height: 32px !important;
        border-radius: 8px !important;
        font-weight: 700 !important;
    }
    .dash-date-badge { 
        flex: 1.2 1 auto !important;
        min-width: 0 !important;
        font-size: 11px !important; 
        padding: 6px !important; 
        height: 32px !important;
        border-radius: 8px !important;
        justify-content: center !important;
        align-items: center !important;
        white-space: nowrap !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04) !important;
    }
    .dash-refresh-btn { 
        flex: 0.8 1 auto !important;
        min-width: 0 !important;
        font-size: 11px !important; 
        padding: 6px !important; 
        height: 32px !important;
        border-radius: 8px !important;
        justify-content: center !important;
        align-items: center !important;
        white-space: nowrap !important;
    }

    /* ── Donut Charts — center properly ── */
    .donut-wrap { flex-direction:column !important; align-items:center !important; gap:14px !important; }
    .donut-chart-area { width:160px !important; height:160px !important; margin:0 auto !important; }
    .donut-stats { text-align:left; width:100%; }
    .donut-stats-row { font-size:13px !important; }

    /* ── Aging Bars ── */
    .aging-legend { font-size:11px !important; gap:8px !important; flex-wrap:wrap !important; }
    .aging-bar { height:12px !important; border-radius:6px; }

    /* ── Chart Boxes — use aspect-ratio so chart fills tightly ── */
    .chart-box { height:auto !important; aspect-ratio: 16/10; width:100%; min-width:0; max-height:250px; }

    /* ── Quick Links — Premium 2 Column Layout ── */
    .quick-links-grid { grid-template-columns:repeat(2,1fr) !important; gap:12px !important; padding: 0; }
    .quick-link { padding:14px 10px !important; gap:10px !important; border-radius:14px !important; box-shadow:0 2px 8px rgba(0,0,0,0.03); }
    .quick-link .ql-icon { width:38px !important; height:38px !important; font-size:18px !important; border-radius:10px !important; }
    .quick-link .ql-label { font-size:12px !important; }
    .quick-link .ql-desc { display: none !important; }

    /* ── Dash Lists — text WRAPS not hides ── */
    .dash-list { max-height:250px !important; }
    .dash-list-item { padding:8px 0 !important; }
    .dash-list-name { font-size:13px !important; white-space:normal !important; overflow:visible !important; text-overflow:unset !important; }
    .dash-list-amount { font-size:13px !important; flex-shrink:0 !important; }

    /* Page Headers standard layout already defined above */

    /* ── Cards ── */
    .card { padding:14px !important; }

    /* ── Mobile Card View for Listing Pages ── */
    .table-container { display: none !important; }
    .grid-2 .table-container,
    .invoice-preview .table-container,
    .table-responsive,
    [style*="overflow-x:auto"].table-container,
    [style*="border:none"].table-container {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-cards { display: flex !important; }
    .mobile-cards {
        flex-direction: column;
        gap: 12px;
        padding: 0;
    }
    .mobile-card {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-left: 4px solid #f59e0b;
        border-radius: 12px;
        padding: 14px 16px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.04);
        transition: transform 0.2s, box-shadow 0.2s;
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        row-gap: 8px;
    }
    .mobile-card-header {
        grid-column: 1 / -1;
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 4px;
    }
    .mobile-card-avatar {
        width: 42px;
        height: 42px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        font-weight: 800;
        color: #fff;
        flex-shrink: 0;
        box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }
    .mobile-card-info {
        flex: 1;
        min-width: 0;
    }
    .mobile-card-number {
        font-size: 11px;
        font-weight: 700;
        color: #6366f1;
        letter-spacing: 0.5px;
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-card-customer {
        font-size: 15px;
        font-weight: 800;
        color: #1e293b;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-card-sub {
        font-size: 12px;
        color: #64748b;
        margin-top: 2px;
    }
    .mobile-card-body {
        grid-column: 1 / -1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 4px;
    }
    .mobile-card-amount {
        font-size: 16px;
        font-weight: 800;
        letter-spacing: -0.5px;
        color: var(--text-primary);
    }
    .mobile-card-meta {
        grid-column: 1;
        align-self: end;
        font-size: 11px;
        color: var(--text-tertiary);
        display: flex;
        align-items: center;
        gap: 6px;
        margin-bottom: 0;
    }
    .mobile-card-actions {
        grid-column: 2;
        align-self: end;
        display: flex;
        align-items: center;
        gap: 6px;
        padding-top: 0;
        border-top: none;
    }
    .mc-action-btn {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff !important;
        cursor: pointer;
        transition: all 0.2s;
        text-decoration: none;
        flex-shrink: 0;
        padding: 0;
    }
    .mc-action-btn svg {
        width: 14px;
        height: 14px;
        stroke-width: 2.2;
    }
    .mc-action-btn.primary {
        background: linear-gradient(135deg, #6366f1, #818cf8) !important;
        box-shadow: 0 2px 8px rgba(99,102,241,0.35);
    }
    .mc-action-btn.secondary {
        background: linear-gradient(135deg, #8b5cf6, #a78bfa) !important;
        box-shadow: 0 2px 8px rgba(139,92,246,0.35);
    }
    .mc-action-btn.danger {
        background: linear-gradient(135deg, #ef4444, #f87171) !important;
        box-shadow: 0 2px 8px rgba(239,68,68,0.35);
    }
    .mc-action-btn.success {
        background: linear-gradient(135deg, #10b981, #34d399) !important;
        box-shadow: 0 2px 8px rgba(16,185,129,0.35);
    }
    .mc-action-btn.warning {
        background: linear-gradient(135deg, #f59e0b, #fbbf24) !important;
        box-shadow: 0 2px 8px rgba(245,158,11,0.35);
    }
    .mc-action-btn:active { transform: scale(0.92); }
    .mobile-card-ref {
        font-size: 11px;
        color: var(--text-tertiary);
        margin-top: 6px;
        font-weight: 500;
    }

    /* ── Tables — HORIZONTAL SCROLL with full content visible ── */
    .table { min-width:500px !important; }
    .table th, .table td { padding:8px 10px !important; font-size:12px !important; white-space:nowrap !important; }

    /* ── Forms ── */
    .form-group { margin-bottom:12px !important; }
    .form-control { padding:10px 12px !important; font-size:14px !important; }
    .form-grid { grid-template-columns:1fr !important; }

    /* ── Buttons — text NEVER cuts off ── */
    .btn { padding:10px 14px !important; font-size:13px !important; white-space:normal !important; text-align:center !important; }
    .btn-lg { padding:12px 18px !important; font-size:14px !important; }

    /* ── Toolbar — stacked and full width ── */
    .toolbar { flex-direction:column !important; align-items:stretch !important; gap:8px !important; margin-bottom: 12px !important; }
    .toolbar input[type="text"],
    .toolbar input[type="search"],
    .toolbar .form-control { 
        max-width:100% !important; 
        width:100% !important; 
        border-radius: 12px !important;
        background-color: var(--bg-secondary) !important;
        border: 1px solid var(--border-color) !important;
        padding: 10px 14px !important;
        font-size: 13px !important;
        color: var(--text-primary) !important;
        transition: all 0.2s ease !important;
    }
    .toolbar input[type="text"]:focus,
    .toolbar input[type="search"]:focus,
    .toolbar .form-control:focus {
        border-color: var(--primary) !important;
        background-color: var(--bg-card) !important;
        box-shadow: 0 0 0 3px rgba(99,102,241,0.15) !important;
    }
    .toolbar select { width:100% !important; }
    .toolbar .btn { width:100% !important; }
    .toolbar-left, .toolbar-right { flex-wrap:wrap !important; width:100% !important; }
    .toolbar-left > *, .toolbar-right > * { flex:1 1 100% !important; min-width:0 !important; }

    /* ── Modals — full mobile width ── */
    .modal-overlay { padding:8px !important; }
    .modal { width:100% !important; max-width:100% !important; border-radius:14px !important; max-height:92vh !important; }
    .modal-header { padding:14px !important; }
    .modal-header h3 { font-size:16px !important; }
    .modal-body { padding:14px !important; }
    .modal-footer { padding:12px 14px !important; flex-wrap:wrap !important; }
    .modal-footer .btn { flex:1; min-width:100px; }

    /* ── Auth cards ── */
    .auth-card { width:95% !important; padding:24px 18px !important; }

    /* ── Admin Panel ── */
    .admin-nav { flex-wrap:wrap !important; }
    .admin-nav-btn { font-size:11px !important; padding:10px 6px !important; flex:1 1 auto !important; min-width:0 !important; }
    .admin-stat-grid { grid-template-columns:1fr 1fr !important; gap:8px !important; }
    .admin-stat { padding:12px !important; }
    .admin-stat .stat-num { font-size:20px !important; }
    .admin-stat .stat-ico { font-size:22px !important; }
    .user-row { grid-template-columns:1fr !important; gap:4px !important; padding:12px !important; border-bottom:1px solid var(--border-color) !important; }
    .user-row-header { display:none !important; }
    .user-row > span { font-size:13px !important; }
    .user-row > span::before { font-weight:600; color:var(--text-tertiary); font-size:11px; }
    .settings-card { padding:14px !important; }

    /* ── Billing/POS ── */
    .pos-layout { grid-template-columns:1fr !important; height:auto !important; }
    .pos-cart { min-height:auto !important; }
    .product-grid { grid-template-columns:repeat(2,1fr) !important; gap:6px !important; }

    /* ── Invoice View ── */
    .invoice-preview-wrapper { padding: 4px !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; width: 100% !important; }
    .invoice-preview { min-width: 800px !important; margin: 0 !important; padding: 32px !important; box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important; }
    .invoice-preview .invoice-header-section { flex-direction: row !important; gap: inherit !important; }
    .invoice-preview .invoice-meta { text-align: right !important; }
    .invoice-preview .invoice-parties { grid-template-columns: 1fr 1fr !important; gap: 48px !important; }
    .invoice-preview .invoice-totals table { width: auto !important; }

    /* ── Settings ── */
    .settings-layout { grid-template-columns:1fr !important; }
    .settings-menu { padding:6px !important; }
    .settings-panel { padding:14px !important; }

    /* ── Profile ── */
    .profile-header { flex-direction:column !important; text-align:center !important; padding:20px !important; }
    .profile-avatar { width:60px !important; height:60px !important; font-size:24px !important; }

    /* ── Notification panel ── */
    .notification-panel { width:100% !important; right:-100% !important; }
    .notification-panel.open { right:0 !important; }

    /* ── Toast mobile ── */
    .toast-container { top:10px !important; right:10px !important; left:10px !important; }
    .toast { min-width:auto !important; max-width:100% !important; font-size:13px !important; padding:10px 14px !important; }

    /* ── ALL inline grids → 1 column on mobile ── */
    .page-content [style*="grid-template-columns"]:not(.hero-grid):not(.mini-trend-row):not(.inventory-grid):not(.aging-grid):not(.stock-badges):not(#revSummaryRow) { grid-template-columns:1fr !important; }
    /* Keep 2-col for small stat cards and dashboard sub-grids */
    .page-content .stats-grid { grid-template-columns:1fr 1fr !important; }
    .page-content .inventory-grid { grid-template-columns:1fr 1fr !important; }
    .page-content .aging-grid { grid-template-columns:1fr 1fr !important; }
    .page-content .stock-badges { grid-template-columns:1fr 1fr !important; }
    .page-content .mini-trend-row { grid-template-columns:1fr 1fr !important; }
    .page-content .admin-stat-grid { grid-template-columns:1fr 1fr !important; }
    /* Income & Expense summary — always 3 columns */
    #revSummaryRow { grid-template-columns:1fr 1fr 1fr !important; }

    /* ── Tabs — Scrollable Segmented Controls (no scrollbar) ── */
    .tabs, .tab-filters {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        gap: 6px !important;
        background: var(--bg-secondary) !important;
        border: 1px solid var(--border-color) !important;
        padding: 4px !important;
        border-radius: 10px !important;
        scrollbar-width: none !important; /* Firefox */
        -ms-overflow-style: none !important;  /* IE/Edge */
    }
    .tabs::-webkit-scrollbar, .tab-filters::-webkit-scrollbar {
        display: none !important; /* Chrome/Safari */
    }
    .tab-btn {
        flex: 1 1 auto !important;
        flex-shrink: 0 !important;
        font-size: 12px !important;
        font-weight: 700 !important;
        padding: 8px 16px !important;
        border-radius: 7px !important;
        text-align: center !important;
        white-space: nowrap !important;
        transition: all 0.2s ease !important;
    }
    .tab-btn.active {
        background: var(--bg-card) !important;
        color: var(--primary) !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
    }
    .tab-filters .tab-btn {
        font-size: 11px !important;
        padding: 6px 12px !important;
    }

    /* ── Reports ── */
    .dash-table-card { padding:12px !important; }

    /* ── P&L Snapshot grid ── */
    .pnl-row .pnl-value { font-size:14px !important; word-break:break-all !important; }

    /* ── Revenue Projections ── */
    .rev-proj-grid { grid-template-columns:1fr !important; }
    .rev-proj-amount { font-size:18px !important; }

    /* ── Biz Ops ── */
    .biz-ops-grid { grid-template-columns:1fr !important; gap:8px !important; }
    .biz-ops-card { padding:12px !important; }
    .biz-ops-value { font-size:16px !important; }

    /* ── Quick Access ── */
    .quick-access-grid { grid-template-columns:repeat(3,1fr) !important; gap:6px !important; }
    .quick-access-btn { padding:10px 6px !important; font-size:10px !important; }
    .qa-icon { width:34px !important; height:34px !important; font-size:16px !important; }

    /* ── Revenue Inflow ── */
    .rev-inflow-grid { grid-template-columns:1fr !important; }

    /* ── Customer Detail Modal — responsive ── */
    #custDetailModal .modal { max-width:100% !important; border-radius:14px !important; }
    #custDetailModal [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns:1fr !important; }
    #custDetailModal [style*="grid-template-columns:1fr 1fr"] { grid-template-columns:1fr !important; }
    #custDetailModal [style*="grid-template-columns:repeat(auto-fit"] { grid-template-columns:1fr 1fr !important; }

    /* ── Invoice Creation Mobile Styling ── */
    .invoice-form-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
    .invoice-service-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
    .invoice-item-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
    .invoice-totals-wrapper { justify-content: stretch !important; width: 100% !important; }
    .invoice-totals-wrapper > div { width: 100% !important; }
    .invoice-actions-wrapper { flex-direction: column-reverse !important; gap: 12px !important; width: 100% !important; border-top: 1px solid var(--border-color); padding-top: 16px; margin-top: 20px; }
    .invoice-actions-wrapper a.btn, .invoice-actions-wrapper button.btn { width: 100% !important; justify-content: center !important; padding: 12px !important; font-size: 14px !important; min-height: 44px !important; }

    /* ── Premium Card, Label, and Input Overrides on Mobile ── */
    .page-content .card {
        background: var(--bg-card) !important;
        border: 1px solid rgba(99, 102, 241, 0.08) !important;
        border-radius: 18px !important;
        box-shadow: 0 10px 30px rgba(0,0,0,0.02) !important;
        padding: 20px 16px !important;
        margin-bottom: 16px !important;
    }
    .page-content .form-label {
        font-size: 11px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.6px !important;
        color: var(--text-secondary) !important;
        margin-bottom: 8px !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }
    .page-content .form-control {
        height: 46px !important;
        border-radius: 12px !important;
        border: 1.5px solid var(--border-color) !important;
        background: var(--bg-primary) !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        color: var(--text-primary) !important;
        padding: 0 14px !important;
        box-shadow: none !important;
        transition: all 0.2s ease !important;
    }
    .page-content .form-control:focus {
        border-color: var(--primary) !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
        background: var(--bg-card) !important;
    }
    .page-content textarea.form-control {
        height: auto !important;
        padding: 12px 14px !important;
        min-height: 80px !important;
    }
    .page-content .form-control[readonly] {
        background: rgba(99, 102, 241, 0.03) !important;
        border-color: rgba(99, 102, 241, 0.12) !important;
        color: var(--primary) !important;
        font-weight: 700 !important;
    }
    .page-content select.form-control {
        padding-right: 32px !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236366f1' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19.5 8.25l-7.5 7.5-7.5-7.5'%3E%3C/path%3E%3C/svg%3E") !important;
        background-size: 12px !important;
        background-position: right 12px center !important;
        background-repeat: no-repeat !important;
        appearance: none !important;
    }
    .invoice-form-grid .form-group:nth-child(1) .form-label::before { content: "🔢"; font-size: 11px; }
    .invoice-form-grid .form-group:nth-child(2) .form-label::before { content: "👥"; font-size: 11px; }
    .invoice-form-grid .form-group:nth-child(3) .form-label::before { content: "📅"; font-size: 11px; }
    .invoice-form-grid .form-group:nth-child(4) .form-label::before { content: "⌛"; font-size: 11px; }
    .page-content .form-group:has(#invoiceNotes) .form-label::before { content: "📝"; font-size: 11px; }

    /* Mobile order overrides for details grid */
    .invoice-form-grid .form-group:nth-child(2) { order: 1 !important; } /* Customer */
    .invoice-form-grid .form-group:nth-child(3) { order: 2 !important; } /* Invoice Date */
    .invoice-form-grid .form-group:nth-child(1) { order: 3 !important; } /* Invoice Number */
    .invoice-form-grid .form-group:nth-child(4) { order: 4 !important; } /* Due Date */
}

/* ── Invoice Creation Desktop Default Layouts ── */
.invoice-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.invoice-service-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.invoice-item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.invoice-totals-wrapper { display: flex; justify-content: flex-end; margin-top: 20px; }
.invoice-actions-wrapper { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border-color); }

/* ── POS Billing Dark Mode Price & Total Overrides ── */
[data-theme="dark"] .p-card .p-price,
html[data-theme="dark"] .p-card .p-price {
    color: var(--primary-200) !important;
}
[data-theme="dark"] .s-row.s-total,
html[data-theme="dark"] .s-row.s-total,
[data-theme="dark"] .s-row.s-total span,
html[data-theme="dark"] .s-row.s-total span {
    color: var(--primary-200) !important;
}
[data-theme="dark"] .cart-top-row .cart-badge,
html[data-theme="dark"] .cart-top-row .cart-badge {
    color: var(--primary-200) !important;
}
[data-theme="dark"] .c-item .c-rate,
html[data-theme="dark"] .c-item .c-rate {
    color: var(--text-secondary) !important;
}


/* ══════════════════════════════════════════
   SMALL MOBILE (below 480px)
   ══════════════════════════════════════════ */
@media (max-width:480px) {
    .stats-grid { grid-template-columns:1fr 1fr !important; gap:6px !important; }
    .admin-stat-grid { grid-template-columns:1fr !important; }
    .page-content { padding:8px !important; }
    .page-header h1 { font-size:18px !important; }
    .quick-links-grid { grid-template-columns:repeat(2,1fr) !important; }
    .quick-access-grid { grid-template-columns:repeat(2,1fr) !important; }
    .aging-legend { flex-direction:column !important; gap:3px !important; }
    .pnl-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; padding: 6px !important; }
    .pnl-stat { padding: 8px 6px !important; gap: 6px !important; border-radius: 10px !important; }
    .pnl-icon { width: 28px !important; height: 28px !important; font-size: 12px !important; border-radius: 8px !important; }
    .pnl-value { font-size: 11px !important; font-weight: 800 !important; }
    .pnl-label { font-size: 8px !important; letter-spacing: 0.1px !important; }
    .e-card canvas { max-height:45px !important; }
    .mini-trend-row { grid-template-columns:1fr !important; }
    .hero-card { padding:16px !important; }
    .hero-value { font-size:20px !important; }
    .hero-split-value { font-size:16px !important; }
    .toolbar .btn { font-size:12px !important; }
}

/* ── Desktop (1200px+) ── */
@media (min-width:1200px) {
    .e-grid-3 { grid-template-columns:repeat(3,1fr) !important; }
    .e-grid-4 { grid-template-columns:repeat(4,1fr) !important; }
    .g-grid-3 { grid-template-columns:repeat(3,1fr) !important; }
    .hero-grid { grid-template-columns:repeat(3,1fr) !important; }
}

/* ── Touch devices ── */
@media (hover:none) and (pointer:coarse) {
    .btn { min-height:44px; }
    .form-control { min-height:44px; }
    .nav-item { padding:12px 12px !important; }
    select.form-control { min-height:44px; }
}

/* ── Print Styles (A4 optimization, loaded last to override all) ── */
@media print {
    html, body {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        overflow: visible !important;
        background: #fff !important;
    }
    .app-layout, .main-content, .page-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
        flex: none !important;
        overflow: visible !important;
    }
    .invoice-preview {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 15px 25px !important;
        box-shadow: none !important;
        border: none !important;
        transform: none !important;
        overflow: visible !important;
    }
}
