/**
 * Product Bundles Admin Styles
 *
 * @package Swift Commerce
 */

/* ==========================================================================
   Tab Icon
   ========================================================================== */

#woocommerce-product-data ul.wc-tabs li.swift_commerce_bundle_tab a::before {
    content: "\f480";
}

/* ==========================================================================
   TARGETED: Only override overflow on OUR bundle panel, not all of WooCommerce
   ========================================================================== */

/* Only our specific panel should have overflow visible - NOT the entire metabox */
#swift_commerce_bundle_data {
    padding: 0 !important;
    overflow: visible !important;
}

#swift_commerce_bundle_data .woocommerce_options_panel,
#swift_commerce_bundle_data.woocommerce_options_panel,
.woocommerce_options_panel#swift_commerce_bundle_data {
    padding: 0 !important;
    overflow: visible !important;
}

/* Ensure the panel doesn't hide overflow */
.panel#swift_commerce_bundle_data {
    overflow: visible !important;
}

/* Override any WooCommerce input styles inside our container */
#swift_commerce_bundle_data input[type="text"],
.swift-commerce-bundle-panel input[type="text"],
.swift-commerce-bundle-items-section input[type="text"] {
    height: auto !important;
    min-height: 48px !important;
}

.swift-commerce-bundle-panel {
    padding: 20px;
    overflow: visible !important;
}

/* ==========================================================================
   Bundle Header
   ========================================================================== */

.swift-commerce-bundle-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    background: #f8f9fa;
    color: #1e1e1e;
    margin: -20px -20px 20px -20px;
    border-bottom: 1px solid #e0e0e0;
}

.swift-commerce-bundle-header .swift-commerce-icon {
    display: none;
}

.swift-commerce-bundle-header span {
    font-size: 14px;
    font-weight: 600;
    color: #1e1e1e;
}

/* ==========================================================================
   Bundle Pricing
   ========================================================================== */

.swift-commerce-bundle-pricing {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px !important;
    margin: 0 0 24px 0 !important;
}

.swift-commerce-bundle-pricing h4 {
    margin: 0 0 16px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1e1e1e;
}

/* ==========================================================================
   Product Search - Using Swift Commerce Design System
   ========================================================================== */

/* Design tokens scoped to this component */
.swift-commerce-product-search {
    --sc-primary: #002269;
    --sc-primary-light: rgba(53, 95, 115, 0.1);
    --sc-border: #e0e0e0;
    --sc-bg: #ffffff;
    --sc-text: #1e1e1e;
    --sc-muted: #666666;
    --sc-radius: 8px;
    --sc-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Search Container - CRITICAL: Force proper height and stacking */
.swift-commerce-product-search {
    display: block !important;
    position: relative !important;
    width: 100% !important;
    min-height: 52px !important; /* Force container to have height */
    height: auto !important;
    margin-bottom: 20px !important;
    z-index: 9999 !important; /* High z-index for the entire component */
    overflow: visible !important; /* Allow dropdown to overflow */
    box-sizing: border-box !important;
}

/* Clearfix to prevent container collapse */
.swift-commerce-product-search::after {
    content: "" !important;
    display: table !important;
    clear: both !important;
}

/* Search Input - Force static positioning and proper display */
#swift-commerce-product-search-input,
.swift-commerce-product-search input[type="text"] {
    display: block !important;
    position: static !important; /* NOT relative or absolute */
    float: none !important;
    width: 100% !important;
    height: 48px !important; /* Fixed height instead of auto */
    min-height: 48px !important;
    max-height: 48px !important;
    padding: 12px 16px !important;
    margin: 0 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
    font-size: 14px !important;
    line-height: 22px !important; /* Fixed line-height */
    color: var(--sc-text) !important;
    background-color: var(--sc-bg) !important;
    border: 2px solid var(--sc-border) !important;
    border-radius: var(--sc-radius) !important;
    box-sizing: border-box !important;
    box-shadow: none !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    visibility: visible !important;
    opacity: 1 !important;
}

#swift-commerce-product-search-input:focus,
.swift-commerce-product-search input[type="text"]:focus {
    border-color: var(--sc-primary) !important;
    box-shadow: 0 0 0 3px var(--sc-primary-light) !important;
    outline: none !important;
}

/* When dropdown is open */
.swift-commerce-product-search.has-results #swift-commerce-product-search-input,
.swift-commerce-product-search.has-results input[type="text"] {
    border-color: var(--sc-primary) !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-bottom-color: #e8e8e8 !important;
}

/* Search Results Dropdown - Position absolutely relative to container */
.swift-commerce-search-results {
    display: none !important;
    visibility: hidden !important;
}

.swift-commerce-search-results.active {
    display: block !important;
    visibility: visible !important;
    position: absolute !important;
    top: 48px !important; /* Position right below the 48px input */
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-height: 320px !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    background-color: var(--sc-bg) !important;
    border: 2px solid var(--sc-primary) !important;
    border-top: 1px solid #e8e8e8 !important;
    border-radius: 0 0 var(--sc-radius) var(--sc-radius) !important;
    box-shadow: var(--sc-shadow) !important;
    z-index: 999999 !important;
    box-sizing: border-box !important;
}

/* Custom Scrollbar for Results */
.swift-commerce-search-results::-webkit-scrollbar {
    width: 8px;
}

.swift-commerce-search-results::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 0 0 var(--sc-radius) 0;
}

