/**
 * Retail Search Optimizer — Frontend Styles
 *
 * Professional retail store layout:
 *   - Filter sidebar (25% left column)
 *   - Results grid (75% right column, 3-column product cards)
 *   - Fully responsive: 2-col at 768px, 1-col at 480px
 *
 * Colour tokens:
 *   --rso-brand:   #007cba   (WP admin blue — consistent with WooCommerce UI)
 *   --rso-green:   #2e7d32   (in-stock / price)
 *   --rso-text:    #333
 *   --rso-subtle:  #777
 *   --rso-border:  #ddd
 *
 * @package RetailSearchOptimizer
 * @since   1.0.0
 */

/* =============================================================================
   Base reset scoped to the plugin wrapper
   ============================================================================= */

.rso-search-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
        Cantarell, 'Helvetica Neue', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    box-sizing: border-box;
}

.rso-search-wrapper *,
.rso-search-wrapper *::before,
.rso-search-wrapper *::after {
    box-sizing: inherit;
}

/* =============================================================================
   Search bar
   ============================================================================= */

.rso-search-bar {
    position: relative;
    width: 100%;
    margin-bottom: 28px;
}

.rso-search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: #999;
    pointer-events: none;
}

.rso-search-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.rso-search-input {
    display: block;
    width: 100%;
    height: 52px;
    padding: 0 20px 0 50px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    color: #333;
    background: #fff;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    /* Override any theme resets */
    appearance: none;
    -webkit-appearance: none;
}

.rso-search-input:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.15);
}

.rso-search-input::placeholder {
    color: #aaa;
}

/* =============================================================================
   Two-column layout
   ============================================================================= */

.rso-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 32px;
    width: 100%;
}

/* ── Sidebar ── */
.rso-sidebar {
    flex: 0 0 25%;
    max-width: 25%;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 24px;
    position: sticky;
    top: 20px; /* stays visible while scrolling results */
}

.rso-filter-heading {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #007cba;
}

.rso-filter-group {
    margin-bottom: 24px;
}

.rso-filter-group:last-child {
    margin-bottom: 0;
}

.rso-filter-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #555;
    margin-bottom: 10px;
}

/* Category select */
.rso-filter-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: auto;
}

.rso-filter-select:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

/* ── Checkboxes ── */
.rso-checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #444;
    user-select: none;
}

.rso-checkbox-wrapper:hover .rso-checkbox-text {
    color: #007cba;
}

/* Visually hide the native checkbox but keep it accessible */
.rso-checkbox-wrapper input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* Custom checkbox box */
.rso-checkbox-custom {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: 2px solid #ccc;
    border-radius: 3px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.rso-checkbox-wrapper input[type="checkbox"]:checked ~ .rso-checkbox-custom {
    background: #007cba;
    border-color: #007cba;
}

/* Checkmark via CSS */
.rso-checkbox-wrapper input[type="checkbox"]:checked ~ .rso-checkbox-custom::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}

.rso-checkbox-wrapper input[type="checkbox"]:focus-visible ~ .rso-checkbox-custom {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.rso-checkbox-text {
    line-height: 1.3;
}

/* ── Price range inputs ── */
.rso-price-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rso-filter-price {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    text-align: center;
    background: #fff;
    transition: border-color 0.2s;
    /* Hide number input arrows */
    -moz-appearance: textfield;
}

.rso-filter-price::-webkit-outer-spin-button,
.rso-filter-price::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.rso-filter-price:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

.rso-price-range-separator {
    flex-shrink: 0;
    color: #999;
    font-size: 18px;
    font-weight: 300;
    line-height: 1;
}

/* ── In-stock toggle switch ── */
.rso-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.rso-toggle-wrapper input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.rso-toggle-slider {
    flex-shrink: 0;
    position: relative;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    transition: background 0.2s ease;
}

.rso-toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.2s ease;
}

.rso-toggle-wrapper input[type="checkbox"]:checked ~ .rso-toggle-slider {
    background: #007cba;
}

.rso-toggle-wrapper input[type="checkbox"]:checked ~ .rso-toggle-slider::after {
    transform: translateX(20px);
}

