/* ============================================================
   responsive.css — Mobile-First Card Layout System
   Eliminates horizontal scrolling on mobile.
   Tables convert to stacked card rows. Desktop unchanged.
   ============================================================ */

/* ── Mobile Nav Toggle (hidden on desktop) ───────────────── */
.mobile-nav-toggle {
    display: none; background: none; border: none;
    color: rgba(255,255,255,0.85); cursor: pointer;
    padding: 6px; border-radius: 6px; margin-right: 10px;
    line-height: 1; transition: background 0.2s;
}
.mobile-nav-toggle:hover { background: rgba(255,255,255,0.12); }
.mobile-nav-toggle svg { display: block; }

/* ── Table Responsive Wrapper ────────────────────────────── */
.table-responsive {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-radius: inherit; position: relative;
}
.table-responsive::-webkit-scrollbar { height: 5px; }
.table-responsive::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 3px; }

/* ══ LAPTOP ≤1199px ══════════════════════════════════════ */
@media (max-width: 1199px) {
    .container { max-width: 100%; padding: 22px 20px; }
    .dashboard-sidebar { width: 250px; }
}

/* ══ TABLET ≤1023px ══════════════════════════════════════ */
@media (max-width: 1023px) {
    .header { padding: 12px 16px; font-size: 18px; }
    .header-shortcut-link, .zen-toggle-wrapper { display: none; }
    .nav { overflow-x: auto; scrollbar-width: none; }
    .nav::-webkit-scrollbar { display: none; }
    .nav a { white-space: nowrap; font-size: 13px; padding: 10px 12px; }
    .container { padding: 18px 16px; }
    .dashboard-two-col { flex-direction: column; }
    .dashboard-sidebar { width: 100%; }
    .card { min-width: calc(50% - 12px); }
    .header-action-row { flex-direction: column; align-items: flex-start !important; gap: 12px; }
    .header-action-row > div:last-child { flex-wrap: wrap; width: 100%; }
    .pos-grid { grid-template-columns: 1fr !important; }
    .staff-grid { grid-template-columns: 1fr !important; }
    .settings-form-grid { grid-template-columns: 1fr !important; }
    .form-group.full { grid-column: span 1; }
    .nir-summary-grid { grid-template-columns: repeat(2,1fr) !important; }
}

