/**
 * Unvarnished Search Styles
 * Typesense InstantSearch integration
 */

/* Search Overlay */
.unvarnished-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0);
    z-index: 10000;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.unvarnished-search-overlay.is-open {
    opacity: 1;
    visibility: visible;
    background-color: rgba(0, 0, 0, 0);
}

/* Prevent body scroll when search is open */
body.unvarnished-search-open {
    overflow: hidden;
}

/* Search Modal */
.unvarnished-search-modal {
    background: #fff;
    border-radius: 0;
    box-shadow: none;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    transform: none;
    transition: none;
    position: relative;
}

.unvarnished-search-overlay.is-open .unvarnished-search-modal {
    transform: none;
}

/* Search Header */
.unvarnished-search-header {
    display: flex;
    align-items: center;
    padding: 2rem 3rem;
    border-bottom: none;
    position: absolute;
    top: 20vh;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    z-index: 10;
}

/* Search Logo - Top left corner */
.unvarnished-search-logo {
    position: absolute;
    top: 2rem;
    left: 3rem;
    z-index: 11;
}

.unvarnished-search-logo-img {
    height: 50px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    display: block;
}

/* Legacy support for old class names */
.unvarnished-search-logo-default,
.unvarnished-search-logo-for-light-bg,
.unvarnished-search-logo-for-dark-bg {
    height: 50px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    display: block;
}

.unvarnished-search-close {
    background: none;
    border: none;
    padding: 0.5rem;
    margin-left: 1rem;
    cursor: pointer;
    color: #6b7280;
    transition: color 0.2s;
}

.unvarnished-search-close:hover {
    color: #374151;
}

/* Search Box */
.unvarnished-search-box {
    flex: 1;
}

.unvarnished-search-form {
    position: relative;
    display: flex;
    align-items: center;
}

.unvarnished-search-input {
    width: 100%;
    font-size: 2rem;
    padding: 1.5rem 4rem 1.5rem 2.25rem;
    border: 3px solid #e5e7eb;
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.unvarnished-search-input:focus {
    border-color: #3b82f6;
}

.unvarnished-search-submit {
    display: none;
}

.unvarnished-search-reset {
    position: absolute;
    right: 1.5rem;
    background: none;
    border: none;
    padding: 0.75rem;
    cursor: pointer;
    color: #6b7280;
    transition: color 0.2s;
    font-size: 1.5rem;
}

.unvarnished-search-reset:hover {
    color: #374151;
}

/* Search Body */
.unvarnished-search-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    margin-top: calc(20vh + 120px);
    padding: 2rem;
}

/* Search Sidebar */
.unvarnished-search-sidebar {
    width: 250px;
    border-right: 1px solid #e5e7eb;
    padding: 1.5rem;
    overflow-y: auto;
}

/* Search Stats */
.unvarnished-search-stats {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 1rem;
}

/* Clear Button */
.unvarnished-search-clear {
    margin-bottom: 1.5rem;
}

.unvarnished-search-clear-button {
    background: #f3f4f6;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.unvarnished-search-clear-button:hover {
    background: #e5e7eb;
}

.unvarnished-search-clear-button--disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Facets */
.unvarnished-search-facet {
    margin-bottom: 1.5rem;
}

.unvarnished-search-facet-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.unvarnished-search-facet-item {
    margin-bottom: 0.5rem;
}

.unvarnished-search-facet-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.875rem;
}

.unvarnished-search-facet-checkbox {
    margin-right: 0.5rem;
}

.unvarnished-search-facet-count {
    margin-left: auto;
    color: #6b7280;
    font-size: 0.75rem;
}

/* Search Main */
.unvarnished-search-main {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal overflow from grid */
    min-width: 0; /* Allow flex item to shrink below content size */
}

/* Custom scrollbar styling */
.unvarnished-search-main::-webkit-scrollbar {
    width: 8px;
}

.unvarnished-search-main::-webkit-scrollbar-track {
    background: transparent;
}

.unvarnished-search-main::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.unvarnished-search-main::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Firefox scrollbar */
.unvarnished-search-main {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* Search Results */
.unvarnished-search-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(350px, 100%), 1fr));
    gap: 0.25rem;
    width: 100%; /* Explicitly constrain to container width */
}

.unvarnished-search-result-item {
    margin-bottom: 0;
    padding: 1.5rem;
    border: none;
    border-radius: 8px !important;
    background: #fafafa;
    transition: all 0.2s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.unvarnished-search-result-item:has(> .unvarnished-search-result-link:hover) {
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
}

.unvarnished-search-result-title {
    font-size: 1.25rem;
    margin: 0 0 0.5rem;
}

.unvarnished-search-result-link {
    color: inherit;
    text-decoration: none;
    display: block;
    height: 100%;
    width: 100%;
}

.unvarnished-search-result-link:hover {
    color: inherit;
}

.unvarnished-search-result {
    /*padding: 1.5rem;*/
    height: 100%;
    display: flex;
    flex-direction: column;
}

.unvarnished-search-result-summary {
    font-size: 0.875rem;
    color: #4b5563;
    margin: 0.5rem 0;
    line-height: 1.5;
}

.unvarnished-search-result-content {
    font-size: 0.875rem;
    color: #6b7280;
    line-height: 1.6;
    margin: 0.5rem 0;
    flex: 1;
}

.unvarnished-search-result-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.5rem;
}