.rso-toggle-wrapper input[type="checkbox"]:focus-visible ~ .rso-toggle-slider {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.rso-toggle-label {
    font-size: 14px;
    color: #444;
    font-weight: 500;
}

/* ── Main results column ── */
.rso-main {
    flex: 1;
    min-width: 0;
}

/* Results count header */
.rso-results-header {
    font-size: 14px;
    color: #777;
    margin-bottom: 16px;
    min-height: 20px;
}

/* =============================================================================
   Product grid
   ============================================================================= */

.rso-results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%;
}

/* =============================================================================
   Product card
   ============================================================================= */

.rso-product-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.25s ease, transform 0.2s ease, border-color 0.2s;
}

.rso-product-card:hover {
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    border-color: #007cba;
}

.rso-product-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Square thumbnail with object-fit */
.rso-product-card-thumbnail {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #f7f7f7;
}

/* Info section below thumbnail */
.rso-product-card-info {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rso-product-card-stock {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 10px;
    border-radius: 20px;
    width: fit-content;
}

.rso-stock-in {
    background: #e8f5e9;
    color: #2e7d32;
}

.rso-stock-out {
    background: #fce4ec;
    color: #c62828;
}

.rso-product-card-name {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
    margin: 0;
    /* Clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rso-product-card-price {
    font-size: 17px;
    font-weight: 700;
    color: #2e7d32;
    line-height: 1.2;
}

/* WooCommerce price HTML */
.rso-product-card-price del {
    font-size: 14px;
    color: #999;
    font-weight: 400;
    margin-right: 4px;
}

.rso-product-card-price ins {
    text-decoration: none;
    color: #c62828;
}

.rso-product-card-price .amount {
    color: inherit;
}

/* Category badges */
.rso-product-card-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.rso-product-card-category {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    color: #555;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* =============================================================================
   Load More button
   ============================================================================= */

.rso-load-more-wrap {
    text-align: center;
    margin-top: 32px;
}

.rso-load-more-btn {
    display: inline-block;
    padding: 12px 36px;
    background: #007cba;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.rso-load-more-btn:hover,
.rso-load-more-btn:focus {
    background: #006ba1;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0,124,186,0.3);
}

.rso-load-more-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* =============================================================================
   Loading spinner
   ============================================================================= */

.rso-loading {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 64px 0;
}

.rso-loading-more {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 24px 0;
}

.rso-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #007cba;
    border-radius: 50%;
    animation: rso-spin 0.75s linear infinite;
}

@keyframes rso-spin {
    to { transform: rotate(360deg); }
}

/* =============================================================================
   Empty / error states
   ============================================================================= */

.rso-empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 24px;
    text-align: center;
    color: #999;
}

.rso-empty-state-icon {
    margin-bottom: 16px;
    opacity: 0.5;
}

.rso-empty-state-text {
    font-size: 15px;
    color: #999;
    max-width: 320px;
    margin: 0;
}

.rso-error-state {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: #c62828;
    font-size: 15px;
}

/* =============================================================================
   Responsive — 768px breakpoint (tablet)
   ============================================================================= */

@media (max-width: 768px) {

    .rso-layout {
        flex-direction: column;
        gap: 24px;
    }

    .rso-sidebar {
        flex: 0 0 100%;
        max-width: 100%;
        position: static; /* un-stick on mobile */
    }

    .rso-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .rso-search-input {
        height: 48px;
        font-size: 15px;
    }

}

/* =============================================================================
   Responsive — 480px breakpoint (phone)
   ============================================================================= */

@media (max-width: 480px) {

    .rso-results-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .rso-product-card-info {
        padding: 12px;
    }

    .rso-sidebar {
        padding: 16px;
    }

    .rso-search-input {
        height: 44px;
        padding-left: 44px;
        font-size: 15px;
    }

    .rso-search-icon {
        left: 12px;
        width: 18px;
        height: 18px;
    }

}

/* =============================================================================
   Screen-reader only utility (used in shortcode HTML)
   ============================================================================= */

.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}
