/* ============================================
   Pro100Store — Responsive & Cross-Browser Fix
   Этот файл ПЕРЕБИВАЕТ проблемные правила styles.css
   чтобы НЕ ЛОМАТЬ десктоп, но ПОЧИНИТЬ мобильные.
   ============================================ */

/* ============ GLOBAL FIXES ============ */

/* Prevent text-size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* CRITICAL: Prevent horizontal overflow globally */
html,
body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    margin: 0;
    padding: 0;
}

/* Smooth scrolling on iOS */
.chat-conversations,
.chat-messages,
.admin-sidebar,
.key-list,
.modal-content {
    -webkit-overflow-scrolling: touch;
}

/* ============ iOS / Safari Safe Area ============ */

@supports (padding: env(safe-area-inset-bottom)) {
    .header {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .footer {
        padding-bottom: calc(30px + env(safe-area-inset-bottom));
    }

    .mobile-menu-btn {
        top: calc(12px + env(safe-area-inset-top));
        left: calc(12px + env(safe-area-inset-left));
    }

    .cart-notification {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .admin-sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .admin-burger {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* Fix 100vh on mobile Safari */
@supports (-webkit-touch-callout: none) {
    .admin-layout {
        min-height: -webkit-fill-available;
    }

    .chat-layout {
        height: -webkit-fill-available;
    }
}

/* ============ ADMIN: Burger Menu ============ */

.admin-burger {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    background: #1a1a2e;
    color: white;
    border: none;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 999;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.admin-burger:hover {
    transform: scale(1.05);
    background: #2d2d4a;
}

.admin-burger svg {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

.admin-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.admin-overlay.active {
    display: block;
    opacity: 1;
}

/* ============ Desktop: hide mobile-only elements ============ */

.mobile-catalog-row {
    display: none;
}

.mobile-actions {
    display: none;
}

/* ============ FIX: Header overflow on medium screens (1024-1280px) ============ */

@media (max-width: 1024px) {

    /* Allow header to flex instead of overflowing */
    .header-actions {
        min-width: auto !important;
        flex-shrink: 1 !important;
        gap: 8px;
    }

    .header-search-wrapper {
        gap: 16px;
    }

    .header-btn {
        padding: 10px 12px;
        white-space: nowrap;
    }

    .auto-delivery-badge {
        padding: 8px 12px;
        font-size: 12px;
    }

    .auto-delivery-badge span {
        font-size: 11px;
    }

    /* Product Page Gallery Fix */
    .product-page {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        padding: 0 !important;
    }

    .product-gallery {
        max-width: 100% !important;
        margin: 0 !important;
        aspect-ratio: auto !important;
        height: auto !important;
        width: 100% !important;
    }

    .product-main-image {
        height: 280px !important;
        width: 100% !important;
        background: var(--bg-tertiary);
        border-radius: 12px;
        overflow: hidden;
        position: relative;
    }

    .product-main-image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        /* Ensure full art is visible */
        padding: 10px;
    }

    /* FIX: Left align everything on product page */
    .product-details {
        padding: 0 !important;
        text-align: left !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .product-details-title {
        text-align: left !important;
        font-size: 22px !important;
        line-height: 1.2 !important;
        margin-bottom: 12px !important;
        width: 100% !important;
    }

    .product-details-rating {
        display: flex !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 8px !important;
        margin-bottom: 20px !important;
        width: 100% !important;
    }

    /* FIX: Versions/Tariffs labels */
    .product-tariffs {
        width: 100% !important;
        text-align: left !important;
    }

    .tariffs-list {
        gap: 12px !important;
    }

    /* FIX: Out of stock badges on product page (Avoid overlap) */
    .tariff-btn .out-of-stock-badge {
        position: absolute !important;
        top: 4px !important;
        right: 4px !important;
        font-size: 10px !important;
        padding: 4px 8px !important;
        z-index: 5 !important;
        white-space: nowrap !important;
        min-width: fit-content !important;
    }

    /* FIX: Stack buttons vertically and force width */
    .product-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        margin-top: 24px !important;
        width: 100% !important;
    }

    .product-buy-btn,
    .product-cart-btn {
        display: flex !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 54px !important;
        padding: 0 !important;
        font-size: 16px !important;
        margin: 0 !important;
        justify-content: center !important;
        align-items: center !important;
    }

    /* Fix white login icon on mobile */
    .login-btn {
        background: var(--accent) !important;
        color: white !important;
    }

    .login-btn svg {
        stroke: var(--text-primary) !important;
    }

    .login-btn:hover svg,
    .login-btn:active svg {
        stroke: white !important;
    }
}

/* On ≤1024px: switch to icon-only buttons */
@media (max-width: 1024px) {
    .header-btn span {
        display: none;
    }

    .auto-delivery-badge span {
        display: none;
    }

    .auto-delivery-badge {
        padding: 8px 12px;
    }
}

/* ============ TABLET: 1024px ============ */

@media (max-width: 1024px) {

    /* Show mobile catalog row */
    .mobile-catalog-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0;
    }

    /* Catalog button — inline, not fixed */
    .mobile-menu-btn {
        position: static !important;
        display: inline-flex !important;
        align-items: center;
        gap: 10px;
        width: auto;
        height: auto;
        padding: 12px 20px;
        background: var(--bg-secondary, #f0f0f0);
        color: var(--text-primary, #1a1a2e);
        border: none;
        border-radius: 12px;
        font-size: 17px;
        font-weight: 600;
        cursor: pointer;
        z-index: auto;
        box-shadow: none;
    }

    .mobile-menu-btn span {
        display: inline;
        font-family: inherit;
    }

    .mobile-menu-btn svg {
        width: 24px;
        height: 24px;
        flex-shrink: 0;

        /* Mobile back button */
    }

    .mobile-back-btn {
        display: inline-flex !important;
        align-items: center;
        gap: 4px;
        padding: 8px 14px;
        background: var(--bg-secondary, #f0f0f0);
        color: var(--text-primary, #1a1a2e);
        border: 1px solid var(--border-color, #e0e0e0);
        border-radius: 10px;
        font-size: 13px;
        font-weight: 500;
        cursor: pointer;
        white-space: nowrap;
        transition: background 0.2s, transform 0.15s;
    }

    .mobile-back-btn:active {
        transform: scale(0.95);
        background: var(--bg-tertiary, #e0e0e0);
    }

    .mobile-back-btn svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }

    /* Show mobile actions (icons row) */
    .mobile-actions {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .mobile-actions .header-btn {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-actions .header-btn span {
        display: none;
    }

    /* Admin burger visible */
    .admin-burger {
        display: flex;
    }

    /* Admin sidebar: slide-in drawer */
    .admin-sidebar {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        box-shadow: none;
    }

    .admin-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .admin-content {
        padding: 20px;
    }

    /* Chat layout: single column */
    .chat-layout {
        grid-template-columns: 1fr !important;
        height: calc(100vh - 80px);
    }

    .chat-sidebar {
        display: none;
    }

    .chat-sidebar.mobile-active {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 500;
    }

    .chat-detail-panel {
        display: none;
    }

    /* Product page: single column */
    .product-page {
        grid-template-columns: 1fr !important;
    }

    .product-details {
        position: static !important;
    }

    /* Stats grid on tablet */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Product images: SQUARE on tablet/mobile */
    .product-image {
        aspect-ratio: 1 / 1;
        overflow: hidden;
        border-radius: 10px;
    }

    .product-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

/* ============ TABLET SMALL / PHABLET: 768px ============ */

/* Sold Out Badges (Centralized) */
.out-of-stock-badge {
    position: absolute;
    top: -6px !important;
    right: -6px !important;
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
    color: white;
    font-size: 10px !important;
    padding: 4px 10px !important;
    border-radius: 8px;
    font-weight: 700;
    z-index: 100 !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.tariff-btn .out-of-stock-badge {
    top: -8px !important;
    right: -8px !important;
    font-size: 10px !important;
    padding: 3px 8px !important;
}

@media (max-width: 768px) {

    /* === HEADER: Combined Catalog + Actions row (Like Screenshot) === */
    .header-top-content {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        padding: 12px 16px !important;
    }

    .header-search-wrapper {
        display: contents !important;
    }

    /* Hide logo and desktop actions strictly */
    .logo,
    .auto-delivery-badge,
    .header-info,
    .header-actions {
        display: none !important;
    }

    /* Row 1: Catalog Button + Icons (mobile-actions) */
    .mobile-catalog-row {
        order: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .mobile-menu-btn {
        padding: 10px 14px !important;
        font-size: 16px !important;
        background: var(--bg-tertiary) !important;
        border-radius: 10px !important;
        gap: 8px !important;
    }

    .mobile-actions {
        display: flex !important;
        gap: 8px !important;
    }

    .mobile-actions .header-btn {
        background: var(--bg-tertiary) !important;
        border-radius: 10px !important;
        width: 44px !important;
        height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
    }

    .mobile-actions .header-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Row 2: Search box full width */
    .search-box {
        order: 2 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .search-box input {
        height: 48px !important;
        border-radius: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .header-btn {
        padding: 0 !important;
        width: 44px !important;
        height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
        background: var(--bg-tertiary) !important;
    }

    .header-top {
        padding: 0;
    }



    /* Banner: prevent text clipping */
    .promo-slider,
    .featured-section {
        overflow: hidden;
    }

    .promo-slide h2,
    .featured-slide h2 {
        font-size: 18px !important;
        line-height: 1.3;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .promo-slide p,
    .featured-slide p {
        font-size: 13px !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Products Consistency */
    .products-section {
        margin-bottom: 30px !important;
        padding: 0 !important;
    }

    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
        /* Adjusted from repeat(2, 1fr) for better flexibility */
        grid-auto-rows: 1fr !important;
        gap: 16px !important;
        padding: 0 16px !important;
    }

    .products-section.super-prices {
        padding: 10px 0 !important;
        margin-bottom: 30px !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    .products-section.super-prices .container {
        padding: 0 !important;
    }

    .products-section.super-prices .products-grid {
        padding: 0 10px !important;
        gap: 12px !important;
    }

    .product-image {
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        margin-bottom: 12px !important;
        overflow: visible !important;
        /* Allow out-of-stock badge to be visible */
        position: relative !important;
        background: var(--bg-tertiary) !important;
        border-radius: var(--radius-md) !important;
    }

    .product-image img {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    .product-card {
        padding: 8px !important;
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .product-info {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Admin content */
    .admin-content {
        padding: 16px;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .admin-title {
        font-size: 22px;
    }

    /* Tables: scrollable */
    .admin-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-table th,
    .admin-table td {
        white-space: nowrap;
        padding: 10px 14px;
        font-size: 13px;
    }

    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .keys-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .stat-card {
        padding: 16px;
    }

    @media (max-width: 768px) {
        .banner-content {
            overflow: hidden;
            min-height: 180px !important;
            /* Ensure banner doesn't shrink too much on mobile */
            padding: 20px !important;
        }

        .banner-title {
            font-size: clamp(16px, 4.5vw, 24px) !important;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
            word-break: break-word;
        }

        .banner-subtitle {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
        }
    }

    /* Catalog grid */
    .catalog-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 12px;
    }

    /* Product list (category page) */
    .product-list-item {
        grid-template-columns: 80px 1fr !important;
        gap: 12px;
        padding: 14px;
    }

    .product-list-actions {
        grid-column: 1 / -1;
    }

    /* Modals */
    .modal {
        padding: 12px;
    }

    .modal-content {
        max-width: 100%;
        border-radius: var(--radius-lg);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }

    /* Login / Auth */
    .login-container,
    .auth-card {
        padding: 20px !important;
        margin: 12px;
        max-width: 100% !important;
    }

    /* Account */
    .account-container,
    .account-content {
        padding: 16px !important;
    }

    /* Cart */
    .cart-container {
        padding: 16px;
    }

    .cart-item {
        flex-direction: column;
        gap: 12px;
    }

    .cart-summary {
        position: static !important;
    }

    /* Tabs: scrollable */
    .tabs-header {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }

    .tabs-header::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 10px 12px;
        font-size: 12px;
    }

    /* Footer */
    .footer-top {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .payment-methods {
        flex-direction: column;
        align-items: center;
    }

    /* Tariffs: 2 columns for better space usage */
    .tariffs-list {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .tariff-btn {
        min-width: 0 !important;
        width: 100% !important;
        padding: 12px 8px !important;
        align-items: center !important;
        text-align: center !important;
    }

    .tariff-name {
        font-size: 13px !important;
        margin-bottom: 2px !important;
    }

    .tariff-price {
        font-size: 12px !important;
    }

    /* Product buttons */
    .product-buttons {
        grid-template-columns: 1fr !important;
    }

    /* Breadcrumb */
    .breadcrumb {
        font-size: 12px;
        flex-wrap: wrap;
    }
}

/* ============ MOBILE: 480px ============ */
/* THIS IS THE KEY FIX: override styles.css `products-grid: 1fr` at 480px */

/* Banner Overflow Fixes */
.banner-section {
    width: 100% !important;
    margin-bottom: 30px !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
}

.banner-slider {
    width: 100% !important;
    border-radius: var(--radius-lg) !important;
}

.banner-slide {
    min-width: 100% !important;
}

.banner-content {
    padding: 20px !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 180px !important;
    text-align: center !important;
}

.banner-text {
    max-width: 100% !important;
    margin-bottom: 20px !important;
}

.banner-title {
    font-size: 20px !important;
    margin-bottom: 8px !important;
}

.banner-subtitle {
    font-size: 13px !important;
}

.banner-image {
    max-height: 120px !important;
    width: auto !important;
    margin: 0 auto !important;
}

/* Product Tabs - Horizontal Scroll Fix */
.product-info-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 10px !important;
    margin: 0 -15px 20px !important;
    padding: 0 15px !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.tab-btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    padding: 10px 15px !important;
    font-size: 13px !important;
}

/* Breadcrumb Trim */
.breadcrumb {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
    display: block !important;
}

.product-image-container img {
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
}

/* Product page padding fixes */
.product-details {
    padding: 0 15px !important;
}

.product-title {
    font-size: 20px !important;
    line-height: 1.3 !important;
    margin-bottom: 12px !important;
    margin-top: 16px !important;
    padding: 0 15px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    word-wrap: break-word !important;
    max-height: 52px !important;
}


.product-buttons {
    padding: 0 15px !important;
    margin-top: 20px !important;
}

.product-buy-btn,
.product-cart-btn {
    margin: 0 0 12px 0 !important;
    border: 1px solid var(--border-color) !important;
}

.product-cart-btn {
    background: transparent !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.product-cart-btn:hover {
    background: var(--bg-tertiary) !important;
}

/* Tariff buttons spacing */
.tariff-btn {
    margin: 8px 0 !important;
    padding: 12px !important;
}

/* Product features list */
.product-features {
    padding: 0 15px !important;
    margin-top: 20px !important;
}

/* Tab content padding */
.tab-content {
    padding: 15px !important;
}

/* End of 768px fixes */

@media (max-width: 480px) {

    /* Container */
    .container {
        padding: 0 12px;
    }

    /* FORCE 2 columns and consistent padding */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        padding: 0 10px !important;
    }

    .products-section.super-prices {
        padding: 15px 0 !important;
    }

    /* Force button stacking on narrowest screens */
    .product-buttons {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        margin-top: 20px !important;
    }

    .product-buy-btn,
    .product-cart-btn {
        width: 100% !important;
        height: 52px !important;
        margin: 0 !important;
    }

    /* Fix breadcrumb clipping */
    .breadcrumb {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block !important;
        font-size: 11px !important;
    }

    /* Product cards: compact */
    .product-card {
        padding: 10px;
    }

    .product-image {
        aspect-ratio: 1 / 1 !important;
        overflow: hidden;
        border-radius: 8px;
    }

    .product-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .product-card-name {
        font-size: 12px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-word;
        line-height: 1.3;
    }

    .product-card-price {
        font-size: 15px !important;
    }

    .product-card-old-price {
        font-size: 11px;
    }

    .product-card-bottom {
        gap: 6px;
    }

    .product-card-rating {
        font-size: 12px;
    }

    .btn-buy {
        padding: 8px 12px;
        font-size: 12px;
    }

    .btn-cart {
        width: 36px;
        height: 36px;
    }

    /* Header compact */
    .logo-text {
        font-size: 20px;
    }

    .header-top {
        padding: 8px 0;
    }

    .auto-delivery-badge {
        font-size: 11px;
        padding: 6px 10px;
    }

    /* Banner: very compact */
    .banner-content {
        padding: 20px 14px;
        min-height: 150px !important;
    }

    .banner-title {
        font-size: 16px !important;
    }

    .banner-subtitle {
        font-size: 11px;
    }

    .banner-slide img {
        max-height: 100px;
        opacity: 0.5;
    }

    /* Catalog grid */
    .catalog-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .catalog-item {
        padding: 14px;
    }

    .catalog-icon {
        width: 40px;
        height: 40px;
        margin-bottom: 8px;
    }

    .catalog-item-title {
        font-size: 12px;
    }

    /* Info badges */
    .info-badges {
        grid-template-columns: 1fr !important;
        padding: 16px;
        gap: 12px;
    }

    /* Sections */
    .section-header h2 {
        font-size: 18px;
    }

    .main {
        padding: 12px 0;
    }

    /* Footer */
    .footer {
        padding: 24px 0 20px;
        margin-top: 30px;
    }

    .payment-icons {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Admin compact */
    .admin-content {
        padding: 12px;
    }

    .admin-title {
        font-size: 20px;
    }

    .btn-primary,
    .btn-secondary {
        padding: 10px 16px;
        font-size: 13px;
    }

    /* Forms: prevent iOS zoom on focus (font-size >= 16px) */
    .form-input,
    .form-select,
    .form-textarea,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Modals: fullscreen on small phones */
    .modal {
        padding: 0;
    }

    .modal-content {
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        height: 100%;
    }

    /* Product page */
    .product-details {
        padding: 16px;
    }

    .product-details-title {
        font-size: 20px;
    }

    .product-details-price .product-price {
        font-size: 22px;
    }

    /* Cart */
    .cart-container {
        padding: 12px;
    }
}

/* ============ VERY SMALL: 360px ============ */

@media (max-width: 360px) {

    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .product-card {
        padding: 8px;
    }

    .product-image {
        aspect-ratio: 1 / 1 !important;
    }

    .product-card-name {
        font-size: 11px !important;
    }

    .product-card-price {
        font-size: 14px !important;
    }

    .logo-text {
        font-size: 18px;
    }

    .banner-title {
        font-size: 14px !important;
    }

    .catalog-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============ VERY SMALL: 320px ============ */

@media (max-width: 320px) {
    .products-grid {
        grid-template-columns: 1fr !important;
    }

    .header-btn {
        padding: 8px;
    }
}

/* ============ TOUCH OPTIMIZATION ============ */

@media (hover: none) and (pointer: coarse) {

    /* Minimum 44px touch targets (Apple HIG) */
    .sidebar-link,
    .admin-nav-link {
        min-height: 44px;
    }

    .header-btn,
    .btn-buy,
    .btn-cart,
    .tab-btn,
    .sort-btn,
    .page-btn,
    .pagination-btn,
    .faq-question {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch */
    .product-card:hover {
        transform: none !important;
    }

    .product-card:active {
        transform: scale(0.98);
    }

    .btn-buy:hover,
    .btn-cart:hover {
        transform: none !important;
    }

    /* Larger checkboxes */
    input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
}

/* ============ LANDSCAPE MOBILE ============ */

@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 100vh;
        max-height: 100dvh;
    }

    .banner-content {
        min-height: 120px !important;
        padding: 16px;
    }
}

/* ============ 4K / LARGE SCREENS ============ */

@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }
}

/* ============ PRINT ============ */

@media print {

    .header,
    .footer,
    .sidebar,
    .admin-sidebar,
    .mobile-menu-btn,
    .admin-burger,
    .admin-overlay,
    .cart-notification,
    .chat-input-area {
        display: none !important;
    }

    .admin-layout,
    .main-layout {
        display: block;
    }

    .admin-content {
        padding: 0;
    }
}

/* ============ MOBILE: 768px ============ */
@media (max-width: 768px) {

    /* Mobile-only container and body rules */
    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .container {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden !important;
        padding: 0 12px !important;
        box-sizing: border-box !important;
    }

    /* Main layout: force single column, full width */
    .main-layout {
        display: block !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    .content {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* Header: full width, no overflow */
    .header {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .header-top-content {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .header-search-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Main section */
    .main {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Footer */
    footer,
    .footer {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* ====== INDEX PAGE / COMMON MOBILE FIXES ====== */

    /* Products grid: never exceed viewport */
    .products-grid {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* Product card: contained */
    .product-card {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .product-card-image {
        width: 100% !important;
        max-width: 100% !important;
    }

    .product-card-image img {
        width: 100% !important;
        max-width: 100% !important;
        object-fit: cover !important;
    }

    .product-card-name {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        white-space: normal !important;
    }

    /* Section header */
    .section-header {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .section-header h2 {
        font-size: 18px !important;
        word-break: break-word !important;
    }

    .section-subtitle {
        font-size: 13px !important;
        word-break: break-word !important;
    }

    /* Banner section */
    .banner-section,
    .banner-content,
    .banner-slide {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* Info badges */
    .info-badges {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* Override inline styles for sales-badge from product.js */
    .sales-badge,
    #salesBadge {
        max-width: 100% !important;
        margin-left: 0 !important;
        flex-shrink: 1 !important;
        white-space: nowrap !important;
    }

    /* Rating row must wrap — fix inline flex */
    .product-details-rating {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Stars + reviews count + sales badge — wrap onto second line */
    .product-details-rating>* {
        flex-shrink: 1 !important;
    }

    #headerReviewsCount {
        flex-shrink: 1 !important;
    }

    /* Related/Popular products sections */
    .related-products,
    .popular-products {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }

    /* ====== PRODUCT PAGE MOBILE FIXES ====== */

    /* Product page: single column, full width */
    .product-page {
        flex-direction: column !important;
        gap: 16px !important;
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    /* Product gallery: full width, no max-width limit */
    .product-gallery {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .product-main-image {
        height: auto !important;
        max-height: 300px !important;
    }

    .product-main-image img,
    .product-page-img {
        max-height: 300px !important;
        width: 100% !important;
        object-fit: contain !important;
    }

    /* Product details: full width, proper padding */
    .product-details {
        position: static !important;
        padding: 16px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* Product title: no truncation, wrap properly */
    .product-details-title {
        font-size: 20px !important;
        line-height: 1.3 !important;
        margin-bottom: 12px !important;
        max-height: none !important;
        -webkit-line-clamp: unset !important;
        display: block !important;
        overflow: visible !important;
        text-overflow: unset !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        padding: 0 !important;
    }

    /* Rating row: wrap to multi-line */
    .product-details-rating {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        align-items: center !important;
        margin-bottom: 16px !important;
    }

    .sales-badge {
        margin-left: 0 !important;
        margin-top: 4px !important;
    }

    /* Tariffs: 2 columns grid, fit inside container */
    .product-tariffs {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .tariffs-title {
        font-size: 15px !important;
        margin-bottom: 10px !important;
    }

    .tariffs-list {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .tariff-btn {
        min-width: 0 !important;
        width: 100% !important;
        padding: 12px 8px !important;
        text-align: center !important;
        align-items: center !important;
        position: relative !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    .tariff-name {
        font-size: 13px !important;
        word-break: break-word !important;
    }

    .tariff-price {
        font-size: 12px !important;
    }

    /* Price section */
    .product-details-price {
        flex-wrap: wrap !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
    }

    .product-details-price .product-price {
        font-size: 24px !important;
    }

    /* Promo code: fit inside container */
    .product-promo {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .product-promo div[style*="display: flex"] {
        width: 100% !important;
    }

    #productPromoInput {
        min-width: 0 !important;
        flex: 1 1 0 !important;
    }

    /* Product buttons: full width, stacked */
    .product-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        margin-top: 16px !important;
        padding: 0 !important;
    }

    .product-buy-btn,
    .product-cart-btn {
        width: 100% !important;
        max-width: 100% !important;
        height: 52px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    /* Product features */
    .product-features {
        padding: 0 !important;
        margin-top: 16px !important;
    }

    /* Tabs: horizontal scroll without cutting off */
    .tabs-header {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding: 4px !important;
        gap: 2px !important;
        margin: 0 0 16px 0 !important;
    }

    .tabs-header::-webkit-scrollbar {
        display: none !important;
    }

    .tab-btn {
        flex: 0 0 auto !important;
        white-space: nowrap !important;
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    /* Tab content: proper padding, text wrapping */
    .tab-content {
        padding: 0 !important;
    }

    /* Product description: text wrapping fix */
    .product-description {
        padding: 16px !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        hyphens: auto !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .product-description p,
    .product-description ul,
    .product-description li {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        max-width: 100% !important;
    }

    .product-description h3 {
        font-size: 16px !important;
        word-break: break-word !important;
    }

    /* Confirmations block */
    .product-confirmations {
        box-sizing: border-box !important;
        width: 100% !important;
    }

    /* Breadcrumb: scrollable, not truncated */
    .breadcrumb {
        white-space: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        text-overflow: unset !important;
        display: flex !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        max-width: 100% !important;
        font-size: 12px !important;
        padding-bottom: 4px !important;
    }

    .breadcrumb::-webkit-scrollbar {
        display: none !important;
    }

    /* Reviews section */
    .reviews-section {
        margin-bottom: 30px !important;
    }

    .reviews-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }

    .reviews-avg {
        font-size: 36px !important;
    }

    .review-card {
        padding: 16px !important;
    }

    .review-header {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    /* FAQ accordion mobile */
    .faq-item {
        padding: 0 16px !important;
    }

    .faq-question {
        font-size: 14px !important;
        padding: 14px 0 !important;
    }

    .faq-answer {
        font-size: 13px !important;
        padding: 0 0 14px !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* ====== CATEGORY PAGE MOBILE FIXES ====== */

    /* Category header */
    .category-header {
        margin-bottom: 16px !important;
    }

    .category-header h1 {
        font-size: 22px !important;
        line-height: 1.3 !important;
    }

    /* Sort bar: wrap buttons, fit viewport */
    .sort-bar {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .sort-label {
        width: 100% !important;
        font-size: 13px !important;
    }

    .sort-btn {
        padding: 6px 12px !important;
        font-size: 12px !important;
    }

    /* Products list: full width, vertical stack */
    .products-list {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        gap: 12px !important;
    }

    /* Product list item: single column stack instead of 3-column grid */
    .product-list-item {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: unset !important;
        gap: 12px !important;
        padding: 16px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* Product list image: bigger, centered */
    .product-list-image {
        width: 140px !important;
        height: 140px !important;
        flex-shrink: 0 !important;
        align-self: center !important;
        border-radius: 12px !important;
    }

    .product-list-image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* Product list info: full width, text wrap */
    .product-list-info {
        width: 100% !important;
        max-width: 100% !important;
    }

    .product-list-title {
        font-size: 15px !important;
        line-height: 1.3 !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }

    .product-list-meta {
        gap: 8px !important;
        font-size: 12px !important;
        flex-wrap: wrap !important;
    }

    .product-list-desc {
        font-size: 13px !important;
        line-height: 1.4 !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }

    /* Product list actions: full width, left align */
    .product-list-actions {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
    }

    .product-list-price {
        text-align: left !important;
    }

    .product-list-price .product-price {
        font-size: 20px !important;
    }

    /* Pagination mobile */
    .pagination {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .page-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 13px !important;
    }

    /* Sold-out badge on list items */
    .product-list-item .sold-out-badge {
        font-size: 10px !important;
        padding: 2px 6px !important;
    }
}