:root {
    --primary-color: #0088cc;
    --secondary-color: #f8fafc;
    --accent-color: #f59e0b;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --text-color: #0f172a;
    --text-muted: #64748b;
    --border-color: #f1f5f9;
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --card-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    --card-shadow-hover: 0 8px 30px rgba(15, 23, 42, 0.12);
    --theme-radius: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.4;
    overflow-x: hidden;
    padding-bottom: calc(var(--safe-area-inset-bottom) + 68px);
    -webkit-font-smoothing: antialiased;
    font-size: 13px;
}

.container {
    padding: 0 12px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* ── Bottom Navigation ── */
.main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    height: calc(60px + var(--safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    padding-bottom: var(--safe-area-inset-bottom);
    box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.06), 0 -8px 20px rgba(0, 0, 0, 0.04);
    z-index: 9999;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    text-decoration: none;
    flex: 1;
    transition: var(--transition);
    padding: 6px 0;
    gap: 3px;
    border-radius: 14px;
}

.nav-item i {
    font-size: 1.15rem;
    transition: var(--transition);
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item.active i {
    transform: translateY(-1px);
}

/* ── Page Transitions ── */
.page {
    display: none;
    animation: fadeSlideUp 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 10;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page.active {
    display: block;
}

/* ── Header ── */
header {
    background: var(--card-bg);
    padding: calc(10px + var(--safe-area-inset-top)) 14px 10px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 1px 0 var(--border-color);
}

/* ── Search Bar ── */
.search-bar {
    background: var(--bg-color);
    border-radius: 14px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1.5px solid transparent;
    transition: var(--transition);
    margin-top: 8px;
}

.search-bar:focus-within {
    border-color: var(--primary-color);
    background: var(--card-bg);
    box-shadow: 0 0 0 4px rgba(0, 136, 204, 0.08);
}

.search-bar input {
    border: none;
    background: none;
    width: 100%;
    outline: none;
    font-size: 0.88rem;
    color: var(--text-color);
    font-family: inherit;
}

.search-bar i {
    color: var(--text-muted);
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ── Category Chips ── */
.categories {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 8px 0 4px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

.categories::-webkit-scrollbar {
    display: none;
}

.cat-chip {
    padding: 6px 14px;
    background: var(--card-bg);
    border-radius: 50px;
    white-space: nowrap;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: var(--transition);
    border: 1.5px solid var(--border-color);
    cursor: pointer;
    flex-shrink: 0;
    color: var(--text-muted);
}

.cat-chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 14px rgba(0, 136, 204, 0.3);
}

.cat-chip:not(.active):active {
    transform: scale(0.96);
}

/* ── Product Grid ── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 12px 0 20px;
}

@media (min-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 600px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 900px) {
    .product-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1200px) {
    .product-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ── Product Card — Premium Redesign ── */
.product-card {
    background: var(--card-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    position: relative;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.product-card:active {
    transform: scale(0.96);
    box-shadow: var(--card-shadow);
}

.product-img-wrapper {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--bg-color);
    overflow: hidden;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.product-card:active .product-image {
    transform: scale(1.04);
}

/* Discount Badge */
.discount-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    padding: 3px 8px;
    border-radius: 50px;
    font-size: 0.62rem;
    font-weight: 800;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.35);
    letter-spacing: 0.03em;
}

/* Product Info */
.product-info {
    padding: 10px 10px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-name {
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
}

.price-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin-top: auto;
    padding-top: 6px;
}

.current-price {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 0.88rem;
    letter-spacing: -0.02em;
}

.old-price {
    text-decoration: line-through;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 500;
}

/* Add to Cart Button on Card */
.card-add-btn {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 136, 204, 0.35);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.25s ease;
}

.card-add-btn:active {
    transform: scale(0.9);
}

/* ── Banner Slider (Edge-to-Edge) ── */
.banner-slider {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 0;
    padding: 0;
    margin: 0 -12px 16px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.banner-slider::-webkit-scrollbar {
    display: none;
}

.banner-slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
    border-radius: 0;
    overflow: hidden;
    position: relative;
    aspect-ratio: 16/7;
    background: var(--border-color);
}

.banner-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ── Product Detail Overlay — Premium Polish ── */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    background: var(--card-bg);
    z-index: 10001;
    display: none;
    flex-direction: column;
    animation: drawerUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    height: 100%;
}

.overlay.active {
    display: flex !important;
}

@media (min-width: 768px) {
    .overlay {
        width: 440px;
        margin: 0 auto;
        left: 50%;
        transform: translateX(-50%);
        height: 85vh;
        top: 7.5vh;
        border-radius: 28px;
        box-shadow: 0 40px 100px rgba(0, 0, 0, 0.25);
    }
}

.overlay-header {
    background: var(--card-bg);
    padding: calc(10px + var(--safe-area-inset-top)) 16px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.overlay-header h3 {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-color);
    letter-spacing: -0.01em;
}

.overlay-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
}

.overlay-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
    flex-shrink: 0;
}

