/* ─────────────────────────────────────────────────────────────────
   CSS-переменные Telegram-темы.
   В Telegram заполняются автоматически из настроек темы юзера.
   В браузере — fallback на тёмную тему по умолчанию.
   ───────────────────────────────────────────────────────────────── */
:root {
    --tg-theme-bg-color: #17212b;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #708499;
    --tg-theme-link-color: #6ab3f3;
    --tg-theme-button-color: #5288c1;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #232e3c;

    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── Базовый сброс ───────────────────────────────────────────── */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    -webkit-tap-highlight-color: transparent;
}

#app {
    min-height: 100%;
    padding: 16px;
}

/* ─── Универсальные классы ────────────────────────────────────── */
.loader {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--tg-theme-hint-color);
}

.error {
    background: rgba(255, 80, 80, 0.15);
    color: #ff6b6b;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px 0;
}

.screen-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ─── Список категорий ────────────────────────────────────────── */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-button {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    transition: opacity 0.15s;
    width: 100%;
}

.category-button:active {
    opacity: 0.7;
}

.category-name {
    font-weight: 500;
}

.category-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-top: 4px;
}

/* ─── Категории, новый стиль через ссылку ──────────────────────── */
.category-card {
    display: block;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    text-decoration: none;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    transition: opacity 0.15s;
}

.category-card:active {
    opacity: 0.7;
}

/* ─── Назад ────────────────────────────────────────────────────── */
.back-link {
    display: inline-block;
    color: var(--tg-theme-link-color);
    text-decoration: none;
    margin-bottom: 16px;
    font-size: 16px;
}

/* ─── Сетка товаров ────────────────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding-bottom: 80px; /* чтобы не закрывался cart-badge */
}

.product-card {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 12px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 12px;
    align-items: center;
}

.product-image {
    width: 80px;
    height: 80px;
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;  /* ← добавить */
}

/* ← новое */
.product-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-placeholder {
    font-size: 32px;
    opacity: 0.5;
}

.product-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-name {
    font-weight: 500;
    font-size: 15px;
}

.product-price {
    color: var(--tg-theme-button-color);
    font-weight: 600;
    font-size: 16px;
}

.product-stock {
    color: var(--tg-theme-hint-color);
    font-size: 12px;
}

