/* --- ПЕРЕМЕННЫЕ --- */
:root {
    --main: #8c4a2f;
    --bg: #f8f4f0;
    --card: #ffffff;
    --text: #2b2b2b;
    --accent: #e1ccff; /* Цвет фона обычных товаров в корзине */
    --delivery-bg: rgba(0, 0, 0, 0.04); /* Фон для строки доставки */
    --shadow-color: rgba(0, 0, 0, 0.08);
    --disabled: #a5acb4;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-header: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Заставляем все элементы управления использовать шрифт из переменной */
button,
input,
optgroup,
select,
textarea {
    font-family: inherit; /* Наследовать шрифт от родителя (body) */
    font-size: 100%; /* Чтобы размер не «скакал» */
    line-height: 1.15;
    margin: 0;
}

/* --- БАЗОВЫЕ СТИЛИ --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    scrollbar-gutter: stable;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding: 16px;
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    padding-top: 100px;
}

.container {
    max-width: 500px;
    margin: 0 auto;
}

.no-scroll {
    overflow: hidden;
}

/* --- ШАПКА --- */
.header-block {
    background: var(--card);
    padding: 24px 16px;
    border-radius: 20px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px var(--shadow-color);
}

    .header-block h1 {
        font-family: var(--font-header);
        font-size: 1.6rem;
        color: var(--main);
        margin-bottom: 4px;
    }

    .header-block .subtitle {
        font-size: 0.9rem;
        opacity: 0.7;
    }

/* --- СЕТКА ТОВАРОВ --- */
.products-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.product-card {
    background: var(--card);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 10px var(--shadow-color);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

    .product-card:active {
        transform: scale(0.97);
    }
    .product-card img {
        background-color: #e0e0e0; /* Светло-серый фон пока грузится фото */
        display: block;
    }

.out-of-stock {
    filter: grayscale(1);
    opacity: 0.6;
    pointer-events: none;
}

.product-card img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

.product-info {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
}

.product-tag {
    font-size: 11px;
    color: var(--main);
    font-weight: 500;
}

.product-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--main);
    margin-top: auto;
}

/* --- МОДАЛЬНОЕ ОКНО (ШТОРКА) --- */
.modal-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: none;
    align-items: flex-end;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);   
}

.modal-content {
    position: relative;
    width: 100%;
    background: var(--card);
    border-radius: 28px 28px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 500px;
    margin: 0 auto;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: var(--text);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-img {
    width: 100%;
    height: 50%;
    object-fit: cover;
}

.modal-body {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.modal-price {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--main);
    margin: 8px 0;
}

.modal-desc {
    font-size: 0.95rem;
    opacity: 0.8;
    margin-bottom: 20px;
}

.add-btn {
    width: 100%;
    padding: 18px;
    background: var(--main);
    color: #fff;
    border: none;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-top: auto;
}

/* --- КОРЗИНА --- */
.cart-section {
    margin: 32px 0;
    background: var(--card);
    padding: 20px;
    border-radius: 24px;
    box-shadow: 0 4px 15px var(--shadow-color);
}

.cart-header h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-list {
    list-style: none;
    margin-bottom: 20px;
}

    .cart-list li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 15px;
        background: var(--accent);
        border-radius: 14px;
        margin-bottom: 10px;
    }

/* Специальный стиль для строки доставки */
.delivery-item {
    background: var(--delivery-bg) !important;
    border: 1px dashed rgba(0,0,0,0.1);
}

.cart-item-text {
    display: flex;
    flex-direction: row; /* Изменили с column на row */
    align-items: baseline; /* Выравнивание по базовой линии текста */
    gap: 8px; /* Расстояние между именем и цветом */
    flex-wrap: wrap; /* Чтобы на очень узких экранах текст не вылезал за границы */
}

    .cart-item-text .name {
        font-weight: 600;
        font-size: 15px;
    }

    .cart-item-text .color {
        font-size: 12px;
        opacity: 0.7;
        margin-top: 1px;
    }

.delivery-price {
    font-weight: 700;
    color: var(--text);
}

.remove-btn {
    width: 32px;
    height: 32px;
    border: 1.5px solid var(--text);
    border-radius: 10px;
    background: #fff;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Поля ввода */
.order-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

    .order-fields input {
        width: 100%;
        padding: 16px;
        border: 1.5px solid var(--accent);
        border-radius: 14px;
        background: var(--bg);
        font-size: 16px;
        outline: none;
        transition: border-color 0.2s;
    }

        .order-fields input:focus {
            border-color: var(--main);
        }

/* Кнопка заказа */
.order-btn {
    width: 100%;
    padding: 20px;
    border-radius: 18px;
    border: none;
    font-size: 1.1rem;
    font-weight: 700;
    transition: all 0.2s;
    cursor: pointer;
}

    .order-btn:disabled {
        background: var(--disabled) !important;
        color: #6a6d70;
        cursor: not-allowed;
        transform: none;
    }

    .order-btn:not(:disabled) {
        background: var(--main);
        color: #fff;
        box-shadow: 0 4px 15px rgba(140, 74, 47, 0.3);
    }

        .order-btn:not(:disabled):active {
            transform: scale(0.98);
        }
/* Контейнер слайдера */
.slider-container {
    position: relative;
    width: 100%;
    height: 50vh; /* Ограничиваем высоту картинки на пол-экрана */
    overflow: hidden;
    background: #eee;
}

.slider-track {
    display: flex;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

    .slider-track .modal-img {
        min-width: 100%;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

/* Кнопки навигации */
.slider-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 50%;
    font-size: 20px;
    z-index: 5;
    cursor: pointer;
}

    .slider-nav.prev {
        left: 10px;
    }

    .slider-nav.next {
        right: 10px;
    }

/* Индикаторы (точки) */
.slider-dots {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 5;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.2s;
}

    .dot.active {
        background: #fff;
        transform: scale(1.3);
    }

/* Кнопки добавления в корзину в каталоге */
.card-actions {
    margin-top: 10px;
    height: 36px;
    width: 100%;
}

.cart-add-btn {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
    background: var(--main, #a73afd);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

    .cart-add-btn:active {
        opacity: 0.8;
    }

.cart-controls {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    height: 100%;
}

.cart-ctrl-btn {
    width: 40px;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--main, #a73afd);
    font-weight: bold;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .cart-ctrl-btn:active {
        background: rgba(0,0,0,0.05);
        border-radius: 8px;
    }

.cart-ctrl-count {
    font-weight: bold;
    font-size: 1em;
}

/* --- ПЛАВАЮЩАЯ КНОПКА КОРЗИНЫ --- */
.floating-cart-btn {
    font-size: 28px;
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: 20px;
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--main);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    z-index: 1000;
}

#floatingBadge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #fff;
    color: var(--main);
    font-size: 12px;
    font-weight: 800;
    min-width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
/* Анимация ухода вниз */
@keyframes slideDown {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(100%);
    }
}

/* Анимация исчезновения затемнения */
@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* Классы, которые мы будем добавлять через JS */
.modal-content.closing {
    animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.modal-overlay.closing {
    animation: fadeOut 0.3s ease forwards;
}

.modal-content, .slider-track, .spinner, .floating-cart-btn {
    will-change: transform, opacity; /* Подсказка браузеру */
    transform: translateZ(0); /* Принудительный слой GPU */
}