﻿/**
 * StoreEdge - Mobile PWA Enhancements
 * Touch-friendly, responsive styles for mobile devices
 */

/* ===========================
   CSS CUSTOM PROPERTIES FOR MOBILE
   =========================== */
:root {
    /* Safe area insets for notched devices */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    
    /* Touch-friendly sizing */
    --touch-target-min: 44px;
    --touch-spacing: 8px;
    
    /* Mobile typography */
    --mobile-font-base: 16px;
    --mobile-font-sm: 14px;
    --mobile-font-lg: 18px;
}

/* ===========================
   VIEWPORT & SAFE AREAS
   =========================== */

/* Ensure the main content container is always touchable.
   Creates a stacking context above any stale overlays
   and guarantees interactive elements receive touch events.
   NOTE: .main-container is intentionally excluded here because
   giving it a stacking context (z-index:1) traps the dashboard
   sidebar (position:fixed; z-index:99) *inside* that context,
   placing it below the sidebar-overlay (z-index:98 at root level)
   and making the sidebar visible but unclickable on mobile. */
.page,
.pos-layout,
.content {
    position: relative;
    z-index: 1;
}

@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-bottom: var(--safe-area-bottom);
        padding-left: var(--safe-area-left);
        padding-right: var(--safe-area-right);
    }
    
    /* Top safe-area only on standalone PWA (no browser chrome) */
    @media (display-mode: standalone) {
        body {
            padding-top: var(--safe-area-top);
        }
    }
    
    /* Fixed headers need safe area */
    .navbar-fixed, 
    .fixed-top,
    .navbar,
    header.fixed {
        padding-top: var(--safe-area-top);
    }
    
    /* Mobile nav overlay needs safe area */
    .mobile-nav {
        padding-top: 0;
    }
    
    .mobile-nav-close {
        /* handled by mobile-nav-header now */
    }
    
    /* POS mobile cart close needs safe area */
    .mobile-cart-close {
        padding-top: env(safe-area-inset-top, 0px);
    }
    
    /* Modal headers in POS need safe area */
    .cust-modal-header,
    .modal-close,
    .confirm-close,
    .dup-close {
        margin-top: env(safe-area-inset-top, 0px);
    }
    
    /* Fixed footers/bottom bars */
    .fixed-bottom,
    .pos-bottom-bar,
    .mobile-bottom-nav {
        padding-bottom: var(--safe-area-bottom);
    }
}

/* ===========================
   GLOBAL MOBILE INTERACTION FIXES
   =========================== */

/* Eliminate 300ms tap delay on all interactive elements.
   Modern browsers respect this from viewport meta, but older
   WebViews and in-app browsers (Instagram, Facebook, etc.) need it. */
html {
    touch-action: manipulation;
}

a, button, input, select, textarea, label,
[onclick], [role="button"], [tabindex] {
    touch-action: manipulation;
}

/* Suppress the default iOS/Android tap highlight flash */
a, button, input, select, textarea, label,
[onclick], [role="button"], [tabindex],
.btn, .nav-link, .action-btn, .action-button,
.stat-card, .item-card, .cat-chip, .pay-chip,
.status-tab, .nav-section-header, .nav-item,
.quick-nav-link, .quick-nav-section-item,
.fab, .mobile-fab, .mobile-cart-toggle {
    -webkit-tap-highlight-color: transparent;
}

/* iOS requires cursor:pointer on non-<a>/<button> elements
   for click/touch events to fire. Apply to all overlay and
   onclick div/span patterns used throughout the app. */
