/* FITZONE RESPONSIVE CSS */
/* Handles all mobile and tablet breakpoints */

/* Prevent horizontal overflow on the body */
body {
    overflow-x: hidden;
}

/* =========================================
   SIDEBAR & LAYOUT (Mobile: < 992px)
   ========================================= */
@media (max-width: 991px) {
    .app-layout {
        display: block !important;
    }
    
    .sidebar {
        position: fixed !important;
        left: -300px;
        top: 0;
        bottom: 0;
        width: 280px !important;
        max-width: 85vw;
        z-index: 1050 !important;
        height: 100vh !important;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: 0 0 15px rgba(0,0,0,0.5);
    }
    
    body.sidebar-open .sidebar {
        left: 0 !important;
    }
    
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1040;
        backdrop-filter: blur(2px);
    }
    
    body.sidebar-open .sidebar-backdrop {
        display: block;
    }
    
    #sidebar-toggle {
        display: inline-flex !important;
        background: transparent;
        border: none;
        color: var(--text-primary);
        font-size: 20px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin-right: 12px;
    }
    
    .sidebar-close-btn {
        display: flex !important;
        background: rgba(255,255,255,0.1);
        border: none;
        color: #fff;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    .top-bar-new {
        padding: 10px 16px !important;
    }
    
    /* Make summary KPI cards 2x2 on tablets as well */
    #kpiGrid, .summary-kpi-grid, .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }
    
    /* Force exactly 3 columns on tablet specifically for Backup & Restore */
    .summary-kpi-grid.force-3-col {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* Fix Notification Dropdown overflow on tablet and mobile */
    .notification-dropdown {
        position: fixed !important;
        top: 65px !important;
        right: 16px !important;
        width: 320px !important;
        max-width: calc(100vw - 32px) !important;
        z-index: 1050 !important;
    }

    /* ---- POS LAYOUT (Tablet) ---- */
    .pos-grid {
        grid-template-columns: 1fr !important;
        height: auto !important;
        min-height: auto !important;
    }

    .pos-grid > div:first-child {
        min-height: 0 !important;
    }

    /* Products panel - give a reasonable scrollable height */
    .pos-grid #panel-products {
        max-height: 55vh;
        min-height: 300px;
        overflow-y: auto;
    }

    /* History panel - let it flow naturally, don't constrain with max-height */
    .pos-history-panel {
        flex: none !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .pos-history-table {
        flex: none !important;
        max-height: 50vh;
        overflow-y: auto !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        min-height: 200px !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .pos-history-table table {
        min-width: 100% !important;
        width: 100% !important;
    }

    /* Cart panel - stack below products, auto height */
    .pos-cart {
        height: auto !important;
        min-height: auto !important;
    }

    .pos-cart #cart-items {
        max-height: 30vh;
        min-height: 120px;
    }
}

/* =========================================
   DESKTOP SPECIFIC (>= 992px)
   ========================================= */
@media (min-width: 992px) {
    #sidebar-toggle {
        display: none !important;
    }
    
    .sidebar-close-btn {
        display: none !important;
    }
    
    .sidebar-backdrop {
        display: none !important;
    }
}

@media (min-width: 768px) {
    .pos-refund-footer {
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 8px !important;
    }
    .pos-refund-footer .pos-refund-btn-group {
        display: contents !important;
    }
    .pos-refund-footer .btn {
        width: auto !important;
        flex: none !important;
    }
}


/* =========================================
   TABLETS & MOBILES (< 768px)
   ========================================= */
