/* ============================================
   assets/css/search.css - Enhanced Search Styles
   Version: 1.0
   Description: Styles for autocomplete search dropdown,
                recent searches, and search page
   ============================================ */

/* ============================================
   SEARCH INPUT & CONTAINER
   ============================================ */

   .nav-search {
    position: relative;
    flex: 1;
    max-width: 400px;
    min-width: 200px;
}

.nav-search input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 25px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.nav-search input:focus {
    outline: none;
    background: rgba(255,255,255,0.2);
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.2);
}

.nav-search input::placeholder {
    color: rgba(255,255,255,0.6);
}

/* Loading indicator в input */
.nav-search.loading::after {
    content: '';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spinLoader 0.8s linear infinite;
}

@keyframes spinLoader {
    to { 
        transform: translateY(-50%) rotate(360deg); 
    }
}

/* ============================================
   SEARCH RESULTS DROPDOWN
   ============================================ */

.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
    animation: slideDown 0.2s ease-out;
    /* Позволява на dropdown да стане по-широк ако е нужно */
    min-width: 400px;
    width: max-content;
    max-width: min(600px, 90vw);
}

/* За малки екрани - връщаме на 100% ширина */
@media (max-width: 968px) {
    .search-results {
        min-width: 100%;
        width: 100%;
        max-width: 100%;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-dropdown {
    padding: 0.5rem 0;
}

/* ============================================
   SECTION TITLE
   ============================================ */

.search-section-title {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: var(--cream);
}

/* ============================================
   SEARCH RESULT ITEMS
   ============================================ */

.search-results-section {
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    gap: 1rem;
    padding: 0.875rem 1rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    /* Подобрение за дълги заглавия */
    align-items: flex-start;
}

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

.search-result-item:hover,
.search-result-item.active {
    background: var(--cream);
    padding-left: 1.25rem;
}

.result-thumb {
    width: 90px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: var(--cream);
}

.result-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.result-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.35rem 0;
    color: var(--text-primary);
    line-height: 1.4;
    /* Позволява на заглавието да се пренася на 2 реда */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    /* Подобрена четимост */
    hyphens: auto;
}

.result-title mark {
    background: var(--gold);
    color: white;
    padding: 0 0.2rem;
    border-radius: 2px;
    font-weight: 700;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.result-category,
.result-year,
.result-duration {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.result-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.result-views {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.result-rating {
    color: var(--gold);
    font-weight: 600;
}

/* ============================================
   RECENT SEARCHES
   ============================================ */

.recent-search-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.recent-search-item:last-of-type {
    border-bottom: none;
}

.recent-search-item:hover,
.recent-search-item.active {
    background: var(--cream);
    padding-left: 1.25rem;
}

.recent-icon {
    font-size: 1.1rem;
    opacity: 0.5;
    flex-shrink: 0;
}

.recent-text {
    flex: 1;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-recent {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.remove-recent:hover {
    background: rgba(255,0,0,0.1);
    color: #dc3545;
    transform: scale(1.1);
}

/* ============================================
   SEARCH FOOTER
   ============================================ */

.search-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--cream);
}

.view-all-btn,
.clear-recent-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    text-align: center;
    text-decoration: none;
    color: var(--gold);
    font-weight: 600;
    border-radius: 6px;
    transition: all 0.2s ease;
    background: transparent;
    border: 2px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
}

.view-all-btn:hover,
.clear-recent-btn:hover {
    background: var(--gold);
    color: white;
    border-color: var(--gold);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(201, 169, 97, 0.3);
}

/* ============================================
   LOADING STATE
   ============================================ */

.search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(201,169,97,0.2);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spinLoader 0.8s linear infinite;
}

.search-loading span {
    font-size: 0.9rem;
}

/* ============================================
   NO RESULTS STATE
   ============================================ */

.no-results {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.no-results-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
    opacity: 0.5;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

.no-results p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
}

.no-results strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ============================================
   ERROR STATE
   ============================================ */

.search-error {
    text-align: center;
    padding: 2rem;
    color: #dc3545;
}

.error-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 1rem;
}

.search-error p {
    margin: 0;
    font-size: 0.9rem;
}

/* ============================================
   DARK THEME ADJUSTMENTS
   ============================================ */

:root[data-theme="dark"] .search-results {
    background: #2a2a2a;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

:root[data-theme="dark"] .search-section-title {
    background: #1e1e1e;
    border-bottom-color: #444;
}

:root[data-theme="dark"] .search-result-item,
:root[data-theme="dark"] .recent-search-item {
    border-bottom-color: #444;
}

:root[data-theme="dark"] .search-result-item:hover,
:root[data-theme="dark"] .search-result-item.active,
:root[data-theme="dark"] .recent-search-item:hover,
:root[data-theme="dark"] .recent-search-item.active {
    background: #333;
}

:root[data-theme="dark"] .search-footer {
    background: #1e1e1e;
    border-top-color: #444;
}

:root[data-theme="dark"] .result-thumb {
    background: #1e1e1e;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

.search-results::-webkit-scrollbar,
.search-results-section::-webkit-scrollbar {
    width: 8px;
}

.search-results::-webkit-scrollbar-track,
.search-results-section::-webkit-scrollbar-track {
    background: var(--cream);
}

.search-results::-webkit-scrollbar-thumb,
.search-results-section::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}

.search-results::-webkit-scrollbar-thumb:hover,
.search-results-section::-webkit-scrollbar-thumb:hover {
    background: var(--dark-gold);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 1200px) {
    .nav-search {
        max-width: 250px;
        min-width: 150px;
    }
}

@media (max-width: 968px) {
    .nav-search {
        order: 3;
        flex: 1 1 100%;
        max-width: 100%;
        width: 100%;
        margin: 0;
    }

    .search-results {
        max-height: 400px;
        border-radius: 8px;
        /* Върни на 100% за mobile */
        min-width: 100%;
        width: 100%;
        max-width: 100%;
    }

    .result-thumb {
        width: 70px;
        height: 52px;
    }

    .result-title {
        font-size: 0.875rem;
    }

    .result-meta,
    .result-stats {
        font-size: 0.75rem;
    }

    .search-loading,
    .no-results {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .search-result-item,
    .recent-search-item {
        padding: 0.75rem;
    }

    .search-result-item:hover,
    .search-result-item.active,
    .recent-search-item:hover,
    .recent-search-item.active {
        padding-left: 1rem;
    }

    .result-info {
        font-size: 0.85rem;
    }

    .result-thumb {
        width: 50px;
        height: 38px;
    }

    .no-results-icon {
        font-size: 2.5rem;
    }

    .error-icon {
        font-size: 2rem;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus styles for keyboard navigation */
.search-result-item:focus,
.recent-search-item:focus,
.view-all-btn:focus,
.clear-recent-btn:focus,
.remove-recent:focus {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .search-results,
    .search-result-item,
    .recent-search-item,
    .view-all-btn,
    .clear-recent-btn,
    .remove-recent,
    .loading-spinner {
        animation: none !important;
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
    .search-results {
        border: 2px solid var(--text-primary);
    }

    .search-result-item,
    .recent-search-item {
        border-bottom: 2px solid var(--text-primary);
    }

    .result-title mark {
        outline: 2px solid var(--text-primary);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .search-results {
        display: none !important;
    }
}

/* ============================================
   SEARCH PAGE SPECIFIC STYLES
   ============================================ */

/* Search Page Layout */
.search-page {
    padding: 2rem 0;
    min-height: 80vh;
}

.search-header {
    margin-bottom: 2rem;
    text-align: center;
}

.search-header .section-title {
    justify-content: center;
    margin-bottom: 0.5rem;
}

.search-count {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-size: 1rem;
}

/* Filters Wrapper */
.search-filters-wrapper {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 3rem;
    overflow: hidden;
}

:root[data-theme="dark"] .search-filters-wrapper {
    background: #2a2a2a;
}

.filters-toggle {
    display: none;
    width: 100%;
    padding: 1rem;
    background: var(--gold);
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    font-size: 1rem;
    font-family: inherit;
}

.filters-toggle:hover {
    background: var(--dark-gold);
}

.filters-badge {
    display: inline-block;
    background: white;
    color: var(--gold);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    margin-left: 0.5rem;
    font-weight: 700;
}

/* Search Filters Form */
.search-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
}

.filter-group-wide {
    grid-column: 1 / -1;
}

.filter-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
    font-size: 0.95rem;
}

:root[data-theme="dark"] .filter-group label {
    color: var(--text-primary);
}

.filter-input,
.filter-select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.1);
}

/* Filter Actions */
.filter-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 1rem;
}

.filter-actions .btn {
    flex: 1;
}

/* Checkbox styling */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s ease;
    margin-top: 1.5rem;
}

.checkbox-label:hover {
    background: var(--cream);
}

.filter-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--gold);
}

