: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);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --card-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

* {
    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.2;
    overflow-x: hidden;
    padding-bottom: calc(var(--safe-area-inset-bottom) + 55px);
    -webkit-font-smoothing: antialiased;
    font-size: 10.5px;
    /* Improved readability, still compact */
}

.container {
    padding: 0 10px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Tabs Navigation */
.main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    height: calc(52px + var(--safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    padding: 6px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 9999;
    padding-bottom: var(--safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: none;
    flex: 1;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i {
    font-size: 1rem;
    margin-bottom: 1px;
}

.nav-item.active {
    color: var(--primary-color);
    transform: translateY(-2px);
}

/* Pages */
.page {
    display: none;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page.active {
    display: block;
}

/* Header & Search */
header {
    background: white;
    padding: calc(8px + var(--safe-area-inset-top)) 10px 8px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.search-bar {
    background: #f1f5f9;
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-bar input {
    border: none;
    background: none;
    width: 100%;
    outline: none;
    font-size: 0.9rem;
    color: var(--text-color);
    font-family: inherit;
}

/* Category Scroller */
.categories {
    display: flex;
    overflow-x: auto;
    gap: 5px;
    padding: 6px 0;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

.categories::-webkit-scrollbar {
    display: none;
}

.cat-chip {
    padding: 4px 10px;
    background: white;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: var(--card-shadow);
    font-size: 0.65rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: 0.3s;
    border: 1px solid var(--border-color);
}

.cat-chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 136, 204, 0.2);
}

/* Product Cards */
.product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px 0;
}

/* Tablet */
@media (min-width: 600px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Wide Tablet / Small Desktop */
@media (min-width: 900px) {
    .product-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Large Desktop */
@media (min-width: 1200px) {
    .product-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

.product-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    position: relative;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
}

.product-card:active {
    transform: scale(0.97);
}

.product-img-wrapper {
    position: relative;
    aspect-ratio: 1/1;
    background: #f8fafc;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-slide {
    flex: 0 0 85%;
    scroll-snap-align: center;
    border-radius: var(--theme-radius);
    overflow: hidden;
    position: relative;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
    aspect-ratio: 16/6;
    /* More compact banner */
    background: #eee;
}

.discount-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #ef4444;
    color: white;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.2);
}

.product-info {
    padding: 4px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-name {
    font-weight: 700;
    font-size: 0.65rem;
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.1;
}

.price-row {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: auto;
}

.current-price {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 0.75rem;
}

.old-price {
    text-decoration: line-through;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
}

/* Detail Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 4%;
    right: 4%;
    bottom: 0;
    width: 92%;
    background: white;
    z-index: 10001;
    display: none;
    flex-direction: column;
    animation: drawerUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: 100%;
}

/* Full screen on mobile actually means it should cover everything */
.overlay {
    left: 0;
    right: 0;
    width: 100%;
}

@media (min-width: 768px) {
    .overlay {
        width: 380px;
        margin: 0 auto;
        left: 50%;
        transform: translateX(-50%);
        height: 80vh;
        top: 10vh;
        border-radius: 20px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        border: 1px solid var(--border-color);
    }
}

@keyframes drawerUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.overlay.active {
    display: flex;
}

.overlay-header {
    background: white;
    padding: calc(5px + var(--safe-area-inset-top)) 10px 5px;
    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: 700;
}

.overlay-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 5px;
}

.overlay-footer {
    padding: 8px;
    border-top: 1px solid var(--border-color);
    background: white;
    flex-shrink: 0;
    z-index: 10;
}

.gallery {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    height: 25vh;
    /* Very compact */
    background: #f8fafc;
}

.gallery img {
    min-width: 100%;
    height: 100%;
    object-fit: cover;
    scroll-snap-align: start;
}

.cart-overlay {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: white;
    z-index: 10002;
    padding: 15px 15px calc(15px + var(--safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.1);
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cart-overlay.active {
    bottom: 0;
}

@media (min-width: 768px) {
    .cart-overlay {
        max-width: 400px;
        left: 50%;
        transform: translateX(-50%);
        bottom: -100%;
        border-radius: 20px;
        margin-bottom: 20px;
    }

    .cart-overlay.active {
        bottom: 0;
    }
}

.cart-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.qty-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f1f5f9;
    padding: 3px 8px;
    border-radius: 10px;
}

.qty-btn {
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Buttons */
.btn {
    padding: 7px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 8px 24px rgba(0, 136, 204, 0.3);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-color);
}

/* Order Cards */
.order-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
}

.status-pill {
    padding: 5px 12px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}

/* Utils */
.mb-2 {
    margin-bottom: 8px;
}

.text-center {
    text-align: center;
}

@media (min-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Forms (Profile / Checkout) ── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

.form-input {
    width: 100%;
    padding: 7px 10px;
    background: #fff;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.75rem;
    font-family: inherit;
    color: var(--text-color);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 136, 204, 0.1);
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

/* Language Selector */
.lang-select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 3px 12px;
    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: #f8fafc;
    color: var(--text-color);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    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: all 0.2s;
    margin-bottom: 0;
}

.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;
}

/* Checkout pay button */
.btn-checkout-pay {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
    border-radius: 18px;
    font-size: 1rem;
    letter-spacing: 0.03em;
    margin-top: 10px;
}

/* Status badges (app) */
.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: 16px 8px;
}

#profileStats>*:first-child {
    border-right: 1px solid var(--border-color);
}

#profileStats .stat-val {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary-color);
    display: block;
}

#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: 2px;
}