* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
.text-secondary, .text-secondary * { color: var(--hint) !important; }
.verified { color: var(--link); }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--link); font-weight: 600; font-size: .9rem; }

.app-content {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar-h-mobile) + 40px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

/* ==========================================================================
   НАВБАР: 3 ФОРМ-ФАКТОРА (Desktop Header / Tablet Bar / Mobile & TG TabBar)
   ========================================================================== */

/* 1. Базовый режим: Mobile (<= 767px) или Telegram Mini App (html.is-tg-webapp) */
.store-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tabbar-h-mobile) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface-elevated);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    z-index: 200;
}

.store-nav__inner {
    height: 100%;
    display: flex;
    align-items: center;
}

.store-nav__left,
.store-nav__search {
    display: none;
}

.store-nav__links {
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.store-nav__item {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    color: var(--hint);
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.18s var(--ease), background-color 0.18s var(--ease);
}

.store-nav__item.is-active {
    color: var(--accent);
    font-weight: 600;
}

.store-nav__icon {
    font-size: 1.25rem;
    line-height: 1;
}

.store-nav__badge {
    position: absolute;
    top: 2px;
    right: 50%;
    transform: translateX(22px);
    background: #ff3b30;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* 2. Общие правила для верхней шапки в браузере (Tablet + Desktop >= 768px) */
@media (min-width: 768px) {
    html:not(.is-tg-webapp) .store-nav {
        top: 0;
        bottom: auto;
        padding-bottom: 0;
        border-top: none;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-sm);
    }

    html:not(.is-tg-webapp) .store-nav__inner {
        max-width: var(--container-max);
        margin: 0 auto;
        justify-content: space-between;
    }

    html:not(.is-tg-webapp) .store-nav__item--mobile-only {
        display: none;
    }

    html:not(.is-tg-webapp) .store-nav__left {
        display: flex;
        align-items: center;
        gap: 14px;
        flex-shrink: 0;
    }

    html:not(.is-tg-webapp) .store-nav__brand {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-weight: 800;
        letter-spacing: -0.02em;
    }

    html:not(.is-tg-webapp) .store-nav__catalog-btn {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 9px 15px;
        border-radius: var(--radius-sm);
        background: var(--accent);
        color: var(--accent-text);
        font-weight: 600;
        font-size: 0.9rem;
        transition: background-color 0.18s var(--ease);
    }

    html:not(.is-tg-webapp) .store-nav__catalog-btn:hover {
        background: var(--accent-hover);
        color: var(--accent-text);
    }

    html:not(.is-tg-webapp) .store-nav__search {
        display: flex;
        align-items: center;
        flex: 1;
        max-width: 520px;
        margin: 0 20px;
        position: relative;
    }

    html:not(.is-tg-webapp) .store-nav__search-icon {
        position: absolute;
        left: 14px;
        color: var(--hint);
        pointer-events: none;
    }

    html:not(.is-tg-webapp) .store-nav__search-input {
        width: 100%;
        height: 40px;
        padding: 0 34px 0 38px;
        border-radius: 12px;
        border: 1px solid var(--border);
        background: var(--bg);
        color: var(--text);
        font-size: 0.9rem;
        transition: border-color 0.18s var(--ease), background-color 0.18s var(--ease);
    }

    html:not(.is-tg-webapp) .store-nav__search-input:focus {
        outline: none;
        background: var(--surface);
        border-color: var(--accent);
    }

    html:not(.is-tg-webapp) .store-nav__search-clear {
        position: absolute;
        right: 12px;
        color: var(--hint);
        font-size: 0.85rem;
    }

    html:not(.is-tg-webapp) .store-nav__links {
        width: auto;
        gap: 6px;
    }

    html:not(.is-tg-webapp) .store-nav__item.is-active {
        background: var(--accent-soft);
        color: var(--text);
        font-weight: 600;
        opacity: 1;
    }
    /* Скрываем второй инпут поиска в теле каталога, так как поиск уже в верхней шапке */
    html:not(.is-tg-webapp) .app-content .search-bar {
        justify-content: flex-end;
    }
    html:not(.is-tg-webapp) .app-content .search-bar__input {
        display: none;
    }
}

/* 3. Специфика Tablet (768px – 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    html:not(.is-tg-webapp) .app-content {
        padding: calc(var(--header-h-tablet) + 20px) 24px 48px;
    }

    html:not(.is-tg-webapp) .store-nav {
        height: var(--header-h-tablet);
    }

    html:not(.is-tg-webapp) .store-nav__inner {
        padding: 0 24px;
    }

    html:not(.is-tg-webapp) .store-nav__brand {
        font-size: 1.1rem;
    }

    html:not(.is-tg-webapp) .store-nav__item {
        flex: none;
        flex-direction: row;
        gap: 7px;
        padding: 8px 14px;
        border-radius: 999px;
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--text);
        opacity: 0.82;
    }
}

/* 4. Специфика Desktop (>= 1024px) */
@media (min-width: 1024px) {
    html:not(.is-tg-webapp) .app-content {
        padding: calc(var(--header-h-desktop) + 28px) 32px 64px;
    }

    html:not(.is-tg-webapp) .store-nav {
        height: var(--header-h-desktop);
    }

    html:not(.is-tg-webapp) .store-nav__inner {
        padding: 0 32px;
    }

    html:not(.is-tg-webapp) .store-nav__brand {
        font-size: 1.25rem;
    }

    html:not(.is-tg-webapp) .store-nav__item {
        flex: none;
        flex-direction: row;
        gap: 7px;
        padding: 8px 14px;
        border-radius: 999px;
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--text);
        opacity: 0.82;
    }

    html:not(.is-tg-webapp) .store-nav__item:hover {
        background: var(--accent-soft);
        opacity: 1;
    }

    html:not(.is-tg-webapp) .store-nav__icon {
        font-size: 1.05rem;
    }

    html:not(.is-tg-webapp) .store-nav__badge {
        position: static;
        transform: none;
        margin-left: 2px;
    }
}

