/* ==========================================================================
   EKROM SHOP - Ultra-Smooth Mobile Architecture & Touch Containment
   Native 120Hz Scrolling, Zero Tap-Delay, Crisp Typography & Airtight Modals
   ========================================================================== */

/* 1. Global Typography & Crisp Antialiasing */
html, body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 2. Fast Tap & High-Performance Touch Defaults */
*, *::before, *::after {
    -webkit-tap-highlight-color: transparent;
}

button, a, select, input, textarea, [onclick] {
    touch-action: manipulation;
}

/* Prevent auto-zooming on input focus on iOS/Android */
@media screen and (max-width: 768px) {
    input:not([type="checkbox"]):not([type="radio"]), select, textarea {
        font-size: 16px !important;
    }
}

/* 3. Modal & Drawer Scroll Lock (Eliminates Background Scroll Leak) */
body.modal-open,
html:has(body.modal-open) {
    overflow: hidden !important;
    height: 100% !important;
    touch-action: none !important;
}

body.drawer-open {
    overflow: hidden !important;
}

/* Modal overlays overscroll containment */
#detailModal,
#profileModal,
#buyModal,
#mobileMenu {
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Modal card constraints */
#detailModal > div,
#profileModal > div,
#buyModalContent {
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
    max-height: 88vh;
    max-height: 88dvh;
}

/* Scrollable containers inside modals & Config Textarea */
#detailModal .overflow-y-auto,
#profileModal .overflow-y-auto,
#buyModalContent .overflow-y-auto,
#modalConfig,
#backupConfigText {
    overscroll-behavior: contain !important;
    overscroll-behavior-y: contain !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
}

#modalConfig,
#backupConfigText {
    font-size: 10px !important;
    line-height: 1.45 !important;
    letter-spacing: -0.01em !important;
}

