/*
 * Дизайн-токены (цвета/шрифты) извлечены 1:1 из local/templates/main/assets/css/main.css,
 * чтобы Web App визуально совпадал с сайтом kshop.uz (main.css:1, main.css:2280-2330).
 * Структура layout (нижняя навигация, компактные карточки, минималистичная
 * шапка) — по образцу референса от пользователя, палитра — своя, kshop-овая.
 */
@import url("https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Poiret+One&display=swap");

:root {
    --brand: #FF63B0;
    --brand-light: #FFB7DA;
    --brand-border: #FDD6E9;
    --disabled-bg: #E6E2E4;
    --disabled-text: #DBD0D9;
    --muted: #9F8189;
    --text: #2b2b2b;
    --bg: #ffffff;
    --bg-soft: #FFF6FA;
    --card-radius: 16px;
    --btn-radius: 10px;
    --tabbar-height: 54px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-soft);
    color: var(--text);
    font-family: "Montserrat", sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 8px);
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
}

/* Минималистичная белая шапка — Telegram уже даёт своё название/крестик,
   здесь только заголовок текущего экрана + при необходимости "назад". */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg);
    color: var(--text);
    padding: 14px 16px;
    border-bottom: 1px solid var(--brand-border);
}

.app-header .back {
    color: var(--brand);
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
}

.app-header .title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Поиск закреплён в шапке (sticky), а не в потоке страницы */
.app-header-search {
    padding: 10px 16px;
}

.app-header-search .search-form {
    flex: 1;
    margin-bottom: 0;
}

.container {
    padding: 12px 12px 8px;
}

/* Приветственная карусель баннеров на главной */
/*
 * Слайдер — горизонтальный scroll-snap (свайп пальцем работает всегда, даже
 * без JS). initBannerCarousel() в app.js достраивает сверху точки-индикаторы
 * и автопрокрутку; при одном баннере JS ничего не делает — выглядит как
 * обычная картинка, скролл не появляется.
 */
.home-banner-carousel {
    margin-bottom: 14px;
}

.home-banner-slider {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
    border-radius: var(--card-radius);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.home-banner-slider::-webkit-scrollbar {
    display: none;
}

.home-banner-slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(159, 129, 137, 0.15);
}

.home-banner-slide img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    pointer-events: none;
}

.home-banner-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.home-banner-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: var(--brand-border);
    transition: background 0.2s, transform 0.2s;
}

.home-banner-dot.active {
    background: var(--brand);
    transform: scale(1.2);
}

/* Поиск на главной */
.search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.search-form input[type="search"] {
    flex: 1;
    border: 1px solid var(--brand-border);
    border-radius: 999px;
    padding: 11px 16px;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--bg-soft);
    color: var(--text);
}

.search-form input[type="search"]::placeholder {
    color: var(--muted);
}


/* Заголовок секции ("🔥 Хиты продаж" и т.п.) */
.section-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 14px 2px 10px;
}

/* Список разделов */
/* Разделы каталога — блоками (картинка + название), как товары */
.section-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.section-card {
    background: var(--bg);
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(159, 129, 137, 0.12);
    display: block;
    text-align: center;
}

.section-card .img {
    position: relative;
    width: 100%;
    padding-top: 78%;
    background: var(--bg-soft);
}

.section-card .img img,
.section-card .img .no-photo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.75rem;
}

.section-card .name {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
    line-height: 1.3;
    padding: 14px 12px;
}

/* Сетка товаров */
.product-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 12px;
}

.product-card {
    background: var(--bg);
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(159, 129, 137, 0.12);
    display: flex;
    flex-direction: column;
    height: 100%;
}

/*
 * Квадратный блок картинки через классический padding-top-хак, а не
 * CSS aspect-ratio: свойство aspect-ratio не всегда поддерживается
 * встроенным WebView Telegram на старых Android-клиентах, из-за чего
 * карточки без фото "схлопывались" и были короче карточек с фото.
 */
.product-card .img {
    position: relative;
    width: 100%;
    padding-top: 100%;
    background: var(--bg-soft);
    display: block;
}

.product-card .img img,
.product-card .img .no-photo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.75rem;
    text-align: center;
}

.product-card .img img {
    object-fit: cover;
}

