/* Основные стили маркетплейса */
.market-shell {
    display: grid;
    max-width: 100%;
    overflow-x: hidden;
}

.market-hero {
    border: 1px solid #e9edf3;
    border-radius: 16px;
    padding-bottom: 16px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.market-title-wrap h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
    color: #009688;
    display: flex;
    align-items: center;
    gap: 10px;
}

.market-title-wrap p {
    margin: 6px 0 0;
    color: #64748b;
    font-size: 0.92rem;
}

.market-cart-trigger {
    border: 1px solid #dbe7ff;
    background: #f8fbff;
    color: #1f3b88;
    border-radius: 12px;
    padding: 9px 14px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.market-cart-trigger i {
    font-size: 1.4rem;
}

.market-cart-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.15);
}

.cart-pill {
    min-width: 24px;
    height: 24px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #3b82f6;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
    padding: 0 6px;
}

/* Сетка товаров */
.market-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    min-width: 0;
}

/* Карточка товара */
.product-card {
    background: #fff;
    /* border: 1px solid #e0e0e0; */
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
    min-width: 0;
    max-width: 100%;
}

.product-card.is-clickable {
    cursor: pointer;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
    border-color: #d8e5fb;
}

.product-card.hidden-by-filter {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

.product-card.visible-by-filter {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.product-cover {
    width: 100%;
    aspect-ratio: 4/3;
    background: #f3f6fb;
    border-bottom: 1px solid #edf2f8;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-cover img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.product-body {
    padding: 12px;
    display: grid;
    gap: 10px;
    min-width: 0;
}

.product-head {
    display: grid;
    gap: 6px;
}

.product-name {
    font-size: 14px;
}

.product-price {
    font-weight: 800;
    font-size: 1.02rem;
    color: #E91E63;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.product-lp {
    font-size: 0.9rem;
    color: #64748b;
    font-weight: 700;
}

.product-lp-label {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-right: 2px;
}

.product-controls {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
    min-width: 0;
}

/* Количество товара */
.qty-stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid #e4ebf5;
    border-radius: 10px;
    overflow: hidden;
    background: #fbfdff;
    min-height: 38px;
}

.qty-stepper button {
    border: none;
    background: transparent;
    width: 34px;
    color: #475569;
    font-weight: 700;
    transition: background .15s ease;
}

.qty-stepper button:hover {
    background: #f0f5ff;
}

.qty-stepper input {
    width: 38px;
    border: none;
    text-align: center;
    background: transparent;
    font-weight: 700;
    color: #1f2937;
}

.qty-stepper input:focus {
    outline: none;
}

/* Кнопка добавления */
.add-btn {
    border: 1px solid #d9e7ff;
    background: #edf4ff;
    color: #1f3b88;
    border-radius: 10px;
    min-height: 38px;
    font-weight: 700;
    transition: all .2s ease;
}

.add-btn:hover {
    background: #e1eeff;
}

.add-btn.in-cart {
    border-color: #bbf7d0;
    background: #ecfdf3;
    color: #166534;
}

/* Группировка по категориям */
.category-section {
    width: 100%;
    display: block;
    margin-top: 20px;
}

.category-section:first-child {
    margin-top: 0;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 10px;
    /* padding: 12px 16px; */
    /* background: linear-gradient(135deg, #f0f9ff 0%, #0096882e 100%); */
    /* border: 1px solid #bae6fd; */
    /* border-radius: 12px; */
    margin-bottom: 14px;
}

.category-header-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0ea5e9;
    border-radius: 10px;
    color: #fff;
    font-size: 1.1rem;
}

.category-header-title {
    font-size: 1.0rem;
    color: #0369a1;
}

.category-header-count {
    margin-left: auto;
    background: #fff;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #0891b2;
}

.category-products {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 14px !important;
}

/* Переключатель вида */
.view-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid #e5eaf2;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.view-toggle button {
    border: none;
    background: transparent;
    padding: 8px 12px;
    color: #64748b;
    transition: all .2s ease;
}

.view-toggle button.active {
    background: #0ea5e9;
    color: #fff;
}

.view-toggle button:hover:not(.active) {
    background: #f1f5f9;
}

/* Панель выбранных товаров */
.selected-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 1040;
}

