/**
 * TWC Search for Clonable - Complete Standalone Styles
 * Theme-independent CSS - works with any WordPress theme
 *
 * @package TWC_Search
 * @version 2.0.0
 * @author The WP Clan
 */

/* ==========================================================================
   CSS Variables (Customizable)
   ========================================================================== */

:root {
    /* Colors - Light Theme */
    --twc-search-bg: #ffffff;
    --twc-search-text: #1a1a1a;
    --twc-search-text-muted: #666666;
    --twc-search-border: #e0e0e0;
    --twc-search-input-bg: #f5f5f5;
    --twc-search-input-focus-bg: #ffffff;
    --twc-search-accent: #0073aa;
    --twc-search-accent-hover: #005a87;
    --twc-search-overlay: rgba(0, 0, 0, 0.7);
    --twc-search-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --twc-search-result-hover: #f9f9f9;

    /* Sizing */
    --twc-search-input-height: 48px;
    --twc-search-border-radius: 8px;
    --twc-search-popup-width: 600px;
    --twc-search-popup-max-height: 80vh;

    /* Typography */
    --twc-search-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --twc-search-font-size: 16px;
    --twc-search-font-size-small: 14px;
    --twc-search-font-size-large: 18px;

    /* Transitions */
    --twc-search-transition: 0.2s ease;
}

/* Dark Theme Variables */
.twc-search--dark {
    --twc-search-bg: #1a1a1a;
    --twc-search-text: #ffffff;
    --twc-search-text-muted: #a0a0a0;
    --twc-search-border: #333333;
    --twc-search-input-bg: #2a2a2a;
    --twc-search-input-focus-bg: #333333;
    --twc-search-result-hover: #2a2a2a;
}

/* ==========================================================================
   Toggle Button (Opens Popup)
   ========================================================================== */

.twc-search-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    transition: opacity var(--twc-search-transition);
}

.twc-search-toggle:hover {
    opacity: 0.7;
}

.twc-search-toggle svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Popup Container
   ========================================================================== */

.twc-search-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--twc-search-transition), visibility var(--twc-search-transition);
}

.twc-search-popup.is-active {
    opacity: 1;
    visibility: visible;
}

.twc-search-popup__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--twc-search-overlay);
}

.twc-search-popup__inner {
    position: relative;
    width: 100%;
    max-width: var(--twc-search-popup-width);
    max-height: var(--twc-search-popup-max-height);
    margin: 0 20px;
    background: var(--twc-search-bg);
    border-radius: var(--twc-search-border-radius);
    box-shadow: var(--twc-search-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(-20px);
    transition: transform var(--twc-search-transition);
}

.twc-search-popup.is-active .twc-search-popup__inner {
    transform: translateY(0);
}

.twc-search-popup__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--twc-search-text-muted);
    border-radius: 50%;
    transition: background var(--twc-search-transition), color var(--twc-search-transition);
    z-index: 10;
}

.twc-search-popup__close:hover {
    background: var(--twc-search-input-bg);
    color: var(--twc-search-text);
}

.twc-search-popup__close svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Inline Search (Non-Popup)
   ========================================================================== */

.twc-search-inline {
    font-family: var(--twc-search-font-family);
    background: var(--twc-search-bg);
    border-radius: var(--twc-search-border-radius);
}

/* ==========================================================================
   Search Form
   ========================================================================== */

.twc-search-form {
    padding: 20px;
    font-family: var(--twc-search-font-family);
}

.twc-search-form__wrapper {
    display: flex;
    align-items: center;
    background: var(--twc-search-input-bg);
    border: 2px solid transparent;
    border-radius: var(--twc-search-border-radius);
    transition: border-color var(--twc-search-transition), background var(--twc-search-transition);
}

.twc-search-form__wrapper:focus-within {
    border-color: var(--twc-search-accent);
    background: var(--twc-search-input-focus-bg);
}