/* Компактная кнопка "+" поверх фото вместо полноширинной плашки —
   ближе к референсу и меньше отвлекает от самой карточки. */
.product-card .quick-add {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 2;
}

.product-card .info {
    padding: 10px 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.product-card .price {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--brand);
}

.product-card .name {
    font-size: 0.8rem;
    line-height: 1.25;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.4em;
}

.product-card .stock {
    font-size: 0.72rem;
    color: var(--muted);
}

/* Круглая кнопка быстрого добавления ("+") */
.quick-add-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--brand);
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(255, 99, 176, 0.45);
    cursor: pointer;
}

/* Компактный степпер (используется и как quick-add, и на карточке товара) */
.stepper {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--brand);
    border-radius: 999px;
    padding: 2px;
    box-shadow: 0 2px 6px rgba(255, 99, 176, 0.45);
}

.stepper button {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stepper button:disabled {
    opacity: 0.5;
}

.stepper .qty {
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 16px;
    text-align: center;
}

/* Полноширинный вариант степпера — карточка товара (sticky-bottom) */
.stepper.full {
    width: 100%;
    justify-content: space-between;
    padding: 4px 6px;
    border-radius: var(--btn-radius);
}

.stepper.full button {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 1.2rem;
}

.stepper.full .qty {
    font-size: 0.95rem;
}

/* Обычные кнопки (используются на карточке товара, чекбоксах и т.п.) */
.btn {
    text-align: center;
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    line-height: 1.4rem;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    border: none;
    border-radius: var(--btn-radius);
    cursor: pointer;
    background: var(--brand);
    color: #fff;
}

.btn.outline {
    background: transparent;
    color: var(--brand);
    border: 1px solid var(--brand-border);
}

/* Детальная карточка товара */
.product-detail .img {
    position: relative;
    width: 100%;
    padding-top: 100%;
    background: var(--bg-soft);
    border-radius: var(--card-radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.product-detail .img img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.product-detail h1 {
    font-size: 1.1rem;
    margin: 0 0 6px;
}

.product-detail .price {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--brand);
    margin-bottom: 4px;
}

.product-detail .stock {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.product-detail .description {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 16px;
    white-space: pre-line;
}

.sticky-bottom {
    position: sticky;
    bottom: var(--tabbar-height);
    background: var(--bg);
    padding: 10px 12px;
    box-shadow: 0 -2px 10px rgba(159, 129, 137, 0.12);
    z-index: 15;
}

/*
 * Нижняя навигация — по образцу референса: иконки без подписей,
 * активный пункт получает розовую "таблетку" вокруг иконки.
 */
.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--bg);
    box-shadow: 0 -2px 12px rgba(159, 129, 137, 0.15);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}

.tab-item {
    position: relative;
    flex: 0 0 84px;
    width: 84px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 30px;
    border-radius: 999px;
    color: var(--muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-item svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tab-item.active {
    color: #fff;
    background: var(--brand);
}

/* Тост */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-height) + 14px);
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 40px 16px;
    font-size: 0.9rem;
}

/* Счётчик товаров на вкладке корзины */
.tab-icon {
    position: relative;
    display: flex;
}

.tab-badge {
    position: absolute;
    top: -9px;
    left: 13px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ff4d4f;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border: 2px solid var(--bg);
    box-sizing: content-box;
}

.tab-badge[hidden] {
    display: none;
}

/* Корзина */
.cart-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 12px 4px 2px;
}

.cart-sub {
    font-style: italic;
    color: var(--muted);
    font-size: 0.88rem;
    margin: 0 4px 12px;
    min-height: 1.2em;
}

.cart-item {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--bg);
    border-radius: var(--card-radius);
    padding: 8px;
    margin-bottom: 10px;
    box-shadow: 0 2px 10px rgba(159, 129, 137, 0.12);
}

.cart-img {
    flex: 0 0 84px;
    width: 84px;
    height: 84px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: center;
}

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

.cart-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

.cart-name {
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-price {
    color: var(--brand);
    font-weight: 600;
    font-size: 0.85rem;
}

.cart-item .stepper {
    background: var(--bg);
    border: 1px solid var(--brand-border);
    box-shadow: none;
}

.cart-item .stepper button,
.cart-item .stepper .qty {
    color: var(--text);
}
