:root {
    --primary: #ff5722;
    --primary-dark: #e64a19;
    --dark: #1b1f2a;
    --gray-bg: #f4f5f7;
    --border: #e2e4e9;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #2563eb;
    --tabbar-height: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--gray-bg);
    color: #1b1f2a;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overscroll-behavior-y: none;
}
.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* iOS-safe form controls: 16px min font size prevents Safari auto-zoom on focus */
input, select, textarea, button {
    font-family: inherit;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 6px;
}
button, .btn, input[type="submit"], input[type="button"] {
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    touch-action: manipulation;
}
a, button, .btn, .icon-link, .mobile-tab, .category-nav a {
    touch-action: manipulation;
}

/* Header */
.topbar { background: var(--dark); color: #fff; font-size: 13px; }
.topbar-inner { padding: 6px 16px; padding-top: calc(6px + env(safe-area-inset-top)); }
.header-main { display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: #fff; position: relative; flex-wrap: nowrap; }
.logo { font-size: 22px; font-weight: 800; color: var(--primary); white-space: nowrap; }
.search-form { flex: 1; display: flex; min-width: 0; }
.search-form input { flex: 1; min-width: 0; padding: 11px 14px; border: 2px solid var(--border); border-right: none; border-radius: 6px 0 0 6px; }
.search-form button { padding: 0 16px; background: var(--primary); color: #fff; border: none; border-radius: 0 6px 6px 0; font-weight: 600; min-height: 44px; }
.search-toggle-btn { display: none; background: none; border: none; font-size: 18px; padding: 8px; min-width: 44px; min-height: 44px; }
.header-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.icon-link { font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; background: none; border: none; }
.icon-link-label { display: inline; }

/* Hamburger (hidden on desktop) */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    flex-shrink: 0;
}
.hamburger-btn span { display: block; width: 22px; height: 2px; background: var(--dark); border-radius: 2px; }

/* Dropdown - tap-to-open (JS toggles .open); keep hover for desktop pointer devices */
.dropdown { position: relative; }
.dropdown-trigger { background: none; border: none; font-size: 15px; }
.dropdown-menu { display: none; position: absolute; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 40; overflow: hidden; }
.dropdown-menu a { display: block; padding: 12px 14px; font-size: 14px; }
.dropdown-menu a:hover, .dropdown-menu a:active { background: var(--gray-bg); }
.dropdown.open .dropdown-menu { display: block; }
@media (hover: hover) and (pointer: fine) {
    .dropdown:hover .dropdown-menu { display: block; }
}

.category-nav { background: var(--dark); }
.category-nav .container { display: flex; gap: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.category-nav .container::-webkit-scrollbar { display: none; }
.category-nav a { color: #d7d9e0; padding: 12px 2px; font-size: 14px; white-space: nowrap; }
.category-nav a:hover { color: #fff; }

/* Mobile slide-in menu */
.mobile-menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
.mobile-menu-overlay.open { display: block; }
.mobile-menu {
    position: fixed; top: 0; bottom: 0; left: 0; width: 82%; max-width: 320px;
    background: #fff; z-index: 91; transform: translateX(-100%);
    transition: transform .25s ease; overflow-y: auto;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}
.mobile-menu.open { transform: translateX(0); }
.mobile-menu-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.mobile-menu-header button { background: none; border: none; font-size: 20px; width: 44px; height: 44px; }
.mobile-menu-body { display: flex; flex-direction: column; padding: 8px 0; }
.mobile-menu-body a { padding: 14px 20px; font-size: 15px; font-weight: 600; border-bottom: 1px solid #f3f4f6; min-height: 44px; display: flex; align-items: center; gap: 10px; }
.mobile-menu-body hr { border: none; border-top: 6px solid var(--gray-bg); margin: 8px 0; }
.mobile-menu-label { padding: 8px 20px 0; font-size: 12px; text-transform: uppercase; color: #9ca3af; font-weight: 700; margin: 0; }

/* Mobile bottom tab bar */
.mobile-tabbar {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 80;
    background: #fff; border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
.mobile-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 8px 0; font-size: 11px; font-weight: 600; color: #6b7280; min-height: 50px;
}
.mobile-tab span { font-size: 19px; line-height: 1; }
.mobile-tab.active { color: var(--primary); }

/* Buttons */
.btn { display: inline-block; padding: 11px 18px; border-radius: 6px; font-weight: 600; text-align: center; min-height: 44px; line-height: 1.3; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border: 2px solid var(--primary); color: var(--primary); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 38px; }
.btn-block { display: block; width: 100%; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin: 16px 0; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }

/* Hero */
.hero { background: linear-gradient(135deg, var(--primary), #ff8a50); border-radius: 12px; padding: 36px 24px; color: #fff; margin: 20px 0; }
.hero h1 { font-size: 26px; margin: 0 0 10px; }
.hero p { font-size: 15px; opacity: .95; }

/* Section */
.section { margin: 28px 0; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.section-title h2 { font-size: 19px; margin: 0; }
.section-title a { color: var(--primary); font-weight: 600; font-size: 14px; }

/* Product grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.product-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; transition: box-shadow .15s; }
.product-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.product-card img { width: 100%; height: 120px; object-fit: cover; background: #eee; display: block; }
.product-card-body { padding: 10px; }
.product-card-body h3 { font-size: 13px; margin: 0 0 6px; line-height: 1.3; height: 34px; overflow: hidden; }
.product-price { color: var(--primary); font-weight: 700; font-size: 15px; }
.product-meta { display: flex; justify-content: space-between; font-size: 11px; color: #6b7280; margin-top: 6px; flex-wrap: wrap; gap: 4px; }
.badge-instant { display: inline-block; background: #dcfce7; color: #166534; font-size: 10px; padding: 2px 8px; border-radius: 4px; font-weight: 700; margin-bottom: 6px; }

/* Category chips */
.category-chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.category-chip { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px 10px; text-align: center; font-weight: 600; font-size: 13px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.category-chip:hover { border-color: var(--primary); color: var(--primary); }

/* Card / panels */
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 18px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.form-control { width: 100%; padding: 11px 12px; border: 1px solid var(--border); font-size: 16px; min-height: 44px; }
textarea.form-control { min-height: unset; }
.auth-box { max-width: 400px; margin: 30px auto; }

/* Badges */
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-warning { background: #fef3c7; color: var(--warning); }
.badge-info { background: #dbeafe; color: var(--info); }
.badge-success { background: #dcfce7; color: var(--success); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-secondary { background: #e5e7eb; color: #374151; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #fafafa; font-weight: 700; }

/* Product detail */
.product-detail { display: grid; grid-template-columns: 380px 1fr; gap: 30px; }
.product-detail img { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.variant-option { display: flex; justify-content: space-between; align-items: center; padding: 14px; border: 2px solid var(--border); border-radius: 8px; margin-bottom: 10px; cursor: pointer; min-height: 44px; gap: 10px; flex-wrap: wrap; }
.variant-option.selected { border-color: var(--primary); background: #fff7ed; }
.variant-option input { margin-right: 10px; width: 20px; height: 20px; }

/* Payment options */
.pay-option { display: flex; align-items: center; gap: 10px; padding: 15px 14px; border: 2px solid var(--border); border-radius: 8px; margin-bottom: 10px; cursor: pointer; min-height: 44px; }
.pay-option.selected { border-color: var(--primary); background: #fff7ed; }
.pay-option input { width: 20px; height: 20px; }

/* Footer */
.site-footer { background: var(--dark); color: #cbd0dc; margin-top: 50px; padding: 40px 0 0; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 30px; padding-bottom: 30px; }
.footer-grid h4 { color: #fff; margin-bottom: 10px; }
.footer-grid a { display: block; color: #a5abba; margin-bottom: 6px; padding: 4px 0; }
.footer-bottom { border-top: 1px solid #2c3040; text-align: center; padding: 16px; font-size: 13px; color: #8b90a0; }

/* ===================== MOBILE BREAKPOINT ===================== */
@media (max-width: 860px) {
    .hamburger-btn { display: flex; }
    .search-form { display: none; width: 100%; order: 5; flex-basis: 100%; }
    .search-form.mobile-visible { display: flex; }
    .search-toggle-btn { display: block; }
    .header-main { flex-wrap: wrap; }
    .icon-link-label { display: none; }
    .header-actions { gap: 8px; }
    .header-actions .btn-sm { display: none; } /* Sign Up button - use hamburger menu instead */
    .category-nav { display: none; } /* replaced by mobile "Browse" tab + slide-in menu */

    body { padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom)); }
    .mobile-tabbar { display: flex; }

    .product-detail { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr; }
    .site-footer { padding-bottom: calc(40px + var(--tabbar-height) + env(safe-area-inset-bottom)); }

    .hero { padding: 26px 18px; }
    .hero h1 { font-size: 22px; }

    .two-col-layout {
        display: block !important;
    }
    .two-col-layout > aside,
    .two-col-layout > *:first-child {
        margin-bottom: 16px;
    }

    /* Let cards containing wide tables scroll horizontally instead of squishing content */
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 480px; }
}

@media (max-width: 480px) {
    /* Inline-styled flex rows (buttons, form rows) wrap instead of overflowing on narrow phones */
    div[style*="display:flex"] { flex-wrap: wrap; }

    .product-grid { grid-template-columns: repeat(2, 1fr); }
    .category-chip-grid { grid-template-columns: repeat(2, 1fr); }
    .logo { font-size: 19px; }
}