.sidebar-overlay,
.ma-sidebar-overlay,
.quick-nav-overlay,
.purchase-nav-overlay,
.left-panel-overlay,
.cust-modal-overlay,
.cust-first-overlay,
.modal-overlay,
.confirm-overlay,
.dup-overlay,
.cancel-modal-overlay,
.result-modal-overlay,
[class*="-overlay"][onclick],
[class*="-overlay"],
.mobile-cart-close button,
.quick-add {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* ── CRITICAL: OVERLAY POINTER-EVENTS SAFETY NET ──
   backdrop-filter on fixed overlays creates compositing layers
   that can intercept touch events on mobile WebKit/Blink even
   when the overlay is invisible (visibility:hidden / opacity:0).
   Ensure ALL hidden overlays have pointer-events:none so they
   never block touch on the page behind them.
   When shown (.show / .open / display:flex), pointer-events resets to auto. */
.sidebar-overlay:not(.open),
.ma-sidebar-overlay:not(.open),
.quick-nav-overlay:not(.show),
.purchase-nav-overlay:not(.show),
.left-panel-overlay:not(.show),
.pwa-modal-overlay:not(.show),
.loading-overlay:not(.show),
.submit-modal-overlay:not(.active) {
    pointer-events: none !important;
}

/* Overlays that use display:none + .show class toggle:
   When NOT shown, ensure pointer-events:none so they can't
   intercept touch (especially overlays with backdrop-filter).
   Overlays toggled via display:none are inherently safe,
   but adding pointer-events:none as a defense-in-depth measure.
   NOTE: Some pages use .active instead of .show as toggle class. */
.cust-modal-overlay:not(.show),
.cust-first-overlay:not(.show),
.confirm-overlay:not(.show),
.confirm-modal-overlay:not(.show),
.dup-overlay:not(.show),
.cancel-modal-overlay:not(.show),
.result-modal-overlay:not(.show),
.modal-overlay:not(.show):not(.active) {
    pointer-events: none;
}

/* Re-enable pointer-events on all overlay types when active */
.cust-modal-overlay.show,
.cust-first-overlay.show,
.confirm-overlay.show,
.confirm-modal-overlay.show,
.dup-overlay.show,
.cancel-modal-overlay.show,
.result-modal-overlay.show,
.modal-overlay.show,
.modal-overlay.active,
.submit-modal-overlay.active,
.loading-overlay.show,
.sidebar-overlay.open,
.ma-sidebar-overlay.open,
.quick-nav-overlay.show,
.purchase-nav-overlay.show,
.left-panel-overlay.show,
.pwa-modal-overlay.show {
    pointer-events: auto !important;
}

/* Ensure modals opened via inline style.display (not .show class)
   still receive pointer events */
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display:flex"] {
    pointer-events: auto !important;
}

/* Generic fallback: any element with [class*="-overlay"] that is
   hidden via visibility or has opacity 0 must not capture events */
[class*="-overlay"][style*="visibility: hidden"],
[class*="-overlay"][style*="display: none"],
[class*="overlay"][style*="visibility: hidden"],
[class*="overlay"][style*="display: none"] {
    pointer-events: none !important;
}

/* User dropdown menu – small element but uses visibility:hidden/opacity:0.
   The parent .user-dropdown gets the .open class via JS, not .active on the menu itself. */
.user-dropdown-menu {
    pointer-events: none;
}
.user-dropdown.open .user-dropdown-menu {
    pointer-events: auto;
}

/* Disable user-select on interactive tap targets to prevent
   accidental text selection during rapid tapping */
@media (hover: none) and (pointer: coarse) {
    .stat-card[onclick],
    .item-card[onclick],
    .cat-chip[onclick],
    .nav-section-header[onclick],
    .action-button[onclick],
    [role="button"] {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ===========================
   TOUCH-FRIENDLY ELEMENTS
   =========================== */

/* Minimum touch target size (44x44px per Apple HIG) */
.btn,
.nav-link,
.dropdown-item,
.list-group-item {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

/* Better touch feedback */
@media (hover: none) and (pointer: coarse) {
    .btn {
        transition: transform 0.1s ease, opacity 0.1s ease;
    }
    
    .btn:active {
        transform: scale(0.97);
        opacity: 0.9;
    }
    
    /* Remove hover states on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Larger click areas for links */
    a {
        padding: 4px;
        margin: -4px;
    }
}

/* ===========================
   MOBILE FORMS
   =========================== */
@media (max-width: 768px) {
    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Larger form controls */
    .form-control,
    .form-select {
        padding: 12px 16px;
        font-size: 16px;
        border-radius: 10px;
    }
    
    .form-check-label {
        padding-left: 8px;
        font-size: 16px;
    }
    
    /* Stack form labels on mobile */
    .form-label {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 6px;
    }
}

/* ===========================
   MOBILE NAVIGATION
   =========================== */
@media (max-width: 768px) {
    /* Full-width navbar items */
    .navbar-nav {
        width: 100%;
    }
    
    .navbar-nav .nav-link {
        padding: 14px 20px;
        font-size: 16px;
        border-bottom: 1px solid var(--border-light);
    }
    
    /* Mobile hamburger menu */
    .navbar-toggler {
        padding: 10px;
        border: none;
    }
    
    .navbar-toggler:focus {
        box-shadow: none;
        outline: 2px solid var(--primary-lighter);
        outline-offset: 2px;
    }
}

/* ===========================
   BOTTOM NAVIGATION BAR (Mobile)
   =========================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1050;
    padding-bottom: var(--safe-area-bottom);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
    }
    
    /* Add padding to body to prevent content hiding */
    body.has-bottom-nav {
        padding-bottom: calc(70px + var(--safe-area-bottom));
    }
}

.mobile-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    min-height: 60px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.mobile-bottom-nav .nav-item.active {
    color: var(--primary);
}

.mobile-bottom-nav .nav-item .nav-icon {
    font-size: 22px;
    margin-bottom: 4px;
}

.mobile-bottom-nav .nav-item .nav-label {
    font-size: 11px;
    font-weight: 500;
}

/* ===========================
   MOBILE CARDS & LISTS
   =========================== */
@media (max-width: 768px) {
    .card {
        border-radius: 12px;
        margin-bottom: 12px;
    }
    
    .card-body {
        padding: 16px;
    }
    
    .card-header {
        padding: 14px 16px;
    }
    
    /* Swipeable list items */
    .list-group-item {
        padding: 14px 16px;
        border-left: none;
        border-right: none;
    }
    
    .list-group-item:first-child {
        border-top: none;
    }
}

/* ===========================
   MOBILE TABLES (Responsive)
   =========================== */
@media (max-width: 768px) {
    /* Card-style tables on mobile */
    .table-mobile-cards {
        border: none;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 12px;
        background: var(--bg-card);
        border-radius: 10px;
        box-shadow: var(--shadow-sm);
        padding: 12px;
    }
    
    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid var(--border-light);
    }
    
    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 13px;
    }
    
    /* Horizontal scroll for complex tables */
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
}

