/**
 * Live Search Styles - Nowoczesny autocomplete
 * Mobile-first, UX-optimized, accessibility-ready
 * @version 1.0.0
 */

/* === SEARCH TOGGLE BUTTON (LUPKA) === */
.search-toggle-btn {
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    border-radius: 50%;
}

.search-toggle-btn:hover,
.search-toggle-btn:focus {
    background: rgba(42, 51, 146, 0.1);
    color: var(--tb-theme-color);
}

.search-toggle-btn .dashicons {
    font-size: 20px; /* 10% mniejsza niż standardowe 22px */
    width: 20px;
    height: 20px;
}

/* === DESKTOP SEARCH BAR (rozwijany) === */
.desktop-search-bar {
    width: 100%;
    background: #fff;
    border-bottom: 2px solid #e0e0e0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    animation: slideDown 0.3s ease-out;
    position: relative;
    z-index: 999;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.desktop-search-bar .container-main {
    padding-top: 16px;
    padding-bottom: 16px;
}

/* === SEARCH WRAPPER === */
.header-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
}

.desktop-search-bar .header-search-wrapper {
    max-width: 100%;
}

/* === SEARCH CLOSE BUTTON (X) === */
.search-close-btn {
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 10px;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.search-close-btn:hover,
.search-close-btn:focus {
    background: #f0f0f0;
    color: #222;
}

.search-close-btn .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
}

/* === SEARCH FORM === */
#live-search-form {
    position: relative;
    width: 100%;
    flex: 1;
}

/* === INPUT FIELD === */
#live-search-input {
    width: 100%;
    padding: 10px 40px 10px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    font-size: 15px;
    line-height: 1.5;
    font-family: 'Helvetica', Arial, sans-serif;
    transition: all 0.25s ease;
    background: #fff;
    box-sizing: border-box;
}

#live-search-input:focus {
    outline: none;
    border-color: var(--tb-theme-color);
    box-shadow: 0 0 0 3px rgba(42, 51, 146, 0.1);
}

#live-search-input::placeholder {
    color: #999;
    font-size: 14px;
}

/* === SEARCH BUTTON === */
.search-submit-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--tb-theme-color);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.25s ease;
    color: #fff;
}

.search-submit-btn:hover,
.search-submit-btn:focus {
    background: var(--tb-theme-color-hover);
}

.search-submit-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* === LOADING SPINNER === */
.live-search-loading {
    position: absolute;
    right: 48px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
}

.live-search-loading .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(42, 51, 146, 0.2);
    border-top-color: var(--tb-theme-color);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === RESULTS CONTAINER === */
.live-search-results {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    max-height: 480px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
}

.desktop-search-bar .live-search-results {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    max-width: 700px;
    width: calc(100% - 30px);
}

/* Custom scrollbar */
.live-search-results::-webkit-scrollbar {
    width: 8px;
}

.live-search-results::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 0 12px 12px 0;
}

.live-search-results::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.live-search-results::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* === SUGGESTIONS LIST === */
.search-suggestions-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* === SINGLE SUGGESTION ITEM === */
.search-suggestion-item {
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    color: #232323;
}

.search-suggestion-item:last-child {
    border-bottom: none;
}

.search-suggestion-item:hover,
.search-suggestion-item.selected {
    background: #f8f9ff;
}