/* На широких экранах — два товара в ряд */
@media (min-width: 600px) {
    .product-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.product-action {
    grid-column: 1 / -1;
    margin-top: 4px;
}

/* ─── Кнопка добавления ────────────────────────────────────────── */
.add-btn {
    width: 100%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.add-btn:active:not(:disabled) {
    opacity: 0.8;
}

.add-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─── Счётчик +/− ──────────────────────────────────────────────── */
.qty-counter {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    background: var(--tg-theme-button-color);
    border-radius: 8px;
    overflow: hidden;
}

.qty-btn {
    background: transparent;
    border: none;
    color: var(--tg-theme-button-text-color);
    font-size: 20px;
    font-weight: 600;
    height: 36px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.qty-btn:active {
    opacity: 0.7;
}

.qty-value {
    text-align: center;
    color: var(--tg-theme-button-text-color);
    font-weight: 600;
    font-size: 15px;
}

/* ─── Нижний плавающий бар «Корзина» ───────────────────────────── */
.cart-badge {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    max-width: calc(600px - 32px);
    margin: 0 auto;

    display: flex;
    align-items: center;
    gap: 12px;

    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-radius: 12px;
    padding: 12px 16px;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;

    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: opacity 0.15s;
    z-index: 100;
}

.cart-badge:active {
    opacity: 0.85;
}

.cart-badge-icon {
    font-size: 18px;
}

.cart-badge-text {
    flex: 1;
}

.cart-badge-info {
    font-weight: 600;
}

/* ─── Пустая корзина ───────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-hint {
    color: var(--tg-theme-hint-color);
    margin-bottom: 24px;
}

/* ─── Список позиций корзины ───────────────────────────────────── */
.cart-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.cart-line {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    grid-template-columns: 60px 1fr;       /* ← было без grid */
    gap: 12px;
    align-items: center;
}

/* ← новое */
.cart-line-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--tg-theme-bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-line-info {
    margin-bottom: 12px;
}

.cart-line-name {
    font-weight: 500;
    font-size: 15px;
    margin-bottom: 4px;
}

.cart-line-price {
    color: var(--tg-theme-hint-color);
    font-size: 13px;
}

.cart-line-controls {
    grid-column: 1 / -1;   /* ← растянуть на оба столбца */
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-line-controls .qty-counter {
    flex: 1;
    max-width: 140px;
}

.remove-btn {
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.remove-btn:active {
    opacity: 0.6;
}

/* ─── Итог корзины ─────────────────────────────────────────────── */
.cart-summary {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.cart-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.cart-summary-total {
    border-top: 1px solid var(--tg-theme-bg-color);
    padding-top: 12px;
    margin-top: 8px;
    font-size: 17px;
}

/* ─── Главные кнопки ───────────────────────────────────────────── */
.primary-btn {
    display: block;
    width: 100%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    margin-bottom: 8px;
    transition: opacity 0.15s;
}

.primary-btn:active {
    opacity: 0.85;
}

.secondary-btn {
    display: block;
    width: 100%;
    background: transparent;
    color: var(--tg-theme-link-color);
    border: 1px solid var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.secondary-btn:active {
    opacity: 0.7;
}

/* ╔══════════════════════════════════════════════════════════════╗ */
/* ║                  ПОЛИРОВКА И АНИМАЦИИ                        ║ */
/* ╚══════════════════════════════════════════════════════════════╝ */

/* ─── Универсальные плавные переходы ───────────────────────────── */
* {
    -webkit-tap-highlight-color: transparent;
}

button, a {
    transition: opacity 0.15s ease, transform 0.1s ease;
}

button:active, a:active {
    transform: scale(0.97);
}

/* ─── Появление контента ───────────────────────────────────────── */
#app {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Skeleton-loader ──────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--tg-theme-secondary-bg-color) 0%,
        rgba(255, 255, 255, 0.06) 50%,
        var(--tg-theme-secondary-bg-color) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 16px;
}

.skeleton-card {
    height: 80px;
    margin-bottom: 8px;
}

.skeleton-product {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 12px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
}

.skeleton-product-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
}

.skeleton-product-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.skeleton-line {
    height: 14px;
    width: 100%;
}

.skeleton-line-short {
    height: 14px;
    width: 60%;
}

/* ─── Заголовок: тонкая корректировка ──────────────────────────── */
.screen-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.3px;
}

/* ─── Категории — мягкие тени и анимация ───────────────────────── */
.category-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.category-card:active {
    transform: scale(0.98);
}

/* ─── Карточки товаров — улучшения ─────────────────────────────── */
.product-card {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    transition: transform 0.15s ease;
}

/* Анимация появления цены при добавлении */
.product-price {
    transition: transform 0.2s ease;
}

/* ─── Бэдж корзины — пульс при изменении ───────────────────────── */
.cart-badge {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cart-badge.pulse {
    animation: pulse 0.4s ease;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ─── Кнопки — улучшения ───────────────────────────────────────── */
.primary-btn {
    box-shadow: 0 2px 8px rgba(82, 136, 193, 0.25);
}

.primary-btn:active {
    box-shadow: 0 1px 4px rgba(82, 136, 193, 0.15);
}

/* ─── Счётчик +/− — финальная полировка ────────────────────────── */
.qty-counter {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.qty-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* ─── Возврат — тоньше и заметнее ──────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    font-weight: 500;
}

.back-link:active {
    opacity: 0.6;
}

/* ─── Iframe Telegram — учёт safe area ─────────────────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: max(env(safe-area-inset-top), 12px);
        padding-bottom: max(env(safe-area-inset-bottom), 12px);
    }
}

/* ─── Картинки-плейсхолдеры — улучшение ────────────────────────── */
.image-placeholder {
    background: linear-gradient(
        135deg,
        var(--tg-theme-secondary-bg-color) 0%,
        var(--tg-theme-bg-color) 100%
    );
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    opacity: 0.6;
}

/* ─── Корзина — расстояния и тени ──────────────────────────────── */
.cart-line {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.cart-summary {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* ─── Состав заказа на checkout ────────────────────────────────── */
.checkout-section {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.checkout-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.summary-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--tg-theme-bg-color);
}

.summary-line {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.summary-total {
    font-size: 16px;
    margin-top: 4px;
}

/* ─── Поля формы ───────────────────────────────────────────────── */
.form-input {
    width: 100%;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: box-shadow 0.15s;
}

.form-input:focus {
    box-shadow: 0 0 0 2px var(--tg-theme-button-color);
}

.form-textarea {
    resize: vertical;
    min-height: 60px;
}

/* Заглушка для разделов, которые ещё не реализованы */
.checkout-placeholder {
    color: var(--tg-theme-hint-color);
    font-size: 13px;
    padding: 16px;
    text-align: center;
    margin-bottom: 12px;
}

/* Отступ снизу — место под MainButton */
.checkout-bottom-spacer {
    height: 80px;
}

/* ─── Браузерный fallback для MainButton ───────────────────────── */
.browser-main-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    z-index: 200;
    transition: opacity 0.15s;
}

.browser-main-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.browser-main-btn:active:not(:disabled) {
    opacity: 0.85;
}

/* ─── Ошибка валидации поля ────────────────────────────────────── */
.form-input-invalid {
    box-shadow: 0 0 0 2px #ff6b6b !important;
}

.form-error {
    color: #ff6b6b;
    font-size: 12px;
    margin-top: 6px;
    min-height: 16px;
}

/* ─── Группа кнопок выбора ────────────────────────────────────── */
.delivery-method-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.choice-btn {
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    border: 1px solid var(--tg-theme-bg-color);
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
}

.choice-btn:active {
    transform: scale(0.98);
}

.choice-btn-active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-color: var(--tg-theme-button-color);
    font-weight: 500;
}

/* ─── select-стиль ─────────────────────────────────────────────── */
.form-row {
    margin-bottom: 8px;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3e%3cpath fill='%23708499' d='M6 8L0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 36px;
    cursor: pointer;
}

.form-select option {
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
}

/* Подпись 'необязательно' рядом с заголовком секции */
.checkout-section-title .optional {
    color: var(--tg-theme-hint-color);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 12px;
    margin-left: 4px;
}


/* ─── Экран успешного заказа ───────────────────────────────────── */
.success-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 24px;
    text-align: center;
}

.success-icon {
    font-size: 72px;
    margin-bottom: 16px;
    animation: success-pop 0.4s ease;
}

@keyframes success-pop {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.success-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.success-id {
    font-size: 16px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 24px;
}

.success-info {
    width: 100%;
    max-width: 400px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.success-info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 15px;
}

.success-hint {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    margin-bottom: 24px;
    max-width: 400px;
}

.success-screen .primary-btn,
.success-screen .secondary-btn {
    max-width: 400px;
}

/* ─── Список заказов ───────────────────────────────────────────── */
.orders-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 80px;
}

.order-card {
    display: block;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    text-decoration: none;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.order-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.order-id {
    font-weight: 600;
    font-size: 16px;
}

.order-status {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
}

/* Цвета статусов: ненавязчивые, на фоне theme-secondary */
.order-status.status-new {
    background: rgba(112, 132, 153, 0.2);
    color: #708499;
}

.order-status.status-paid {
    background: rgba(82, 136, 193, 0.2);
    color: #6ab3f3;
}

.order-status.status-shipped {
    background: rgba(255, 165, 0, 0.2);
    color: #ffa500;
}

.order-status.status-delivered {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
}

.order-status.status-cancelled {
    background: rgba(244, 67, 54, 0.2);
    color: #f44336;
}

.order-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.order-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.order-label {
    color: var(--tg-theme-hint-color);
}

/* ─── Шапка карточки заказа ────────────────────────────────────── */
.order-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.order-detail-id {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* ─── Строки деталей ───────────────────────────────────────────── */
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 6px 0;
    font-size: 14px;
}

.detail-row:not(:last-child) {
    border-bottom: 1px solid var(--tg-theme-bg-color);
    padding-bottom: 10px;
    margin-bottom: 4px;
}

.detail-label {
    color: var(--tg-theme-hint-color);
    flex-shrink: 0;
    min-width: 80px;
}

.detail-value-wrap {
    text-align: right;
    word-break: break-word;
}

.detail-comment {
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    padding: 10px 12px;
    font-style: italic;
    color: var(--tg-theme-hint-color);
}

/* ─── Опасная кнопка (Отменить) ────────────────────────────────── */
.danger-btn {
    display: block;
    width: 100%;
    background: transparent;
    color: #ff6b6b;
    border: 1px solid #ff6b6b;
    border-radius: 12px;
    padding: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.15s ease;
}

.danger-btn:active {
    background: rgba(255, 107, 107, 0.1);
}