.selected-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.selected-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(420px, 100%);
    height: 100dvh;
    max-height: 100dvh;
    background: #fff;
    border-left: 1px solid #e6ecf5;
    transform: translateX(100%);
    transition: transform .24s ease;
    z-index: 1041;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.selected-panel.open {
    transform: translateX(0);
}

.selected-head,
.selected-foot {
    padding: 14px;
    border-bottom: 1px solid #edf1f7;
}

.selected-foot {
    border-bottom: none;
    border-top: 1px solid #edf1f7;
    background: #fbfdff;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.selected-items {
    padding: 12px;
    overflow: auto;
    display: grid;
    gap: 8px;
    align-content: start;
    min-height: 0;
}

.selected-close-btn {
    border: none;
    background: transparent;
    color: #64748b;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.selected-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-weight: 700;
    color: #0f172a;
}

.selected-item {
    border: 1px solid #e7edf7;
    border-radius: 12px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: flex-start;
}

.selected-item-image {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f1f5f9;
}

.selected-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.selected-item-content {
    flex: 1;
    min-width: 0;
}

.selected-item-qty {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
}

.qty-btn {
    width: 24px;
    height: 24px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.qty-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

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

.qty-value {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
}

.selected-item-title {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    color: #111827;
}

.selected-item-meta {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 0.82rem;
}

.selected-remove {
    border: 1px solid #fee2e2;
    background: #fef2f2;
    color: #b91c1c;
    border-radius: 10px;
    width: 34px;
    height: 34px;
}

.checkout-btn {
    width: 100%;
    min-height: 42px;
    border: 1px solid #bbf7d0;
    background: #22c55e;
    color: #fff;
    border-radius: 12px;
}

.checkout-btn:disabled {
    background: #cbd5e1;
    border-color: #cbd5e1;
    cursor: not-allowed;
}

/* Модальное окно заказа */
.order-modal {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.order-modal.open {
    display: flex;
}

.order-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 1055;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
}

.order-modal-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.order-modal-dialog {
    position: relative;
    width: min(560px, 100%);
    background: #ffffff;
    border-radius: 20px;
    border: 1px solid #e6ecf5;
    padding: 24px;
    box-shadow: 0 25px 50px rgba(15, 23, 42, 0.15);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: auto;
    z-index: 1061;
}

.order-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.order-modal-close {
    border: 1px solid #e5ecf6;
    background: #fff;
    border-radius: 12px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    transition: border-color .2s ease, transform .2s ease;
}

.order-modal-close:hover {
    border-color: #1d4ed8;
    transform: translateY(-1px);
}

.order-modal-form {
    display: grid;
    gap: 12px;
}

.order-modal-form .form-label {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: #0f172a;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.order-form {
    padding: 20px 0;
}

.order-preview {
    border: 1px solid #dde5f0;
    border-radius: 16px;
    padding: 16px;
    background: #f8fbff;
    display: none;
    flex-direction: column;
    gap: 12px;
}

.order-preview.visible {
    display: flex;
}

.order-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.order-preview-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
    font-size: 0.85rem;
    color: #475569;
}

.order-preview-details dt,
.order-preview-details dd {
    margin: 0;
}

.order-preview-items {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
    max-height: 220px;
    overflow: auto;
}

.order-preview-items li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e9eef6;
    font-size: 0.85rem;
    color: #0f172a;
}

.order-preview-total {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1rem;
    color: #111827;
}

.order-preview-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.order-feedback {
    min-height: 22px;
    font-size: 0.85rem;
    color: #0f172a;
}

.order-feedback:empty {
    display: none;
}

.order-feedback.error {
    color: #b91c1c;
}

/* .form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
} */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

/* Адаптивность */

