/**
 * Enhanced Search UI
 * Prominent search button with keyboard shortcut hints
 * Full-screen modal with instant search and recent searches
 *
 * @package YAWC
 * @version 1.0.0
 */

/* =================================================================
   Search Trigger Button (Header)
   ================================================================= */

.yawc-search-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--theme-spacing-sm, 0.5rem);
    padding: 0.625rem 1rem;
    min-height: 44px;
    background: var(--theme-bg-secondary, #f8f9fa);
    border: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    border-radius: var(--theme-radius-md, 8px);
    color: var(--theme-text-secondary, #666666);
    cursor: pointer;
    transition: all var(--theme-transition-fast, 0.15s ease);
    font-size: 0.875rem;
    font-weight: var(--theme-font-weight-medium, 500);
    text-decoration: none;
}

.yawc-search-trigger:hover {
    background: var(--theme-bg-primary, #ffffff);
    border-color: var(--theme-accent, #4f46e5);
    color: var(--theme-text-primary, #1a1a1a);
    box-shadow: var(--theme-shadow-sm, 0 2px 4px rgba(0, 0, 0, 0.1));
}

.yawc-search-trigger:focus-visible {
    outline: 3px solid var(--theme-accent, #4f46e5);
    outline-offset: 2px;
}

.yawc-search-trigger-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.yawc-search-trigger-text {
    color: var(--theme-text-secondary, #666666);
}

.yawc-search-trigger-kbd {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background: var(--theme-bg-tertiary, #e9ecef);
    border: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    border-radius: 4px;
    font-family: var(--theme-font-mono, 'Fira Code', monospace);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-text-secondary, #666666);
    line-height: 1;
    margin-left: var(--theme-spacing-xs, 0.25rem);
}

/* =================================================================
   Search Modal
   ================================================================= */

.yawc-search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    opacity: 0;
    visibility: hidden;
    transition: all var(--theme-transition-base, 0.3s ease);
}

.yawc-search-modal.is-open {
    opacity: 1;
    visibility: visible;
}

.yawc-search-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
}

.yawc-search-modal-content {
    position: relative;
    background: var(--theme-bg-primary, #ffffff);
    border-radius: var(--theme-radius-xl, 16px);
    box-shadow: var(--theme-shadow-2xl, 0 24px 48px rgba(0, 0, 0, 0.22));
    width: 90%;
    max-width: 640px;
    max-height: 80vh;
    overflow: hidden;
    border: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    transform: scale(0.95) translateY(-20px);
    transition: transform var(--theme-transition-base, 0.3s ease);
}

.yawc-search-modal.is-open .yawc-search-modal-content {
    transform: scale(1) translateY(0);
}

/* =================================================================
   Search Input Area
   ================================================================= */

.yawc-search-input-wrapper {
    position: relative;
    padding: var(--theme-spacing-lg, 1.5rem);
    border-bottom: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
}

.yawc-search-input-icon {
    position: absolute;
    left: calc(var(--theme-spacing-lg, 1.5rem) + 12px);
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--theme-text-secondary, #666666);
    pointer-events: none;
}

.yawc-search-input {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 3rem;
    border: 2px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    border-radius: var(--theme-radius-md, 8px);
    font-size: 1rem;
    color: var(--theme-text-primary, #1a1a1a);
    background: var(--theme-bg-primary, #ffffff);
    transition: all var(--theme-transition-fast, 0.15s ease);
}

.yawc-search-input:focus {
    outline: none;
    border-color: var(--theme-accent, #4f46e5);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.yawc-search-input::placeholder {
    color: var(--theme-text-tertiary, #999999);
}

.yawc-search-close {
    position: absolute;
    right: calc(var(--theme-spacing-lg, 1.5rem) + 8px);
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--theme-radius-sm, 4px);
    color: var(--theme-text-secondary, #666666);
    cursor: pointer;
    transition: all var(--theme-transition-fast, 0.15s ease);
}

.yawc-search-close:hover {
    background: var(--theme-bg-tertiary, #e9ecef);
    color: var(--theme-text-primary, #1a1a1a);
}

.yawc-search-close svg {
    width: 20px;
    height: 20px;
}

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

.yawc-search-results {
    overflow-y: auto;
    max-height: calc(80vh - 100px);
    padding: var(--theme-spacing-md, 1rem);
}

.yawc-search-results-empty {
    text-align: center;
    padding: calc(var(--theme-spacing-3xl, 4rem) * 0.75) var(--theme-spacing-xl, 2rem);
    color: var(--theme-text-secondary, #666666);
}

.yawc-search-results-empty-icon {
    font-size: 3rem;
    margin-bottom: var(--theme-spacing-md, 1rem);
    opacity: 0.5;
}

.yawc-search-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--theme-text-secondary, #666666);
    padding: var(--theme-spacing-sm, 0.5rem) var(--theme-spacing-md, 1rem);
    margin-bottom: var(--theme-spacing-xs, 0.25rem);
}

.yawc-search-result-item {
    display: flex;
    align-items: flex-start;
    gap: var(--theme-spacing-md, 1rem);
    padding: var(--theme-spacing-md, 1rem);
    border-radius: var(--theme-radius-md, 8px);
    cursor: pointer;
    transition: all var(--theme-transition-fast, 0.15s ease);
    text-decoration: none;
    color: inherit;
}

.yawc-search-result-item:hover {
    background: var(--theme-bg-secondary, #f8f9fa);
}

.yawc-search-result-item:focus {
    outline: 2px solid var(--theme-accent, #4f46e5);
    outline-offset: 2px;
    background: var(--theme-bg-secondary, #f8f9fa);
}

.yawc-search-result-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: var(--theme-radius-sm, 4px);
    background: var(--theme-bg-tertiary, #e9ecef);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-accent, #4f46e5);
}

.yawc-search-result-icon svg {
    width: 20px;
    height: 20px;
}

.yawc-search-result-content {
    flex: 1;
    min-width: 0;
}

.yawc-search-result-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--theme-text-primary, #1a1a1a);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.yawc-search-result-excerpt {
    font-size: 0.8125rem;
    color: var(--theme-text-secondary, #666666);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.yawc-search-result-meta {
    display: flex;
    gap: var(--theme-spacing-sm, 0.5rem);
    margin-top: var(--theme-spacing-xs, 0.25rem);
    font-size: 0.75rem;
    color: var(--theme-text-tertiary, #999999);
}

/* Highlight search term */
.yawc-search-highlight {
    background: rgba(79, 70, 229, 0.2);
    color: var(--theme-accent, #4f46e5);
    font-weight: 600;
    padding: 0 2px;
    border-radius: 2px;
}

/* =================================================================
   Loading State
   ================================================================= */

.yawc-search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--theme-spacing-2xl, 3rem);
    color: var(--theme-text-secondary, #666666);
    gap: var(--theme-spacing-md, 1rem);
}

.yawc-search-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    border-top-color: var(--theme-accent, #4f46e5);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* =================================================================
   Recent Searches
   ================================================================= */

.yawc-recent-searches {
    margin-bottom: var(--theme-spacing-md, 1rem);
}

.yawc-recent-search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--theme-spacing-sm, 0.5rem) var(--theme-spacing-md, 1rem);
    border-radius: var(--theme-radius-sm, 4px);
    cursor: pointer;
    transition: all var(--theme-transition-fast, 0.15s ease);
    color: var(--theme-text-secondary, #666666);
    font-size: 0.875rem;
}

.yawc-recent-search-item:hover {
    background: var(--theme-bg-secondary, #f8f9fa);
    color: var(--theme-text-primary, #1a1a1a);
}

.yawc-recent-search-text {
    display: flex;
    align-items: center;
    gap: var(--theme-spacing-sm, 0.5rem);
}

.yawc-recent-search-text svg {
    width: 16px;
    height: 16px;
    opacity: 0.5;
}

.yawc-recent-search-remove {
    opacity: 0;
    transition: opacity var(--theme-transition-fast, 0.15s ease);
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--theme-text-tertiary, #999999);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.yawc-recent-search-remove svg {
    width: 16px;
    height: 16px;
}

.yawc-recent-search-item:hover .yawc-recent-search-remove {
    opacity: 1;
}

.yawc-recent-search-remove:hover {
    color: var(--theme-text-primary, #1a1a1a);
}

/* =================================================================
   Keyboard Navigation Hints
   ================================================================= */

.yawc-search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--theme-spacing-md, 1rem) var(--theme-spacing-lg, 1.5rem);
    border-top: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    background: var(--theme-bg-secondary, #f8f9fa);
    font-size: 0.75rem;
    color: var(--theme-text-secondary, #666666);
}

.yawc-search-keyboard-hints {
    display: flex;
    gap: var(--theme-spacing-md, 1rem);
}

.yawc-search-kbd-hint {
    display: flex;
    align-items: center;
    gap: 4px;
}

.yawc-search-kbd {
    padding: 2px 6px;
    background: var(--theme-bg-primary, #ffffff);
    border: 1px solid var(--theme-border-primary, rgba(0, 0, 0, 0.1));
    border-radius: 4px;
    font-family: var(--theme-font-mono, 'Fira Code', monospace);
    font-size: 0.6875rem;
    font-weight: 600;
}

/* =================================================================
   Mobile Optimizations
   ================================================================= */

@media (max-width: 768px) {
    .yawc-search-trigger-text {
        display: none;
    }

    .yawc-search-trigger-kbd {
        display: none;
    }

    .yawc-search-trigger {
        width: 44px;
        justify-content: center;
        padding: 0.625rem;
    }

    .yawc-search-modal {
        padding-top: 0;
        align-items: stretch;
    }

    .yawc-search-modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

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

    .yawc-search-footer {
        display: none;
    }
}

/* =================================================================
   Dark Mode Support
   ================================================================= */

[data-theme="dark"] .yawc-search-modal-backdrop {
    background: rgba(0, 0, 0, 0.8);
}

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

@media (prefers-reduced-motion: reduce) {
    .yawc-search-modal,
    .yawc-search-modal-content,
    .yawc-search-trigger,
    .yawc-search-result-item,
    .yawc-search-recent-search-item {
        transition: none;
    }

    .yawc-search-spinner {
        animation: none;
        border-top-color: transparent;
    }
}

/* Screen reader only */
.yawc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus trap - prevent scrolling when modal is open */
body.yawc-search-modal-open {
    overflow: hidden;
}
