/* ====== Base & Telegram Theme ====== */
:root {
    --tg-theme-bg: var(--tg-theme-bg-color, #ffffff);
    --tg-theme-text: var(--tg-theme-text-color, #000000);
    --tg-theme-hint: var(--tg-theme-hint-color, #999999);
    --tg-theme-link: var(--tg-theme-link-color, #2678b6);
    --tg-theme-btn: var(--tg-theme-button-color, #2678b6);
    --tg-theme-btn-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-theme-secondary: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tg-theme-secondary);
    color: var(--tg-theme-text);
    line-height: 1.5;
    padding-bottom: 80px;
    -webkit-font-smoothing: antialiased;
}

/* ====== Заголовок ====== */
.header {
    background: var(--tg-theme-bg);
    padding: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ====== Нижняя панель корзины ====== */
.cart-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--tg-theme-bg);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding: 10px 16px;
    display: none; /* скрыта когда корзина пуста */
}

.cart-bottom-bar.visible {
    display: flex;
}

.cart-bottom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    text-decoration: none;
}

.cart-bottom-btn:active { opacity: 0.85; }

.cart-bottom-count {
    background: rgba(255,255,255,0.25);
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 13px;
    font-weight: 700;
}

/* ====== Поиск и фильтры ====== */
.search-bar {
    padding: 8px 16px 12px;
    background: var(--tg-theme-bg);
}

.search-bar input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--tg-theme-secondary);
    border-radius: 10px;
    font-size: 15px;
    background: var(--tg-theme-secondary);
    color: var(--tg-theme-text);
    outline: none;
}

.search-bar input:focus {
    border-color: var(--tg-theme-btn);
}

.categories {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.categories::-webkit-scrollbar { display: none; }

.cat-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--tg-theme-hint);
    background: transparent;
    color: var(--tg-theme-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.cat-btn.active {
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
    border-color: var(--tg-theme-btn);
}

/* ====== Сетка товаров ====== */
.product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px 16px;
}

.product-card {
    background: var(--tg-theme-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.product-card-link {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.product-card-link:active { opacity: 0.9; }

.product-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.product-info {
    padding: 10px;
    flex: 1;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

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

.product-stock {
    font-size: 11px;
    color: var(--tg-theme-hint);
    margin-top: 2px;
}

.product-card-actions {
    padding: 0 10px 10px;
}

.product-add-btn {
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.product-add-btn:active { opacity: 0.85; }

.product-add-btn.in-cart {
    background: transparent;
    border: 1.5px solid var(--tg-theme-btn);
    color: var(--tg-theme-btn);
}

.product-add-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ====== Страница товара ====== */
.detail-page { padding: 0; }

.detail-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.detail-content {
    padding: 16px;
    background: var(--tg-theme-bg);
    border-radius: var(--radius) var(--radius) 0 0;
    margin-top: -16px;
    position: relative;
}

.detail-category {
    font-size: 12px;
    color: var(--tg-theme-hint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-name {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.detail-price {
    font-size: 24px;
    font-weight: 800;
    color: var(--tg-theme-link);
    margin-bottom: 12px;
}

.detail-description {
    font-size: 15px;
    color: var(--tg-theme-hint);
    line-height: 1.6;
    margin-bottom: 20px;
}

.qty-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.qty-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--tg-theme-hint);
    background: transparent;
    font-size: 20px;
    color: var(--tg-theme-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:active { background: var(--tg-theme-secondary); }

.qty-value {
    font-size: 18px;
    font-weight: 600;
    min-width: 30px;
    text-align: center;
}

.add-to-cart-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.add-to-cart-btn:active { opacity: 0.85; }

/* ====== Корзина ====== */
.cart-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--tg-theme-hint);
}

.cart-empty-icon { font-size: 48px; margin-bottom: 12px; }

.cart-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: var(--tg-theme-bg);
    margin-bottom: 1px;
}

.cart-item img {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.cart-item-info { flex: 1; }
.cart-item-name { font-size: 14px; font-weight: 600; }

.cart-item-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--tg-theme-link);
}

.cart-item-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.cart-qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--tg-theme-hint);
    background: transparent;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text);
}

.cart-remove {
    margin-left: auto;
    color: #ff3b30;
    background: none;
    border: none;
    font-size: 13px;
    cursor: pointer;
}

.cart-summary {
    background: var(--tg-theme-bg);
    padding: 16px;
    margin-top: 10px;
    border-radius: var(--radius);
    margin: 10px 16px;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 18px;
    font-weight: 700;
}

/* ====== Форма оформления ====== */
.checkout-form {
    padding: 16px;
}

.form-section {
    background: var(--tg-theme-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.form-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--tg-theme-hint);
    margin-bottom: 4px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--tg-theme-secondary);
    border-radius: 8px;
    font-size: 15px;
    background: var(--tg-theme-secondary);
    color: var(--tg-theme-text);
    outline: none;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--tg-theme-btn);
}

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