/* ===========================
   MOBILE MODALS & SHEETS
   =========================== */
@media (max-width: 768px) {
    /* Bottom sheet style modals */
    .modal-mobile-sheet .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: auto;
        max-height: 90vh;
    }
    
    .modal-mobile-sheet .modal-content {
        border: none;
        border-radius: 20px 20px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .modal-mobile-sheet .modal-header {
        border-radius: 20px 20px 0 0;
        padding: 16px 20px;
    }
    
    /* Sheet drag indicator */
    .modal-mobile-sheet .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-default);
        border-radius: 2px;
    }
    
    .modal-mobile-sheet .modal-body {
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Full-screen modals on mobile */
    .modal-fullscreen-mobile .modal-dialog {
        margin: 0;
        max-width: 100%;
        width: 100%;
        height: 100%;
    }
    
    .modal-fullscreen-mobile .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }
}

/* ===========================
   MOBILE BUTTONS
   =========================== */
@media (max-width: 768px) {
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 10px;
    }
    
    .btn-sm {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .btn-lg {
        padding: 16px 28px;
        font-size: 18px;
    }
    
    /* Full-width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }
    
    /* Floating action button */
    .fab {
        position: fixed;
        bottom: calc(80px + var(--safe-area-bottom));
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1040;
    }
    
    .fab i {
        font-size: 24px;
    }
}

/* ===========================
   POS MOBILE OPTIMIZATIONS
   =========================== */