.twc-search-form__label {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.twc-search-form__input {
    flex: 1;
    height: var(--twc-search-input-height);
    padding: 0 16px;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: var(--twc-search-font-size);
    color: var(--twc-search-text);
}

.twc-search-form__input::placeholder {
    color: var(--twc-search-text-muted);
}

.twc-search-form__input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.twc-search-form__submit {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--twc-search-input-height);
    padding: 0 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--twc-search-text-muted);
    transition: color var(--twc-search-transition);
}

.twc-search-form__submit:hover {
    color: var(--twc-search-accent);
}

.twc-search-form__submit svg {
    width: 20px;
    height: 20px;
}

.twc-search-form__submit-text {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ==========================================================================
   Search Results
   ========================================================================== */

.twc-search-results {
    max-height: 400px;
    overflow-y: auto;
    border-top: 1px solid var(--twc-search-border);
}

.twc-search-results:empty {
    display: none;
}

.twc-search-results:empty + .twc-search-more {
    display: none;
}

/* Loading State */
.twc-search-results.is-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    color: var(--twc-search-text-muted);
    font-size: var(--twc-search-font-size-small);
}

.twc-search-results.is-loading::before {
    content: "";
    width: 24px;
    height: 24px;
    margin-right: 10px;
    border: 2px solid var(--twc-search-border);
    border-top-color: var(--twc-search-accent);
    border-radius: 50%;
    animation: twc-search-spin 0.8s linear infinite;
}

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

/* No Results */
.twc-search-results--empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--twc-search-text-muted);
    font-size: var(--twc-search-font-size);
}

/* ==========================================================================
   Single Result Item
   ========================================================================== */

.twc-search-result {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 20px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--twc-search-border);
    transition: background var(--twc-search-transition);
}

.twc-search-result:last-child {
    border-bottom: none;
}

.twc-search-result:hover {
    background: var(--twc-search-result-hover);
}

.twc-search-result__image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--twc-search-input-bg);
}

.twc-search-result__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.twc-search-result__content {
    flex: 1;
    min-width: 0;
}

.twc-search-result__title {
    margin: 0 0 4px 0;
    font-size: var(--twc-search-font-size);
    font-weight: 600;
    color: var(--twc-search-text);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.twc-search-result__excerpt {
    margin: 0 0 6px 0;
    font-size: var(--twc-search-font-size-small);
    color: var(--twc-search-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.twc-search-result__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--twc-search-text-muted);
}

.twc-search-result__type {
    display: inline-block;
    padding: 2px 8px;
    background: var(--twc-search-input-bg);
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   More Results Link
   ========================================================================== */

.twc-search-more {
    display: none;
    padding: 16px 20px;
    text-align: center;
    border-top: 1px solid var(--twc-search-border);
}

.twc-search-more.is-visible {
    display: block;
}

.twc-search-more__link {
    display: inline-block;
    padding: 10px 24px;
    background: var(--twc-search-accent);
    color: #ffffff;
    font-size: var(--twc-search-font-size-small);
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--twc-search-border-radius);
    transition: background var(--twc-search-transition);
}

.twc-search-more__link:hover {
    background: var(--twc-search-accent-hover);
    color: #ffffff;
}

/* ==========================================================================
   Body Class When Popup is Open
   ========================================================================== */

body.twc-search-popup-open {
    overflow: hidden;
}

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

@media (max-width: 768px) {
    :root {
        --twc-search-popup-width: 100%;
        --twc-search-input-height: 44px;
        --twc-search-font-size: 16px;
    }

    .twc-search-popup {
        padding-top: 0;
        align-items: stretch;
    }

    .twc-search-popup__inner {
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .twc-search-results {
        max-height: calc(100vh - 200px);
    }

    .twc-search-result {
        padding: 12px 16px;
        gap: 12px;
    }

    .twc-search-result__image {
        width: 50px;
        height: 50px;
    }

    .twc-search-form {
        padding: 16px;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible styles */
.twc-search-toggle:focus-visible,
.twc-search-popup__close:focus-visible,
.twc-search-more__link:focus-visible {
    outline: 2px solid var(--twc-search-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .twc-search-popup,
    .twc-search-toggle,
    .twc-search-inline {
        display: none !important;
    }
}