.suggestion-icon {
    color: #999;
    font-size: 18px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.suggestion-text {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

.suggestion-text mark {
    background: #fff3cd;
    color: #856404;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 600;
}

/* === PRODUCT COUNT INFO === */
.search-product-count {
    padding: 10px 16px;
    background: #e7f3ff;
    border-top: 1px solid #b3d9ff;
    font-size: 13px;
    color: #004085;
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-product-count .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

/* === PRODUCT IMAGE === */
.search-result-image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* === PRODUCT CONTENT === */
.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-size: 15px;
    font-weight: 600;
    color: #222;
    margin-bottom: 6px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search-result-title mark {
    background: #fff3cd;
    color: #856404;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 700;
}

/* === META (PRICE + STOCK) === */
.search-result-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.search-result-price {
    font-weight: 700;
    color: var(--tb-theme-color);
}

.search-result-price .amount {
    font-size: 14px;
}

.search-result-stock {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.search-result-stock.in-stock {
    background: #d4edda;
    color: #155724;
}

.search-result-stock.out-of-stock {
    background: #f8d7da;
    color: #721c24;
}

/* === SHOW ALL RESULTS (gdy więcej niż 7) === */
.show-all-results {
    padding: 12px 16px;
    background: #fff3cd;
    border-top: 1px solid #ffc107;
    border-bottom: 1px solid #ffc107;
    transition: background 0.2s ease;
}

.show-all-results:hover {
    background: #ffe69c;
}

.show-all-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #856404;
    text-decoration: none;
    transition: color 0.2s ease;
}

.show-all-link:hover,
.show-all-link:focus {
    color: #533f03;
    text-decoration: underline;
}

.show-all-link .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* === VIEW ALL RESULTS === */
.view-all-results {
    padding: 12px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    transition: background 0.2s ease;
}

.view-all-results.selected {
    background: #e9ecef;
}

.view-all-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--tb-theme-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.view-all-link:hover,
.view-all-link:focus {
    color: var(--tb-theme-color-hover);
    text-decoration: underline;
}

.view-all-link .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* === NO RESULTS === */
.search-no-results {
    padding: 32px 20px;
    text-align: center;
    color: #666;
}

.search-no-results .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: #ccc;
    margin-bottom: 12px;
}

.search-no-results p {
    margin: 12px 0 16px 0;
    font-size: 15px;
    line-height: 1.5;
}

.search-no-results strong {
    color: #222;
    font-weight: 600;
}

.search-all-link {
    display: inline-block;
    padding: 10px 20px;
    background: var(--tb-theme-color);
    color: #fff;
    text-decoration: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.25s ease;
}

.search-all-link:hover,
.search-all-link:focus {
    background: var(--tb-theme-color-hover);
    color: #fff;
    text-decoration: none;
}

/* === MOBILE SEARCH BAR === */
.mobile-search-bar {
    width: 100%;
    background: #fff;
    padding: 12px 15px;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.mobile-search-bar .header-search-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.mobile-search-bar #live-search-form-mobile {
    flex: 1;
}

.mobile-search-close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.mobile-search-close:hover,
.mobile-search-close:focus {
    background: #f0f0f0;
    color: #222;
}

.mobile-search-close .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.mobile-search-toggle {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-search-toggle .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
}

/* === MOBILE STYLES === */
@media (max-width: 767px) {
    .header-search-wrapper {
        max-width: 100%;
    }

    #live-search-input {
        font-size: 16px; /* Zapobiega zoom na iOS */
        padding: 12px 44px 12px 16px;
    }

    .search-submit-btn {
        width: 40px;
        height: 40px;
    }

    .live-search-results {
        max-height: 70vh;
        border-radius: 8px;
        top: calc(100% + 6px);
    }

    .search-result-link {
        padding: 10px 12px;
        gap: 12px;
    }

    .search-result-image {
        width: 50px;
        height: 50px;
    }

    .search-result-title {
        font-size: 14px;
    }

    .search-result-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .view-all-link {
        font-size: 13px;
    }
}

/* === DESKTOP OPTIMIZATION === */
@media (min-width: 768px) {
    .header-search-wrapper {
        min-width: 320px;
    }

    .live-search-results {
        min-width: 420px;
    }
}

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
    #live-search-input,
    .search-result-item,
    .view-all-results,
    .search-submit-btn,
    .search-all-link {
        transition: none;
    }

    .live-search-loading .spinner {
        animation: none;
        border-color: var(--tb-theme-color);
    }
}

/* === FOCUS VISIBLE (KEYBOARD NAVIGATION) === */
.search-result-link:focus-visible,
.view-all-link:focus-visible,
.search-all-link:focus-visible {
    outline: 2px solid var(--tb-theme-color);
    outline-offset: 2px;
}