.checkout-items {
    font-size: 13px;
    color: var(--tg-theme-hint);
}

.checkout-items div {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.checkout-total {
    border-top: 1px solid var(--tg-theme-secondary);
    padding-top: 8px;
    margin-top: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--tg-theme-text);
    display: flex;
    justify-content: space-between;
}

/* ====== Список заказов ====== */
.order-card {
    background: var(--tg-theme-bg);
    border-radius: var(--radius);
    margin: 10px 16px;
    padding: 14px;
    box-shadow: var(--shadow);
}

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

.order-id { font-weight: 700; font-size: 15px; }

.order-status {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-new { background: #fff3cd; color: #856404; }
.status-confirmed { background: #d4edda; color: #155724; }
.status-processing { background: #cce5ff; color: #004085; }
.status-shipped { background: #d1ecf1; color: #0c5460; }
.status-delivered { background: #d4edda; color: #155724; }
.status-cancelled { background: #f8d7da; color: #721c24; }

.order-items { font-size: 13px; color: var(--tg-theme-hint); }
.order-total { font-weight: 700; margin-top: 6px; }
.order-date { font-size: 12px; color: var(--tg-theme-hint); margin-top: 4px; }

/* ====== Загрузка и прочее ====== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--tg-theme-hint);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--tg-theme-secondary);
    border-top-color: var(--tg-theme-btn);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--tg-theme-link);
    font-size: 15px;
    cursor: pointer;
    padding: 4px 0;
}

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 999;
    white-space: nowrap;
}

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

/* ====== Админ-панель ====== */
.admin-login {
    max-width: 400px;
    margin: 60px auto;
    padding: 0 16px;
    text-align: center;
}

.admin-login h2 { margin-bottom: 16px; }

.admin-header {
    background: var(--tg-theme-bg);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.admin-tabs {
    display: flex;
    gap: 0;
    background: var(--tg-theme-secondary);
    border-radius: 8px;
    padding: 2px;
    margin-top: 8px;
}

.admin-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--tg-theme-hint);
    cursor: pointer;
}

.admin-tab.active {
    background: var(--tg-theme-bg);
    color: var(--tg-theme-text);
    box-shadow: var(--shadow);
}

.admin-content { padding: 12px 16px; }

.admin-table {
    width: 100%;
    background: var(--tg-theme-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.admin-row {
    padding: 12px;
    border-bottom: 1px solid var(--tg-theme-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-row:last-child { border-bottom: none; }

.admin-row img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
}

.admin-row-info { flex: 1; }
.admin-row-name { font-size: 14px; font-weight: 600; }
.admin-row-meta { font-size: 12px; color: var(--tg-theme-hint); }

.admin-row-actions {
    display: flex;
    gap: 6px;
}

.admin-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.admin-btn-primary { background: var(--tg-theme-btn); color: var(--tg-theme-btn-text); }
.admin-btn-danger { background: #ff3b30; color: #fff; }
.admin-btn-outline {
    background: transparent;
    border: 1.5px solid var(--tg-theme-btn);
    color: var(--tg-theme-btn);
}

.admin-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
    border: none;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Модальное окно */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal {
    background: var(--tg-theme-bg);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal h3 { margin-bottom: 16px; font-size: 18px; }

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.modal-actions button { flex: 1; padding: 12px; }

/* Статус заказа */
select.status-select {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--tg-theme-hint);
    font-size: 12px;
    background: var(--tg-theme-bg);
    color: var(--tg-theme-text);
}

@media (min-width: 500px) {
    .product-grid { grid-template-columns: repeat(3, 1fr); }
}

.grid-qty-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    width: 100%;
}

.grid-qty-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--tg-theme-btn);
    background: transparent;
    color: var(--tg-theme-btn);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.grid-qty-btn:active {
    background: var(--tg-theme-btn);
    color: var(--tg-theme-btn-text);
}

.grid-qty-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.grid-qty-value {
    font-size: 15px;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}