/* ══ MOBILE ≤767px ═══════════════════════════════════════ */
@media (max-width: 767px) {

    /* ── Hamburger ───────────────────────────────────── */
    .mobile-nav-toggle { display: flex; align-items: center; justify-content: center; }

    /* ── Header ──────────────────────────────────────── */
    .header { padding: 10px 12px; font-size: 15px; gap: 6px; }
    .header-brand { font-size: 13px; gap: 6px; }
    .header-brand-icon { width: 26px; height: 26px; }
    .header-user { gap: 4px; font-size: 11px; }
    .header-user-name, .role-badge, .header-shortcut-link, .zen-toggle-wrapper { display: none; }
    .logout-btn { padding: 4px 10px; font-size: 11px; }
    .notification-bell-wrapper { position: static; }

    /* ── Nav ─────────────────────────────────────────── */
    .nav { display: none; flex-direction: column; padding: 0; gap: 0; }
    .nav.nav-open { display: flex; }
    .nav a { padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px; }
    .nav a:last-child { border-bottom: none; }

    /* ── Container ───────────────────────────────────── */
    .container { padding: 12px 10px; }
    .section-title { font-size: 15px; margin-bottom: 10px; }

    /* ── Prevent ANY horizontal overflow ─────────────── */
    html, body { overflow-x: hidden; }
    .container, .dashboard-main, .panel, .nir-shell,
    .add-staff-box, .settings-card, .ret-shell,
    .form-section, .staff-card { 
        max-width: 100%; overflow-x: hidden; box-sizing: border-box;
    }
    
    .hide-on-mobile { display: none !important; }

    /* ─────────────────────────────────────────────────
       MOBILE CARD TABLE LAYOUT
       Converts ALL data tables to stacked card rows.
       No horizontal scrolling needed.
       ───────────────────────────────────────────────── */
    .table-responsive { overflow: hidden; max-width: 100vw; }
    .table-responsive::after { display: none; }

    .table-responsive table,
    #lowStockPanel table,
    #expiredPanel table,
    #expiringSoonPanel table,
    .ret-table-wrap table {
        display: block !important;
        min-width: 0 !important;
        width: 100% !important;
    }
    
    .table-responsive table tbody,
    #lowStockPanel table tbody,
    #expiredPanel table tbody,
    #expiringSoonPanel table tbody {
        display: block !important;
        width: 100% !important;
    }

    .table-responsive table thead,
    #lowStockPanel table thead,
    #expiredPanel table thead,
    #expiringSoonPanel table thead {
        display: none;
    }

    .table-responsive table tbody tr,
    #lowStockPanel table tbody tr,
    #expiredPanel table tbody tr,
    #expiringSoonPanel table tbody tr {
        display: block;
        border: 1px solid var(--border-color, #e2e8f0);
        border-radius: 10px;
        margin-bottom: 8px;
        padding: 6px 10px;
        background: var(--bg-card, #fff);
    }
    [data-theme="dark"] .table-responsive table tbody tr,
    [data-theme="dark"] #lowStockPanel table tbody tr,
    [data-theme="dark"] #expiredPanel table tbody tr,
    [data-theme="dark"] #expiringSoonPanel table tbody tr {
        background: var(--dk-bg-surface, #1a1d27);
        border-color: var(--dk-border, #2c3050);
    }

    .table-responsive table tbody td,
    #lowStockPanel table tbody td,
    #expiredPanel table tbody td,
    #expiringSoonPanel table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 4px 0;
        border: none;
        border-bottom: 1px solid rgba(0,0,0,0.04);
        font-size: 13px;
        text-align: right;
        gap: 6px;
        word-break: break-word;
        white-space: normal;
    }
    .table-responsive table tbody td > *,
    #lowStockPanel table tbody td > *,
    #expiredPanel table tbody td > *,
    #expiringSoonPanel table tbody td > * {
        max-width: 60%;
        text-align: right;
    }
    .table-responsive table tbody td:last-child,
    #lowStockPanel table tbody td:last-child,
    #expiredPanel table tbody td:last-child,
    #expiringSoonPanel table tbody td:last-child {
        border-bottom: none;
    }
    [data-theme="dark"] .table-responsive table tbody td,
    [data-theme="dark"] #lowStockPanel table tbody td {
        border-bottom-color: rgba(255,255,255,0.05);
    }

    .table-responsive table tbody td::before,
    #lowStockPanel table tbody td::before,
    #expiredPanel table tbody td::before,
    #expiringSoonPanel table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        color: var(--text-muted, #7f8c8d);
        text-align: left;
        flex-shrink: 0;
        min-width: 80px;
    }

    /* Hide the td label when data-label is empty */
    .table-responsive table tbody td[data-label=""]::before,
    .table-responsive table tbody td:not([data-label])::before {
        display: none;
    }
    
    .price-label { display: none !important; }

    /* Limit dashboard lists to top 3 on mobile to reduce clutter */
    .dashboard-main table:not(.expanded-mobile) tbody tr:nth-child(n+4),
    #lowStockPanel table:not(.expanded-mobile) tbody tr:nth-child(n+4),
    #expiredPanel table:not(.expanded-mobile) tbody tr:nth-child(n+4),
    #expiringSoonPanel table:not(.expanded-mobile) tbody tr:nth-child(n+4) {
        display: none !important;
    }
    
    .mobile-only-expand { display: block !important; }

    /* Action buttons inside card rows */
    .table-responsive table tbody td.actions-cell,
    .table-responsive table tbody td.inv-actions {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        gap: 6px;
        padding: 12px 0 6px 0;
        flex-wrap: wrap;
        border-top: 1px solid rgba(0,0,0,0.06);
        margin-top: 6px;
    }
    .table-responsive table tbody td.actions-cell::before { display: none; }
    .table-responsive table tbody td.actions-cell > *,
    .table-responsive table tbody td.inv-actions > * {
        max-width: none !important;
        text-align: center;
    }
    .table-responsive table tbody td.actions-cell button,
    .table-responsive table tbody td.actions-cell a.btn-sm,
    .table-responsive table tbody td.inv-actions button {
        font-size: 12px !important;
        padding: 8px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        justify-content: center !important;
        text-align: center !important;
        margin: 0 !important;
        white-space: nowrap !important;
        word-break: normal !important;
    }
    
    /* Batch Rows Styling */
    .table-responsive table tbody tr.batch-row {
        background: #f8fafc;
        border: 1px solid #cbd5e1;
        box-shadow: inset 4px 0 0 #3b82f6;
        margin-left: 12px;
        margin-right: 12px;
        margin-top: -4px;
    }
    .table-responsive table tbody td.batch-loading {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        padding: 16px;
        max-width: 100% !important;
    }
    .table-responsive table tbody td.batch-loading > * {
        max-width: 100% !important;
        text-align: center;
    }
    [data-theme="dark"] .table-responsive table tbody tr.batch-row {
        background: #1e2235;
        border-color: #2c3050;
        box-shadow: inset 4px 0 0 #3b82f6;
    }
    .batch-edit-btn {
        padding: 6px 8px !important;
        font-size: 11px !important;
        font-weight: 600;
    }

    /* ── Dashboard Stat Cards ───────────────────────── */
    .cards {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .card { min-width: 0; width: auto; }
    .card-stat { padding: 10px; gap: 6px; }
    .card-value { font-size: 20px; }
    .card-label { font-size: 9px; }
    .card-sub { font-size: 9px; }
    .card-icon { width: 32px; height: 32px; }
    .card-icon-img { width: 16px; height: 16px; }

    /* ── Dashboard Welcome ──────────────────────────── */
    .dashboard-welcome { flex-direction: column; padding: 12px; gap: 4px; }
    .dashboard-welcome-title { font-size: 14px; }
    .dashboard-welcome-sub { font-size: 11px; }
    .dashboard-date { font-size: 11px; }
    
    /* ── Modals ─────────────────────────────────────── */
    #batchEditForm, #addBatchForm {
        width: 90vw !important;
        max-width: 420px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* ── Dashboard Alert Panels ─────────────────────── */
    .alert-panel-title { font-size: 13px; padding: 8px 12px; }
    .btn-zen-link { font-size: 11px !important; padding: 8px 14px !important; }

    /* ── Dashboard Filters ──────────────────────────── */
    .filter-bar, div[style*="display:flex"][style*="flex-wrap:wrap"][style*="gap:10px"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .filter-input, .filter-select {
        width: 100% !important;
        min-width: unset !important;
        font-size: 13px;
        box-sizing: border-box;
    }
    .result-count { margin-left: 0; text-align: left; font-size: 12px; }

    /* ── Products Action Buttons ────────────────────── */
    .header-action-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px;
    }
    .header-action-row > div:last-child { flex-wrap: wrap; gap: 6px; }
    .btn-import-ghost {
        font-size: 12px; padding: 10px 12px;
        flex: 1 1 calc(50% - 4px); min-width: 0;
        justify-content: center; text-align: center;
    }
    .header-action-row > div:last-child .btn-primary {
        flex: 1 1 100%;
        padding: 12px 20px !important;
        font-size: 14px !important;
        margin-top: 4px;
    }

    /* ── Forms ───────────────────────────────────────── */
    input, select, textarea {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .form-section .form-row { flex-direction: column; gap: 10px; }
    .form-section .form-group { width: 100%; }
    .form-section input, .form-section select { width: 100% !important; }

    /* ── Order Create POS ───────────────────────────── */
    .pos-grid { grid-template-columns: 1fr !important; gap: 10px; }
    .pos-grid .panel { padding: 12px; min-height: auto !important; }
    .pos-grid .panel-title { font-size: 13px; }
    .form-stack { gap: 6px; }
    .form-stack .form-group input,
    .form-stack .form-group select { padding: 9px 10px; font-size: 14px; }
    .form-row { grid-template-columns: 1fr 1fr; gap: 6px; }
    .kbd-hint { display: none; }
    .btn-add { padding: 10px; font-size: 14px; }

    /* Cart table — keep as compact table, not cards */
    .cart-table { font-size: 10px; }
    .cart-table th { font-size: 8px; padding: 4px 3px; }
    .cart-table td { padding: 4px 3px; font-size: 10px; }
    .cart-totals { padding: 8px; }
    .trow { font-size: 12px; }
    .trow.grand { font-size: 14px; }
    .action-buttons { flex-direction: column; gap: 8px; }
    .btn-place-order { padding: 12px; font-size: 15px; }
    .btn-clear-cart { padding: 10px; text-align: center; }

    /* ── Order Invoices ─────────────────────────────── */
    .ret-filter-bar { grid-template-columns: 1fr !important; gap: 8px; }
    .ret-shell { padding: 14px; }

    /* Return table — card layout */
    .ret-table-wrap { overflow-x: visible; }
    .ret-table { min-width: 0 !important; }
    .ret-table thead { display: none; }
    .ret-table tbody tr {
        display: block; border: 1px solid #e8edf5;
        border-radius: 10px; margin-bottom: 10px;
        padding: 10px 12px; background: #fff;
    }
    [data-theme="dark"] .ret-table tbody tr {
        background: var(--dk-bg-surface); border-color: var(--dk-border);
    }
    .ret-table tbody td {
        display: flex; justify-content: space-between; align-items: center;
        padding: 4px 0; border: none;
        border-bottom: 1px solid rgba(0,0,0,0.04);
        font-size: 12px; text-align: right;
    }
    .ret-table tbody td:last-child { border-bottom: none; }
    .ret-table tbody td::before {
        content: attr(data-label);
        font-weight: 700; font-size: 10px;
        text-transform: uppercase; letter-spacing: 0.3px;
        color: #7f8c8d; text-align: left;
        flex-shrink: 0; min-width: 70px;
    }

    /* Page tabs */
    .page-switch { gap: 4px; }
    .page-btn {
        padding: 6px 10px !important; font-size: 11px !important;
        flex: 1; text-align: center; justify-content: center;
    }

    /* ── Direct Returns ─────────────────────────────── */
    .nir-shell { padding: 12px; }
    .nir-head { flex-direction: column; gap: 6px; }
    .nir-head h3 { font-size: 15px; }
    .nir-settings-grid { display: flex !important; flex-direction: column; gap: 8px; }
    .nir-field { grid-column: auto !important; }
    .nir-entry-grid { grid-template-columns: 1fr !important; gap: 8px; }
    .entry-actions { grid-column: auto !important; }

    /* Return table card layout */
    .return-table { min-width: 0 !important; }
    .nir-table-wrap { overflow-x: visible; }
    .return-table thead { display: none; }
    .return-table tbody tr {
        display: block; border: 1px solid #e6edf6;
        border-radius: 10px; margin-bottom: 10px;
        padding: 10px; background: #f9fbff;
    }
    [data-theme="dark"] .return-table tbody tr {
        background: var(--dk-bg-raised); border-color: var(--dk-border);
    }
    .return-table tbody td {
        display: flex; justify-content: space-between; align-items: center;
        padding: 4px 0; border: none;
        border-bottom: 1px solid rgba(0,0,0,0.04);
        font-size: 12px;
    }
    .return-table tbody td:last-child { border-bottom: none; }
    .return-table tbody td::before {
        content: attr(data-label);
        font-weight: 700; font-size: 10px;
        text-transform: uppercase; color: #7f8c8d;
        flex-shrink: 0; min-width: 70px; text-align: left;
    }
    .return-table tbody td .nir-inline-input {
        max-width: 120px;
    }

    .nir-summary-grid { grid-template-columns: 1fr 1fr !important; gap: 6px; }
    .nir-stat strong { font-size: 14px; }
    .nir-stat.items strong { font-size: 18px; }
    .actions { flex-direction: column; }
    .actions button { min-width: 0 !important; width: 100%; }

    /* ── Modals ──────────────────────────────────────── */
    .modal-content {
        max-width: calc(100vw - 16px); margin: 8px; padding: 14px;
    }
    .modal-content.modal-large {
        max-width: calc(100vw - 16px); max-height: 90vh;
    }
    .modal-box {
        width: calc(100vw - 16px) !important;
        max-width: none !important;
        padding: 14px !important;
        border-radius: 10px !important;
        max-height: 90vh !important;
    }
    .modal-buttons { flex-direction: column; gap: 6px; }
    .modal-buttons button { width: 100%; }

    /* Invoice & Batch modals */
    .inv-meta { flex-direction: column; gap: 6px; }
    .inv-meta div[style*="text-align:right"] { text-align: left !important; }
    .inv-table { font-size: 11px; }
    .inv-table th { font-size: 9px; padding: 6px 4px; }
    .inv-table td { padding: 6px 4px; font-size: 11px; }
    .inv-totals { max-width: 100%; }
    .inv-totals .row { grid-template-columns: 1fr auto; gap: 8px; font-size: 12px; }
    .inv-totals .grand { grid-template-columns: 1fr auto; gap: 8px; font-size: 15px; }
    .no-print[style*="display:flex"] { flex-wrap: wrap; gap: 4px; }
    .no-print .btn-sm { padding: 7px 12px !important; font-size: 11px !important; flex: 1 1 auto; min-width: 0; }
    #inv-edit-panel div[style*="display:flex"] { flex-direction: column; }
    #inv-edit-panel select, #inv-edit-panel input {
        width: 100% !important; min-width: unset !important;
    }
    
    #batchEditForm, #addBatchForm {
        width: calc(100vw - 32px) !important;
        padding: 16px !important;
    }
    #batchEditForm div[style*="display:flex"],
    #addBatchForm div[style*="display:flex"] {
        flex-direction: column;
        gap: 10px !important;
    }

    /* ── Admin Panel ─────────────────────────────────── */
    .staff-grid { grid-template-columns: 1fr !important; gap: 12px; }
    .staff-card-header { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
    .staff-name { font-size: 13px; }
    .staff-email { font-size: 10px; }
    .perms-body { padding: 10px 12px; }
    .perms-grid { grid-template-columns: 1fr !important; gap: 8px; }
    .perm-item { font-size: 12px; }
    .staff-card-footer { padding: 8px 12px; flex-wrap: wrap; gap: 4px; }
    .staff-card-footer button { font-size: 10px; padding: 5px 8px; flex: 1 1 auto; min-width: 0; }
    .add-staff-box { padding: 14px; }
    .add-staff-box .form-row { flex-direction: column; gap: 8px; }
    .add-staff-box .form-row input,
    .add-staff-box .form-row select { width: 100% !important; }
    .add-staff-box .form-row button { margin-top: 2px !important; width: 100%; }
    .add-staff-box div[style*="display: flex"] { flex-direction: column; gap: 6px; }
    .add-staff-box div[style*="display: flex"] a,
    .add-staff-box div[style*="display: flex"] button { text-align: center; width: 100%; }
    .role-switch { width: 100%; }
    .role-btn { flex: 1; text-align: center; padding: 8px 8px; font-size: 12px; }

    /* ── Settings ────────────────────────────────────── */
    .settings-container { max-width: 100%; }
    .settings-card { padding: 14px; }
    .settings-section-title { font-size: 14px; }
    .settings-section-desc { font-size: 12px; }
    .settings-form-grid { grid-template-columns: 1fr !important; gap: 12px; }
    .form-group.full { grid-column: span 1 !important; }
    .settings-form-grid[style*="repeat(3"] { grid-template-columns: 1fr !important; }
    .theme-option { padding: 10px; }
    .toggle-row { padding: 12px; flex-wrap: wrap; gap: 8px; }
    .settings-tabs { gap: 4px; }
    .tab-btn { padding: 6px 10px !important; font-size: 11px !important; }
    div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    .save-btn { padding: 12px 18px; font-size: 14px; }

    /* ── Suppliers ───────────────────────────────────── */
    #supplierForm div[style*="display:flex"] { flex-direction: column; gap: 8px; }
    #supplierForm input { width: 100% !important; }

    /* ── Notifications ──────────────────────────────── */
    .notif-dropdown { width: calc(100vw - 16px); right: -8px; max-width: none; }
    .notif-item { padding: 10px 12px; }
    .notif-delete-btn { opacity: 1; }

    /* ── Chatbot ─────────────────────────────────────── */
    #cb-panel {
        right: 0; bottom: 0; left: 0;
        width: 100vw; height: calc(100vh - 56px);
        border-radius: 14px 14px 0 0;
        max-height: none; max-width: 100vw;
        box-sizing: border-box;
    }
    #cb-panel.cb-open { transform: translateY(0) scale(1); }
    #cb-fab { bottom: 14px; right: 14px; width: 50px; height: 50px; }
    #cb-fab svg { width: 20px; height: 20px; }
    #cb-input { font-size: 16px; padding: 10px 12px; }
    #cb-send-btn { width: 40px; height: 40px; min-width: 40px; }
    #cb-input-row { padding: 8px 10px 12px; gap: 6px; }
    .cb-msg { max-width: 90%; font-size: 13px; }
    #cb-suggestions button { font-size: 10px; padding: 5px 8px; }
    .cb-quick-panel { margin-bottom: 12px; }
    .cb-quick-btn { padding: 7px 10px; font-size: 12px; }

    /* ── Pagination ──────────────────────────────────── */
    .pagination-wrapper { flex-wrap: wrap; justify-content: center; gap: 3px; }
    .pagination-wrapper button { padding: 5px 8px; font-size: 11px; }

    /* ── Reports ─────────────────────────────────────── */
    .report-card { min-width: calc(50% - 4px) !important; }
    .report-tab, .page-btn, .tab-btn { padding: 5px 10px !important; font-size: 11px !important; }

    /* ── Touch-friendly ──────────────────────────────── */
    button { min-height: 34px; }
    .profile-card { padding: 14px; }
}