/* Gallery - immersive aspect ratio */
.gallery {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg-color);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.gallery::-webkit-scrollbar {
    display: none;
}

.gallery img {
    min-width: 100%;
    height: 100%;
    object-fit: cover;
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ── Cart Bottom Sheet — Premium Polish ── */
.cart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--card-bg);
    z-index: 15000;
    display: none;
    flex-direction: column;
    overflow-y: auto;
}

.cart-overlay.active {
    display: flex;
}


.cart-header {
    padding: calc(10px + var(--safe-area-inset-top)) 16px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--card-bg);
    flex-shrink: 0;
}

.cart-header-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-count-badge {
    background: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 50px;
    min-width: 24px;
}

.cart-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-color);
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.cart-items-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.cart-item-img {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--bg-color);
    flex-shrink: 0;
    border: 1px solid var(--border-color);
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-variant {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.cart-item-price {
    font-weight: 800;
    color: var(--primary-color);
    margin-top: 4px;
}

.qty-controls {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border-radius: 10px;
    padding: 2px;
    gap: 8px;
}

.qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: white;
    border: none;
    color: var(--text-color);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    cursor: pointer;
}

.qty-num {
    font-weight: 800;
    font-size: 0.85rem;
    min-width: 20px;
    text-align: center;
}

/* Consolidated Cart Footer & Forms */
.cart-footer {
    padding: 12px 18px calc(12px + var(--safe-area-inset-bottom));
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.cart-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.cart-total-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.cart-total-amount {
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--primary-color);
    letter-spacing: -0.01em;
}

/* ── Form Elements ── */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-color);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-color);
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

/* Consolidating duplicates */
.cart-item-delete {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #fff0f0;
    border: none;
    color: #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
}

/* ── Buttons ── */
/* Consolidated Buttons & Order cards */
.btn {
    padding: 8px 14px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    font-family: inherit;
}

.btn-checkout-pay {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    padding: 12px;
}

.order-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
}

textarea.form-input {
    resize: vertical;
    min-height: 60px;
}

/* ── Language Selector ── */
.lang-select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-color);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 4px 14px;
    cursor: pointer;
}

.lang-select-wrapper i {
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.lang-select-wrapper select {
    flex: 1;
    background: transparent;
    border: none;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-color);
    outline: none;
    padding: 9px 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

/* ── GPS / Location Button ── */
.checkout-location-btn {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    padding: 12px 18px;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.checkout-location-btn:active,
.checkout-location-btn.active {
    background: #ecfdf5;
    border-color: #10b981;
    color: #065f46;
}

.checkout-location-btn i {
    color: var(--primary-color);
    font-size: 0.9rem;
}

/* ── Status Badges ── */
.badge-paid {
    background: #dcfce7;
    color: #166534;
}

.badge-unpaid {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Profile Stats Card ── */
#profileStats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    text-align: center;
    overflow: hidden;
}

#profileStats>* {
    padding: 18px 8px;
}

#profileStats>*:first-child {
    border-right: 1px solid var(--border-color);
}