/* ==========================================================================
   ОБЩИЕ КОМПОНЕНТЫ (Кнопки, поиск, чипсы категорий, профиль, поддержка)
   ========================================================================== */
.page-title { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 16px; }
.section-title { font-size: 1.15rem; font-weight: 700; margin: 24px 0 12px; }

.btn-outline-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    font-size: 0.85rem; font-weight: 600;
}

.btn-buy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    white-space: nowrap;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 13px 18px;
    cursor: pointer;
    transition: background-color 0.18s var(--ease), transform 0.12s var(--ease);
}

.btn-buy:hover { background: var(--accent-hover); }
.btn-buy:active { transform: scale(0.99); }
.btn-buy:disabled { opacity: 0.5; cursor: default; }
.btn-buy--ok { background: #34c759 !important; }

/* Поиск и сортировка в каталоге */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar__input {
    flex: 1; height: 42px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); color: var(--text); font-size: 0.9rem;
}
.search-bar__input:focus { outline: none; border-color: var(--accent); }
.search-bar__sort {
    appearance: none; -webkit-appearance: none;
    border: 1px solid var(--border); border-radius: 12px; height: 42px;
    padding: 0 32px 0 12px; background-color: var(--surface); color: var(--text); font-size: 0.85rem; cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://w3.org' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center; background-size: 11px;
}

/* Лента чипсов категорий */
.category-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 8px; }
.category-chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    white-space: nowrap; padding: 7px 14px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); font-size: 0.85rem; font-weight: 500;
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Профиль, поддержка и шапка магазина */
.profile-card { text-align: center; padding: 12px 0 20px; }
.profile-card__avatar {
    width: 88px; height: 88px; border-radius: 50%; overflow: hidden; margin: 0 auto 12px;
background: var(--surface); border: 1px solid var(--border);
display: flex; align-items: center; justify-content: center; font-size: 2.4rem;
}
.profile-card__avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-card__name { font-size: 1.2rem; font-weight: 700; }
.profile-card__id { font-size: 0.8rem; color: var(--hint); margin-top: 4px; }
.profile-actions { display: flex; flex-direction: column; gap: 10px; max-width: 480px; margin: 0 auto; }
.profile-action {
display: block; padding: 14px 18px; border-radius: var(--radius-md);
background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600;
}
.profile-action--accent { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.shop-header { text-align: center; padding: 8px 0 16px; }
.shop-header__logo { width: 88px; height: 88px; border-radius: 50%; overflow: hidden; margin: 0 auto 12px; background: var(--surface); }
.shop-header__logo img { width: 100%; height: 100%; object-fit: cover; }
.shop-header__placeholder {
width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
font-size: 2.4rem; font-weight: 800; color: #fff;
background: linear-gradient(135deg, hsl(var(--hue, 220), 75%, 58%), hsl(calc(var(--hue, 220) + 45), 80%, 46%));
}
.shop-header__name { font-size: 1.35rem; font-weight: 800; margin: 0; }
.shop-header__desc { font-size: 0.9rem; color: var(--hint); margin: 8px 0 0; }
.support-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; margin-bottom: 12px; }
.support-hint { font-size: 0.88rem; color: var(--hint); margin: 0 0 10px; }
.support-textarea {
width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px;
background: var(--bg); color: var(--text); font-size: 0.95rem; resize: vertical; font-family: inherit;
}
.support-send-btn {
margin-top: 10px; width: 100%; border: none; border-radius: var(--radius-sm); padding: 12px;
background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 0.95rem; cursor: pointer;
}
.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px; }
.ticket-card__top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ticket-card__id { font-weight: 700; font-size: 0.92rem; }
.ticket-card__subject { margin: 6px 0; font-size: 0.92rem; }
.ticket-card__meta { font-size: 0.76rem; color: var(--hint); }
.ticket-status { font-size: 0.72rem; padding: 3px 9px; border-radius: 8px; white-space: nowrap; background: rgba(128,128,128,.16); }
.ticket-status.status--open { background: rgba(255,149,0,.18); color: #d97706; }
.ticket-status.status--answered { background: rgba(52,199,89,.18); color: #16a34a; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.bubble { max-width: 85%; padding: 10px 12px; border-radius: 14px; }
.bubble--me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.bubble--staff { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble__author { font-size: 0.72rem; opacity: 0.8; margin-bottom: 3px; }
.bubble__text { font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; }
.bubble__time { font-size: 0.68rem; opacity: 0.65; margin-top: 4px; text-align: right; }
.catalog-loader { display: flex; justify-content: center; padding: 20px 0; }
.catalog-spinner {
width: 26px; height: 26px; border-radius: 50%;
border: 3px solid rgba(128,128,128,.25); border-top-color: var(--accent);
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state__icon { font-size: 3rem; }

.sort-container {
  display: flex;
  justify-content: flex-end; /* Сдвигает форму с кнопкой вправо */
  width: 100%; /* Растягивает контейнер на всю доступную ширину */
}