@media (max-width: 768px) {
    /* Stack POS layout vertically */
    .pos-container {
        flex-direction: column;
    }
    
    .pos-products,
    .pos-cart {
        width: 100%;
        height: auto;
    }
    
    /* Smaller product cards grid */
    .pos-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 8px;
    }
    
    .pos-product-card {
        padding: 10px;
    }
    
    .pos-product-card .product-name {
        font-size: 13px;
        line-height: 1.3;
    }
    
    .pos-product-card .product-price {
        font-size: 14px;
    }
    
    /* Fixed cart at bottom */
    .pos-cart-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-light);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 1000;
        padding-bottom: var(--safe-area-bottom);
    }
    
    /* Collapsible cart */
    .pos-cart-summary {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        cursor: pointer;
    }
    
    .pos-cart-items {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .pos-cart-mobile.expanded .pos-cart-items {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* ===========================
   PULL TO REFRESH
   =========================== */
.pull-to-refresh {
    position: absolute;
    top: -50px;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

.pull-to-refresh .spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===========================
   MOBILE SEARCH
   =========================== */
@media (max-width: 768px) {
    .search-mobile {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1060;
        background: var(--bg-surface);
        padding: 12px 16px;
        padding-top: calc(12px + var(--safe-area-top));
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .search-mobile.active {
        transform: translateY(0);
    }
    
    .search-mobile .form-control {
        padding-left: 44px;
        padding-right: 44px;
    }
    
    .search-mobile .search-icon {
        position: absolute;
        left: 28px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-muted);
    }
    
    .search-mobile .search-close {
        position: absolute;
        right: 28px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: var(--text-muted);
        padding: 8px;
    }
}

/* ===========================
   MOBILE NOTIFICATIONS/TOASTS
   =========================== */
@media (max-width: 768px) {
    .toast-container {
        bottom: calc(80px + var(--safe-area-bottom)) !important;
        left: 16px !important;
        right: 16px !important;
    }
    
    .toast {
        width: 100%;
        border-radius: 12px;
    }
}

/* ===========================
   SWIPE GESTURES SUPPORT
   =========================== */
.swipe-container {
    touch-action: pan-y;
    overflow-x: hidden;
}

.swipe-item {
    position: relative;
    overflow: hidden;
}

.swipe-item .swipe-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform 0.2s ease;
}

.swipe-item.swiped .swipe-actions {
    transform: translateX(0);
}

.swipe-action-btn {
    width: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.swipe-action-btn.delete {
    background: var(--danger);
}

.swipe-action-btn.edit {
    background: var(--primary);
}

/* ===========================
   INSTALL PROMPT BANNER
   =========================== */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-area-bottom));
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
    z-index: 1100;
    display: none;
    border-top: 1px solid var(--border-light);
}

.pwa-install-banner.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pwa-install-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    flex-shrink: 0;
}

.pwa-install-text {
    flex: 1;
}