.swift-commerce-search-results::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 4px;
}

.swift-commerce-search-results::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

/* Search Result Items */
.swift-commerce-search-result-item {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 12px 16px !important;
    cursor: pointer !important;
    border-bottom: 1px solid #f0f0f0 !important;
    background-color: var(--sc-bg) !important;
    transition: background-color 0.15s ease !important;
}

.swift-commerce-search-result-item:last-child {
    border-bottom: none !important;
}

.swift-commerce-search-result-item:hover {
    background-color: #f5f8f9 !important;
}

.swift-commerce-search-result-item:active {
    background-color: #e8eff2 !important;
}

/* Click indicator */
.swift-commerce-search-result-item::after {
    content: '+';
    font-size: 18px;
    font-weight: 600;
    color: var(--sc-primary);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.swift-commerce-search-result-item:hover::after {
    opacity: 1;
}

/* Result Item Image */
.swift-commerce-search-result-image {
    width: 48px !important;
    height: 48px !important;
    border-radius: 6px !important;
    object-fit: cover !important;
    border: 1px solid #e0e0e0 !important;
    flex-shrink: 0 !important;
}

/* Result Item Info */
.swift-commerce-search-result-info {
    flex: 1 !important;
    min-width: 0 !important;
}

.swift-commerce-search-result-name {
    font-weight: 500 !important;
    color: var(--sc-text) !important;
    font-size: 13px !important;
    margin: 0 !important;
}

.swift-commerce-search-result-price {
    color: var(--sc-muted) !important;
    font-size: 12px !important;
    margin-top: 2px !important;
}

/* Result Item Type Badge */
.swift-commerce-search-result-type {
    font-size: 11px !important;
    padding: 3px 10px !important;
    border-radius: 12px !important;
    background: #e8e8e8 !important;
    color: #666 !important;
    flex-shrink: 0 !important;
}

.swift-commerce-search-result-type.variable {
    background: #e8f5e9 !important;
    color: #2e7d32 !important;
}

/* Loading and No Results States */
.swift-commerce-search-loading,
.swift-commerce-search-no-results {
    padding: 24px 16px !important;
    text-align: center !important;
    color: var(--sc-muted) !important;
    background-color: var(--sc-bg) !important;
    font-size: 14px !important;
}
}

/* ==========================================================================
   Bundle Items Section
   ========================================================================== */

.swift-commerce-bundle-items-section {
    margin-top: 0;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    overflow: visible !important; /* Allow dropdown to overflow */
    position: relative !important;
}

.swift-commerce-bundle-items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.swift-commerce-bundle-items-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #1e1e1e;
}

.swift-commerce-bundle-items-section h4 {
    margin: 0 0 15px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1e1e1e;
}

.swift-commerce-bundle-items-count {
    font-size: 12px;
    font-weight: 500;
    color: #666;
    background: #f0f0f0;
    padding: 4px 12px;
    border-radius: 20px;
}

.swift-commerce-no-items {
    padding: 30px 20px;
    text-align: center;
    background: #fff;
    border-radius: 6px;
    border: 1px dashed #d1d5db;
}

.swift-commerce-no-items-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 10px;
}

