/* ===== CSS Variables (Telegram Theme) ===== */
:root {
    --bg-color: var(--tg-theme-bg-color, #1a1a2e);
    --text-color: var(--tg-theme-text-color, #ffffff);
    --hint-color: var(--tg-theme-hint-color, #8b8b9e);
    --link-color: var(--tg-theme-link-color, #5eaeff);
    --button-color: var(--tg-theme-button-color, #5eaeff);
    --button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #16213e);

    --accent: #e94560;
    --accent-light: #ff6b6b;
    --success: #00d26a;
    --warning: #ffc107;
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --radius: 16px;
    --radius-sm: 12px;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

.app {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 100px;
}

/* ===== Header ===== */
.header {
    text-align: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--accent) 0%, #e91e63 100%);
    border-radius: 0 0 32px 32px;
    margin-bottom: 16px;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

/* ===== Navigation ===== */
.nav {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-color);
    padding-top: 8px;
    padding-bottom: 8px;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--hint-color);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.nav-btn .icon {
    font-size: 20px;
}

.nav-btn.active {
    background: var(--button-color);
    color: var(--button-text-color);
    border-color: var(--button-color);
}

.badge {
    position: absolute;
    top: 4px;
    right: 8px;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Tab Content ===== */
.tab-content {
    display: none;
    padding: 0 16px;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Products Grid ===== */
.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.product-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-card:active {
    transform: scale(0.98);
}

.product-image {
    width: 100%;
    height: 120px;
    background: linear-gradient(135deg, #2a2a4a 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-info {
    padding: 12px;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}

.product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-light);
}

.product-stock {
    font-size: 11px;
    color: var(--hint-color);
    margin-top: 4px;
}

.product-stock.low {
    color: var(--warning);
}

.product-stock.out {
    color: var(--accent);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--hint-color);
}

.empty-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 24px;
}

/* ===== Cart Items ===== */
.cart-item {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.cart-item-image {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #2a2a4a 0%, #1a1a2e 100%);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    flex-shrink: 0;
    overflow: hidden;
}

.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-price {
    color: var(--accent-light);
    font-weight: 600;
    font-size: 14px;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.cart-qty-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--button-color);
    color: var(--button-text-color);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item-qty {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
}

.cart-item-delete {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

/* ===== Cart Footer ===== */
.cart-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: var(--secondary-bg);
    border-top: 1px solid var(--card-border);
    max-width: 480px;
    margin: 0 auto;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--button-color);
    color: var(--button-text-color);
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-lg {
    width: 100%;
    padding: 16px;
    font-size: 16px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--link-color);
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    font-size: 14px;
}

/* ===== Form ===== */
.checkout-form {
    padding-bottom: 32px;
}

.checkout-form h2 {
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--hint-color);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--button-color);
}

.form-group textarea {
    resize: none;
}

/* ===== Radio Cards ===== */
.radio-group {
    display: flex;
    gap: 12px;
}

.radio-card {
    flex: 1;
    cursor: pointer;
}

.radio-card input {
    display: none;
}

.radio-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
}

.radio-icon {
    font-size: 24px;
}

.radio-card input:checked+.radio-content {
    border-color: var(--button-color);
    background: rgba(94, 174, 255, 0.1);
}

/* ===== Saved Address Hint ===== */
.saved-address-hint {
    background: rgba(94, 174, 255, 0.1);
    border: 1px solid var(--button-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
    font-size: 13px;
}

#saved-address-text {
    font-weight: 500;
}

/* ===== Checkout Summary ===== */
.checkout-summary {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--hint-color);
}

.summary-row.total {
    margin-bottom: 0;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--card-border);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
}

/* ===== Orders List ===== */
.order-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.order-id {
    font-weight: 700;
    font-size: 16px;
}

.order-status {
    font-size: 12px;
    padding: 4px 8px;
    background: rgba(94, 174, 255, 0.2);
    border-radius: 8px;
}

.order-details {
    display: flex;
    justify-content: space-between;
    color: var(--hint-color);
    font-size: 13px;
}

/* ===== Success ===== */
.success-content {
    text-align: center;
    padding: 48px 16px;
}

.success-icon {
    font-size: 80px;
    margin-bottom: 24px;
}

.success-content h2 {
    margin-bottom: 8px;
}

.success-order-id {
    color: var(--hint-color);
    margin-bottom: 16px;
}

.success-content p {
    color: var(--hint-color);
    margin-bottom: 24px;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: flex-end;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--secondary-bg);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1;
}

.modal-body {
    padding: 24px;
}

.modal-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, #2a2a4a 0%, #1a1a2e 100%);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    margin-bottom: 20px;
    overflow: hidden;
}

.modal-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-body h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.modal-body p {
    color: var(--hint-color);
    margin-bottom: 12px;
}

.modal-price {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-light) !important;
}

.modal-stock {
    font-size: 13px;
}

/* ===== Quantity Selector ===== */
.quantity-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 24px 0;
}

.qty-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--button-color);
    color: var(--button-text-color);
    font-size: 24px;
    cursor: pointer;
}

#modal-qty {
    font-size: 24px;
    font-weight: 700;
    min-width: 48px;
    text-align: center;
}

/* ===== Loader ===== */
.loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.loader.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--card-border);
    border-top-color: var(--button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Toast Notifications ===== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary-bg);
    color: var(--text-color);
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
    font-size: 14px;
    font-weight: 500;
    z-index: 3000;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.2s forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}