/* 4. Customer Mobile Layout Rules (< 1024px) */
@media (max-width: 1023px) {
    html {
        width: 100%;
        min-height: 100%;
        box-sizing: border-box;
        overflow-x: clip;
        scroll-padding-top: 4.5rem;
    }

    *, *::before, *::after { box-sizing: inherit; }

    body.mobile-safe-layout {
        margin: 0;
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-x: clip;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        align-items: stretch;
    }

    body.mobile-safe-layout > main {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        min-height: 0;
        flex: 1 0 auto;
        overflow: visible;
        padding-top: calc(4.25rem + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
    }

    body.mobile-safe-layout > .mobile-topbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-height: calc(3.6rem + env(safe-area-inset-top, 0px)) !important;
        padding-top: max(0.65rem, env(safe-area-inset-top, 0px)) !important;
        padding-bottom: 0.65rem !important;
        padding-right: 14px !important;
        padding-left: 14px !important;
        gap: 0.5rem !important;
        z-index: 50 !important;
        box-sizing: border-box !important;
        background: #ffffff !important;
        border-bottom: 1px solid rgba(226, 232, 240, 0.85) !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04) !important;
        touch-action: pan-y !important;
    }

    .mobile-topbar,
    .mobile-topbar * {
        touch-action: pan-y !important;
    }

    .mobile-topbar > div:first-child { min-width: 0; }
    .mobile-topbar > div:first-child > span {
        max-width: calc(100vw - 180px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .mobile-topbar > div:last-child { flex-shrink: 0; }

    /* Topbar Modern Wallet Badge & Hamburger */
    .mobile-topbar .wallet-badge {
        display: inline-flex !important;
        align-items: center !important;
        gap: 0.35rem !important;
        padding: 0.25rem 0.55rem 0.25rem 0.3rem !important;
        border-radius: 9999px !important;
        background: linear-gradient(135deg, rgba(236, 253, 245, 0.95) 0%, rgba(209, 250, 229, 0.85) 100%) !important;
        border: 1px solid rgba(16, 185, 129, 0.35) !important;
        box-shadow: 0 2px 6px -1px rgba(16, 185, 129, 0.16), 0 1px 2px rgba(0, 0, 0, 0.04) !important;
        cursor: pointer !important;
        transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
        user-select: none !important;
        -webkit-tap-highlight-color: transparent !important;
        max-width: 175px !important;
    }
    .mobile-topbar .wallet-badge:hover {
        background: linear-gradient(135deg, #ecfdf5 0%, #a7f3d0 100%) !important;
        border-color: rgba(16, 185, 129, 0.6) !important;
        transform: translateY(-1px) !important;
        box-shadow: 0 4px 12px -2px rgba(16, 185, 129, 0.28) !important;
    }
    .mobile-topbar .wallet-badge:active {
        transform: scale(0.95) !important;
    }
    .mobile-topbar .wallet-badge .wallet-icon {
        width: 1.55rem !important;
        height: 1.55rem !important;
        border-radius: 9999px !important;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
        color: #ffffff !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 0.78rem !important;
        font-weight: 900 !important;
        box-shadow: 0 2px 5px rgba(16, 185, 129, 0.35) !important;
        flex-shrink: 0 !important;
    }
    .mobile-topbar .wallet-badge .wallet-amount {
        font-size: 0.85rem !important;
        font-weight: 800 !important;
        color: #065f46 !important;
        font-family: 'JetBrains Mono', monospace, -apple-system, BlinkMacSystemFont, sans-serif !important;
        letter-spacing: -0.01em !important;
        line-height: 1 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .mobile-topbar .wallet-badge .wallet-add-btn {
        width: 1.2rem !important;
        height: 1.2rem !important;
        border-radius: 9999px !important;
        background: #10b981 !important;
        color: #ffffff !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 0.75rem !important;
        font-weight: 900 !important;
        line-height: 1 !important;
        margin-left: 0.1rem !important;
        flex-shrink: 0 !important;
        transition: all 0.2s ease !important;
        box-shadow: 0 1px 3px rgba(16, 185, 129, 0.25) !important;
    }
    .mobile-topbar .wallet-badge:hover .wallet-add-btn {
        transform: rotate(90deg) scale(1.1) !important;
        background: #059669 !important;
    }

    .mobile-topbar .hamburger-btn {
        width: 2.35rem !important;
        height: 2.35rem !important;
        border-radius: 0.85rem !important;
        background: rgba(241, 245, 249, 0.95) !important;
        color: #334155 !important;
        border: 1px solid rgba(203, 213, 225, 0.7) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
        flex-shrink: 0 !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
    }
    .mobile-topbar .hamburger-btn:hover {
        background: rgba(253, 242, 248, 0.95) !important;
        color: #ec4899 !important;
        border-color: rgba(244, 114, 182, 0.4) !important;
        transform: translateY(-1px) !important;
    }
    .mobile-topbar .hamburger-btn:active {
        transform: scale(0.92) !important;
    }

    /* Mobile Drawer Container - Responsive, Crisp, Balanced */
    #mobileDrawer {
        width: clamp(275px, 82vw, 330px) !important;
        max-width: 85vw !important;
        max-height: 100% !important;
        max-height: 100dvh !important;
        padding: clamp(1rem, 3.5vw, 1.5rem) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain !important;
        -webkit-overflow-scrolling: touch !important;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45) !important;
    }

    #mobileDrawer nav {
        display: flex !important;
        flex-direction: column !important;
        gap: clamp(0.25rem, 0.9vh, 0.5rem) !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain !important;
        -webkit-overflow-scrolling: touch !important;
        min-height: 0 !important;
        flex: 1 1 0% !important;
    }

    #mobileDrawer nav a,
    #mobileDrawer .sidebar-link {
        padding: clamp(0.55rem, 1.4vh, 0.75rem) clamp(0.75rem, 2.5vw, 1rem) !important;
        font-size: clamp(0.92rem, 3vw, 1.05rem) !important;
        font-weight: 600 !important;
        line-height: 1.4 !important;
        border-radius: 0.85rem !important;
    }

    #mobileDrawer nav a span:first-child,
    #mobileDrawer .sidebar-link span:first-child {
        font-size: clamp(1.1rem, 3.5vw, 1.3rem) !important;
    }

    #mobileDrawer .drawer-header {
        margin-bottom: clamp(1.5rem, 4.5vh, 2.5rem) !important;
        flex-shrink: 0 !important;
    }

    #mobileDrawer .drawer-logo {
        width: clamp(2.35rem, 7.5vw, 2.75rem) !important;
        height: clamp(2.35rem, 7.5vw, 2.75rem) !important;
        font-size: clamp(0.85rem, 2.8vw, 1rem) !important;
        border-radius: 0.8rem !important;
    }

    #mobileDrawer .drawer-title {
        font-size: clamp(1.05rem, 4vw, 1.25rem) !important;
        font-weight: 800 !important;
    }

    #mobileDrawer .drawer-close-btn {
        width: clamp(2.2rem, 7vw, 2.5rem) !important;
        height: clamp(2.2rem, 7vw, 2.5rem) !important;
    }

    #mobileDrawer .drawer-footer {
        margin-top: auto !important;
        padding-top: clamp(0.5rem, 1.5vh, 0.85rem) !important;
        border-top: 1px solid rgba(241, 245, 249, 0.8) !important;
        flex-shrink: 0 !important;
    }

    #mobileDrawer .drawer-footer button {
        padding: clamp(0.55rem, 1.4vh, 0.75rem) clamp(0.75rem, 2.5vw, 1rem) !important;
        font-size: clamp(0.92rem, 3vw, 1.05rem) !important;
        font-weight: 600 !important;
        border-radius: 0.85rem !important;
    }

    #categoryFilter {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
    }
}

@media (prefers-reduced-motion: reduce) {
    html:focus-within { scroll-behavior: auto; }
}
