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

:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #000000;
    --tg-theme-button-color: #000000;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f1f1f1;
    --primary-color: #000000;
    --success-color: #4caf50;
    --danger-color: #f44336;
    --border-color: #cccccc; /* 20% darker than white (#ffffff) */
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --site-background: #ffffff;
    --gender-filter-inactive-bg: #f0f0f5; /* Default for light backgrounds */
    --secondary-text-color: #000000; /* Secondary text color for product names, placeholders, etc. */
    --nav-active-icon-color: #000000; /* Active navigation icon color */
    --nav-inactive-icon-color: #999999; /* Inactive navigation icon color */
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    line-height: 1.6;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    /* Prevent layout shift */
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

.app-container {
    max-width: 100%;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 80px;
    position: relative;
}

.page-content {
    display: block;
    padding: 16px 0;
}

/* Header */
.header {
    background: var(--tg-theme-bg-color);
    padding: calc(24px + env(safe-area-inset-top)) 16px 16px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.header-logo {
    max-height: 40px;
    max-width: 200px;
    height: auto;
    width: auto;
    object-fit: contain;
    will-change: transform;
    transform: translateZ(0);
    margin-top: 8px;
}

/* Horizontal Scroll Section */
.horizontal-scroll-section {
    padding: 16px 0;
    background: var(--tg-theme-bg-color);
}

.horizontal-scroll-container {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 0 16px;
    /* Don't restrict touch-action - let browser handle scrolling naturally */
    will-change: scroll-position;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.horizontal-scroll-container::-webkit-scrollbar {
    display: none;
}

.horizontal-scroll-item {
    flex-shrink: 0;
    width: 120px;
    cursor: pointer;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    /* Don't restrict touch-action - let browser handle it */
}

.horizontal-scroll-item:active {
    transform: scale(0.95);
}

.horizontal-scroll-image {
    width: 120px;
    height: 120px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--tg-theme-secondary-bg-color);
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

.horizontal-scroll-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    touch-action: none;
}

.horizontal-scroll-title {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    color: var(--tg-theme-text-color);
    line-height: 1.3;
    padding: 0 4px;
}

/* Categories */
.categories {
    padding: 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    contain: layout style paint;
}

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

.category-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    cursor: pointer;
    white-space: nowrap;
    font-size: 14px;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    will-change: background-color;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.category-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Products Grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 12px;
    contain: layout style paint;
}

.product-card {
    background: transparent;
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    cursor: pointer;
    transition: opacity 0.2s ease-out;
    will-change: opacity;
    -webkit-tap-highlight-color: transparent;
}

.product-card:active {
    opacity: 0.8;
}

.product-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: transparent;
    display: block;
    will-change: opacity;
    transition: opacity 0.2s ease;
    border-radius: 12px; /* Закругленные углы для всех фотографий товаров */
}

.product-image[loading="lazy"] {
    opacity: 0;
}

.product-image.loaded {
    opacity: 1;
}

.product-info {
    padding: 8px 4px 0 4px;
}

.product-name {
    font-size: 13px;
    font-weight: 400;
    margin-top: 4px;
    margin-bottom: 0;
    color: var(--secondary-text-color, var(--tg-theme-text-color, #000000));
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.product-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    margin-bottom: 0;
    line-height: 1.2;
}

.product-actions {
    display: flex;
    gap: 8px;
}

.btn-add-cart {
    flex: 1;
    padding: 8px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-add-cart:active {
    opacity: 0.8;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid transparent;
    border-top-color: var(--secondary-text-color, #A0A4AE);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    will-change: transform;
    transform: translateZ(0);
}

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

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    will-change: opacity;
    backface-visibility: hidden;
    overflow: hidden;
    overscroll-behavior: contain;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: calc(80px + env(safe-area-inset-top));
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--site-background, var(--tg-theme-bg-color));
    border-radius: 16px 16px 0 0;
    width: 100%;
    /* Calculate height: 100vh minus header height */
    /* Header: padding-top (24px + safe-area) + logo (40px + 8px margin-top) + padding-bottom (16px) = ~88px + safe-area */
    max-height: calc(100vh - 88px - env(safe-area-inset-top));
    height: calc(100vh - 88px - env(safe-area-inset-top));
    overflow: hidden;
    position: relative;
    will-change: transform;
    transform: translateZ(0);
    display: flex;
    flex-direction: column;
    contain: layout style paint;
}

/* Checkout modal - rounded top corners */
#checkoutContactModal .modal-content {
    border-radius: 16px 16px 0 0;
}

.modal.active .modal-content {
    animation: slideUpFromBelowHeader 0.3s ease-out;
}

/* Cart Page */
.cart-page {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--tg-theme-bg-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cart-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--site-background, var(--tg-theme-bg-color));
    position: sticky;
    top: 0;
    z-index: 10;
}