@media (max-width: 767px) {
    /* Hide username in top bar to save space */
    .top-bar-user-name, .top-bar-user-role {
        display: none !important;
    }
    
    .top-bar-user {
        gap: 0 !important;
    }
    
    /* Make stat cards wrap (except summary grids) */
    .kpi-grid, [style*="grid-template-columns: repeat"], [style*="grid-template-columns:repeat"] {
        grid-template-columns: 1fr !important;
        display: grid !important;
        gap: 16px !important;
    }
    
    /* Make summary KPI cards 2x2 on mobile */
    #kpiGrid, .summary-kpi-grid, .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    /* Force exactly 3 columns on mobile specifically for Backup & Restore */
    .summary-kpi-grid.force-3-col {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }
    
    /* Auth Pages */
    /* Summary Cards Shrink */
    .hover-card, .metric-pill, .summary-kpi-grid > div, .summary-kpi-grid > a > div {
        padding: 14px !important;
        gap: 12px !important;
        border-radius: 12px !important;
    }
    .hover-card > div > div[style*="font-size:30px"] {
        font-size: 22px !important;
    }
    .hover-card > div > div[style*="font-size:22px"] {
        font-size: 18px !important;
    }
    
    .metric-icon-wrapper {
        width: 36px !important;
        height: 36px !important;
        font-size: 14px !important;
    }
    .metric-title {
        font-size: 11px !important;
    }
    .metric-value {
        font-size: 18px !important;
    }
    
    .stats-card {
        padding: 15px !important;
    }
    
    .content-card {
        padding: 15px !important;
    }
    
    .auth-container {
        padding: 20px !important;
    }
    
    .auth-card {
        width: 100% !important;
        max-width: 100% !important;
        padding: 24px 20px !important;
        border-radius: 16px !important;
    }
    
    /* Dashboard headers / Page headers */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }
    
    .page-header .btn, .header-actions {
        width: 100% !important;
        justify-content: flex-start !important;
    }

    /* Keep Back buttons on the right side in mobile mode */
    .page-top-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        gap: 10px !important;
        margin-bottom: 16px !important;
    }

    .page-top-header h2 {
        font-size: 18px !important;
        line-height: 1.25 !important;
        margin: 0 !important;
        flex: 1 1 auto !important;
    }

    .page-back-btn {
        margin-left: auto !important;
        width: auto !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        font-size: 13px !important;
        padding: 8px 14px !important;
        min-height: 38px !important;
        display: inline-flex !important;
        align-items: center !important;
        align-self: center !important;
    }
    
    /* Ensure cards inside flex column don't stretch page horizontally */
    .card, .content-card, .hover-card, .main-content > * {
        min-width: 0 !important;
        max-width: 100% !important;
    }
    
    /* Settings & POS Layouts */
    .settings-container, .pos-layout {
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        height: auto !important;
        gap: 16px !important;
        display: flex !important; /* overrides grid for pos-layout to let it stack or fallback gracefully */
        align-items: stretch !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .settings-sidebar {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .settings-content {
        width: 100% !important;
        padding: 20px 16px !important;
        box-sizing: border-box !important;
    }
    
    /* Modals */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
        max-height: 90vh !important;
        border-radius: 16px !important;
    }
    
    .modal-header, .modal-content form, .modal-content > div {
        padding: 16px !important;
    }
    
    /* Force grid layouts inside modals to stack vertically */
    .modal-content form > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        display: grid !important;
        gap: 12px !important;
    }
    
    .modal-content .btn, .modal-actions > *, .button-row > *, .btn-row > * {
        flex: none !important;
        width: 100% !important;
        justify-content: center !important;
        min-height: 44px !important;
        height: auto !important;
    }
    
    /* Ensure tap targets are large enough */
    .btn, button, .nav-link, select, input {
        min-height: 44px !important;
    }
    
    /* Header action buttons in modals should remain compact and not expand or become huge */
    .modal-header .btn,
    .modal-header button,
    .print-modal-btn,
    #historyAddLogBtn {
        width: auto !important;
        flex: none !important;
        min-height: 34px !important;
        height: 34px !important;
        padding: 0 12px !important;
        font-size: 13px !important;
        white-space: nowrap !important;
    }
    .modal-header .close-btn {
        width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
        font-size: 22px !important;
        padding: 0 !important;
        flex: none !important;
    }

    /* Modal actions and backup history row responsiveness on mobile */
    .modal-actions {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100% !important;
    }
    .backup-row-actions {
        width: 100% !important;
        justify-content: flex-end !important;
        margin-left: auto !important;
        margin-top: 6px !important;
    }
    .backup-row-actions .btn,
    .backup-row-actions button {
        width: auto !important;
        min-height: 32px !important;
        height: auto !important;
        flex: none !important;
        padding: 5px 12px !important;
    }

    /* POS Refund Modal Responsiveness on mobile */
    #posRefundModal .modal-content {
        max-height: 94vh !important;
        width: 96vw !important;
        max-width: 96vw !important;
        margin: auto !important;
        border-radius: 16px !important;
    }
    #posRefundModal #posRefundForm {
        padding: 0 !important;
    }
    #posRefundModal .modal-header {
        padding: 12px 14px !important;
    }
    #posRefundModal .pos-refund-modal-body {
        padding: 12px 14px 24px 14px !important;
    }
    .pos-refund-footer {
        padding: 10px 12px !important;
        background: #f9fafb !important;
        border-top: 1px solid #e5e7eb !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .pos-refund-footer .btn-pos-refund-instant {
        width: 100% !important;
        min-height: 38px !important;
        height: 38px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 12px !important;
        flex: none !important;
        box-sizing: border-box !important;
    }
    .pos-refund-footer .pos-refund-btn-group {
        display: flex !important;
        gap: 6px !important;
        width: 100% !important;
    }
    .pos-refund-footer .pos-refund-btn-group .btn {
        flex: 1 1 50% !important;
        width: 50% !important;
        min-height: 38px !important;
        height: 38px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 10px !important;
        white-space: nowrap !important;
        box-sizing: border-box !important;
    }

    /* ---- POS LAYOUT (Mobile) ---- */
    /* Prevent the generic grid-1fr rule from crushing the products grid */
    .pos-grid #products-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 10px !important;
    }

    /* Smaller product card images on mobile */
    .pos-grid .product-card img,
    .pos-grid .product-card > div[style*="height:140px"] {
        height: 100px !important;
    }

    /* Stack search + category filter vertically */
    .pos-search-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .pos-search-row > div {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Tab buttons - full width, stacked */
    .pos-tab-bar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .pos-tab-bar .btn {
        flex: 1 1 100% !important;
        width: 100% !important;
        font-size: 13px !important;
    }

    /* Cart discount row - stack vertically */
    .pos-cart > div[style*="display:flex"][style*="gap:12px"][style*="margin-bottom:16px"] {
        flex-direction: column !important;
    }

    /* Products panel - shorter on phone */
    .pos-grid #panel-products {
        max-height: 50vh;
        min-height: 250px;
    }

    /* History panel on mobile - let it flow, constrain the inner table */
    .pos-history-panel {
        flex: none !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .pos-cart #cart-items {
        max-height: 25vh;
        min-height: 100px;
    }

    /* POS Transaction History table - allow horizontal scroll */
    .pos-history-table {
        flex: none !important;
        max-height: 45vh;
        overflow-y: auto !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        min-height: 200px !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .pos-history-table table {
        min-width: 100% !important;
        width: 100% !important;
    }

    /* Hide Ref No. and Cashier columns on mobile to save horizontal space while keeping Status visible */
    .pos-grid #panel-history .admin-data-table th:nth-child(6),
    .pos-grid #panel-history .admin-data-table td:nth-child(6),
    .pos-grid #panel-history .admin-data-table th:nth-child(8),
    .pos-grid #panel-history .admin-data-table td:nth-child(8) {
        display: none !important;
    }

    /* Make action buttons in history stack vertically */
    .pos-grid #panel-history .admin-data-table td:last-child {
        flex-direction: column !important;
        gap: 4px !important;
    }
}

