/* ── Базовые стили с Telegram Theming ── */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1a1a1a);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #2481cc);
    --btn-bg: var(--tg-theme-button-color, #2481cc);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --section-bg: var(--tg-theme-section-bg-color, #ffffff);
    --accent: var(--tg-theme-accent-text-color, #2481cc);
    --destructive: var(--tg-theme-destructive-text-color, #cc2424);
    --separator: var(--tg-theme-section-separator-color, #e5e5e5);

    /* Фирменные цвета Fresh Market */
    --green: #43A047;
    --green-light: #66BB6A;
    --green-dark: #2E7D32;
    --orange: #FF6D00;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 80px;
    -webkit-font-smoothing: antialiased;
}

/* ── Хедер с градиентом ── */
.header {
    padding: 20px 16px 12px;
    text-align: center;
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: #fff;
    margin-bottom: 0;
}

.header__title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #fff;
}

.header__subtitle {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    line-height: 1.4;
}

/* ── Категории (горизонтальный скролл, sticky) ── */
.categories {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    border-bottom: 1px solid var(--separator);
}

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

.category-chip {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--separator);
    background: var(--section-bg);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.category-chip--active {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

/* ── Товары (сетка) ── */
.products {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px 12px 16px;
}

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

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

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

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

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

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

.product-card__price {
    display: flex;
    align-items: center;
    gap: 6px;
}

.price-current {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.price-old {
    font-size: 12px;
    color: var(--hint);
    text-decoration: line-through;
}

/* Бейдж скидки — зелёный (тренд) */
.product-card__badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--green);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    z-index: 2;
}

/* ── Кнопка добавления / inline-контроллер ── */
.product-card__add-wrap {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 0;
}

.product-card__add {
    min-width: 34px;
    height: 34px;
    border-radius: 17px;
    background: var(--green);
    color: #fff;
    border: none;
    font-size: 20px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    line-height: 1;
    padding: 0;
}

.product-card__add:active {
    transform: scale(0.9);
}

/* Inline qty-контроллер на карточке */
.product-card__qty {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--green);
    border-radius: 17px;
    padding: 2px;
    height: 34px;
}

.product-card__qty-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    line-height: 1;
}

.product-card__qty-btn:active {
    background: rgba(255,255,255,0.35);
}

.product-card__qty-val {
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 28px;
    text-align: center;
    white-space: nowrap;
}

/* ── Skeleton-загрузка ── */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--hint);
    font-size: 15px;
}

.skeleton-grid {
    display: contents;
}

.skeleton-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    overflow: hidden;
}

.skeleton-img {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(90deg, var(--secondary-bg) 25%, #e8e8e8 50%, var(--secondary-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-text {
    margin: 10px;
}

.skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--secondary-bg) 25%, #e8e8e8 50%, var(--secondary-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    margin-bottom: 8px;
}

.skeleton-line--short {
    width: 60%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Плавающая кнопка корзины ── */
.cart-fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--green);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(67,160,71,0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform 0.2s ease;
    border: none;
}

.cart-fab:active {
    transform: scale(0.9);
}

.cart-fab__icon {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.cart-fab__count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: var(--orange);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2.5px solid var(--bg);
    animation: badgeBounce 0.3s ease;
}

@keyframes badgeBounce {
    0% { transform: scale(0.5); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ── Модальные окна ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal__content {
    position: relative;
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 0 20px 20px;
    animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Ручка модалки (тренд) */
.modal__content::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--separator);
    margin: 10px auto 16px;
}

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

.modal__img {
    width: 100%;
    aspect-ratio: 1.2;
    background: var(--secondary-bg);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    margin-bottom: 16px;
    overflow: hidden;
}

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

.modal__title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}

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

.modal__price {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--green-dark);
}

.modal__actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

/* ── Кнопки ── */
.btn {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.btn:active {
    opacity: 0.7;
    transform: scale(0.98);
}

.btn--primary {
    background: var(--green);
    color: #fff;
}

.btn--outline {
    background: var(--secondary-bg);
    color: var(--text);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Корзина ── */
.cart-items {
    margin: 12px 0;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: var(--secondary-bg);
    border-radius: var(--radius-sm);
    transition: opacity 0.2s;
}

.cart-item__thumb {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--section-bg);
}

.cart-item__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cart-item__info {
    flex: 1;
    min-width: 0;
}

.cart-item__name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item__price {
    font-size: 12px;
    color: var(--hint);
    margin-top: 2px;
}

.cart-item__subtotal {
    font-size: 14px;
    font-weight: 700;
    color: var(--green-dark);
    margin-top: 1px;
}

.cart-item__qty {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.qty-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: var(--section-bg);
    color: var(--text);
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.qty-btn:active {
    background: var(--separator);
    transform: scale(0.9);
}

.cart-item__count {
    font-size: 13px;
    font-weight: 700;
    min-width: 32px;
    text-align: center;
    white-space: nowrap;
}

.cart-summary {
    margin-top: 8px;
    padding: 16px 0;
    border-top: 1.5px solid var(--separator);
}

.cart-total {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cart-total__label {
    color: var(--hint);
    font-size: 15px;
    font-weight: 500;
}

.cart-total__count {
    font-size: 13px;
    color: var(--hint);
    font-weight: 400;
    margin-bottom: 4px;
}

.input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--separator);
    background: var(--section-bg);
    color: var(--text);
    font-size: 15px;
    margin-bottom: 8px;
    outline: none;
    transition: border-color 0.2s;
}

.input:focus {
    border-color: var(--green);
}

.input::placeholder {
    color: var(--hint);
}

/* ── Успех ── */
.modal__content--success {
    text-align: center;
    padding: 40px 20px;
}

.success-icon {
    font-size: 64px;
    margin-bottom: 16px;
    animation: successPop 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes successPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.success-text {
    font-size: 15px;
    color: var(--hint);
    margin-bottom: 20px;
    line-height: 1.4;
}

/* ── Пустая корзина ── */
.cart-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--hint);
}

.cart-empty__icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.cart-empty__text {
    font-size: 16px;
    font-weight: 500;
}

.cart-empty__hint {
    font-size: 13px;
    margin-top: 4px;
}

/* ── Весовой бейдж ── */
.product-card__weight-tag {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 2;
}