.cart-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: var(--tg-theme-text-color, #000000);
}

.cart-close-btn {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--tg-theme-text-color);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.cart-close-btn:active {
    background-color: var(--tg-theme-secondary-bg-color);
}

.cart-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.cart-items {
    flex: 1;
    padding: 16px;
    min-height: 0;
}

.cart-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--tg-theme-bg-color);
    position: sticky;
    bottom: 0;
}

.empty-cart {
    text-align: center;
    padding: 40px 20px;
    color: var(--tg-theme-hint-color);
    font-size: 16px;
}

.settings-content {
    padding: 16px;
}

.settings-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
}

.settings-section {
    margin-bottom: 32px;
    padding: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.settings-section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.logo-settings {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.logo-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    min-height: 80px;
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
    }
    to { 
        opacity: 1; 
    }
}

@keyframes slideUp {
    from { 
        transform: translateY(100%) translateZ(0); 
    }
    to { 
        transform: translateY(0) translateZ(0); 
    }
}

@keyframes slideUpFromBelowHeader {
    from { 
        transform: translateY(100%) translateZ(0); 
    }
    to { 
        transform: translateY(0) translateZ(0); 
    }
}

.modal-close {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top));
    right: 16px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 24px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 24px;
    padding-bottom: 150px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    min-height: 0;
    touch-action: pan-y;
    overscroll-behavior: contain;
    box-sizing: border-box;
}

/* Product Images Gallery - Horizontal Scroll */
.product-images-gallery {
    margin-bottom: 16px;
    width: 100%;
}

.gallery-images-scroll-container {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    gap: 12px;
    padding-bottom: 4px;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: thin;
    scrollbar-color: var(--tg-theme-hint-color) transparent;
}

.gallery-images-scroll-container::-webkit-scrollbar {
    height: 4px;
}

.gallery-images-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-images-scroll-container::-webkit-scrollbar-thumb {
    background: var(--tg-theme-hint-color);
    border-radius: 2px;
}

.gallery-image-item {
    flex: 0 0 100%;
    width: 100%;
    aspect-ratio: 1;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    border-radius: 12px;
    overflow: hidden;
    background: var(--tg-theme-secondary-bg-color);
    position: relative;
}

.product-detail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    display: block;
}

/* Product Sizes Selector */
.product-sizes-selector {
    margin-bottom: 24px;
}

.sizes-label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 16px;
}

.sizes-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.size-btn {
    padding: 10px 20px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-width: 50px;
    text-align: center;
}

.size-btn:active {
    transform: scale(0.95);
}

.size-btn.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.product-detail-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.product-detail-price {
    font-size: 28px;
    font-weight: 700;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    margin-bottom: 16px;
}

.product-detail-description {
    color: var(--tg-theme-hint-color);
    margin-bottom: 24px;
    line-height: 1.6;
}

/* Cart */
.cart-items {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    contain: layout style paint;
}

.cart-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--site-background, #ffffff);
    align-items: flex-start;
    cursor: pointer;
    transition: background-color 0.2s ease;
    /* Add border-bottom only if not last child */
    border-bottom: 1px solid var(--border-color);
    /* Prevent tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
    tap-highlight-color: transparent;
}

.cart-item:last-child {
    border-bottom: none;
}

/* Only show active state if clicking directly on cart-item, not on buttons */
.cart-item:active:not(.button-active) {
    background-color: var(--tg-theme-secondary-bg-color);
}

