/**
 * SimRacing Affiliate Tables - Contextual Search Styles
 * Version: 2.1.2
 * 
 * Adaptive styles that work in both full-width homepage and contained blog post contexts
 */

/* ==========================================================================
   Base Search Form Styles - Always Applied
   ========================================================================== */

.sps-search-form {
    max-width: 800px;
    margin: 0 auto 2rem;
    animation: fadeInUp 0.8s ease-out 0.2s backwards;
}

.sps-search-box {
    position: relative;
    display: flex;
    gap: 1rem;
    align-items: stretch;
    background: white;
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 10px 40px rgba(0, 15, 65, 0.08);
    transition: all 0.3s ease;
}

.sps-search-box:hover {
    box-shadow: 0 15px 50px rgba(0, 15, 65, 0.12);
    transform: translateY(-2px);
}

.sps-search-input {
    flex: 1;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    outline: none;
    background: transparent;
    color: #000F41;
    font-weight: 500;
}

.sps-search-input::placeholder {
    color: #999;
    font-weight: 400;
}

.sps-search-button {
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: #FB643C;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.sps-search-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}

.sps-search-button:hover {
    background: #e5542f;
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(251, 100, 60, 0.3);
}

.sps-search-button:hover::before {
    left: 100%;
}

.sps-search-button:active {
    transform: translateY(0);
}

/* ==========================================================================
   Context Detection & Wrapper Styles
   ========================================================================== */

/* Default contained style - for blog posts, pages, widget areas */
.sps-search-wrapper {
    padding: 2rem 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 15, 65, 0.06);
    border: 1px solid rgba(0, 15, 65, 0.08);
    position: relative;
    margin: 2rem 0;
}

/* Subtle background pattern for contained version */
.sps-search-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 50px, rgba(0,15,65,.01) 50px, rgba(0,15,65,.01) 100px);
    pointer-events: none;
    border-radius: inherit;
}

/* Container for proper width control */
.sps-search-container {
    position: relative;
    z-index: 1;
}

/* Contained heading style */
.sps-search-heading {
    font-size: 1.75rem;
    color: #000F41;
    font-weight: 700;
    text-align: center;
    margin: 0 0 2rem 0;
    animation: fadeInUp 0.8s ease-out;
}

/* ==========================================================================
   Full-Width Mode - Activated by CSS classes or attributes
   ========================================================================== */

/* Full-width when explicitly requested or in homepage context */
.sps-search-wrapper.sps-full-width,
.sps-search-wrapper[data-layout="fullwidth"],
body.home .sps-search-wrapper,
body.front-page .sps-search-wrapper,
.page-template-page-homepage .sps-search-wrapper,
.sps-hero-section .sps-search-wrapper {
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    padding: 80px 0;
    background: #f8f9fa;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    margin-top: 0;
    margin-bottom: 0;
}

/* Full-width container adjustments */
.sps-search-wrapper.sps-full-width .sps-search-container,
.sps-search-wrapper[data-layout="fullwidth"] .sps-search-container,
body.home .sps-search-wrapper .sps-search-container,
body.front-page .sps-search-wrapper .sps-search-container,
.page-template-page-homepage .sps-search-wrapper .sps-search-container,
.sps-hero-section .sps-search-wrapper .sps-search-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Full-width heading adjustments */
.sps-search-wrapper.sps-full-width .sps-search-heading,
.sps-search-wrapper[data-layout="fullwidth"] .sps-search-heading,
body.home .sps-search-wrapper .sps-search-heading,
body.front-page .sps-search-wrapper .sps-search-heading,
.page-template-page-homepage .sps-search-wrapper .sps-search-heading,
.sps-hero-section .sps-search-wrapper .sps-search-heading {
    font-size: 2.5rem;
    margin-bottom: 50px;
}

/* Enhanced background pattern for full-width */
.sps-search-wrapper.sps-full-width::before,
.sps-search-wrapper[data-layout="fullwidth"]::before,
body.home .sps-search-wrapper::before,
body.front-page .sps-search-wrapper::before,
.page-template-page-homepage .sps-search-wrapper::before,
.sps-hero-section .sps-search-wrapper::before {
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 50px, rgba(0,15,65,.02) 50px, rgba(0,15,65,.02) 100px);
}

/* ==========================================================================
   Compact Mode - For sidebars, widgets, tight spaces
   ========================================================================== */

