/**
 * AI Search Styles - تنسيقات البحث الذكي
 *
 * @package Qedama
 */

/* =============================================
   Main Container (Fixed, Full Screen)
   ============================================= */
.ai-search-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    pointer-events: none;
    display: none;
}

.ai-search-container.active {
    display: block;
}

/* =============================================
   Background Blur Overlay
   ============================================= */
.ai-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: auto;
}

.ai-search-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* =============================================
   Cloned Search Input Wrapper (Above Blur)
   ============================================= */
.ai-search-input-wrapper {
    position: fixed;
    z-index: 100001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: auto;
}

.ai-search-input-wrapper.active {
    opacity: 1;
    visibility: visible;
}

.ai-search-form {
    width: 100%;
}

.ai-search-form__inner {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 50px;
    border: 2px solid #0077B5;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25), 0 0 0 4px rgba(0, 119, 181, 0.15);
    overflow: hidden;
    transition: all 0.3s ease;
}

.ai-search-form__inner:focus-within {
    border-color: #0077B5;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), 0 0 0 6px rgba(0, 119, 181, 0.2);
}

.ai-search-form__input {
    flex: 1;
    border: none;
    outline: none;
    padding: 15px 25px;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: #1f2937;
    direction: rtl;
}

.ai-search-form__input::placeholder {
    color: #9ca3af;
    transition: opacity 0.3s ease;
}

.ai-search-form__btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 25px;
    margin: 5px;
    border: none;
    background: linear-gradient(135deg, #0077B5, #00A0DC);
    color: #fff;
    border-radius: 50px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.3s ease;
}

