/* ===== Telegram theme variables (с фолбэками для браузера) ===== */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1c1c1e);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --link: var(--tg-theme-link-color, #2481cc);
    --button: var(--tg-theme-button-color, #2481cc);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --card-bg: var(--tg-theme-secondary-bg-color, #f3f3f7);
    --radius: 14px;
    --nav-h: 64px;
}

* { box-sizing: border-box; }

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

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

.app-content {
    padding-top: 14px;
    padding-bottom: calc(var(--nav-h) + 48px + env(safe-area-inset-bottom));
    max-width: 720px;
    min-height: 100vh;
}

.page-title { font-size: 1.5rem; font-weight: 700; margin: 4px 0 16px; }
.section-title { font-size: 1.1rem; font-weight: 600; margin: 24px 0 12px; }
.text-secondary, .text-secondary * { color: var(--hint) !important; }
.verified { color: var(--link); }

/* ===== Bottom navigation ===== */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: var(--nav-h);
    display: flex; justify-content: space-around; align-items: center;
    background: var(--bg);
    border-top: 1px solid rgba(128,128,128,.2);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
}
.bottom-nav__item {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--hint); font-size: .72rem; flex: 1; padding: 6px 0;
}
.bottom-nav__item.is-active { color: var(--link); }
.bottom-nav__icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav__badge {
    position: absolute; top: 0; right: 50%; transform: translateX(22px);
    background: #ff3b30; color: #fff; font-size: .65rem; font-weight: 700;
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
}

/* ===== Back link (браузерный fallback) ===== */
.back-link { display: inline-block; margin-bottom: 12px; color: var(--link); font-weight: 600; font-size: .9rem; }

/* ===== Search bar ===== */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar__input {
    flex: 1; border: none; border-radius: 10px; padding: 10px 14px;
    background: var(--card-bg); color: var(--text); font-size: .9rem;
}
.search-bar__input:focus { outline: 2px solid var(--button); }
.search-bar__sort {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    border: none; border-radius: 10px; height: 42px;
    padding: 0 30px 0 12px;
    background-color: var(--card-bg); color: var(--text); font-size: .85rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' 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;
}
.search-bar__input { height: 42px; padding: 0 14px; }

/* ===== Infinite scroll loader ===== */
.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(--link);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Category chips ===== */
.category-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 4px; }
.category-chips::-webkit-scrollbar { display: none; }
.chip {
    white-space: nowrap; padding: 7px 14px; border-radius: 999px;
    background: var(--card-bg); color: var(--text); font-size: .85rem; font-weight: 500;
}
.chip.is-active { background: var(--button); color: var(--button-text); }

