/**
 * TP4R Search Styles
 * Beautiful AJAX search with icon toggle and open modes
 */

/* ===== Base Styles ===== */
.tp4r-search {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* ===== Icon Mode Toggle Button ===== */
.tp4r-search__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 50%;
}

.tp4r-search__toggle:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.05);
}

/* ===== Search Container ===== */
.tp4r-search__container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #fff;
    padding: 0;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.tp4r-search__container.is-open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

/* Open Mode - Always visible inline */
.tp4r-search--open-mode .tp4r-search__container {
    position: relative;
    transform: none;
    opacity: 1;
    visibility: visible;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

/* ===== Search Form ===== */
.tp4r-search__form {
    max-width: 800px;
    margin: 0 auto;
    padding: 30px 40px;
}

.tp4r-search--open-mode .tp4r-search__form {
    padding: 0;
    max-width: 100%;
}

.tp4r-search__input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #f5f5f5;
    border-radius: 50px;
    padding: 0 20px;
    transition: all 0.3s ease;
}

.tp4r-search__input-wrapper:focus-within {
    background: #fff;
    box-shadow: 0 0 0 2px var(--tp4r-primary-color, #5BBFBA);
}

.tp4r-search__icon {
    color: #888;
    font-size: 18px;
    margin-left: 12px;
}

.tp4r-search__input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 15px 0;
    font-size: 16px;
    outline: none;
    width: 100%;
    font-family: inherit;
}

.tp4r-search__input::placeholder {
    color: #aaa;
}

.tp4r-search__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.tp4r-search__close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

/* Hide close button in open mode */
.tp4r-search--open-mode .tp4r-search__close {
    display: none;
}

/* ===== Search Results ===== */
.tp4r-search__results {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 40px 30px;
    max-height: 400px;
    overflow-y: auto;
}

.tp4r-search--open-mode .tp4r-search__results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    padding: 15px;
    margin-top: 10px;
    z-index: 100;
    max-width: 100%;
}

.tp4r-search__results:empty {
    display: none;
}

/* ===== Result Item ===== */
.tp4r-search__result {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.tp4r-search__result:hover {
    background: #f5f5f5;
}

.tp4r-search__result-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f5f5;
}

.tp4r-search__result-info {
    flex: 1;
    min-width: 0;
}

.tp4r-search__result-title {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin: 0 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp4r-search__result-category {
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}

.tp4r-search__result-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--tp4r-primary-color, #5BBFBA);
}

.tp4r-search__result-price del {
    color: #999;
    font-weight: 400;
    margin-left: 8px;
}

.tp4r-search__result-price ins {
    text-decoration: none;
}

.tp4r-search__result-excerpt {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    line-height: 1.4;
}

/* ===== Loading & Messages ===== */
.tp4r-search__loading,
.tp4r-search__no-results,
.tp4r-search__error {
    text-align: center;
    padding: 30px 20px;
    color: #888;
    font-size: 14px;
}

.tp4r-search__loading i {
    font-size: 24px;
    margin-bottom: 10px;
    animation: tp4r-spin 1s linear infinite;
}

@keyframes tp4r-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== View All Link ===== */
.tp4r-search__view-all {
    display: block;
    text-align: center;
    padding: 15px;
    margin-top: 10px;
    background: var(--tp4r-primary-color, #5BBFBA);
    color: #fff !important;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.tp4r-search__view-all:hover {
    filter: brightness(0.95);
    transform: translateY(-1px);
}

/* ===== Overlay ===== */
.tp4r-search__overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.tp4r-search--icon-mode .tp4r-search__container.is-open ~ .tp4r-search__overlay {
    opacity: 1;
    visibility: visible;
}

/* Hide overlay in open mode */
.tp4r-search--open-mode .tp4r-search__overlay {
    display: none;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .tp4r-search__form {
        padding: 20px;
    }

    .tp4r-search__results {
        padding: 0 20px 20px;
        max-height: 60vh;
    }

    .tp4r-search__result {
        gap: 10px;
        padding: 10px;
    }

    .tp4r-search__result-image {
        width: 50px;
        height: 50px;
    }
}

/* ===== RTL Support ===== */
[dir="rtl"] .tp4r-search__icon {
    margin-left: 0;
    margin-right: 12px;
}

[dir="rtl"] .tp4r-search__result-price del {
    margin-left: 0;
    margin-right: 8px;
}

