/* ==========================================================================
   search.css — LegalnyMedyk Globalna Wyszukiwarka (Etap 4)
   Topbar dropdown suggest + strona wynikow /szukaj/
   Mobile-first. Uses CSS variables from main.css :root.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Utility: screen-reader only (defensive duplicate)
   -------------------------------------------------------------------------- */
.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;
}

/* ==========================================================================
   TOPBAR SEARCH — komponent wbudowany w .topbar-content
   ========================================================================== */

.topbar-search {
    position: relative;
    /* Grows to fill space between nav and topbar-actions */
    flex: 1 1 auto;
    max-width: 480px;
    min-width: 160px;
    margin: 0 24px;
}

/* Mobile trigger hidden on desktop — visible only on mobile via media query */
.topbar-search__mobile-trigger {
    display: none;
}

.topbar-search__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.topbar-search__icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-600, #888);
    pointer-events: none;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.topbar-search__input {
    width: 100%;
    height: 38px;
    padding: 0 14px 0 38px;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink-900, #333);
    background: var(--ink-100, #F5F7FA);
    border: 1.5px solid var(--ink-300, #E0E8F0);
    border-radius: 20px;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    /* Remove native search decorations */
    -webkit-appearance: none;
    appearance: none;
}

.topbar-search__input::placeholder {
    color: var(--ink-600, #888);
    font-size: 13px;
}

.topbar-search__input:focus {
    background: var(--white, #fff);
    border-color: var(--brand-primary, #2EA4D9);
    box-shadow: 0 0 0 3px var(--brand-primary-light, rgba(46, 164, 217, 0.12));
}

.topbar-search__input:focus ~ .topbar-search__icon,
.topbar-search__input-wrap:focus-within .topbar-search__icon {
    color: var(--brand-primary, #2EA4D9);
}

/* Remove native X clear button in webkit */
.topbar-search__input::-webkit-search-cancel-button,
.topbar-search__input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* --------------------------------------------------------------------------
   Dropdown wynikow autosuggest
   -------------------------------------------------------------------------- */

.topbar-search__dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    /* Dropdown szerokosc: 120% wzgledem pola - wyglada lepiej */
    min-width: 360px;
    background: var(--white, #fff);
    border: 1px solid var(--ink-300, #E0E8F0);
    border-radius: var(--border-radius-card, 8px);
    box-shadow: var(--shadow-xl, 0 8px 32px rgba(0, 0, 0, 0.15));
    z-index: 10100;
    overflow: hidden;
    max-height: 480px;
    overflow-y: auto;
    /* Smooth scroll */
    scroll-behavior: smooth;
}

.topbar-search__dropdown[hidden] {
    display: none;
}

/* Scrollbar styling */
.topbar-search__dropdown::-webkit-scrollbar {
    width: 4px;
}
.topbar-search__dropdown::-webkit-scrollbar-track {
    background: transparent;
}
.topbar-search__dropdown::-webkit-scrollbar-thumb {
    background: var(--ink-400, #D1D1D1);
    border-radius: 2px;
}

/* Sekcja w dropdownie */
.search-dd-section {
    padding: 0;
}

.search-dd-section + .search-dd-section {
    border-top: 1px solid var(--ink-100, #F5F7FA);
}

.search-dd-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-600, #888);
    background: var(--ink-100, #F5F7FA);
}

/* Wynik w dropdownie */
.search-dd-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--ink-900, #333);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.12s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.search-dd-item:hover,
.search-dd-item:focus,
.search-dd-item[aria-selected="true"] {
    background: var(--brand-primary-light, rgba(46, 164, 217, 0.08));
    outline: none;
}

.search-dd-item__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ink-300, #E0E8F0);
}

.search-dd-item__icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    background: var(--brand-primary-light, rgba(46, 164, 217, 0.1));
    color: var(--brand-primary, #2EA4D9);
}

.search-dd-item__thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ink-300, #E0E8F0);
}

.search-dd-item__body {
    flex: 1;
    min-width: 0;
}

.search-dd-item__name {
    font-weight: 600;
    font-size: 14px;
    color: var(--ink-900, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-dd-item__meta {
    font-size: 12px;
    color: var(--ink-600, #888);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Link "Zobacz wszystkie wyniki" na dole */
.search-dd-footer {
    display: block;
    padding: 10px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--brand-primary, #2EA4D9);
    text-decoration: none;
    background: var(--ink-100, #F5F7FA);
    border-top: 1px solid var(--ink-300, #E0E8F0);
    transition: background 0.12s ease;
}

.search-dd-footer:hover {
    background: var(--brand-primary-light, rgba(46, 164, 217, 0.1));
    text-decoration: underline;
}

/* Stan "Wyszukuje..." w dropdownie */
.search-dd-loading,
.search-dd-empty {
    padding: 20px 16px;
    text-align: center;
    font-size: 14px;
    color: var(--ink-600, #888);
}

.search-dd-loading-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.search-dd-loading-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-primary, #2EA4D9);
    animation: dd-bounce 1.2s infinite ease-in-out;
}
.search-dd-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.search-dd-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dd-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   STRONA WYNIKOW /szukaj/ — .search-results-page
   ========================================================================== */

.search-results-page {
    max-width: var(--container-max, 1320px);
    margin: 0 auto;
    padding: 40px 24px 80px;
}

/* Header strony */
.search-page-header {
    margin-bottom: 32px;
}

.search-page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ink-900, #333);
    margin-bottom: 16px;
}

.search-page-header h1 em {
    font-style: normal;
    color: var(--brand-primary, #2EA4D9);
}

/* Pasek wyszukiwania na stronie wynikow */
.search-page-bar {
    display: flex;
    gap: 8px;
    max-width: 600px;
}

.search-page-bar__wrap {
    position: relative;
    flex: 1;
}

.search-page-bar__icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-600, #888);
    pointer-events: none;
}

.search-page-bar__input {
    width: 100%;
    height: 48px;
    padding: 0 14px 0 44px;
    font-family: inherit;
    font-size: 15px;
    color: var(--ink-900, #333);
    background: var(--white, #fff);
    border: 1.5px solid var(--ink-300, #E0E8F0);
    border-radius: var(--border-radius-card, 8px);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.search-page-bar__input:focus {
    border-color: var(--brand-primary, #2EA4D9);
    box-shadow: 0 0 0 3px var(--brand-primary-light, rgba(46, 164, 217, 0.12));
}

.search-page-bar__input::-webkit-search-cancel-button,
.search-page-bar__input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

.search-page-bar__btn {
    height: 48px;
    padding: 0 24px;
    background: var(--brand-primary, #2EA4D9);
    color: var(--white, #fff);
    border: none;
    border-radius: var(--border-radius-button, 6px);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.search-page-bar__btn:hover {
    background: var(--brand-primary-dark, #2590C0);
}

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */

.search-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 28px;
    border-bottom: 2px solid var(--ink-300, #E0E8F0);
    padding-bottom: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.search-tabs::-webkit-scrollbar {
    display: none;
}

.search-tab {
    flex-shrink: 0;
    padding: 10px 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink-600, #888);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
    border-radius: 0;
    white-space: nowrap;
}

.search-tab:hover {
    color: var(--brand-primary, #2EA4D9);
}

.search-tab.is-active {
    color: var(--brand-primary, #2EA4D9);
    border-bottom-color: var(--brand-primary, #2EA4D9);
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Stany: loading / empty / error / onboarding
   -------------------------------------------------------------------------- */

.search-state {
    padding: 60px 24px;
    text-align: center;
    color: var(--ink-600, #888);
    font-size: 15px;
}

.search-state__icon {
    font-size: 40px;
    margin-bottom: 16px;
    display: block;
    opacity: 0.5;
}

.search-state__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink-700, #4A4A4A);
    margin-bottom: 8px;
}

.search-state__desc {
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}

.search-loading-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--ink-300, #E0E8F0);
    border-top-color: var(--brand-primary, #2EA4D9);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

/* --------------------------------------------------------------------------
   Kontener wynikow i sekcje per typ
   -------------------------------------------------------------------------- */

#search-results-container {
    /* JS fills this */
}

.search-section {
    margin-bottom: 40px;
}

.search-section__title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-600, #888);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--ink-300, #E0E8F0);
}

/* Siatka wynikow */
.search-result-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-result-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: var(--white, #fff);
    border: 1px solid var(--ink-300, #E0E8F0);
    border-radius: var(--border-radius-card, 8px);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.search-result-item:hover {
    box-shadow: var(--shadow-lg, 0 4px 12px rgba(0, 0, 0, 0.1));
    transform: translateY(-1px);
}

/* Avatar / grafika */
.search-result-item__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ink-200, #E0E8F0);
}

.search-result-item__thumb {
    width: 72px;
    height: 72px;
    border-radius: var(--border-radius-card, 8px);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ink-200, #E0E8F0);
}

.search-result-item__cat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-card, 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 22px;
}

/* Tresc wyniku */
.search-result-item__body {
    flex: 1;
    min-width: 0;
}

.search-result-item__name {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-900, #333);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-item__sub {
    font-size: 13px;
    color: var(--ink-600, #888);
    margin-bottom: 4px;
}

.search-result-item__meta {
    font-size: 12px;
    color: var(--ink-500, #888);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.search-result-item__badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--brand-primary-light, rgba(46, 164, 217, 0.1));
    color: var(--brand-primary, #2EA4D9);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.search-result-item__price {
    font-size: 14px;
    font-weight: 700;
    color: var(--brand-primary, #2EA4D9);
    white-space: nowrap;
}

/* Autorzy pisza post excerpt */
.search-result-item__excerpt {
    font-size: 13px;
    color: var(--ink-700, #4A4A4A);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Siatka kategorii (opcjonalna, jesli chcemy grid zamiast listy)
   -------------------------------------------------------------------------- */

.search-section--categories .search-result-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.search-section--categories .search-result-item {
    align-items: center;
}

/* --------------------------------------------------------------------------
   Brak wynikow dla sekcji
   -------------------------------------------------------------------------- */

.search-section[hidden] {
    display: none;
}

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

/* Tablet */
@media (max-width: 1024px) {
    .topbar-search {
        max-width: 340px;
        margin: 0 16px;
    }
}

/* Mobile — topbar search zmniejsza sie */
@media (max-width: 768px) {
    .topbar-search {
        /* Na mobile: ikona-only przycisk otwierajacy overlay */
        max-width: 40px;
        min-width: 40px;
        margin: 0 8px;
        overflow: visible;
    }

    .topbar-search__input-wrap {
        /* Ukryj pole, pokazuj tylko ikone */
        display: none;
    }

    /* Przycisk trigger widoczny na mobile */
    .topbar-search__mobile-trigger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border: none;
        background: none;
        color: var(--ink-700, #4A4A4A);
        cursor: pointer;
        border-radius: 50%;
        transition: background 0.2s ease;
        padding: 0;
        flex-shrink: 0;
    }

    .topbar-search__mobile-trigger:hover {
        background: var(--ink-100, #F5F7FA);
    }

    /* Overlay fullscreen na mobile */
    .search-mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: var(--white, #fff);
        z-index: 10200;
        flex-direction: column;
    }

    .search-mobile-overlay.is-open {
        display: flex;
    }

    .search-mobile-overlay__header {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 12px 16px;
        border-bottom: 1px solid var(--ink-300, #E0E8F0);
    }

    .search-mobile-overlay__input {
        flex: 1;
        height: 44px;
        padding: 0 14px 0 40px;
        font-family: inherit;
        font-size: 16px; /* min 16px to prevent zoom on iOS */
        color: var(--ink-900, #333);
        background: var(--ink-100, #F5F7FA);
        border: 1.5px solid var(--ink-300, #E0E8F0);
        border-radius: 22px;
        outline: none;
        -webkit-appearance: none;
        appearance: none;
    }

    .search-mobile-overlay__input:focus {
        border-color: var(--brand-primary, #2EA4D9);
    }

    .search-mobile-overlay__icon {
        position: absolute;
        left: 28px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--ink-600, #888);
        pointer-events: none;
    }

    .search-mobile-overlay__input-wrap {
        position: relative;
        flex: 1;
    }

    .search-mobile-overlay__close {
        flex-shrink: 0;
        padding: 8px 12px;
        border: none;
        background: none;
        font-family: inherit;
        font-size: 14px;
        font-weight: 600;
        color: var(--brand-primary, #2EA4D9);
        cursor: pointer;
    }

    .search-mobile-overlay__results {
        flex: 1;
        overflow-y: auto;
        /* Wyniki dropdown wbudowane tutaj na mobile */
    }

    /* Na mobile wyniki sa pelna szerokosc */
    .search-mobile-overlay .search-dd-section {
        border-top: none;
    }

    /* Strona wynikow na mobile */
    .search-results-page {
        padding: 24px 16px 60px;
    }

    .search-page-header h1 {
        font-size: 1.375rem;
    }

    .search-page-bar {
        flex-direction: column;
    }

    .search-tabs {
        gap: 0;
    }

    .search-tab {
        padding: 10px 14px;
        font-size: 13px;
    }

    .search-section--categories .search-result-list {
        grid-template-columns: 1fr 1fr;
    }
}

/* Bardzo male ekrany */
@media (max-width: 480px) {
    .search-section--categories .search-result-list {
        grid-template-columns: 1fr;
    }

    .search-result-item__thumb {
        width: 56px;
        height: 56px;
    }
}