/* =========================================
   GLOBAL UTILITIES
   ========================================= */
@media (max-width: 991px) {
    .action-group {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
    }
    .action-group button,
    .action-group a,
    .action-group .btn,
    .action-group span {
        width: 120px !important;
        box-sizing: border-box !important;
        flex: 0 0 auto !important;
        min-height: 0 !important;
        padding: 4px 10px !important;
        font-size: 11px !important;
        justify-content: center !important;
        text-align: center !important;
    }
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    margin-bottom: 24px;
}

.table-responsive table {
    width: 100%;
    min-width: 600px; /* Force horizontal scroll if container is smaller */
    border: none;
    box-shadow: none;
    margin-bottom: 0;
}

/* Fix missing icons in sidebar toggle */
#sidebar-toggle i {
    font-size: 20px;
}


/* =========================================
   POS PAGE SPECIFIC FIXES (Added for better mobile UX)
   ========================================= */

@media (max-width: 991px) {
    /* Make the pos-grid flex properly instead of overflowing the screen */
    .pos-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .pos-main-col {
        min-width: 0 !important;
    }
    
    /* Allow the tab bar to wrap if needed */
    .pos-tab-bar {
        flex-wrap: wrap !important;
    }
}

@media (max-width: 767px) {
    /* Scale KPI cards slightly so they fit cleanly side-by-side */
    .pos-kpi-value {
        font-size: 22px !important;
    }
    .pos-kpi-value-small {
        font-size: 17px !important;
    }

    /* Tab bar full width */
    .pos-tab-bar {
        gap: 8px !important;
    }
    .pos-tab-bar .custom-tab-box {
        flex: 1 1 100% !important;
        width: 100% !important;
        display: flex !important;
    }
    .pos-tab-bar .custom-tab-box button {
        flex: 1 1 50% !important;
        font-size: 13px !important;
        padding: 0 10px !important;
        text-align: center;
        justify-content: center;
    }
    .pos-refunds-btn {
        margin-left: 0 !important;
        width: 100% !important;
        justify-content: center !important;
    }

    /* Transaction History - Stacked Cards Layout */
    .pos-history-cards table,
    .pos-history-cards thead,
    .pos-history-cards tbody,
    .pos-history-cards th,
    .pos-history-cards td,
    .pos-history-cards tr {
        display: block !important;
    }
    
    .pos-history-cards thead tr {
        position: absolute !important;
        top: -9999px !important;
        left: -9999px !important;
    }
    
    .pos-history-cards tr.history-row {
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 12px;
        background: #fff;
        padding: 12px;
    }
    
    .pos-history-cards td {
        border: none !important;
        border-bottom: 1px solid #f3f4f6 !important;
        position: relative !important;
        padding-left: 45% !important;
        text-align: right !important;
        min-height: 36px;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }
    
    .pos-history-cards td:last-child {
        border-bottom: none !important;
        padding-left: 0 !important;
        text-align: center !important;
        padding-top: 16px !important;
    }
    
    .pos-history-cards td:last-child:before {
        display: none !important;
        content: none !important;
    }
    
    .pos-history-cards td:before {
        position: absolute;
        top: 10px;
        left: 0;
        width: 40%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--color-text-muted);
        content: attr(data-label);
    }
    
    .pos-history-actions {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        width: 100% !important;
    }
    
    .pos-history-actions > * {
        flex: 1 1 auto !important;
        justify-content: center !important;
    }

    /* Override the generic hidden nth-child for history panels */
    .pos-grid #panel-history .admin-data-table th:nth-child(6),
    .pos-grid #panel-history .admin-data-table td:nth-child(6),
    .pos-grid #panel-history .admin-data-table th:nth-child(8),
    .pos-grid #panel-history .admin-data-table td:nth-child(8) {
        display: block !important;
    }
}