#profileStats .stat-val {
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--primary-color);
    display: block;
    letter-spacing: -0.03em;
}

#profileStats .stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-top: 3px;
}

/* ── Utils ── */
.mb-2 {
    margin-bottom: 8px;
}

.text-center {
    text-align: center;
}

/* ── Card ── */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

/* ══════════════════════════════════════
   MOBILE-FIRST RESPONSIVE — App (index)
   ══════════════════════════════════════ */

/* Small phones ≤ 390px — very compact */
@media (max-width: 390px) {
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 8px;
    }

    .product-info {
        padding: 8px 10px 10px;
    }

    .product-name {
        font-size: 0.78rem;
    }

    .current-price {
        font-size: 0.82rem;
    }

    .card-add-btn {
        width: 26px;
        height: 26px;
    }

    /* Banner slightly taller on very small */
    .banner-slide {
        aspect-ratio: 16/8;
    }

    /* Cart items tighter */
    .cart-item {
        padding: 10px;
        gap: 8px;
    }

    .cart-item-img {
        width: 48px;
        height: 48px;
        border-radius: 10px;
    }

    .qty-btn {
        width: 26px;
        height: 26px;
        font-size: 0.8rem;
    }

    .qty-display {
        font-size: 0.85rem;
        min-width: 24px;
    }

    /* Bottom nav tighter */
    .bottom-nav {
        height: 56px;
    }

    .nav-item {
        font-size: 0.6rem;
    }

    .nav-icon {
        font-size: 1.1rem;
    }

    /* Search bar */
    .search-bar {
        padding: 10px 14px;
        font-size: 0.88rem;
    }

    /* Category chips */
    .cat-chip {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
}

/* Standard phones ≤ 480px */
@media (max-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }

    /* Overlay full-screen */
    .overlay-content {
        padding-bottom: 16px;
    }

    .overlay-footer {
        padding: 12px 16px;
    }

    /* Checkout form fields stacked */
    .checkout-row {
        flex-direction: column;
        gap: 10px;
    }

    /* Floating cart btn touch area */
    #floatingCartBtn {
        width: 56px;
        height: 56px;
        font-size: 1.3rem;
        bottom: 72px;
        right: 16px;
    }

    /* Cart sheet */
    .cart-sheet .cart-header {
        padding: 12px 16px;
    }

    .cart-sheet .cart-footer {
        padding: 12px 16px;
    }

    .cart-item-name {
        font-size: 0.85rem;
    }

    .cart-item-price {
        font-size: 0.82rem;
    }

    .cart-total-row {
        font-size: 0.9rem;
    }

    .cart-total-amount {
        font-size: 1.1rem;
    }

    .btn-checkout {
        height: 48px;
        font-size: 0.9rem;
        border-radius: 14px;
    }

    /* Orders list */
    .order-card {
        padding: 14px;
        border-radius: 14px;
        gap: 10px;
    }

    /* Profile form */
    .profile-section {
        padding: 14px;
    }

    .profile-label {
        font-size: 0.7rem;
    }
}

/* Medium phones / large phones in portrait ≤ 600px */
@media (max-width: 600px) {

    /* Ensure viewport meta didn't zoom */
    html {
        touch-action: manipulation;
    }

    /* Header */
    .app-header {
        padding: 10px 14px;
    }

    /* Product grid — always 2 columns up to 600px */
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Detail overlay gallery taller for better UX */
    #detailGallery {
        height: 28vh;
    }

    /* Bottom nav items bigger tap targets */
    .nav-item {
        padding: 6px 0;
        min-width: 56px;
    }

    /* Variant chips wrap nicely */
    .variant-chips {
        flex-wrap: wrap;
        gap: 6px;
    }

    .variant-chip {
        padding: 7px 14px;
        font-size: 0.8rem;
    }
}