.sps-search-wrapper.sps-compact,
.sps-search-wrapper[data-layout="compact"],
.widget .sps-search-wrapper,
.sidebar .sps-search-wrapper {
    padding: 1.5rem;
    margin: 1rem 0;
    box-shadow: 0 3px 12px rgba(0, 15, 65, 0.04);
}

.sps-search-wrapper.sps-compact .sps-search-heading,
.sps-search-wrapper[data-layout="compact"] .sps-search-heading,
.widget .sps-search-wrapper .sps-search-heading,
.sidebar .sps-search-wrapper .sps-search-heading {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
}

.sps-search-wrapper.sps-compact .sps-search-box,
.sps-search-wrapper[data-layout="compact"] .sps-search-box,
.widget .sps-search-wrapper .sps-search-box,
.sidebar .sps-search-wrapper .sps-search-box {
    flex-direction: column;
    gap: 0.5rem;
}

.sps-search-wrapper.sps-compact .sps-search-button,
.sps-search-wrapper[data-layout="compact"] .sps-search-button,
.widget .sps-search-wrapper .sps-search-button,
.sidebar .sps-search-wrapper .sps-search-button {
    padding: 0.75rem 1.5rem;
}

/* ==========================================================================
   Popular Searches / Suggestions - Contextual
   ========================================================================== */

.sps-search-suggestions {
    margin: 2rem 0 0;
    text-align: center;
    animation: fadeInUp 0.8s ease-out 0.4s backwards;
}

.sps-search-suggestions h3 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: #000F41;
    font-weight: 600;
    opacity: 0.9;
}

/* Full-width version gets larger popular search titles */
.sps-search-wrapper.sps-full-width .sps-search-suggestions h3,
.sps-search-wrapper[data-layout="fullwidth"] .sps-search-suggestions h3,
body.home .sps-search-wrapper .sps-search-suggestions h3,
body.front-page .sps-search-wrapper .sps-search-suggestions h3,
.page-template-page-homepage .sps-search-wrapper .sps-search-suggestions h3,
.sps-hero-section .sps-search-wrapper .sps-search-suggestions h3 {
    font-size: 1.25rem;
    margin: 3rem 0 1.5rem;
}

.sps-search-suggestion-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    list-style: none;
    margin: 0;
    padding: 0;
}

.sps-search-suggestion {
    display: inline-block;
    padding: 0.6rem 1.4rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: #000F41;
    background: white;
    border-radius: 25px;
    text-decoration: none;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    box-shadow: 0 2px 10px rgba(0, 15, 65, 0.06);
    opacity: 0;
    animation: suggestionFadeIn 0.5s ease-out forwards;
}

/* Compact mode gets smaller suggestions */
.sps-search-wrapper.sps-compact .sps-search-suggestion,
.sps-search-wrapper[data-layout="compact"] .sps-search-suggestion,
.widget .sps-search-wrapper .sps-search-suggestion,
.sidebar .sps-search-wrapper .sps-search-suggestion {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
}

/* Stagger animations for suggestions */
.sps-search-suggestion:nth-child(1) { animation-delay: 0.5s; }
.sps-search-suggestion:nth-child(2) { animation-delay: 0.55s; }
.sps-search-suggestion:nth-child(3) { animation-delay: 0.6s; }
.sps-search-suggestion:nth-child(4) { animation-delay: 0.65s; }
.sps-search-suggestion:nth-child(5) { animation-delay: 0.7s; }
.sps-search-suggestion:nth-child(6) { animation-delay: 0.75s; }
.sps-search-suggestion:nth-child(7) { animation-delay: 0.8s; }
.sps-search-suggestion:nth-child(8) { animation-delay: 0.85s; }
.sps-search-suggestion:nth-child(9) { animation-delay: 0.9s; }
.sps-search-suggestion:nth-child(10) { animation-delay: 0.95s; }

.sps-search-suggestion:hover {
    color: white;
    background: #FB643C;
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(251, 100, 60, 0.2);
}

/* ==========================================================================
   Search Results & Other Components - Remain the Same
   ========================================================================== */

.sps-dynamic-page-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #000F41;
    margin: 0 0 2rem 0;
    line-height: 1.2;
    animation: fadeInUp 0.8s ease-out;
}

.sps-search-summary {
    margin: 2rem 0;
    padding: 1.5rem 2rem;
    background: white;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0, 15, 65, 0.08);
    animation: fadeInUp 0.8s ease-out 0.2s backwards;
}

.sps-search-summary h2 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
    color: #000F41;
    font-weight: 600;
}

.sps-search-summary p {
    margin: 0;
    color: #666;
    font-size: 1.05rem;
}