.swift-commerce-no-items p {
    margin: 0;
    color: #444;
    font-size: 14px;
    font-weight: 500;
}

.swift-commerce-no-items-hint {
    color: #888 !important;
    font-weight: 400 !important;
    font-size: 13px !important;
    margin-top: 5px !important;
}

/* ==========================================================================
   Bundle Item Card
   ========================================================================== */

.swift-commerce-bundle-items {
    display: block;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
    margin: 0;
    margin-top: 16px;
    clear: both;
}

.swift-commerce-bundle-items .swift-commerce-bundle-item-card {
    margin-bottom: 12px;
}

.swift-commerce-bundle-items .swift-commerce-bundle-item-card:last-child {
    margin-bottom: 0;
}

/* Custom scrollbar for bundle items */
.swift-commerce-bundle-items::-webkit-scrollbar {
    width: 6px;
}

.swift-commerce-bundle-items::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.swift-commerce-bundle-items::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.swift-commerce-bundle-items::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.swift-commerce-bundle-item-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.swift-commerce-bundle-item-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #002269;
    border-radius: 6px 0 0 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.swift-commerce-bundle-item-card:hover::before {
    opacity: 1;
}

.swift-commerce-bundle-item-card:hover {
    border-color: #002269;
    box-shadow: 0 2px 8px rgba(53, 95, 115, 0.1);
}

/* Added item indicator */
.swift-commerce-bundle-item-card .swift-commerce-item-badge {
    position: absolute;
    top: -6px;
    right: 8px;
    background: #002269;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    z-index: 1;
}

.swift-commerce-bundle-item-card.ui-sortable-helper {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-color: #002269;
}

.swift-commerce-bundle-item-card.ui-sortable-placeholder {
    visibility: visible !important;
    background: #f0f5f7;
    border: 2px dashed #002269;
}

/* Drag Handle */
.swift-commerce-bundle-item-drag {
    display: flex;
    align-items: center;
    cursor: grab;
    color: #bbb;
    padding: 0 2px;
}

.swift-commerce-bundle-item-drag:active {
    cursor: grabbing;
}

.swift-commerce-bundle-item-drag::before {
    content: '⋮⋮';
    font-size: 14px;
    letter-spacing: -2px;
}