/* ══ SMALL MOBILE ≤479px ═════════════════════════════════ */
@media (max-width: 479px) {
    .header { padding: 8px; font-size: 13px; }
    .header-brand { font-size: 11px; }
    .header-brand-icon { width: 22px; height: 22px; }
    .container { padding: 8px 6px; }
    .cards { grid-template-columns: 1fr !important; }
    .card-stat { padding: 10px; }
    .card-value { font-size: 18px; }
    .notif-dropdown { width: calc(100vw - 12px); right: -4px; }
    .btn-import-ghost { flex: 1 1 100%; }
    #cb-panel { height: calc(100vh - 48px); }
    #cb-fab { bottom: 10px; right: 10px; width: 44px; height: 44px; }
    .report-card { min-width: 100% !important; }
    .nir-summary-grid { grid-template-columns: 1fr !important; }
    .report-tab, .page-btn, .tab-btn { padding: 4px 7px !important; font-size: 10px !important; }
}

/* ══ PRINT ═══════════════════════════════════════════════ */
@media print {
    .header, .nav, .mobile-nav-toggle, #cb-fab, #cb-panel,
    .notification-bell-wrapper, .zen-toggle-wrapper, #zen-restore-btn,
    .cb-quick-panel, .filter-bar, .btn-import-ghost,
    .pagination-wrapper, .dashboard-sidebar { display: none !important; }
    .container { max-width: 100%; padding: 0; }
    .dashboard-two-col { flex-direction: column; }
    .dashboard-main { width: 100%; }
    body { background: #fff !important; color: #000 !important; }
    table { box-shadow: none !important; }
}
