/* ========================================================================
   PRODUCTS MODULE — List, import wizard, product form
   ======================================================================== */

/* Customer export field picker (Customers index) */
.customer-export-fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem 1rem;
    max-height: 280px;
    overflow-y: auto;
    padding: 0.75rem;
    border: 1px solid var(--surface-border, #e8ecf0);
    border-radius: var(--radius-md, 10px);
    background: var(--surface-alt, #f8f9fb);
}

.customer-export-field-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.875rem;
    cursor: pointer;
}

.customer-export-field-check span {
    line-height: 1.4;
}

/* ---- List: product thumb in table ---- */
.product-thumb {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--surface-border);
    background: var(--surface-muted);
}

/* Additional / gallery images — multiple thumbs (form preview + product details modal) */
.product-additional-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-start;
}

.product-additional-gallery-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 140px;
}

.product-additional-gallery-item img {
    width: 120px;
    height: 120px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--surface-border);
    background: var(--surface-muted);
}

.product-additional-gallery-item--invalid {
    max-width: 100%;
}

/* Main image URL — single preview on product form */
.product-main-image-preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.product-main-image-preview-img {
    max-width: 100%;
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--surface-border);
    background: var(--surface-muted);
}

/* Category section image previews — match homepage box aspect ratios with cover crop */
.category-section-preview-frame {
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid var(--surface-border);
    background: var(--surface-muted);
    max-width: 100%;
}

.category-section-preview-frame--desktop {
    width: min(100%, 360px);
    aspect-ratio: 738 / 488.4;
}

.category-section-preview-frame--mobile {
    width: min(100%, 320px);
    aspect-ratio: 2 / 1;
}

.category-card-preview-frame {
    width: min(100%, 280px);
    aspect-ratio: 4 / 3;
}

.category-section-preview-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center;
}

.category-section-image-help {
    white-space: pre-line;
}

