/* --- ПЕРЕМЕННЫЕ --- */
:root {
    --main: #ffffff;
    --bg: #f8f4f0;
    --card: #ffffff;
    --text: #2b2b2b;
    --accent: #ffffff; /* Цвет фона обычных товаров в корзине */
    --delivery-bg: rgba(0, 0, 0, 0.04); /* Фон для строки доставки */
    --shadow-color: rgba(0, 0, 0, 0.08);
    --disabled: #e2e8f0; /* UI-ИЗМЕНЕНИЕ: Более чистый базовый цвет для неактивных элементов */
    --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 !important;
}

/* --- ШАПКА --- */
.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: 16px;
    font-weight: 600;
}

.product-tag {
    font-size: 15px;
    color: var(--main);
    font-weight: 500;
}

.product-price {
    font-size: 18px;
    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);
    transition: all 0.3s ease;
}

    /* UI-ИЗМЕНЕНИЕ: Если через JS добавляется класс пустоты, плавно скрываем инпуты оформления, чтобы не перегружать интерфейс */
    .cart-section.is-empty .order-fields {
        display: none;
    }

.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;
    align-items: center; /* Центрирует всё по вертикали */
    justify-content: space-between;
    padding: 12px 15px;
    background: rgb(from var(--accent) r g b / 0.1);
    border-radius: 14px;
    margin-bottom: 10px;
}

/* Контейнер текста (имя + цвет) */
.cart-item-text {
    display: flex;
    flex-direction: column; /* Цвет под именем */
    gap: 2px; /* Небольшой отступ между именем и цветом */
    flex-grow: 1; /* Занимает место слева */
}

/* Блок цены и кнопки (справа) */
.cart-item-price-wrapper {
    display: flex;
    align-items: center;
    gap: 15px; /* Расстояние между ценой и крестиком */
    margin-left: 20px; /* Отступ от текстового блока */
}

.cart-item-price {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap; /* Чтобы цена не переносилась */
}

/* Контейнер для названия и цвета */
.cart-item-text {
    display: flex;
    flex-direction: column; /* Название сверху, цвет снизу */
    margin-right: 10px;
    flex-grow: 1; /* Занимает доступное место */
}

.cart-item-text .name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.cart-item-text .color {
    font-size: 13px;
    opacity: 0.7;
    margin-top: 2px;
}

/* Блок цены и кнопки удаления */
.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 12px; /* Расстояние между ценой и кнопкой × */
    flex-shrink: 0; /* Не дает цене сжиматься */
}

.cart-item-price {
    font-weight: 700;
    font-size: 15px;
}

.delivery-price {
    font-weight: 700;
    color: var(--text);
}

.remove-btn {
    width: 32px;
    height: 32px;
    border: 1.5px solid var(--text);
    border-radius: 10px;
    background: rgb(from var(--accent) r g b / 0.1);
    font-size: 21px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Поля ввода */
.order-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

    /* UI-ИЗМЕНЕНИЕ: Увеличен отступ сверху текста описания, чтобы отделить его от списка товаров */
    .order-fields p {
        font-size: 0.95rem;
        font-weight: 500;
        margin-top: 8px;
        margin-bottom: 2px;
        color: #4a4a4a;
    }

    /* UI-ИЗМЕНЕНИЕ: Границы инпута заменены на нейтральные серые в обычном состоянии для явного UX-акцента при фокусе */
    .order-fields input {
        width: 100%;
        padding: 16px;
        border: 1.5px solid #d1d5db;
        border-radius: 14px;
        background: var(--bg);
        font-size: 16px;
        outline: none;
        transition: border-color 0.2s, box-shadow 0.2s;
    }

        /* При фокусе инпут ярко подсвечивается основным цветом */
        .order-fields input:focus {
            border-color: var(--main);
            box-shadow: 0 0 0 3px rgb(from var(--main) r g b / 0.12);
        }

        .order-fields input::placeholder {
            color: #374151; /* Темно-серый контрастный цвет */
            opacity: 1; /* Сбрасываем стандартную полупрозрачность браузера */
            font-weight: 500;
        }

/* Кнопка заказа */
.order-btn {
    width: 100%;
    padding: 20px;
    border-radius: 18px;
    border: none;
    font-size: 1.1rem;
    font-weight: 700;
    transition: all 0.2s;
    cursor: pointer;
}

    /* UI-ИЗМЕНЕНИЕ: Значительно улучшена контрастность текста на заблокированной кнопке заказа */
    .order-btn:disabled {
        background: var(--disabled) !important;
        color: #71777f;
        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 */
}
/* Перекрываем стили, чтобы окно успеха работало независимо */
#successModal {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999 !important;
    background: rgba(0, 0, 0, 0.6) !important;
    display: none;
    align-items: center;
    justify-content: center;
}

    #successModal .modal-content {
        animation: none !important; /* Убираем анимацию, чтобы не было "дерганий" */
        transform: scale(1);
        width: 85%;
        max-width: 320px;
        padding: 25px;
        border-radius: 20px;
        text-align: center;
        margin: 0 auto;
    }
.spinner-small {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top: 3px solid var(--main);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px auto;
}
#cartList li {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
/* --- СЕТКА КНОПОК ВРЕМЕНИ --- */
.time-grid {
    display: grid;
    /* Кнопки будут автоматически подстраиваться под ширину экрана */
    grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
    gap: 10px;
    margin-top: 15px;
    margin-bottom: 5px;
}

.time-btn {
    padding: 12px 10px;
    border: 1.5px solid var(--main);
    background: transparent;
    color: var(--text);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

    /* Эффект при клике на неактивную кнопку */
    .time-btn:not(.active):active {
        background: rgba(0, 0, 0, 0.05);
    }

    /* Выбранное время */
    .time-btn.active {
        background: var(--main);
        color: #fff;
        box-shadow: 0 4px 10px rgb(from var(--main) r g b / 0.3);
    }
/* Перекрашиваем выбранную дату в ваш основной цвет */
.flatpickr-calendar {
    width: 100% !important; /* На всю ширину контейнера */
    box-shadow: none !important;
    border: 1.5px solid #d1d5db !important;
    border-radius: 20px !important;
}

/* Красим дни в ваш основной цвет */
.flatpickr-day.selected {
    background: var(--main) !important;
    border-color: var(--main) !important;
}

/* Улучшаем читаемость заголовка месяца */
.flatpickr-current-month {
    font-weight: 700;
}
/* Стили для поля с ошибкой валидации */
.error-field {
    border: 2px solid #ff4d4d !important;
    background-color: rgba(255, 77, 77, 0.05) !important;
    animation: shake 0.3s ease-in-out; /* Эффект тряски поля */
}

/* Эффект легкой тряски для привлечения внимания */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}