/*
 * BuyNearby Mobile App CSS
 * Applied only on ≤768px — transforms all dashboards into native-app feel.
 * Desktop is untouched.
 */

/* ── Base ────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

html, body {
    -webkit-tap-highlight-color: transparent;
    /* overscroll-behavior and touch-action intentionally NOT set on body/html
       — any restriction here breaks scroll or tap on iOS Safari              */
}

/* Prevent iOS font size adjustment */
body { -webkit-text-size-adjust: 100%; }

/* ── Touch: fast-tap on buttons/inputs only, NOT on links or containers ── */
/* Setting touch-action: manipulation on <a> breaks horizontal strip scroll  */
button, input[type=submit], input[type=button] {
    touch-action: manipulation;
    min-height: 44px;
    cursor: pointer;
}

/* Inputs: 16px prevents iOS zoom-on-focus */
input, textarea, select, .form-control {
    font-size: 16px !important;
    border-radius: 10px !important;
}

/* Qty counter input — restore clean look overridden by the rules above.
   Specificity (0,2,0) = 20 beats input (0,0,1) = 1, wins on load order tie */
.product-qty-controls .product-qty-input {
    width: 52px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    padding: 5px 4px !important;
    border-radius: 8px !important;
    text-align: center !important;
    background: #fff !important;
    color: #1f2937 !important;
    border: 2px solid #d1d5db !important;
    line-height: 1.3 !important;
    min-height: unset !important;
}

/* ── Fix v3-complete.css: overflow-x:hidden on ancestors kills iOS scroll ──
   iOS Safari bug: overflow:hidden on ANY ancestor of a -webkit-overflow-
   scrolling element consumes the touch event before the strip sees it.
   These selectors override those rules with higher specificity.           */

/* .product-section is the direct parent of .product-row — MUST be visible */
#departments-section .product-section,
#departments-section .product-row,
section.product-section {
    overflow-x: visible !important;
}
/* product-row must be flex (v3-complete sets display:grid on mobile) */
#departments-section .product-row,
.stores-strip ~ .product-row,
section.product-section > .product-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
}

/* ── Horizontal scroll strips: native momentum scroll ─────────────────── */
.stores-strip,
.deals-scroll, .sale-scroll,
.product-row, .flash-strip, .en-flash-strip,
.app-chips, .en-dept-pills, .en-tiers,
.cf-presets {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-x: contain !important;
    /* pan-x pan-y: horizontal → strip scrolls; vertical → propagates to page
       (strip has overflow-y:hidden so it can't absorb vertical, passes it up) */
    touch-action: pan-x pan-y !important;
    /* NO transform/will-change — they break -webkit-overflow-scrolling layer */
}

/* Children: auto lets the browser decide per-gesture — pan-x here blocks
   vertical page scroll when a finger starts on a card.                   */
.stores-strip > *,
.deals-scroll > *,
.sale-scroll > *,
.product-row > *,
.en-flash-strip > * {
    touch-action: auto !important;
    flex-shrink: 0 !important;
}

/* ── Vertical page scroll ──────────────────────────────────────────────── */
#main-content, #app-root,
.store-content, .page-content,
.cf-messages, .cf-feed-body,
.cart-container, .content-area {
    -webkit-overflow-scrolling: touch;
    /* overscroll-behavior-y: contain removed — can suppress scroll chaining */
}

/* ── Admin: hide desktop sidebar, show bottom sheet nav ──────────────── */
.admin-layout .sidebar,
.layout-sidebar {
    display: none !important;
}

.admin-layout .main-content,
.main-content {
    margin-left: 0 !important;
    padding: 12px !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
}

/* ── Store dashboard: side nav is already handled by store-dashboard.css ──
   It uses max-height: 0 / max-height: 100dvh — do NOT hide with display:none
   or the open state won't work. ────────────────────────────────────────── */

.store-content,
.dashboard-content,
.page-content {
    margin-left: 0 !important;
    padding: 12px !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
}

/* ── Top header: compact app bar ─────────────────────────────────────── */
.top-header,
.admin-header,
.store-header-bar {
    position: sticky !important;
    top: 0 !important;
    z-index: 200 !important;
    padding: 10px 14px !important;
    min-height: 56px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    backdrop-filter: blur(10px) !important;
}

.top-header h1,
.admin-header h1,
.page-title {
    font-size: 1.05rem !important;
    font-weight: 800 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55vw;
}