.product-name-cell .title {
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-name-cell .subtitle {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    display: block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.products-table-wrap {
    /* Keep horizontal scroll. Menus are portaled to body so they are not clipped here. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.products-table-wrap .data-table {
    min-width: 1480px;
}

.categories-list-table.products-table-wrap .data-table {
    min-width: 980px;
}

/* Categories index: avoid clipping row content against card edges */
.categories-index-card,
.categories-index-card-body {
    overflow: visible;
}

/* Categories: compact sticky Actions column (⋮ menu) */
.categories-list-table .category-actions-cell {
    vertical-align: middle;
    white-space: nowrap;
    padding-inline: var(--space-2);
}

.categories-list-table .category-inline-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: nowrap;
}

.categories-list-table .category-inline-actions .btn-icon {
    flex-shrink: 0;
}

.categories-list-table .category-inline-actions a.btn-icon {
    text-decoration: none;
    color: var(--text-secondary);
}

.categories-list-table.products-table-wrap .data-table th:last-child,
.categories-list-table.products-table-wrap .data-table td:last-child {
    min-width: 3.25rem;
    width: 3.25rem;
}

/* Custody status badges */
.badge-custody-active {
    background: var(--success-light);
    color: #059669;
}

.badge-custody-returned {
    background: var(--info-light);
    color: var(--info);
}

.badge-custody-partial {
    background: var(--warning-light);
    color: #B45309;
}

.badge-custody-closed {
    background: #F1F5F9;
    color: #64748B;
}

@media print {
    .custody-print-hide {
        display: none !important;
    }

    .main-wrapper {
        margin: 0 !important;
        width: 100% !important;
    }

    .main-content {
        padding: 0 !important;
    }
}

.products-table-wrap .data-table th,
.products-table-wrap .data-table td {
    vertical-align: middle;
    white-space: nowrap;
}

.products-table-wrap .data-table td.text-wrap-allow {
    white-space: normal;
    max-width: 240px;
}

/* Actions column: keep controls usable (links must match button layout) + sticky on horizontal scroll */
.products-table-wrap .data-table th:last-child,
.products-table-wrap .data-table td:last-child {
    position: sticky;
    inset-inline-end: 0;
    min-width: 56px;
    background: var(--surface-card);
    border-inline-start: 1px solid var(--surface-border);
    z-index: 2;
    white-space: normal;
    vertical-align: middle;
    overflow: visible;
}

.products-table-wrap .data-table thead th:last-child {
    z-index: 3;
}

.products-table-wrap .data-table tbody tr:hover td:last-child {
    background: var(--surface-hover);
}

/* Row actions: single ⋮ button opens Bootstrap dropdown */
.products-table-wrap .product-row-actions {
    display: flex;
    justify-content: flex-end;
}

.products-table-wrap .product-row-actions > .dropdown-toggle::after {
    display: none;
}

.products-table-wrap .product-row-actions .dropdown-menu {
    min-width: 12rem;
    font-size: var(--fs-sm);
}

.products-table-wrap .product-row-actions .dropdown-item {
    display: flex;
    align-items: center;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.products-table-wrap .product-row-actions .dropdown-item i {
    opacity: 0.85;
}

/* Orders index: ⋮ actions menu (also styled in order-details.css) */
.products-table-wrap .order-actions-menu {
    min-width: 15.5rem;
    max-width: 20rem;
    padding: 0.4rem 0;
    border: 1px solid var(--surface-border, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.products-table-wrap .order-actions-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: normal;
    line-height: 1.35;
    width: 100%;
    border: none;
    background: transparent;
}

.products-table-wrap .order-actions-menu .dropdown-item-label {
    flex: 1 1 auto;
    min-width: 0;
}

.products-table-wrap .order-actions-menu .dropdown-item-icon {
    flex: 0 0 auto;
    font-size: 1.05rem;
    opacity: 0.75;
    color: var(--text-secondary, #64748b);
}

.products-table-wrap .order-actions-menu .dropdown-item.active,
.products-table-wrap .order-actions-menu .dropdown-item.active:hover {
    background-color: #0d6efd;
    color: #fff;
    font-weight: 600;
}

.products-table-wrap .order-actions-menu .dropdown-item.active .dropdown-item-icon {
    color: #fff;
    opacity: 1;
}

/* Product status badges */
.badge-prod-active {
    background: var(--success-light);
    color: #059669;
}

.badge-prod-inactive {
    background: #F1F5F9;
    color: #64748B;
}

.badge-prod-draft {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-prod-outofstock {
    background: var(--danger-light);
    color: var(--danger);
}

/* Stock badges */
.badge-stock-in {
    background: var(--success-light);
    color: #059669;
}

.badge-stock-low {
    background: var(--warning-light);
    color: #B45309;
}

.badge-stock-out {
    background: var(--danger-light);
    color: var(--danger);
}

/* Bulk bar */
.bulk-actions-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
}

.bulk-actions-bar .form-select {
    max-width: 200px;
    font-size: var(--fs-sm);
}

[data-theme="dark"] .bulk-actions-bar {
    background: rgba(99, 102, 241, 0.12);
}

/* Import wizard */
.import-steps {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.import-step {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 600;
    background: var(--surface-muted);
    color: var(--text-secondary);
    border: 1px solid var(--surface-border);
}

.import-step.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.import-step.done {
    background: var(--success-light);
    color: #059669;
    border-color: transparent;
}

.import-panel {
    min-height: 200px;
}

.import-error-list {
    max-height: 180px;
    overflow-y: auto;
    font-size: var(--fs-sm);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: var(--space-3);
    background: var(--danger-light);
    color: var(--danger);
}

.import-preview-table {
    max-height: 260px;
    overflow: auto;
    font-size: var(--fs-sm);
}

.import-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-3);
}

.import-summary-item {
    text-align: center;
    padding: var(--space-4);
    border-radius: var(--radius);
    border: 1px solid var(--surface-border);
    background: var(--surface-card);
}

.import-summary-item .num {
    font-size: var(--fs-2xl);
    font-weight: 800;
    color: var(--text-primary);
}

.import-summary-item .lbl {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* Product form page */
.product-form-page .form-section-card {
    margin-bottom: var(--space-5);
}

.product-url-drop {
    border: 2px dashed var(--surface-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    background: var(--surface-muted);
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.product-url-drop:focus-within {
    border-color: var(--primary);
    background: var(--primary-light);
}

.product-url-drop--tall {
    min-height: 8.5rem;
}

.product-related-shuttle-list {
    min-height: 240px;
}

[dir="rtl"] .product-related-shuttle.row {
    flex-direction: row-reverse;
}

.product-display-flags-row .form-check {
    padding-inline-start: 2.5rem;
    margin-bottom: 0;
}

.filters-bar-products .product-filter-field {
    min-width: 7.5rem;
    max-width: 14rem;
    flex: 1 1 7.5rem;
}

.filters-bar-products .product-filter-field .form-select {
    height: 42px;
    max-height: 42px;
    max-width: 100%;
    text-overflow: ellipsis;
}

.product-form-page .form-section-title {
    font-size: var(--fs-md);
    font-weight: 600;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-primary);
}

.drop-zone {
    border: 2px dashed var(--surface-border);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    text-align: center;
    background: var(--surface-muted);
    transition: border-color var(--transition-fast), background var(--transition-fast);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone input[type="file"] {
    display: none;
}

.image-preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.image-preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--surface-border);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .btn-remove-img {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

[dir="rtl"] .image-preview-item .btn-remove-img {
    right: auto;
    left: 4px;
}

.specs-table input {
    font-size: var(--fs-sm);
}

.related-select {
    min-height: 140px;
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.table-compact-switch .form-check-input {
    cursor: pointer;
}

.product-detail-modal .modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.product-detail-gallery {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.product-detail-gallery img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--surface-border);
}

@media (max-width: 992px) {
    .categories-index-card,
    .categories-index-card-body {
        overflow: hidden;
    }
}

@media (max-width: 768px) {
    .page-header-actions {
        width: 100%;
    }

    .page-header-actions .btn-primary-custom,
    .page-header-actions .btn-secondary-custom {
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .products-table-wrap .data-table {
        min-width: 900px;
    }

    .categories-list-table.products-table-wrap .data-table {
        min-width: 640px;
    }

    .filters-bar-products .product-filter-field {
        flex: 1 1 100%;
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    .filters-bar-products .filter-search {
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    .filters-bar-products {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-bar-products .product-filter-field .form-select,
    .filters-bar-products .filter-search input {
        height: 42px;
        max-height: 42px;
        width: 100%;
    }
}

@media (max-width: 576px) {
    .products-table-wrap .data-table {
        min-width: 760px;
    }

    .categories-list-table.products-table-wrap .data-table {
        min-width: 520px;
    }
}

/* ---- Excel management modal (Products index) ---- */
.product-excel-modal .product-excel-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 0;
    border-bottom: 1px solid var(--surface-border);
    margin-bottom: 0;
}

.product-excel-modal .product-excel-tabs .nav-link {
    white-space: nowrap;
    font-size: var(--fs-sm);
    padding: var(--space-2) var(--space-3);
}

.product-excel-modal .product-excel-tab-content {
    min-height: 12rem;
}

.product-excel-modal .product-excel-subtabs .nav-link {
    font-size: var(--fs-sm);
}

.product-excel-modal .import-required-note {
    max-height: 10rem;
    overflow-y: auto;
}

@media (max-width: 768px) {
    .product-excel-modal .modal-dialog {
        margin: var(--space-3);
        max-width: calc(100dvw - 2 * var(--space-3));
    }

    .product-excel-modal .product-excel-tabs .nav-link {
        font-size: var(--fs-xs);
        padding: var(--space-2);
    }

    .product-excel-modal .btn-primary-custom,
    .product-excel-modal .btn-secondary-custom,
    .product-excel-modal .btn-outline-secondary {
        width: 100%;
        justify-content: center;
    }
}