/* ===== Product grid / card ===== */
.product-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.product-card {
    background: var(--card-bg); border-radius: var(--radius); overflow: hidden;
    display: flex; flex-direction: column;
}
.product-card__photo { position: relative; aspect-ratio: 16/10; background: rgba(128,128,128,.12); }
.product-card__photo img { width: 100%; height: 100%; object-fit: cover; }
.product-card__placeholder,
.product-detail__placeholder,
.cart-item__placeholder,
.shop-header__placeholder {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.4rem;
}
.product-card__badge {
    position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); color: #fff;
    font-size: .68rem; padding: 3px 7px; border-radius: 8px;
}
.product-card__body { padding: 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.product-card__title { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.product-card__desc { font-size: .78rem; color: var(--hint); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.product-card__footer { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.product-card__price { font-weight: 700; font-size: .95rem; }
.product-card__shop { font-size: .72rem; color: var(--hint); text-align: right; }

/* ===== Product detail ===== */
.product-detail__photo { aspect-ratio: 16/10; border-radius: var(--radius); overflow: hidden; background: var(--card-bg); margin-bottom: 16px; }
.product-detail__photo img { width: 100%; height: 100%; object-fit: cover; }
.product-detail__title { font-size: 1.4rem; font-weight: 700; margin: 0 0 8px; }
.product-detail__shop { display: inline-flex; gap: 4px; color: var(--link); font-size: .9rem; }
.product-detail__category { display: inline-block; margin-left: 8px; font-size: .8rem; color: var(--hint); }
.product-detail__price { font-size: 1.6rem; font-weight: 800; margin: 16px 0 6px; }
.product-detail__stock { font-size: .85rem; margin-bottom: 14px; }
.product-detail__stock.in { color: #34c759; }
.product-detail__stock.out { color: #ff3b30; }
.product-detail__description { font-size: .95rem; line-height: 1.5; color: var(--text); margin-bottom: 18px; }

/* ===== Quantity control ===== */
.qty-control { display: inline-flex; align-items: center; gap: 18px; background: var(--card-bg); border-radius: 999px; padding: 6px 14px; margin-bottom: 14px; }
.qty-control__btn { border: none; background: transparent; color: var(--text); font-size: 1.4rem; width: 28px; height: 28px; line-height: 1; cursor: pointer; }
.qty-control__value { min-width: 24px; text-align: center; font-weight: 600; }

/* ===== Buy button ===== */
.btn-buy {
    display: block; width: 100%; border: none; border-radius: var(--radius);
    background: var(--button); color: var(--button-text);
    font-size: 1rem; font-weight: 600; padding: 14px; cursor: pointer;
}
.btn-buy:disabled { opacity: .5; cursor: default; }
.btn-buy--ok { background: #34c759 !important; transition: background .2s; }

/* ===== Cart ===== */
.cart-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.cart-item { display: flex; gap: 12px; background: var(--card-bg); border-radius: var(--radius); padding: 10px; align-items: center; }
.cart-item__photo { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; flex-shrink: 0; background: rgba(128,128,128,.12); }
.cart-item__photo img { width: 100%; height: 100%; object-fit: cover; }
.cart-item__placeholder { font-size: 1.6rem; }
.cart-item__body { flex: 1; min-width: 0; }
.cart-item__title { font-weight: 600; font-size: .92rem; }
.cart-item__meta { font-size: .8rem; color: var(--hint); }
.cart-item__right { text-align: right; }
.cart-item__subtotal { font-weight: 700; }
.cart-item__remove { border: none; background: transparent; color: #ff3b30; font-size: .78rem; cursor: pointer; padding: 4px 0 0; }
.cart-qty { display: inline-flex; align-items: center; gap: 12px; margin-top: 6px; background: rgba(128,128,128,.12); border-radius: 999px; padding: 2px 10px; }
.cart-qty__btn { border: none; background: transparent; color: var(--text); font-size: 1.1rem; width: 22px; height: 22px; line-height: 1; cursor: pointer; }
.cart-qty__value { min-width: 20px; text-align: center; font-weight: 600; font-size: .9rem; }
.cart-summary {
    background: var(--card-bg); border-radius: var(--radius); padding: 16px;
    position: sticky; bottom: calc(var(--nav-h) + 10px); z-index: 50;
    box-shadow: 0 -4px 16px rgba(0,0,0,.12);
}
.cart-summary__row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 1.05rem; }
.cart-summary__total { font-weight: 800; }

/* ===== Orders ===== */
.order-list { display: flex; flex-direction: column; gap: 12px; }
.order-card { background: var(--card-bg); border-radius: var(--radius); padding: 14px; }
.order-card__head { display: flex; justify-content: space-between; align-items: center; }
.order-card__id { font-weight: 700; }
.order-card__status { font-size: .75rem; padding: 3px 9px; border-radius: 8px; background: rgba(128,128,128,.2); }
.order-card__status.status--paid, .order-card__status.status--delivered { background: rgba(52,199,89,.2); color: #34c759; }
.order-card__status.status--refunded { background: rgba(255,59,48,.2); color: #ff3b30; }
.order-card__date { font-size: .78rem; color: var(--hint); margin: 4px 0 10px; }
.order-card__items { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.order-card__items li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.order-card__items li > span:first-child { min-width: 0; word-break: break-word; }
.order-card__items li > span:last-child { white-space: nowrap; flex-shrink: 0; }
.order-card__keys { flex-direction: column; gap: 4px; }
.order-card__keys code { display: block; background: rgba(128,128,128,.15); padding: 4px 8px; border-radius: 6px; font-size: .78rem; word-break: break-all; }
.order-card__total { margin-top: 10px; font-weight: 700; text-align: right; }
.order-refund-btn { margin-top: 10px; width: 100%; border: 1px solid #ff3b30; background: transparent; color: #ff3b30; border-radius: 10px; padding: 9px; font-size: .85rem; font-weight: 600; cursor: pointer; }
.order-refund-btn:disabled { opacity: .5; }

/* ===== Shop header ===== */
.shop-header { text-align: center; padding: 8px 0 4px; }
.shop-header__logo { width: 88px; height: 88px; border-radius: 50%; overflow: hidden; margin: 0 auto 12px; background: var(--card-bg); }
.shop-header__logo img { width: 100%; height: 100%; object-fit: cover; }
.shop-header__logo .shop-header__placeholder {
    font-size: 2.4rem; font-weight: 800; color: #fff; letter-spacing: .5px;
    background: linear-gradient(135deg, hsl(var(--hue, 220), 75%, 58%), hsl(calc(var(--hue, 220) + 45), 80%, 46%));
    text-shadow: 0 1px 2px rgba(0,0,0,.18);
}
.shop-header__name { font-size: 1.3rem; font-weight: 700; margin: 0; }
.shop-header__desc { font-size: .9rem; color: var(--hint); margin: 8px 0 0; }

/* ===== Empty state ===== */
.empty-state__icon { font-size: 3rem; }

/* ===== Profile ===== */
.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(--card-bg); 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: .8rem; color: var(--hint); margin-top: 4px; }
.profile-actions { display: flex; flex-direction: column; gap: 10px; }
.profile-action { display: block; padding: 14px 18px; border-radius: var(--radius); background: var(--card-bg); color: var(--text); font-weight: 600; }
.profile-action--accent { background: var(--button); color: var(--button-text); }

/* ===== Поддержка ===== */
.support-box { background: var(--card-bg); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; }
.support-hint { font-size: .88rem; color: var(--hint); margin: 0 0 10px; }
.support-textarea {
    width: 100%; border: none; border-radius: 10px; padding: 12px;
    background: var(--bg); color: var(--text); font-size: .95rem; resize: vertical;
    font-family: inherit;
}
.support-send-btn {
    margin-top: 10px; width: 100%; border: none; border-radius: 10px; padding: 12px;
    background: var(--button); color: var(--button-text); font-weight: 700; font-size: .95rem;
}
.support-send-btn:disabled { opacity: .6; }

.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket-card { display: block; background: var(--card-bg); border-radius: var(--radius); padding: 14px; }
.ticket-card__top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ticket-card__id { font-weight: 700; font-size: .92rem; }
.ticket-card__subject { margin: 6px 0; font-size: .92rem; }
.ticket-card__meta { font-size: .76rem; color: var(--hint); }

.ticket-status { font-size: .72rem; padding: 3px 9px; border-radius: 8px; white-space: nowrap; background: rgba(128,128,128,.2); }
.ticket-status.status--open { background: rgba(255,149,0,.2); color: #ff9500; }
.ticket-status.status--answered { background: rgba(52,199,89,.2); color: #34c759; }
.ticket-status.status--closed { background: rgba(128,128,128,.2); color: var(--hint); }

.thread-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.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(--button); color: var(--button-text); border-bottom-right-radius: 4px; }
.bubble--staff { align-self: flex-start; background: var(--card-bg); border-bottom-left-radius: 4px; }
.bubble__author { font-size: .72rem; opacity: .8; margin-bottom: 3px; }
.bubble__text { font-size: .95rem; white-space: pre-wrap; word-break: break-word; }
.bubble__time { font-size: .68rem; opacity: .65; margin-top: 4px; text-align: right; }