/* Completely prevent active state and any visual changes when button is clicked */
.cart-item.button-active,
.cart-item.button-active:active,
.cart-item.button-active:focus {
    background-color: var(--site-background, #ffffff) !important;
    outline: none !important;
}

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

.cart-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cart-item-name {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    word-wrap: break-word;
    color: var(--secondary-text-color, var(--tg-theme-text-color, #000000));
}

.cart-item-price {
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 8px;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.quantity-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--site-background, #ffffff);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    color: var(--tg-theme-text-color, #000000);
}

.quantity-btn:active {
    background-color: var(--tg-theme-secondary-bg-color);
}

.quantity {
    font-weight: 500;
    min-width: 30px;
    text-align: center;
    color: var(--tg-theme-text-color, #000000);
}

.remove-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: opacity 0.2s ease;
}

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

.cart-item-remove-x {
    position: absolute;
    top: 0;
    right: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--cart-remove-button-color, #000000);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.cart-item-remove-x:active {
    transform: scale(0.9);
    opacity: 0.8;
}

.cart-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    background: var(--site-background, #ffffff);
    z-index: 10;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
}

.checkout-btn {
    width: 100%;
    padding: 16px;
    background: var(--cart-checkout-button-color, var(--primary-color));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.checkout-btn:active {
    opacity: 0.8;
}

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

.empty-cart {
    text-align: center;
    padding: 40px;
    color: #999999;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999999;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.products-grid .empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 12px;
    margin: 0;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state-icon svg {
    width: 48px;
    height: 48px;
}

.empty-state-text {
    font-size: 16px;
    width: 100%;
    text-align: center;
}

.favorite-btn {
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.favorite-btn:active {
    transform: scale(0.9);
}

.favorite-btn svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.favorite-btn.active svg path {
    stroke-width: 2;
}

.favorite-btn:not(.active) svg path {
    stroke-width: 1.5;
}

/* Catalog Page */
.catalog-page {
    padding: 0;
    padding-bottom: 80px;
}

.gender-filters {
    display: flex;
    justify-content: center;
    padding: 16px;
    background: transparent;
    border-bottom: none;
    position: relative;
    z-index: 10;
}

.gender-filters-wrapper {
    display: flex;
    gap: 8px;
    position: relative;
    background: transparent;
    border-radius: 12px;
    padding: 4px;
}

.gender-filter-indicator {
    position: absolute;
    top: 4px;
    left: 4px;
    height: calc(100% - 8px);
    background: var(--site-background, #ffffff);
    border-radius: 8px;
    z-index: 1;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.gender-filter {
    flex: 1;
    min-width: 140px;
    padding: 12px 24px;
    background: #f0f0f5;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    cursor: pointer;
    transition: background-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
    z-index: 2;
}

.gender-filter.active {
    background: var(--site-background, #ffffff);
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.gender-filter:not(.active) {
    background: var(--gender-filter-inactive-bg, #f0f0f5);
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
}

.gender-filter:active {
    transform: scale(0.98);
}

.catalog-content {
    padding: 16px;
}

.catalog-section {
    margin-bottom: 32px;
}

.catalog-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.catalog-section-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
}

.catalog-section-all {
    background: transparent;
    border: none;
    color: var(--secondary-text-color, var(--primary-color, #000000));
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.catalog-subcategories {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.catalog-subcategory-row {
    display: flex;
    gap: 12px;
    width: 100%;
    align-items: stretch; /* Все элементы в строке растягиваются до одинаковой высоты */
}

.catalog-subcategory-item {
    background: transparent;
    border-radius: 0;
    overflow: hidden;
    cursor: pointer;
    transition: opacity 0.2s ease;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch; /* Растягиваем элементы на всю высоту строки */
}

.catalog-subcategory-item:active {
    transform: scale(0.98);
}

/* Чередующийся макет: большая-маленькая, маленькая-большая */
/* Все изображения имеют одинаковую высоту (aspect-ratio 16:9), разница только в ширине */
.catalog-subcategory-item.large {
    flex: 1.8;
    min-width: 0;
}

.catalog-subcategory-item.small {
    flex: 1;
    min-width: 0;
}

.catalog-subcategory-item.full {
    flex: 1;
    width: 100%;
}

.catalog-subcategory-item.uniform {
    flex: 1;
    min-width: 0;
}

/* Устанавливаем одинаковую фиксированную высоту для всех изображений в строке */
.catalog-subcategory-row .subcategory-image {
    height: 180px !important; /* Фиксированная высота - одинаковая для всех элементов */
    width: 100%; /* Ширина зависит от flex родителя (large/small) */
}

.subcategory-image {
    width: 100%;
    background: transparent;
    overflow: hidden;
    position: relative;
    border-radius: 12px;
    aspect-ratio: 16 / 9; /* По умолчанию для одиночных элементов */
}

.subcategory-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    border-radius: 12px;
}

.subcategory-image-emoji {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
    border-radius: 12px;
}

.subcategory-name-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    background: transparent;
    padding: 0;
    z-index: 2;
    pointer-events: none;
    text-shadow: none;
    -webkit-text-stroke: 0;
}

.subcategory-name {
    display: none; /* Убираем текст под картинкой */
}

.subcategory-name-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 16px;
    font-weight: 600;
    color: #000;
    background: transparent;
    padding: 0;
    z-index: 2;
    pointer-events: none;
    line-height: 1.2;
    max-width: calc(100% - 24px);
}

.catalog-recommendations {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.recommendations-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.recommendations-products {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)); /* Используем minmax для правильного сжатия */
    grid-auto-rows: min-content; /* Автоматическая высота строки на основе контента */
    gap: 12px;
    align-items: stretch; /* Растягиваем карточки на всю высоту строки */
    width: 100%;
    box-sizing: border-box;
}

.recommendation-card {
    background: transparent;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    cursor: pointer;
    transition: opacity 0.2s ease-out;
    will-change: opacity;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%; /* Занимает всю высоту grid-ячейки */
    min-height: 0; /* Позволяет flex-элементам сжиматься */
    min-width: 0; /* Позволяет grid-элементам правильно сжиматься */
    box-sizing: border-box;
}

.recommendation-card:active {
    opacity: 0.8;
}

.recommendation-card > div:first-child {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0; /* Изображение не сжимается */
    min-width: 0; /* Позволяет правильно сжиматься в grid */
    box-sizing: border-box;
}

.recommendation-image {
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: transparent;
    border-radius: 12px; /* Закругленные углы для изображений рекомендаций */
    display: block;
}

.recommendation-info {
    padding: 8px 4px 0 4px;
    flex: 1 1 auto; /* Может расти и сжиматься, но занимает доступное пространство */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 0; /* Позволяет сжиматься */
    min-width: 0; /* Позволяет правильно сжиматься в flex контейнере */
    box-sizing: border-box;
}

.recommendation-name {
    font-size: 13px;
    font-weight: 400;
    margin-top: 4px;
    color: var(--secondary-text-color, var(--tg-theme-text-color, #000000));
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1 1 auto; /* Название может занимать оставшееся пространство */
    min-height: 36px; /* Минимальная высота для 2 строк текста (13px * 1.4 * 2) */
}

.recommendation-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    flex-shrink: 0; /* Цена не сжимается */
    line-height: 1.2;
}

/* Responsive for catalog */
@media (min-width: 480px) {
    .catalog-subcategories {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .recommendations-products {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .catalog-subcategories {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .recommendations-products {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--site-background, #ffffff);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 4px;
    position: relative;
    color: var(--nav-inactive-icon-color, #999999);
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    flex: 1;
    min-width: 0;
    max-width: 100%;
}

.nav-item.active {
    color: var(--nav-active-icon-color, #000000);
}

.nav-icon {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
}

.nav-item.active .nav-icon {
    stroke: var(--nav-active-icon-color, #000000);
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    word-wrap: break-word;
    text-align: center;
    max-width: 100%;
}

.nav-count {
    position: absolute;
    top: 8px;
    /* Position relative to center: 50% (center of nav-item) + 12px (half icon width) + 4px (padding) */
    left: calc(50% + 16px);
    background: var(--danger-color);
    color: white;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    padding: 0 4px;
    white-space: nowrap;
    /* Prevent shifting on zoom/scale changes */
    transform-origin: left center;
}

.nav-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--tg-theme-secondary-bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.nav-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Profile Page */
.profile-content {
    padding: 16px;
}

.profile-card {
    background: var(--border-color, #cccccc);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--tg-theme-secondary-bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: var(--tg-theme-hint-color);
}

.profile-avatar svg {
    width: 40px;
    height: 40px;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.profile-name {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
}

.profile-email {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

.profile-actions {
    margin-bottom: 16px;
}

.profile-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-color, var(--tg-theme-button-color, #000000));
    color: var(--tg-theme-button-text-color, #ffffff);
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.profile-btn:active {
    opacity: 0.8;
}

.profile-btn.secondary {
    background: var(--primary-color, var(--tg-theme-button-color, #000000));
    color: var(--tg-theme-button-text-color, #ffffff);
}

.profile-menu {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.menu-item {
    width: 100%;
    padding: 16px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:active {
    background: var(--tg-theme-secondary-bg-color);
}

.menu-icon {
    font-size: 20px;
}

.menu-item span:not(.menu-icon):not(.menu-arrow) {
    flex: 1;
    text-align: left;
    font-size: 16px;
}

.menu-arrow {
    color: var(--tg-theme-hint-color);
    font-size: 20px;
}

/* Thank You Page */
.thank-you-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    padding: 40px 16px;
    text-align: center;
}

.thank-you-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--success-color, #4caf50);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 24px;
    animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.thank-you-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    margin-bottom: 16px;
}

.thank-you-message {
    font-size: 16px;
    color: var(--secondary-text-color, var(--tg-theme-hint-color, #999999));
    line-height: 1.6;
    max-width: 400px;
    margin: 0 auto;
}

/* Favorites Page */
.favorites-content {
    padding: 16px;
}

/* Form styles for login */
.modal-form {
    padding: 0 20px 20px;
}

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

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--tg-theme-text-color);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    flex: 1;
    padding: 14px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

.form-actions .btn-primary {
    flex: 1;
}

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

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

/* Checkout Form Styles */
.checkout-form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    font-size: 16px;
    background: var(--site-background, var(--tg-theme-bg-color, #ffffff));
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s ease;
}

.checkout-form-input:focus {
    border-color: var(--primary-color, #000000);
}

.checkout-form-input::placeholder {
    color: var(--secondary-text-color, #999999);
    opacity: 0.6;
}

.checkout-form-divider {
    display: none; /* Hide dividers as fields now have borders */
}

/* Checkout form wrappers */
#contactFirstNameWrapper,
#contactLastNameWrapper,
#contactMiddleNameWrapper,
#contactPhoneWrapper,
#contactEmailWrapper {
    background: var(--site-background, var(--tg-theme-bg-color, #ffffff));
    padding: 0 16px;
    margin-bottom: 12px;
}

#contactPhoneWrapper {
    position: relative;
}

/* Textarea styling for notes */
#contactNotes {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background: var(--site-background, var(--tg-theme-bg-color, #ffffff));
    color: var(--global-text-color, var(--tg-theme-text-color, #000000));
    box-sizing: border-box;
    outline: none;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease;
}

#contactNotes:focus {
    border-color: var(--primary-color, #000000);
}

#contactNotes::placeholder {
    color: var(--secondary-text-color, #999999);
    opacity: 0.6;
}

/* Phone input wrapper special styling */
#contactPhoneWrapper {
    padding: 0 16px;
    margin-bottom: 12px;
}

#contactPhoneWrapper > div {
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    background: var(--site-background, var(--tg-theme-bg-color, #ffffff));
    transition: border-color 0.2s ease;
    padding: 0 4px;
}

#contactPhoneWrapper:focus-within > div {
    border-color: var(--primary-color, #000000);
}

#contactPhoneWrapper input {
    padding: 12px 8px !important;
}