/* ==========================================================================
   Refinement Links - Modern Card Layout
   ========================================================================== */

.sps-refinement-section {
    margin: 3rem 0 !important;
    padding: 2rem !important;
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 5px 20px rgba(0, 15, 65, 0.08) !important;
    animation: fadeInUp 0.8s ease-out 0.3s backwards !important;
    display: block !important;
    visibility: visible !important;
}

.sps-refinement-title {
    font-size: 1.5rem !important;
    margin-bottom: 2rem !important;
    text-align: center !important;
    color: #000F41 !important;
    font-weight: 600 !important;
    display: block !important;
}

.sps-refinement-groups {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 3rem !important;
    justify-content: center !important;
    visibility: visible !important;
}

.sps-refinement-group {
    flex: 0 1 auto !important;
    display: block !important;
    visibility: visible !important;
}

.sps-refinement-group h4 {
    margin: 0 0 1rem !important;
    font-size: 1.1rem !important;
    color: #FB643C !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    display: block !important;
}

.sps-refinement-links {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    visibility: visible !important;
}

.sps-refinement-links li {
    margin: 0 !important;
    display: list-item !important;
}

.sps-refinement-links a {
    color: #000F41 !important;
    text-decoration: none !important;
    display: inline-block !important;
    padding: 0.5rem 1.2rem !important;
    border: 2px solid #e5e7eb !important;
    border-radius: 8px !important;
    font-size: 0.95rem !important;
    font-weight: 500 !important;
    transition: all 0.3s ease !important;
    background: white !important;
    visibility: visible !important;
}

.sps-refinement-links a:hover {
    background: #FB643C !important;
    color: white !important;
    border-color: #FB643C !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 3px 15px rgba(251, 100, 60, 0.2) !important;
}

/* ==========================================================================
   Related Searches
   ========================================================================== */

.sps-related-searches {
    margin: 2rem 0;
    text-align: center;
    animation: fadeInUp 0.8s ease-out 0.4s backwards;
}

.sps-related-searches h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: #000F41;
    font-weight: 600;
}

.sps-related-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    list-style: none;
    margin: 0;
    padding: 0;
}

.sps-related-item a {
    display: inline-block;
    padding: 0.6rem 1.4rem;
    color: #FB643C;
    background: white;
    border: 2px solid #FB643C;
    border-radius: 25px;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(251, 100, 60, 0.1);
}

.sps-related-item a:hover {
    color: white;
    background: #FB643C;
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(251, 100, 60, 0.3);
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.sps-search-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: #666;
    animation: fadeInUp 0.8s ease-out 0.2s backwards;
}

