:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --border: #e5e7eb;
    --border-strong: #d7dade;
    --text: #1a1d24;
    --muted: #767c88;
    --accent: #2f6fed;
    --accent-dark: #2258c4;
    --accent-ink: #ffffff;
    --accent-tint: #eaf1ff;
    --danger: #d92d20;
    --ok: #17803d;
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 7px;
    --shadow-card: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-card-hover: 0 6px 18px rgba(16, 24, 40, .10);
    --shadow-pop: 0 20px 50px rgba(16, 24, 40, .18);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { -webkit-font-smoothing: antialiased; }
#app { min-height: 100vh; display: flex; flex-direction: column; }
button { font: inherit; }
::selection { background: var(--accent-tint); }

/* ── Header ─────────────────────────────────────────────────────────── */
.site-header {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 20px;
    height: 64px; padding: 0 24px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.site-header__brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 17px; letter-spacing: -.01em; flex: none;
    color: var(--text);
}
.site-header__brand-mark {
    width: 34px; height: 34px; border-radius: 9px; background: var(--accent);
    color: #fff; display: grid; place-items: center; flex: none;
}
.site-header__search { flex: 1; max-width: 480px; }
.site-header__search input {
    width: 100%; padding: 9px 14px; border-radius: var(--radius-md); border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-size: 14px; transition: border-color .15s, background .15s;
}
.site-header__search input:focus {
    outline: none; border-color: var(--accent); background: var(--surface);
}
.site-header__spacer { flex: 1; }
.cart-btn {
    position: relative; display: flex; align-items: center; gap: 8px; flex: none;
    padding: 9px 16px 9px 12px; border-radius: var(--radius-md); border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.cart-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cart-btn svg { width: 20px; height: 20px; flex: none; }
.cart-btn__badge {
    position: absolute; top: -6px; right: -6px;
    min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
    display: grid; place-items: center; line-height: 1;
}
.cart-btn__label { white-space: nowrap; }

/* ── Layout: sidebar + content ─────────────────────────────────────── */
.layout { flex: 1; display: flex; max-width: 1280px; width: 100%; margin: 0 auto; }

.sidebar { width: 240px; flex: none; padding: 24px 16px 24px 24px; }
.sidebar__title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 12px 10px; }
.sidebar__item {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 9px 12px; border-radius: var(--radius-md); border: none; background: none;
    color: var(--text); font-size: 14px; cursor: pointer; margin-bottom: 2px;
    transition: background .12s;
}
.sidebar__item:hover { background: var(--surface-2); }
.sidebar__item.is-active { background: var(--accent-tint); color: var(--accent-dark); font-weight: 600; }
.sidebar__icon { font-size: 16px; width: 20px; text-align: center; flex: none; }
.sidebar__count { margin-left: auto; font-size: 12px; color: var(--muted); }
.sidebar__item.is-active .sidebar__count { color: var(--accent-dark); }

/* Выпадающий список категорий — только на узких экранах (на широких работает сайдбар). */
.category-bar { display: none; }

.content { flex: 1; min-width: 0; padding: 24px 24px 48px; }
.content__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.content__title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.content__count { font-size: 13px; color: var(--muted); }

/* ── Product grid ───────────────────────────────────────────────────── */
.grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.card {
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    overflow: hidden; box-shadow: var(--shadow-card); transition: box-shadow .15s, border-color .15s, transform .15s;
}
.card:hover { box-shadow: var(--shadow-card-hover); border-color: var(--border-strong); transform: translateY(-1px); }
.card__media {
    height: 96px; display: grid; place-items: center; font-size: 34px; line-height: 1;
}
.card__body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card__tag {
    align-self: flex-start; font-size: 11px; font-weight: 600; color: var(--muted);
    background: var(--surface-2); border-radius: 999px; padding: 3px 9px;
}
.card__name { font-size: 13.5px; font-weight: 600; line-height: 1.35; min-height: 37px; color: var(--text); }
.card__foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card__price { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }

.stepper { display: flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.stepper button {
    width: 28px; height: 28px; border: none; background: var(--surface-2); color: var(--text);
    font-size: 16px; cursor: pointer; display: grid; place-items: center; line-height: 1;
}
.stepper button:hover { background: var(--border); }
.stepper__qty { min-width: 24px; text-align: center; font-weight: 600; font-size: 13px; }
.add-btn {
    padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--accent);
    background: var(--surface); color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer;
    transition: background .12s, color .12s;
}
.add-btn:hover { background: var(--accent); color: #fff; }

.empty { padding: 80px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.pager { display: flex; justify-content: center; padding: 28px 0 8px; }
.load-more-btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 22px; border-radius: 999px; border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
    transition: border-color .12s, background .12s;
}
.load-more-btn:hover { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-dark); }
.load-more-btn__rest {
    background: var(--surface-2); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--muted);
}
.load-more-btn:hover .load-more-btn__rest { background: #fff; color: var(--accent-dark); }

/* ── Drawers (cart / checkout) ─────────────────────────────────────── */
.sheet-backdrop {
    position: fixed; inset: 0; background: rgba(16, 24, 40, .38); z-index: 50;
    display: flex; justify-content: flex-end;
}
.sheet {
    width: 100%; max-width: 420px; height: 100%; overflow-y: auto;
    background: var(--surface); padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-pop);
    animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@media (max-width: 640px) {
    .sheet-backdrop { align-items: flex-end; }
    .sheet { max-width: 100%; height: auto; max-height: 90vh; border-radius: 18px 18px 0 0; }
    @keyframes slide-in { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet__title { font-size: 16px; font-weight: 700; }
.sheet__close {
    width: 30px; height: 30px; border-radius: 999px; border: none; background: var(--surface-2);
    color: var(--muted); font-size: 16px; cursor: pointer; display: grid; place-items: center;
}
.sheet__close:hover { background: var(--border); }

.line { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.line__name { flex: 1; font-size: 13.5px; line-height: 1.4; }
.line__price { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.line__remove {
    width: 26px; height: 26px; border-radius: 999px; border: none; background: none;
    color: var(--muted); font-size: 15px; cursor: pointer; display: grid; place-items: center; flex: none;
}
.line__remove:hover { background: var(--surface-2); color: var(--danger); }

.total-row { display: flex; justify-content: space-between; align-items: center; padding: 16px 0 4px; font-weight: 700; font-size: 16px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field select, .field input[type="date"] {
    width: 100%; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 14px;
}
.field select:focus, .field input[type="date"]:focus { outline: none; border-color: var(--accent); }

.primary-btn {
    width: 100%; padding: 12px; border: none; border-radius: var(--radius-md); background: var(--accent);
    color: var(--accent-ink); font-weight: 700; font-size: 14.5px; cursor: pointer; margin-top: 6px;
    transition: background .12s;
}
.primary-btn:hover { background: var(--accent-dark); }
.primary-btn[disabled] { opacity: .5; cursor: default; }

.empty-cart { text-align: center; padding: 40px 0; color: var(--muted); font-size: 14px; }

.error-msg { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.success { text-align: center; padding: 24px 0 8px; }
.success__icon {
    width: 52px; height: 52px; border-radius: 999px; background: #dcfce7; color: var(--ok);
    display: grid; place-items: center; margin: 0 auto 14px; font-size: 26px;
}
.success h3 { margin: 0 0 6px; font-size: 16px; }
.success p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ── Responsive: two-row header + horizontal category scroller ────── */
@media (max-width: 900px) {
    .site-header {
        flex-wrap: wrap; height: auto; min-height: 56px; padding: 10px 14px; gap: 10px 12px;
        row-gap: 10px;
    }
    .site-header__brand { font-size: 15px; }
    .site-header__brand-mark { width: 30px; height: 30px; font-size: 15px; }
    .site-header__spacer { display: none; }
    .site-header__search { order: 3; flex-basis: 100%; max-width: none; }
    /* Распорка скрыта, поэтому прижимаем корзину к правому краю сами. */
    .cart-btn { padding: 8px 12px; margin-left: auto; }
    .cart-btn__label { display: none; }
    .cart-btn svg { width: 19px; height: 19px; }

    .layout { flex-direction: column; }
    .sidebar { display: none; }

    .category-bar {
        display: flex; align-items: center; gap: 10px;
        padding: 11px 14px;
        background: var(--surface); border-bottom: 1px solid var(--border);
    }
    .category-bar__label {
        flex: none; font-size: 13px; font-weight: 600; color: var(--muted);
    }
    .category-bar__select {
        flex: 1; min-width: 0;
        padding: 10px 12px; border-radius: var(--radius-md);
        border: 1px solid var(--border-strong); background: var(--surface);
        color: var(--text); font-size: 14.5px; font-weight: 500;
        /* Нативная стрелка съедает место — рисуем свою и убираем стандартную. */
        appearance: none; -webkit-appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23767c88' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 34px;
    }
    .category-bar__select:focus { outline: none; border-color: var(--accent); }
    .content { padding: 16px 14px 36px; }
    .content__head { margin-bottom: 12px; }
    .content__title { font-size: 17px; }
    .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card__media { height: 84px; font-size: 30px; }
    .card__body { padding: 10px 11px 11px; }
    .card__name { font-size: 12.5px; min-height: 34px; }
    .card__price { font-size: 14px; }
    .add-btn { padding: 6px 10px; font-size: 12px; }
    .stepper button { width: 26px; height: 26px; }
    .pager { padding: 20px 0 4px; }
    .load-more-btn { width: 100%; justify-content: center; padding: 12px; }
}
