/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #ff6b35;
    --primary-dark: #e55a2b;
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 56px;
    --cats-h: 48px;
    --hero-h: 0px;
    --product-aspect: 1 / 1;
    --bg-image: none;
    --bg-image-opacity: 0;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* Optional full-page background image (design API) */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: var(--bg-image-opacity, 0);
    pointer-events: none;
}

body.miniapp-bg-fixed::before {
    background-attachment: fixed;
}

/* ── Header ──────────────────────────────────────── */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h, 56px);
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.header__logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    min-height: 28px;
}

.header__logo img {
    max-height: 36px;
    max-width: 140px;
    object-fit: contain;
    display: block;
}

/* ── Header layouts (data-header-layout on body) ───────── */
body[data-header-layout="logo_lg_center"] .header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 12px;
}

body[data-header-layout="logo_lg_center"] .header__logo {
    grid-column: 2;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 2px;
}

body[data-header-layout="logo_lg_center"] .header__logo img {
    max-height: 52px;
    max-width: 220px;
}

body[data-header-layout="logo_lg_center"] .header__cart {
    grid-column: 3;
    justify-self: end;
}

body[data-header-layout="logo_sm_center"] .header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

body[data-header-layout="logo_sm_center"] .header__logo {
    grid-column: 2;
    justify-content: center;
    gap: 6px;
}

body[data-header-layout="logo_sm_center"] .header__logo img {
    max-height: 32px;
    max-width: 120px;
}

body[data-header-layout="logo_sm_center"] .header__cart {
    grid-column: 3;
    justify-self: end;
}

body[data-header-layout="text_only"] .header__logo {
    font-size: 18px;
}

/* ── Hero banner ───────────────────────────────────── */
.app-hero {
    position: fixed;
    top: var(--header-h, 56px);
    left: 0;
    right: 0;
    height: var(--hero-h, 0px);
    z-index: 98;
    overflow: hidden;
}

.app-hero[hidden] {
    display: none !important;
}

.app-hero__bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
}

.app-hero__overlay {
    position: absolute;
    inset: 0;
    background: #000;
    opacity: 0.4;
}

.app-hero__inner {
    position: relative;
    z-index: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    text-align: center;
}

.app-hero__text {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    text-shadow: 0 1px 8px rgba(0,0,0,0.45);
    margin: 0;
    max-width: 100%;
}

.header__logo-text {
    line-height: 1.2;
}

.header__cart {
    position: relative;
    cursor: pointer;
    padding: 8px;
    font-size: 22px;
}

.header__cart-count {
    position: absolute;
    top: 2px;
    right: 0;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ── Categories ──────────────────────────────────── */
.categories {
    position: fixed;
    top: calc(var(--header-h, 56px) + var(--hero-h, 0px));
    left: 0;
    right: 0;
    height: var(--cats-h);
    background: var(--card-bg);
    z-index: 99;
    border-bottom: 1px solid var(--border);
}

.categories__scroll {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 6px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.categories__scroll::-webkit-scrollbar {
    display: none;
}

.cat-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.cat-btn--active {
    background: var(--primary);
    color: white;
}

/* ── Products ────────────────────────────────────── */
.products {
    margin-top: calc(var(--header-h, 56px) + var(--cats-h, 48px) + var(--hero-h, 0px));
    padding: 12px;
    padding-bottom: calc(80px + var(--safe-bottom));
}

.products__grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 480px) {
    .products__grid--grid_2 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.products__grid--grid_2 {
    grid-template-columns: repeat(2, 1fr);
}

.products__grid--grid_3 {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 479px) {
    .products__grid--grid_3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.products__grid--large_cards {
    grid-template-columns: 1fr;
}

.products__grid--large_cards .product-card__img {
    aspect-ratio: var(--product-aspect, 16 / 9);
    max-height: 220px;
}

.products__grid--list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.products__grid--list .product-card {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    max-width: 100%;
}

.products__grid--list .product-card__img {
    width: 108px;
    min-width: 108px;
    aspect-ratio: var(--product-aspect, 1);
    height: auto;
    align-self: stretch;
}

.products__grid--list .product-card__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.products__grid--list .product-card__bottom {
    margin-top: auto;
}

.product-card__desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.35;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.15s;
}

.product-card:active {
    transform: scale(0.97);
}

.product-card__img {
    width: 100%;
    aspect-ratio: var(--product-aspect, 1);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: var(--text-secondary);
    overflow: hidden;
}

.product-card__img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-card__emoji {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.product-card__info {
    padding: 8px 10px 10px;
}

.product-card__name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.product-card__weight {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.product-card__bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.product-card__price {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
}

.product-card__add {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    line-height: 1;
}

.product-card__add:active {
    background: var(--primary-dark);
}

/* ── Loading ─────────────────────────────────────── */
.products__loading {
    display: flex;
    justify-content: center;
    padding: 40px 0;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.products__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* ── Modal ───────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
}

.modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
}

.modal__content {
    position: relative;
    width: 100%;
    max-height: 85vh;
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    font-size: 16px;
    cursor: pointer;
    z-index: 1;
}

.modal__body {
    padding: 0;
}

.modal__img {
    width: 100%;
    aspect-ratio: var(--product-aspect, 16 / 10);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    overflow: hidden;
}

.modal__img--photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal__info {
    padding: 16px;
}

.modal__name {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal__weight {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal__desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 16px;
}

.modal__footer {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal__price {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.quantity-ctrl {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.quantity-ctrl__btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card-bg);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quantity-ctrl__val {
    font-size: 18px;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn--primary {
    background: var(--primary);
    color: white;
}

.btn--primary:active {
    background: var(--primary-dark);
}

.btn--block {
    width: 100%;
    margin-top: 12px;
}

/* ── Cart Panel ──────────────────────────────────── */
.cart-panel {
    position: fixed;
    inset: 0;
    z-index: 300;
}

.cart-panel__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
}

.cart-panel__content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 80vh;
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.cart-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.cart-panel__header h2 {
    font-size: 18px;
}

.cart-panel__close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    font-size: 16px;
    cursor: pointer;
}

.cart-panel__items {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.cart-item__info {
    flex: 1;
}

.cart-item__name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.cart-item__price {
    font-size: 13px;
    color: var(--text-secondary);
}

.cart-item__controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-item__btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item__qty {
    font-size: 15px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.cart-panel__footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.cart-panel__total {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.cart-panel__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* ── Bottom Cart Bar ─────────────────────────────── */
.cart-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-bottom));
    z-index: 90;
}

.cart-bar__btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
}

.cart-bar__count {
    background: rgba(255,255,255,0.25);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 13px;
}

/* ── Toast ───────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    z-index: 500;
    animation: fadeInUp 0.3s ease, fadeOut 0.3s ease 1.7s forwards;
    white-space: nowrap;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeOut {
    to { opacity: 0; }
}

/* ── Checkout success ────────────────────────────── */
.checkout-result {
    text-align: center;
    padding: 40px 20px;
}

.checkout-result__icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.checkout-result__title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.checkout-result__text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}
