/* ========================================
   Mini App - Магазин мерча
   ======================================== */

:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --button-color: #6366f1;
    --bg-color: var(--tg-theme-bg-color, #ffffff);
    --text-color: var(--tg-theme-text-color, #1a1a1a);
    --hint-color: var(--tg-theme-hint-color, #999999);
    --link-color: var(--tg-theme-link-color, #6366f1);
    --button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f5f5f5);
    --header-bg: var(--tg-theme-header-bg-color, #ffffff);
    --border-radius: 12px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Header
   ======================================== */

.header {
    background: var(--header-bg);
    padding: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
}

.logo.hidden {
    display: none;
}

#store-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
}

.balance-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 8px 14px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: var(--shadow);
}

.points-icon {
    font-size: 1rem;
}

/* ========================================
   Navigation Tabs
   ======================================== */

.nav-tabs {
    display: flex;
    background: var(--secondary-bg);
    padding: 6px;
    margin: 12px 16px;
    border-radius: var(--border-radius);
    gap: 4px;
}

.nav-tab {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--hint-color);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ========================================
   Main Content
   ======================================== */

.main-content {
    flex: 1;
    padding: 0 16px 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========================================
   Products Grid
   ======================================== */

.products-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

/* ========================================
   Product Card
   ======================================== */

.product-card {
    background: var(--bg-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.product-image-container {
    position: relative;
    padding-top: 56.25%; /* 16:9 ratio */
    background: var(--secondary-bg);
    overflow: hidden;
}

.product-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--hint-color);
}

.product-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
}

.product-badge.out-of-stock {
    background: #ef4444;
}

.product-info {
    padding: 12px;
}

.product-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-color);
    line-height: 1.3;
}

.product-description-container {
    margin-bottom: 10px;
}

.product-description {
    font-size: 0.85rem;
    color: var(--hint-color);
    line-height: 1.4;
}

.product-description.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-description.expanded {
    display: block;
    overflow: visible;
}

.read-more-btn {
    background: none;
    border: none;
    color: var(--link-color);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
    margin-top: 4px;
    display: inline-block;
}

.read-more-btn:hover {
    text-decoration: underline;
}

.product-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.product-price {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--button-color);
    color: var(--button-text-color);
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

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

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text-color);
}

.btn-buy {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.btn-buy.sold-out {
    background: #ef4444;
    opacity: 0.8;
}

/* ========================================
   History
   ======================================== */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-color);
    padding: 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.history-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.history-icon.purchase { background: #fef3c7; }
.history-icon.income { background: #d1fae5; }
.history-icon.expense { background: #fee2e2; }
.history-icon.transfer { background: #dbeafe; }

.history-details {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-desc {
    font-size: 0.8rem;
    color: var(--hint-color);
}

.history-amount {
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.history-amount.positive { color: #10b981; }
.history-amount.negative { color: #ef4444; }

/* ========================================
   Info Section
   ======================================== */

.info-content {
    background: var(--bg-color);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    line-height: 1.6;
}

.info-content h1, .info-content h2, .info-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.info-content p {
    margin-bottom: 12px;
}

.info-content ul, .info-content ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

/* ========================================
   Loading & Empty States
   ======================================== */

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--hint-color);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--secondary-bg);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--hint-color);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
}

.hidden {
    display: none !important;
}

/* ========================================
   Modals
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-color);
    border-radius: 16px;
    max-width: 340px;
    width: 100%;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--secondary-bg);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--hint-color);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 20px;
    text-align: center;
}

.modal-product-image {
    width: 200px;
    height: 112px; /* 16:9 ratio */
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 16px;
    background: var(--secondary-bg);
}

.modal-body h4 {
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.modal-price, .modal-balance {
    font-size: 0.95rem;
    color: var(--hint-color);
    margin-bottom: 8px;
}

.modal-price strong, .modal-balance strong {
    color: var(--text-color);
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--secondary-bg);
}

.modal-footer .btn {
    flex: 1;
}

/* Success Modal */
.modal-success {
    padding: 30px 20px;
    text-align: center;
}

.success-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.modal-success h3 {
    margin-bottom: 12px;
}

.modal-success p {
    color: var(--hint-color);
    margin-bottom: 8px;
}

.new-balance {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* ========================================
   Toast
   ======================================== */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toastSlideUp 0.3s ease;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.toast-icon {
    font-size: 1.1rem;
}

.toast-message {
    font-size: 0.9rem;
}