.checkbox-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* No Results State */
.no-results-full {
    text-align: center;
    padding: 4rem 2rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

:root[data-theme="dark"] .no-results-full {
    background: #2a2a2a;
}

.no-results-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: pulse 2s ease-in-out infinite;
}

.no-results-full h2 {
    color: var(--blue);
    margin-bottom: 1rem;
}

:root[data-theme="dark"] .no-results-full h2 {
    color: var(--gold);
}

.no-results-full p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Video Grid - extends global styles */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

/* Video Category Badge */
.video-category-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 1;
    backdrop-filter: blur(4px);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 3rem;
    flex-wrap: wrap;
}

.pagination-btn {
    padding: 0.75rem 1rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
    min-width: 44px;
    text-align: center;
}

:root[data-theme="dark"] .pagination-btn {
    background: #2a2a2a;
    color: var(--text-primary);
    border-color: #444;
}

.pagination-btn:hover {
    background: var(--gold);
    color: white;
    border-color: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(201, 169, 97, 0.3);
}

.pagination-btn.active {
    background: var(--gold);
    color: white;
    border-color: var(--gold);
}

/* Search Page Mobile Responsive */
@media (max-width: 768px) {
    .search-page {
        padding: 1rem 0;
    }

    .filters-toggle {
        display: block;
    }

    .search-filters {
        display: none;
        grid-template-columns: 1fr;
    }

    .search-filters.active {
        display: grid;
    }

    .filter-actions {
        flex-direction: column;
    }

    .pagination-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
        min-width: 40px;
    }

    .video-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    .search-header .section-title {
        font-size: 1.5rem;
    }

    .search-count {
        font-size: 0.9rem;
    }

    .no-results-icon {
        font-size: 3.5rem;
    }
}