.pwa-install-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.pwa-install-text p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ===========================
   SKELETON LOADING (Mobile)
   =========================== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface-secondary) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-text.sm {
    height: 12px;
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-card {
    height: 120px;
    border-radius: 10px;
}

/* ===========================
   HAPTIC FEEDBACK INDICATOR
   =========================== */
@media (max-width: 768px) {
    .haptic-feedback {
        position: relative;
    }
    
    .haptic-feedback::after {
        content: '';
        position: absolute;
        inset: 0;
        background: var(--primary);
        opacity: 0;
        border-radius: inherit;
        pointer-events: none;
        transition: opacity 0.1s ease;
    }
    
    .haptic-feedback:active::after {
        opacity: 0.1;
    }
}

/* ===========================
   LANDSCAPE MODE ADJUSTMENTS
   =========================== */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-bottom-nav {
        flex-direction: column;
        width: 70px;
        height: 100%;
        bottom: auto;
        top: 0;
        left: 0;
        right: auto;
        border-top: none;
        border-right: 1px solid var(--border-light);
    }
    
    body.has-bottom-nav {
        padding-bottom: 0;
        padding-left: 70px;
    }
    
    .pos-products-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===========================
   DARK MODE MOBILE ADJUSTMENTS
   =========================== */
[data-theme="dark"] .mobile-bottom-nav {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

[data-theme="dark"] .pwa-install-banner {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

[data-theme="dark"] .search-mobile {
    background: var(--bg-surface);
}

/* ===========================
   PRINT MEDIA (Hide Mobile Elements)
   =========================== */
@media print {
    .mobile-bottom-nav,
    .pwa-install-banner,
    .fab,
    .search-mobile {
        display: none !important;
    }
}

/* ===========================
   iOS PWA STANDALONE MODE FIXES
   =========================== */
@media all and (display-mode: standalone) {
    /* Ensure fixed elements account for the iOS status bar / notch */
    .navbar,
    .navbar-fixed,
    .fixed-top,
    header.fixed {
        padding-top: env(safe-area-inset-top, 0px) !important;
    }

    /* Mobile nav drawer needs safe area offset */
    .mobile-nav {
        padding-top: 0 !important;
    }

    .mobile-nav-close {
        /* handled by mobile-nav-header now */
    }

    /* Ensure close/action buttons meet 44x44px minimum touch target */
    .mobile-nav-close,
    .cust-modal-close,
    .modal-close,
    .confirm-close,
    .dup-close,
    .toast-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* POS top bar safe area */
    .top-bar {
        padding-top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
    }

    /* POS cart close on mobile */
    .mobile-cart-close {
        padding-top: calc(env(safe-area-inset-top, 0px) + 14px) !important;
    }

    /* Full-screen modals need safe area on top */
    .cust-modal-overlay,
    .modal-overlay {
        padding-top: env(safe-area-inset-top, 0px);
    }

    /* Bottom safe area for action bars */
    .cart-footer,
    .submit-btn {
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    }
}

/* ===========================
   iOS SAFARI COMPATIBILITY FIXES
   =========================== */

/* 1. cursor:pointer on ALL non-button/non-anchor onclick elements.
      iOS Safari requires cursor:pointer on <div>, <span>, <tr>, <label>
      for click/touch events to fire. */
[onclick],
div[onclick],
span[onclick],
tr[onclick],
td[onclick],
label[onclick],
.stat-card[onclick],
.item-card[onclick],
.cat-chip[onclick],
.pay-chip[onclick],
.unit-card[onclick],
.type-card[onclick],
.color-option[onclick],
.courier-card[onclick],
.alt-tab[onclick],
.alt-item[onclick],
.result-item[onclick],
.channel-pill[onclick],
.reason-chip[onclick],
.variable-tag[onclick],
.unit-card-footer[onclick],
.nav-section-header[onclick],
.sc-remove[onclick],
.quick-add[onclick] {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* 2. iOS 100vh fix — dynamic viewport height with fallback.
      These selectors cover inline styles in templates that use
      min-height: 100vh on body. */
@supports (min-height: 100dvh) {
    body {
        min-height: 100dvh;
    }
    .main-container {
        height: calc(100dvh - 68px);
    }
}

/* 3. iOS momentum scrolling for all scrollable containers */
.sidebar,
.content,
.cart-scroll-area,
.pos-left,
.modal-body,
.alert-card-body,
.nav-items,
[style*="overflow-y: auto"],
[style*="overflow-y:auto"],
[style*="overflow: auto"],
[style*="overflow:auto"] {
    -webkit-overflow-scrolling: touch;
}

/* 4. Fix iOS rubber-band bounce on body when modal/overlay is open */
body.scroll-locked {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

/* 4a. Safety net: unlock scroll-locked body if no overlay is active.
       The JS ios-compat.js handles this, but CSS ensures the body
       is never stuck in locked state when all overlays are hidden.
       Uses :has() (Safari 15.4+, Chrome 105+) as progressive enhancement. */
@supports selector(:has(*)) {
    body.scroll-locked:not(:has(.modal-overlay.show)):not(:has(.quick-nav-overlay.show)):not(:has(.sidebar-overlay.open)):not(:has(.confirm-overlay.show)):not(:has(.pwa-modal-overlay.show)) {
        position: static;
        width: auto;
        overflow: visible;
    }
}

/* 5. iOS input focus zoom prevention — ensure 16px minimum on ALL inputs */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* 6. Fix iOS Safari address bar causing layout shift on scroll.
      Use min-height instead of height where the content can exceed viewport. */
@supports (-webkit-touch-callout: none) {
    /* Safari-only: use -webkit-fill-available as ultimate fallback */
    body {
        min-height: -webkit-fill-available;
    }
}

/* 7. iOS safe area padding for full-width elements */
@supports (padding: max(0px)) {
    .container,
    .container-fluid,
    .pos-layout,
    .top-bar,
    .cart-footer,
    .mobile-bottom-nav {
        padding-left: max(var(--safe-area-left), 0px);
        padding-right: max(var(--safe-area-right), 0px);
    }
}

/* 8. Prevent text selection flash on rapid taps (iOS/touch devices) */
@media (hover: none) and (pointer: coarse) {
    [onclick],
    [role="button"],
    .btn,
    .nav-link,
    .nav-section-header,
    .stat-card,
    .item-card,
    .cat-chip,
    .pay-chip,
    .action-button {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* But always allow text selection in content/form areas */
    input, textarea, [contenteditable="true"],
    p, h1, h2, h3, h4, h5, h6, li, td, th, dd, dt {
        -webkit-user-select: auto;
        user-select: auto;
    }
}

/* 9. Fix stacking context issues with position:fixed on iOS.
      iOS requires -webkit-transform:translateZ(0) to promote
      fixed elements to their own compositing layer. */
.mobile-bottom-nav,
.search-mobile,
.pwa-install-banner,
.fab,
.pos-cart-mobile,
.toast-container {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* 10. iOS Safari overscroll-behavior to contain scroll in modals */
.modal-body,
.cust-modal-overlay,
.modal-overlay,
.confirm-overlay {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
