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

:root {
    --primary-color: #F65606;
    --primary-dark: #D4460A;
    --background: #FFFFFF;
    --surface: #F8F9FA;
    --text-primary: #212529;
    --text-secondary: #6C757D;
    --border: #DEE2E6;
    --success: #28A745;
    --danger: #DC3545;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #1A1A1A;
        --surface: #2D2D2D;
        --text-primary: #FFFFFF;
        --text-secondary: #B0B0B0;
        --border: #404040;
        --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    }

    html {
        background-color: #1A1A1A !important;
    }

    .header {
        background: var(--background) !important;
    }

    .category-tabs {
        background: var(--background) !important;
        border-bottom-color: var(--background) !important;
    }

    .tab-button {
        background: var(--background) !important;
        color: var(--text-primary) !important;
        border: 1px solid var(--border) !important;
    }

    .tab-button.active {
        background: var(--primary-color) !important;
        color: white !important;
        box-shadow: 0 2px 6px rgba(246, 86, 6, 0.3) !important;
        border-color: var(--primary-dark) !important;
    }

}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: 20px;
    /* Disable zoom and double-tap */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent Telegram webapp minimize on scroll */
    overscroll-behavior: none;
    /* Prevent horizontal scroll */
    max-width: 100vw;
}

.container {
    max-width: 100vw;
    min-height: 100vh;
    position: relative;
}

/* Header */
.header {
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    display: flex;                /* enable flexbox */
    align-items: center;          /* vertical centering */
    justify-content: space-between;  /* spread items evenly */
    position: relative;
    top: 0;
    z-index: 100;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.header-section {
    flex: 1;               /* each text section takes equal space */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.header p {
    font-size: 15px;     /* "гир бар" */
    margin: 15px;
    text-align: left;
}

.header-logo {
    width: 90px;     /* adjust width */
    height: auto;
  /* keep aspect ratio */
}



.header-text p {
    font-size: 16px;
    opacity: 0.9;
    margin: 0;
    text-align: right;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    overflow-x: auto;
    overflow-y: visible;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 12px 12px 12px;
    position: -webkit-sticky;
    position: sticky;
    top: 0px;
    z-index: 1001;
    gap: 9px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    /* Force minimum height */
    min-height: 55px;
    height: auto;
    align-items: center;
    /* Prevent dragging */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: pan-x;
    /* Ensure stickiness works on mobile */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Ensure proper containment */
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    /* Force new stacking context */
    will-change: transform;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.tab-button {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid transparent;
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    scroll-snap-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    /* Prevent dragging */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Only apply hover effects on devices that can actually hover (not touch devices) */
@media (hover: hover) {
    .tab-button:hover {
        background: rgba(246, 86, 6, 0.1);
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
}

@media (prefers-color-scheme: dark) and (hover: hover) {
    .tab-button:hover {
        background: rgba(246, 86, 6, 0.2);
    }
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
    border-color: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(246, 86, 6, 0.3);
}

/* Products Grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    padding: 16px;
    transition: opacity 0.2s ease;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.product-card {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    border: 2px solid transparent;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Product card hover effects removed for mobile optimization */

.product-card.in-cart {
    border: 2px solid var(--primary-color);
}

/* Hover effect class removed for mobile optimization */

.product-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.product-info {
    padding: 12px;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}

.product-description {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.3;
    height: 16px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

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

.price-container {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.product-price {
    font-size: 20px;
    font-weight: bold;
    color: var(--primary-color);
}

.product-weight {
    font-size: 12px;
    color: rgba(108, 117, 125, 0.5);
    font-weight: normal;
}

.add-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 16px;
    width: 50px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    margin: 0;
    text-align: center;
}

@media (hover: hover) {
    .add-btn:hover {
        background: var(--primary-dark);
    }
}

/* Quantity Controls */
.quantity-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quantity-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
}

.quantity-display {
    font-size: 14px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* Skeleton Loading */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    padding: 16px;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.skeleton-card {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    animation: pulse 2s ease-in-out infinite;
}

.skeleton-image {
    width: 100%;
    height: 120px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(222, 226, 230, 0.5) 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

.skeleton-info {
    padding: 12px;
}

.skeleton-title {
    height: 16px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(222, 226, 230, 0.5) 50%, var(--border) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    margin-bottom: 8px;
    animation: shimmer 2s infinite;
}

.skeleton-description {
    height: 12px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(222, 226, 230, 0.5) 50%, var(--border) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    margin-bottom: 8px;
    width: 80%;
    animation: shimmer 2s infinite;
}

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

.skeleton-price {
    height: 18px;
    width: 60px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(222, 226, 230, 0.5) 50%, var(--border) 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: shimmer 2s infinite;
}

.skeleton-button {
    height: 32px;
    width: 40px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(222, 226, 230, 0.5) 50%, var(--border) 75%);
    background-size: 200% 100%;
    border-radius: 16px;
    animation: shimmer 2s infinite;
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

/* Dark mode skeleton colors */
@media (prefers-color-scheme: dark) {
    .skeleton-image,
    .skeleton-title,
    .skeleton-description,
    .skeleton-price,
    .skeleton-button {
        background: linear-gradient(90deg, var(--border) 25%, rgba(64, 64, 64, 0.5) 50%, var(--border) 75%);
        background-size: 200% 100%;
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}


/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    align-items: flex-end;
    padding: 0;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--background);
    width: 100%;
    max-height: 80vh;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    max-height: 50vh;
    overflow-y: auto;
}

.cart-items {
    padding: 16px 20px;
}

.cart-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.item-info {
    flex: 1;
}

.item-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.item-price {
    font-size: 12px;
    color: var(--text-secondary);
}

.item-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cart-summary {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
}

.modal-footer {
    padding: 16px 20px;
    display: flex;
    justify-content: center;
    border-top: 1px solid var(--border);
}

.btn-clear {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.3);
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-clear:hover {
    background: rgba(220, 53, 69, 0.15);
    border-color: rgba(220, 53, 69, 0.5);
}

/* Product unavailable */
.product-card.unavailable {
    opacity: 0.5;
    pointer-events: none;
}

.product-card.unavailable::after {
    content: 'Недоступно';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.product-card {
    position: relative;
}

/* Responsive */
@media (max-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 12px;
    }

    .product-card {
        border-radius: 8px;
    }

    .product-image {
        height: 85px;
    }

    .product-info {
        padding: 7px;
    }

    .category-tabs {
        padding: 0 4px;
    }

    .tab-button {
        padding: 10px 12px;
        font-size: 13px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
        margin: 0 auto;
    }

    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}