.sps-search-empty h3 {
    color: #000F41;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes suggestionFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

@media (max-width: 768px) {
    .sps-search-wrapper.sps-full-width,
    .sps-search-wrapper[data-layout="fullwidth"],
    body.home .sps-search-wrapper,
    body.front-page .sps-search-wrapper,
    .page-template-page-homepage .sps-search-wrapper,
    .sps-hero-section .sps-search-wrapper {
        padding: 60px 0;
    }
    
    .sps-search-wrapper {
        padding: 1.5rem;
        margin: 1.5rem 0;
    }
    
    .sps-search-heading {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .sps-search-wrapper.sps-full-width .sps-search-heading,
    .sps-search-wrapper[data-layout="fullwidth"] .sps-search-heading,
    body.home .sps-search-wrapper .sps-search-heading,
    body.front-page .sps-search-wrapper .sps-search-heading,
    .page-template-page-homepage .sps-search-wrapper .sps-search-heading,
    .sps-hero-section .sps-search-wrapper .sps-search-heading {
        font-size: 2rem;
        margin-bottom: 40px;
    }
    
    .sps-search-box {
        flex-direction: column;
        gap: 0.5rem;
        padding: 6px;
    }
    
    .sps-search-input,
    .sps-search-button {
        width: 100%;
    }
    
    .sps-search-button {
        padding: 1rem 2rem;
    }
    
    .sps-search-suggestion-list,
    .sps-related-list {
        gap: 0.5rem;
    }
    
    .sps-search-suggestion,
    .sps-related-item a {
        font-size: 0.85rem;
        padding: 0.5rem 1rem;
    }
    
    .sps-refinement-groups {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .sps-refinement-section {
        padding: 1.5rem;
    }
    
    .sps-refinement-links {
        justify-content: center;
    }
    
    .sps-dynamic-page-title {
        font-size: 1.75rem;
    }
}

@media (max-width: 480px) {
    .sps-search-heading {
        font-size: 1.25rem;
    }
    
    .sps-search-wrapper.sps-full-width .sps-search-heading,
    .sps-search-wrapper[data-layout="fullwidth"] .sps-search-heading,
    body.home .sps-search-wrapper .sps-search-heading,
    body.front-page .sps-search-wrapper .sps-search-heading,
    .page-template-page-homepage .sps-search-wrapper .sps-search-heading,
    .sps-hero-section .sps-search-wrapper .sps-search-heading {
        font-size: 1.75rem;
    }
    
    .sps-search-input {
        font-size: 1rem;
        padding: 0.875rem 1.25rem;
    }
    
    .sps-search-button {
        font-size: 1rem;
    }
}

/* ==========================================================================
   Theme Compatibility
   ========================================================================== */

/* Hide static page titles when dynamic title is present */
.sps-search-results-wrapper + .entry-header,
.sps-search-results-wrapper ~ .entry-header {
    display: none !important;
}

body.page-template-default:has(.sps-search-results-wrapper) {
    /* Various theme selectors */
    .tg-page-header__title,
    .zakra-page-header__title,
    .page-header h1,
    .ast-single-post .entry-header .entry-title,
    .entry-title,
    .page-title,
    h1.entry-title {
        display: none !important;
    }
}

/* Box sizing for all search elements */
.sps-search-wrapper *,
.sps-search-form *,
.sps-search-suggestions *,
.sps-refinement-section *,
.sps-related-searches * {
    box-sizing: border-box;
}

/* Focus states for accessibility */
.sps-search-input:focus {
    outline: 2px solid #FB643C;
    outline-offset: -2px;
}

.sps-search-button:focus,
.sps-search-suggestion:focus,
.sps-refinement-links a:focus,
.sps-related-item a:focus {
    outline: 2px solid #FB643C;
    outline-offset: 2px;
}

/* Aggregate statistics - Modern card style */
.sps-aggregate-stats {
    background-color: white;
    border-left: 4px solid #FB643C;
    padding: 1.5rem 2rem;
    margin: 2rem 0;
    border-radius: 8px;
    box-shadow: 0 3px 15px rgba(0, 15, 65, 0.08);
    animation: fadeInUp 0.8s ease-out 0.3s backwards;
}

.sps-aggregate-stats p {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.6;
    color: #000F41;
}

.sps-aggregate-stats a {
    color: #FB643C;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.sps-aggregate-stats a:hover {
    color: #e5542f;
    text-decoration: underline;
}
/* ==========================================================================
   Enhanced Aggregate Stats Styles
   ========================================================================== */

.sps-aggregate-stats-enhanced {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    border: 1px solid #e9ecef;
}

.sps-stats-summary {
    margin-bottom: 1.5rem;
    text-align: center;
}

.sps-stats-summary p {
    font-size: 1.1rem;
    color: #495057;
    margin: 0;
}

.sps-stats-summary strong {
    color: #000F41;
    font-weight: 600;
}

.sps-stats-summary .currency-note {
    font-size: 0.9rem;
    color: #6c757d;
    font-style: italic;
}

/* Stats Grid */
.sps-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.sps-stat-item {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.sps-stat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #FB643C;
    margin-bottom: 0.25rem;
}

.stat-label {
    display: block;
    font-size: 0.875rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Merchant Summary */
.sps-merchant-summary {
    border-top: 1px solid #dee2e6;
    padding-top: 1.5rem;
}

.sps-merchant-summary p {
    margin-bottom: 1rem;
    color: #495057;
}

.sps-merchant-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.merchant-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    color: #495057;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.merchant-badge:hover {
    background: #FB643C;
    color: white;
    border-color: #FB643C;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(251, 100, 60, 0.2);
}

.merchant-badge.manufacturer {
    background: #e8f4fd;
    border-color: #2c7be5;
    color: #2c7be5;
    font-weight: 500;
}

.merchant-badge.manufacturer:hover {
    background: #2c7be5;
    color: white;
    box-shadow: 0 2px 8px rgba(44, 123, 229, 0.2);
}

/* Responsive Design */
@media (max-width: 768px) {
    .sps-aggregate-stats-enhanced {
        padding: 1rem;
    }
    
    .sps-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .sps-stat-item {
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .merchant-badges {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .sps-stats-summary p {
        font-size: 1rem;
    }
    
    .sps-stats-grid {
        grid-template-columns: 1fr;
    }
}