/* ── App bottom nav ──────────────────────────────────────────────────── */
.mob-app-nav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 300 !important;
    background: #fff !important;
    border-top: 1px solid #e5e7eb !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    box-shadow: 0 -2px 16px rgba(0,0,0,.08) !important;
}

.mob-app-nav-item {
    flex: 1;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    padding: 8px 4px !important;
    min-height: 56px !important;
    text-decoration: none !important;
    color: #9ca3af !important;
    font-size: 10px !important;
    font-weight: 600 !important;
    border: none !important;
    background: none !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s !important;
    position: relative;
}

.mob-app-nav-item i {
    font-size: 1.2rem !important;
    line-height: 1 !important;
}

.mob-app-nav-item.active,
.mob-app-nav-item:active {
    color: #667eea !important;
}

.mob-app-nav-item .mob-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 14px);
    background: #ef4444;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

/* Dark nav (admin/store-dash dark theme) */
.mob-app-nav.dark {
    background: #0f172a !important;
    border-color: #1e293b !important;
}
.mob-app-nav.dark .mob-app-nav-item { color: #475569 !important; }
.mob-app-nav.dark .mob-app-nav-item.active { color: #a78bfa !important; }

/* ── Tables → app cards on mobile ────────────────────────────────────── */
.data-table, table.table {
    display: block !important;
}

.data-table thead, table.table thead { display: none !important; }

.data-table tbody, table.table tbody {
    display: block !important;
}

.data-table tr, table.table tr {
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
    border-radius: 14px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.07) !important;
    margin-bottom: 10px !important;
    padding: 14px 16px !important;
    border: 1.5px solid #f3f4f6 !important;
    gap: 4px !important;
}

.data-table td, table.table td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 5px 0 !important;
    border: none !important;
    font-size: .88rem !important;
    min-height: unset !important;
    border-bottom: 1px solid #f9fafb !important;
}

.data-table td:last-child, table.table td:last-child {
    border-bottom: none !important;
}

.data-table td::before {
    content: attr(data-label) !important;
    font-weight: 700 !important;
    color: #6b7280 !important;
    font-size: .75rem !important;
    text-transform: uppercase !important;
    letter-spacing: .03em !important;
    flex-shrink: 0 !important;
    margin-right: 8px !important;
}

/* Dark tables */
.dark .data-table tr, body[class*=dark] .data-table tr {
    background: #1e293b !important;
    border-color: #334155 !important;
}
.dark .data-table td { border-color: #2d3f55 !important; }

/* ── Modals → bottom sheet ───────────────────────────────────────────── */
.modal-dialog,
.checkout-modal {
    margin: 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    box-shadow: 0 -8px 40px rgba(0,0,0,.2) !important;
    animation: sheet-up .3s cubic-bezier(.32,.72,0,1) !important;
}

@keyframes sheet-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* Pull handle for bottom sheets */
.modal-dialog::before,
.checkout-modal::before {
    content: '' !important;
    display: block !important;
    width: 36px !important;
    height: 4px !important;
    background: #d1d5db !important;
    border-radius: 2px !important;
    margin: 10px auto 6px !important;
    flex-shrink: 0 !important;
    pointer-events: none !important;
}

/* ── Cards: full-width, no side chrome ───────────────────────────────── */
.card, .stat-card, .info-card, .store-card-block {
    border-radius: 14px !important;
    margin-bottom: 10px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,.06) !important;
}

.dashboard-stats {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
}

.stat-card {
    padding: 14px !important;
}

.stat-card h3 {
    font-size: 1.4rem !important;
    margin-bottom: 2px !important;
}

/* ── Form layout ─────────────────────────────────────────────────────── */
.form-row,
.form-grid,
.field-row {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
}

/* Full-width CTAs */
.btn-primary, .btn-success, .btn-primary-large, .sticky-checkout-cta {
    width: 100% !important;
    justify-content: center !important;
    padding: 15px !important;
    font-size: 1rem !important;
    border-radius: 14px !important;
}

/* ── Tablet / POS: full-screen panels ────────────────────────────────── */
.tablet-wrap,
.pos-wrap {
    flex-direction: column !important;
    height: auto !important;
}

.pos-panel,
.tablet-panel {
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid #e5e7eb !important;
    max-height: 50vh !important;
    overflow-y: auto !important;
}

} /* end @media */