.ai-search-form__btn:hover {
    background: linear-gradient(135deg, #005f8f, #0088c2);
    transform: scale(1.02);
}

.ai-search-form__btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* =============================================
   AI Search Results Container
   ============================================= */
.ai-search-results {
    position: fixed;
    min-width: 600px;
    max-width: 700px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(20px);
    transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
    max-height: 60vh;
    overflow-y: auto;
    pointer-events: auto;
    z-index: 100000;
}

.ai-search-results.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* LinkedIn-style Blue Border with Shimmer */
.ai-search-results::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 16px;
    padding: 3px;
    background: linear-gradient(135deg, #0077B5, #00A0DC, #0077B5);
    background-size: 200% 200%;
    animation: shimmerBorder 3s ease infinite;
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

@keyframes shimmerBorder {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* Inner content wrapper */
.ai-search-results__inner {
    position: relative;
    padding: 20px;
    background: #fff;
    border-radius: 13px;
}

/* =============================================
   Close Button
   ============================================= */
.ai-search-close {
    position: absolute;
    top: 15px;
    left: 15px;
    right: auto;
    width: 32px;
    height: 32px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.ai-search-close:hover {
    background: #e5e7eb;
    transform: scale(1.1);
}

.ai-search-close svg {
    width: 16px;
    height: 16px;
    fill: #6b7280;
}

.ai-search-expand {
    position: absolute;
    top: 15px;
    left: 55px;
    /* Positioned next to close button */
    right: auto;
    width: 32px;
    height: 32px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    text-decoration: none;
}

.ai-search-expand:hover {
    background: #e5e7eb;
    transform: scale(1.1);
}

.ai-search-expand svg {
    width: 18px;
    height: 18px;
    fill: #6b7280;
}

/* =============================================
   Guest Login Prompt
   ============================================= */
.ai-search-guest-prompt {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    margin-top: 15px;
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.ai-search-guest-prompt__text {
    font-size: 13px;
    color: #6b7280;
}

.ai-search-guest-prompt__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.ai-search-guest-prompt__btn:hover {
    border-color: #0077B5;
    color: #0077B5;
    background: #f0f9ff;
}

.ai-search-guest-prompt__btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* =============================================
   User Section
   ============================================= */
.ai-search-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 15px;
}

.ai-search-user__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0077B5, #00A0DC);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.ai-search-user__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-search-user__avatar--guest {
    background: linear-gradient(135deg, #6b7280, #9ca3af);
}

.ai-search-user__avatar svg {
    width: 24px;
    height: 24px;
    fill: #fff;
}

.ai-search-user__name {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

.ai-search-user__query {
    font-size: 13px;
    color: #6b7280;
    margin-top: 2px;
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =============================================
   AI Response Section
   ============================================= */
.ai-search-response {
    padding: 15px 0;
}

.ai-search-response__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.ai-search-response__logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-search-response__logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ai-search-response__name {
    font-size: 14px;
    font-weight: 600;
    color: #0077B5;
}

.ai-search-response__text {
    font-size: 15px;
    line-height: 1.7;
    color: #374151;
    white-space: pre-wrap;
}

/* Loading State */
.ai-search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 8px;
}

.ai-search-loading__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #0077B5;
    animation: loadingDot 1.4s infinite ease-in-out both;
}

.ai-search-loading__dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-search-loading__dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loadingDot {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.ai-search-loading__text {
    margin-right: 10px;
    font-size: 14px;
    color: #6b7280;
}

/* =============================================
   Related Posts Section
   ============================================= */
.ai-search-divider {
    height: 1px;
    background: linear-gradient(to left, transparent, #e5e7eb, transparent);
    margin: 20px 0;
}

.ai-search-posts {
    padding-top: 5px;
}

.ai-search-posts__title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-search-posts__title svg {
    width: 18px;
    height: 18px;
    fill: #0077B5;
}

.ai-search-posts__list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-search-post-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 10px;
    background: #f8fafc;
    transition: all 0.2s ease;
    text-decoration: none;
}

.ai-search-post-card:hover {
    background: #f1f5f9;
    transform: translateX(-5px);
}

.ai-search-post-card__thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: #e5e7eb;
}

.ai-search-post-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-search-post-card__thumb--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-search-post-card__thumb--placeholder svg {
    width: 24px;
    height: 24px;
    fill: #9ca3af;
}

.ai-search-post-card__content {
    flex: 1;
    min-width: 0;
}

.ai-search-post-card__title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ai-search-post-card__excerpt {
    font-size: 12px;
    color: #6b7280;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Posts Loading */
.ai-search-posts__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 8px;
}

.ai-search-posts__loading .ai-search-loading__dot {
    width: 8px;
    height: 8px;
}

/* =============================================
   History Navigation
   ============================================= */
.ai-search-history-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding-top: 15px;
    margin-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.ai-search-history-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 15px;
    border: 1px solid #e5e7eb;
    background: #fff;
    border-radius: 8px;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-search-history-btn:hover:not(:disabled) {
    border-color: #0077B5;
    color: #0077B5;
}

.ai-search-history-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-search-history-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* =============================================
   Error State
   ============================================= */
.ai-search-error {
    padding: 20px;
    text-align: center;
    color: #dc2626;
}

.ai-search-error__icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 10px;
    fill: #dc2626;
}

.ai-search-error__message {
    font-size: 14px;
}

/* =============================================
   Mobile Responsive
   ============================================= */
@media (max-width: 768px) {
    .ai-search-input-wrapper {
        left: 15px !important;
        right: 15px !important;
        width: calc(100% - 30px) !important;
    }

    .ai-search-form__input {
        padding: 12px 18px;
        font-size: 15px;
    }

    .ai-search-form__btn {
        padding: 10px 18px;
        font-size: 14px;
    }

    .ai-search-form__btn span {
        display: none;
    }

    .ai-search-results {
        min-width: auto;
        width: calc(100% - 30px) !important;
        left: 15px !important;
        right: 15px;
        transform: translateY(20px) !important;
        max-height: 55vh;
    }

    .ai-search-results.active {
        transform: translateY(0) !important;
    }

    .ai-search-results__inner {
        padding: 15px;
    }

    .ai-search-close {
        top: 10px;
        left: 10px;
        width: 28px;
        height: 28px;
    }

    .ai-search-expand {
        top: 10px;
        left: 48px;
        /* Adjusted for mobile */
        width: 28px;
        height: 28px;
    }

    .ai-search-expand svg {
        width: 14px;
        /* Scaled down */
        height: 14px;
    }

    .ai-search-user__avatar {
        width: 36px;
        height: 36px;
    }

    .ai-search-user__query {
        max-width: 200px;
    }

    .ai-search-response__logo {
        width: 32px;
        height: 32px;
    }

    .ai-search-response__text {
        font-size: 14px;
    }

    .ai-search-post-card {
        padding: 8px;
    }

    .ai-search-post-card__thumb {
        width: 50px;
        height: 50px;
    }

    .ai-search-post-card__title {
        font-size: 13px;
    }

    .ai-search-history-nav {
        flex-wrap: wrap;
    }

    .ai-search-history-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .ai-search-results {
        max-height: 50vh;
    }

    .ai-search-user {
        flex-wrap: wrap;
    }

    .ai-search-post-card__thumb {
        width: 45px;
        height: 45px;
    }
}

/* =============================================
   RTL Adjustments (Arabic)
   ============================================= */
[dir="rtl"] .ai-search-post-card:hover {
    transform: translateX(5px);
}

/* =============================================
   Typing Animation for Response
   ============================================= */
.ai-search-response__text.typing::after {
    content: '|';
    animation: blink 1s infinite;
    color: #0077B5;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* =============================================
   Scrollbar Styling
   ============================================= */
.ai-search-results::-webkit-scrollbar {
    width: 6px;
}

.ai-search-results::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.ai-search-results::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ai-search-results::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}