.unvarnished-search-result-section {
    background: #f3f4f6;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
}

/* Highlighted text */
.unvarnished-search-result mark {
    background: #fef3c7;
    color: inherit;
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
}

/* Pagination */
.unvarnished-search-pagination {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
}

.unvarnished-search-pagination-list {
    display: flex;
    gap: 0.5rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.unvarnished-search-pagination-link {
    display: block;
    padding: 0.5rem 0.75rem;
    background: #f3f4f6;
    color: #4b5563;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
}

.unvarnished-search-pagination-link:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.unvarnished-search-pagination-item--selected
    .unvarnished-search-pagination-link {
    background: #3b82f6;
    color: white;
}

.unvarnished-search-pagination-item--disabled
    .unvarnished-search-pagination-link {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Fix InstantSearch pagination item alignment */
.ais-Pagination-item {
    margin-bottom: 0 !important;
}

/* Search Button - Matches chat toggle style */
.unvarnished-search-button {
    position: fixed;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #32cbff 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    z-index: 9998;
}

/* Button with text - becomes pill-shaped */
.unvarnished-search-button--with-text {
    width: auto;
    padding: 0 20px;
    border-radius: 30px;
}

.unvarnished-search-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.unvarnished-search-button svg {
    width: 24px;
    height: 24px;
    fill: white;
    flex-shrink: 0;
}

.unvarnished-search-button-text {
    color: white;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Position search button to the left of chat button */
.unvarnished-search-button--bottom-right {
    bottom: 20px;
    right: 100px; /* Chat button at 20px + 60px width + 20px gap */
}

.unvarnished-search-button--bottom-left {
    bottom: 20px;
    left: 100px;
}

.unvarnished-search-button--top-right {
    top: 20px;
    right: 100px;
}

.unvarnished-search-button--top-left {
    top: 20px;
    left: 100px;
}

/* Old search trigger styles (keep for backward compatibility) */
.unvarnished-search-trigger {
    transition: all 0.3s ease;
}

.unvarnished-search-trigger:focus {
    transform: translateY(-2px);
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .unvarnished-search-modal {
        background: #1f2937;
        color: #f9fafb;
    }

    .unvarnished-search-header,
    .unvarnished-search-sidebar {
        border-color: #374151;
    }

    /* Dark mode scrollbar */
    .unvarnished-search-main::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
    }

    .unvarnished-search-main::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.3);
    }

    .unvarnished-search-main {
        scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    }

    .unvarnished-search-input {
        background: #111827;
        border-color: #374151;
        color: #f9fafb;
    }

    .unvarnished-search-input:focus {
        border-color: #60a5fa;
    }

    .unvarnished-search-close,
    .unvarnished-search-reset {
        color: #9ca3af;
    }

    .unvarnished-search-close:hover,
    .unvarnished-search-reset:hover {
        color: #f9fafb;
    }

    .unvarnished-search-result-item {
        background: #111827;
    }

    .unvarnished-search-result-item:has(
        > .unvarnished-search-result-link:hover
    ) {
        box-shadow:
            0 4px 6px -1px rgba(0, 0, 0, 0.3),
            0 2px 4px -1px rgba(0, 0, 0, 0.2);
    }

    .unvarnished-search-result-summary {
        color: #d1d5db;
    }

    .unvarnished-search-result-content {
        color: #9ca3af;
    }

    .unvarnished-search-result-section {
        background: #374151;
    }

    .unvarnished-search-result mark {
        background: #b91c1c;
        color: #fef2f2;
    }

    .unvarnished-search-clear-button,
    .unvarnished-search-pagination-link {
        background: #374151;
        color: #d1d5db;
    }

    .unvarnished-search-clear-button:hover,
    .unvarnished-search-pagination-link:hover {
        background: #4b5563;
        color: #f9fafb;
    }

    .unvarnished-search-pagination-item--selected
        .unvarnished-search-pagination-link {
        background: #3b82f6;
        color: white;
    }

    .unvarnished-search-pagination-link {
        background: transparent;
        border: 1px solid white;
        color: white;
    }

    .unvarnished-search-pagination-link:hover {
        background: rgba(255, 255, 255, 0.1);
        color: white;
    }

    /* InstantSearch disabled button states */
    .ais-ClearRefinements-button:disabled[disabled],
    .ais-GeoSearch-redo--disabled,
    .ais-GeoSearch-reset--disabled,
    .ais-InfiniteHits-loadMore:disabled[disabled],
    .ais-InfiniteHits-loadPrevious:disabled[disabled],
    .ais-Pagination-item--disabled .ais-Pagination-link,
    .ais-VoiceSearch-button:disabled {
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: rgba(255, 255, 255, 0.4);
        opacity: 1;
    }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .unvarnished-search-header {
        width: 95%;
        padding: 1rem;
    }

    .unvarnished-search-body {
        flex-direction: column;
        margin-top: calc(20vh + 100px);
        padding: 1rem;
    }

    .unvarnished-search-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
        padding: 1rem;
    }

    .unvarnished-search-main {
        padding: 1rem;
    }

    .unvarnished-search-input {
        font-size: 1.5rem;
        padding: 1rem 3rem 1rem 2.25rem;
    }

    .unvarnished-search-reset {
        right: 1rem;
        font-size: 1.25rem;
    }

    .unvarnished-search-results-list {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}