/* ══════════════════════════════════════════════════════════════
   BARCODE SCANNER MODAL — global (all screen sizes)
   ══════════════════════════════════════════════════════════════ */
#bn-barcode-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0,0,0,.65);
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
}
#bn-barcode-modal.open {
    display: flex;
    pointer-events: auto;
    animation: bn-fade-in .2s ease;
}
@keyframes bn-fade-in { from{opacity:0} to{opacity:1} }
@keyframes bn-sheet-up { from{transform:translateY(100%)} to{transform:translateY(0)} }

#bn-barcode-sheet {
    background: #0f172a;
    border-radius: 20px 20px 0 0;
    /* Constrain width so it doesn't go wider than viewport */
    width: 100%;
    max-width: 480px;
    /* Never taller than 80% of the viewport */
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: bn-sheet-up .3s cubic-bezier(.32,.72,0,1);
    /* Safe area for iPhone home indicator */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

#bn-barcode-sheet .sheet-handle {
    width: 36px; height: 4px; background: #334155;
    border-radius: 2px; margin: 12px auto 4px; flex-shrink: 0;
}
#bn-barcode-sheet .sheet-title {
    font-size: .95rem; font-weight: 800; color: #e2e8f0;
    text-align: center; padding: 4px 16px 10px; flex-shrink: 0;
}
#bn-barcode-sheet .sheet-body {
    flex: 1; overflow-y: auto; padding: 0 14px 14px;
    display: flex; flex-direction: column; gap: 10px;
}

/* Video: fixed height so it doesn't push modal off screen */
#bn-scan-video-wrap {
    position: relative; background: #000;
    border-radius: 12px; overflow: hidden;
    width: 100%; height: 200px; flex-shrink: 0;
}
#bn-scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }

.bn-reticle {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.bn-reticle-box {
    width: 180px; height: 80px;
    border: 2px solid rgba(167,139,250,.9); border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
}
#bn-scan-status {
    position: absolute; bottom: 8px; left: 0; right: 0;
    text-align: center; font-size: .75rem; font-weight: 700;
    color: rgba(255,255,255,.85);
}

.bn-manual-row { display: flex; gap: 8px; }
.bn-manual-input {
    flex: 1; background: #1e293b; border: 1.5px solid #334155;
    border-radius: 10px; color: #e2e8f0; padding: 11px 12px; font-size: 16px;
}
.bn-manual-input:focus { outline: none; border-color: #7c3aed; }
.bn-lookup-btn {
    background: #7c3aed; color: #fff; border: none;
    border-radius: 10px; padding: 0 16px; font-weight: 700;
    cursor: pointer; font-size: .88rem; min-height: 46px;
}

#bn-scan-result {
    background: #1e293b; border: 1.5px solid #334155;
    border-radius: 12px; padding: 12px; display: none;
}
#bn-scan-result.show { display: block; }

.bn-result-name { font-size:.9rem; font-weight:800; color:#e2e8f0; margin-bottom:3px; }
.bn-result-code { font-size:.7rem; color:#64748b; font-family:monospace; margin-bottom:8px; }
.bn-result-badges { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:10px; }
.bn-badge { padding:4px 10px; border-radius:20px; font-size:.75rem; font-weight:700; }
.bn-badge-sell   { background:rgba(124,58,237,.2); color:#a78bfa; }
.bn-badge-cost   { background:rgba(16,185,129,.15); color:#34d399; }
.bn-badge-margin { background:rgba(250,204,21,.15); color:#fbbf24; }
.bn-badge-new    { background:rgba(59,130,246,.15); color:#60a5fa; }
.bn-result-actions { display:flex; gap:8px; }
.bn-act-btn {
    flex:1; padding:10px; border-radius:10px; border:none;
    font-weight:700; font-size:.82rem; cursor:pointer;
    min-height:46px; display:flex; align-items:center; justify-content:center; gap:5px;
}
.bn-act-use    { background:#7c3aed; color:#fff; }
.bn-act-cancel { background:#1e293b; border:1.5px solid #334155; color:#94a3b8; }

#bn-close-btn {
    position: absolute; top: 12px; right: 14px;
    background: #1e293b; border: none; color: #94a3b8;
    font-size: 1rem; width: 30px; height: 30px;
    border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center; z-index: 10;
}