@media (max-width: 767px) {
    /* Stack payment method buttons in the Process Payment modal on phones */
    .payment-method-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 991px) {
    /* Stack the FIT PASS and Stats cards vertically on tablets and phones */
    .member-dashboard-top-grid {
        flex-direction: column !important;
    }
}

@media (max-width: 767px) {
    /* Keep member dashboard stats side-by-side on mobile */
    .member-stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    .member-stats-grid .stat-card {
        padding: 16px !important;
    }
    .member-stats-grid .stat-card i[style*="font-size: 110px"], 
    .member-stats-grid .stat-card i[style*="font-size: 120px"] {
        font-size: 70px !important;
        right: -5px !important;
        bottom: -5px !important;
    }
    .member-stats-grid .stat-card div[style*="font-size: 42px"],
    .member-stats-grid .stat-card div[style*="font-size: 32px"] {
        font-size: 24px !important;
    }
    .member-stats-grid .stat-card div[style*="font-size: 15px"] {
        font-size: 13px !important;
    }
    .member-stats-grid .stat-card div[style*="font-size: 13px"] {
        font-size: 11px !important;
    }
}

@media (max-width: 767px) {
    /* Prevent the Save/Cancel buttons on the Settings page from wrapping text and becoming huge */
    .settings-actions-wrap button {
        padding: 10px 12px !important;
        font-size: 13px !important;
        flex: 1 !important;
        white-space: nowrap !important;
    }
}

@media (max-width: 576px) {
    /* Stack date filter rows cleanly into 1 column on phone viewports to prevent horizontal overflow */
    .backup-filter-dates,
    .att-filter-dates,
    .reports-filter-dates,
    .date-filter-group {
        grid-template-columns: 1fr !important;
        width: 100% !important;
    }
    
    .backup-date-group,
    .att-date-group,
    .reports-date-group {
        width: 100% !important;
    }

    .backup-date-group input[type="date"],
    .att-date-group input[type="date"],
    .reports-date-group input[type="date"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}