/* 3 колонки на экранах от 1000px до 1400px */
@media (max-width: 1400px) {
    .market-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .category-products {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 1200px) {
    .market-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .category-products {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 992px) {
    .market-filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .page-header,
    .market-filters {
        padding: 0px;
        border-radius: 14px;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .product-card {
        /* border: none !important; */
        border-radius: 14px;
        /* box-shadow: none !important; */
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }

    .product-cover {
        aspect-ratio: 10/10;
        flex-shrink: 0 !important;
    }

    .product-body {
        padding: 10px;
        gap: 8px;
        margin-top: auto !important;
    }

    .market-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    /* Скрываем кнопки добавления в корзину в карточках на странице маркета */
    .product-controls {
        display: none !important;
    }

    /* Кнопка корзины прижата к правому краю */
    .page-header {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .page-title {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: 70% !important;
        margin: 0 !important;
        font-size: 1.25rem !important;
        text-align: left !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .page-header-actions {
        flex: 0 0 auto !important;
        margin-left: auto !important;
    }

    .market-cart-trigger {
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 8px 12px !important;
        font-size: 0.9rem !important;
        white-space: nowrap !important;
    }

    .page-header .d-flex {
        display: flex !important;
    }

    .market-filters {
        grid-template-columns: 1fr;
        background: transparent;
        border: none;
        box-shadow: none;
    }
    
    /* Принудительно показываем все фильтры на мобильных */
    .market-filters .market-select,
    .market-filters .market-input {
        border: 2px solid var(--dp-border-color) !important;
        border-radius: 8px !important;
    }
    
    .market-filters .market-select:focus,
    .market-filters .market-input:focus {
        border-color: var(--dp-primary) !important;
        outline: none !important;
        box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.1) !important;
    }
    
    /* Стили для поискового поля */
    .market-filter-group {
        position: relative !important;
        width: 100% !important;
    }
    
    .market-filter-group .bi-search {
        position: absolute !important;
        left: 12px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        color: var(--dp-text-muted) !important;
        z-index: 2 !important;
        pointer-events: none !important;
    }
    
    /* Улучшение touch событий для мобильных */
    .market-filters .market-select,
    .market-filters .market-input {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 150, 136, 0.2) !important;
        cursor: pointer !important;
    }
    
    /* Принудительное отображение нативного селекта на мобильных */
    .market-filters .market-select {
        -webkit-appearance: menulist !important;
        -moz-appearance: menulist !important;
        appearance: menulist !important;
    }

    .product-price {
        font-size: 0.96rem;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px;
        margin-top: auto !important;
    }

    .product-lp {
        align-self: flex-end;
    }

    .product-controls {
        grid-template-columns: auto 1fr;
    }

    .qty-stepper {
        width: auto;
    }

    .add-btn {
        width: 100%;
    }

    .selected-panel {
        width: 100%;
        border-left: none;
    }

    .selected-close-btn {
        border: none;
        box-shadow: none;
    }
}

/* Dark Theme for Marketplace */
[data-theme="dark"] .market-hero {
    background: var(--dp-card-bg);
    border-color: var(--dp-border-color);
}

[data-theme="dark"] .market-title-wrap h1 {
    color: var(--dp-primary);
}

[data-theme="dark"] .market-title-wrap p {
    color: var(--dp-text-secondary);
}

[data-theme="dark"] .market-cart-trigger {
    background: var(--dp-card-bg);
    border-color: var(--dp-border-color);
    color: var(--dp-text-primary);
}

[data-theme="dark"] .product-card {
    background: var(--dp-card-bg);
    border-color: var(--dp-border-color);
}

[data-theme="dark"] .product-image-container {
    background: var(--dp-body-bg);
}

[data-theme="dark"] .product-category {
    background: var(--dp-card-bg);
    color: var(--dp-text-secondary);
}

[data-theme="dark"] .product-title {
    color: var(--dp-text-primary);
}

[data-theme="dark"] .product-price {
    color: var(--dp-primary);
}

[data-theme="dark"] .product-old-price {
    color: var(--dp-text-muted);
}

[data-theme="dark"] .selected-panel {
    background: var(--dp-card-bg);
    border-color: var(--dp-border-color);
}

[data-theme="dark"] .selected-header {
    background: var(--dp-card-bg);
    color: var(--dp-text-primary);
}

[data-theme="dark"] .selected-item {
    background: var(--dp-body-bg);
    border-color: var(--dp-border-color);
}

[data-theme="dark"] .selected-item-title {
    color: var(--dp-text-primary);
}

[data-theme="dark"] .qty-btn {
    background: var(--dp-card-bg);
    border-color: var(--dp-border-color);
    color: var(--dp-text-primary);
}

[data-theme="dark"] .qty-value {
    color: var(--dp-text-primary);
}