/* Product Image */
.swift-commerce-bundle-item-image {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

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

/* Product Info */
.swift-commerce-bundle-item-info {
    flex: 1;
    min-width: 0;
}

.swift-commerce-bundle-item-name {
    font-weight: 500;
    color: #1e1e1e;
    font-size: 13px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.swift-commerce-bundle-item-price {
    color: #666;
    font-size: 12px;
}

.swift-commerce-bundle-item-variation {
    font-size: 11px;
    color: #7c3aed;
    margin-top: 2px;
}

/* Actions */
.swift-commerce-bundle-item-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.swift-commerce-bundle-item-toggle,
.swift-commerce-bundle-item-remove {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 12px;
}

.swift-commerce-bundle-item-toggle {
    background: #f0f0f0;
    color: #666;
}

.swift-commerce-bundle-item-toggle:hover {
    background: #e0e0e0;
}

.swift-commerce-bundle-item-remove {
    background: #ffebee;
    color: #d32f2f;
}

.swift-commerce-bundle-item-remove:hover {
    background: #ffcdd2;
}

/* ==========================================================================
   Bundle Item Settings Panel - Complete Rewrite
   ========================================================================== */

/* Main settings container - hidden by default */
.swift-commerce-bundle-item-settings {
    display: none !important;
    width: 100% !important;
    padding: 24px !important;
    background: #f8fafc !important;
    border-top: 1px solid #e2e8f0 !important;
    margin-top: 16px !important;
    box-sizing: border-box !important;
    border-radius: 0 0 8px 8px !important;
}

/* Show when expanded */
.swift-commerce-bundle-item-card.expanded {
    flex-wrap: wrap !important;
}

.swift-commerce-bundle-item-card.expanded .swift-commerce-bundle-item-settings {
    display: block !important;
    flex-basis: 100% !important;
    width: 100% !important;
}

/* Settings grid - vertical stack */
.swift-commerce-bundle-item-settings-grid {
    display: block !important;
    width: 100% !important;
}

/* ========== SECTION 1: Discount & Name Row ========== */
.swift-commerce-settings-row-main {
    display: flex !important;
    flex-direction: row !important;
    gap: 16px !important;
    margin-bottom: 16px !important;
    width: 100% !important;
}

.swift-commerce-field-discount {
    flex: 0 0 100px !important;
    width: 100px !important;
}

.swift-commerce-field-name {
    flex: 1 1 auto !important;
    min-width: 0 !important;
}

/* ========== SECTION 2: Variation Row ========== */
.swift-commerce-settings-row-variation {
    display: block !important;
    margin-bottom: 16px !important;
    width: 100% !important;
}

.swift-commerce-field-variation {
    display: block !important;
    width: 100% !important;
}

/* ========== SECTION 3: Checkboxes Row ========== */
.swift-commerce-settings-row-checkboxes {
    display: flex !important;
    flex-direction: row !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
    width: 100% !important;
}

.swift-commerce-checkbox-card input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    margin: 0 !important;
    padding: 0 !important;
    cursor: pointer !important;
    accent-color: #7c3aed !important;
    flex-shrink: 0 !important;
}

.swift-commerce-checkbox-card .swift-commerce-checkbox-label {
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #1e293b !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: inline !important;
    line-height: 1.4 !important;
}

/* ========== SECTION 4: Quantity Fields Row ========== */
.swift-commerce-settings-row-qty {
    display: flex !important;
    flex-direction: row !important;
    gap: 12px !important;
    padding-top: 16px !important;
    border-top: 1px solid #e2e8f0 !important;
    width: 100% !important;
}

.swift-commerce-field-qty {
    flex: 1 1 0% !important;
    min-width: 0 !important;
}

.swift-commerce-field-qty input {
    text-align: center !important;
}

/* ========== Common Field Styles ========== */
.swift-commerce-field-discount,
.swift-commerce-field-name,
.swift-commerce-field-variation,
.swift-commerce-field-qty {
    display: flex !important;
    flex-direction: column !important;
}

/* Labels - exclude checkbox cards */
.swift-commerce-field-discount > label,
.swift-commerce-field-name > label,
.swift-commerce-field-variation > label,
.swift-commerce-field-qty > label {
    display: block !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: #64748b !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    margin: 0 0 8px 0 !important;
    padding: 0 !important;
    line-height: 1.2 !important;
}

/* Checkbox card - this IS the label element */
label.swift-commerce-checkbox-card {
    flex: 1 1 0% !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    padding: 16px 20px !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    margin: 0 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #1e293b !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    line-height: 1.4 !important;
}

label.swift-commerce-checkbox-card:hover {
    border-color: #7c3aed !important;
    background-color: #faf5ff !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.1) !important;
}

/* Inputs */
.swift-commerce-bundle-item-settings input[type="text"],
.swift-commerce-bundle-item-settings input[type="number"],
.swift-commerce-bundle-item-settings select {
    width: 100% !important;
    height: auto !important;
    padding: 12px 14px !important;
    margin: 0 !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    font-family: inherit !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
    transition: border-color 0.2s, box-shadow 0.2s !important;
    -webkit-appearance: none !important;
    -moz-appearance: textfield !important;
}

.swift-commerce-bundle-item-settings input:focus,
.swift-commerce-bundle-item-settings select:focus {
    border-color: #7c3aed !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15) !important;
}

/* Number input spinners */
.swift-commerce-bundle-item-settings input[type="number"]::-webkit-outer-spin-button,
.swift-commerce-bundle-item-settings input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

/* ==========================================================================
   Product Type Selector Icon
   ========================================================================== */

.product-type-options .swift_commerce_bundle {
    position: relative;
}

.product-type-options .swift_commerce_bundle::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%237c3aed"><path d="M13 3L4 14h7l-2 7 9-11h-7l2-7z"/></svg>') no-repeat center;
    background-size: contain;
    margin-left: 8px;
    vertical-align: middle;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 782px) {
    .swift-commerce-bundle-item-card {
        flex-wrap: wrap !important;
    }
    
    .swift-commerce-settings-row-main {
        flex-direction: column !important;
    }
    
    .swift-commerce-field-discount {
        flex: 1 1 100% !important;
        width: 100% !important;
    }
    
    .swift-commerce-settings-row-checkboxes {
        flex-direction: column !important;
    }
    
    .swift-commerce-settings-row-qty {
        flex-direction: column !important;
    }
}
