/**
 * Smart Search Autocomplete Styles - Telegram_Group_Links
 * Minimal, clean, modern, and accessible.
 */

/* Form & Input Wrapper Stacking Context (Fixes dropdown appearing behind cards) */
#search-form,
#search-form-second,
#members-search-form,
#search-page-form,
form[role="search"],
.tgt-search-form {
    position: relative !important;
    z-index: 30 !important;
}

.tgt-search-input-wrapper {
    position: relative !important;
    z-index: 35 !important;
}

#search-form.tgt-search-open,
#search-form-second.tgt-search-open,
#members-search-form.tgt-search-open,
#search-page-form.tgt-search-open,
form[role="search"].tgt-search-open,
.tgt-search-form.tgt-search-open,
.tgt-search-input-wrapper.tgt-search-open,
#search-form:focus-within,
#search-form-second:focus-within,
#members-search-form:focus-within,
#search-page-form:focus-within,
form[role="search"]:focus-within,
.tgt-search-form:focus-within,
.tgt-search-input-wrapper:focus-within {
    z-index: 40 !important;
}

/* Ensure post containers and cards never exceed search bar stacking */
.card-container,
.featured-container,
.stickers-gallery,
.sticker-grid,
.blog-container,
#related-groups .grid,
.card,
article.card,
.featured-card,
article.featured-card {
    z-index: 1 !important;
}

/* Dropdown Container */
.tgt-search-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    z-index: 999999 !important;
    background: #ffffff;
    border-radius: 20px;
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: 0 20px 48px -6px rgba(15, 23, 42, 0.14), 0 8px 20px -4px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    max-height: min(480px, 75vh);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    text-align: left;
    transform-origin: top center;
    animation: tgtDropdownFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes tgtDropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Scrollable Results List */
.tgt-search-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
}

/* Custom Thin Scrollbar for List */
.tgt-search-list::-webkit-scrollbar {
    width: 6px;
}
.tgt-search-list::-webkit-scrollbar-track {
    background: transparent;
}
.tgt-search-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.tgt-search-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Result Item */
.tgt-search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
    border: 1px solid transparent;
}

.tgt-search-item:hover,
.tgt-search-item.is-selected {
    background-color: #f0f7fc;
    border-color: #e0f2fe;
}

/* 18+ mode item styling */
.tgt-search-dropdown.tgt-members-dropdown .tgt-search-item:hover,
.tgt-search-dropdown.tgt-members-dropdown .tgt-search-item.is-selected {
    background-color: #fff1f2;
    border-color: #fecdd3;
}

/* Avatar / Thumbnail */
.tgt-search-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #f8fafc;
    border: 1.5px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tgt-search-avatar.tgt-search-avatar-blog {
    border-radius: 8px;
    width: 52px;
    height: 38px;
    aspect-ratio: 16 / 9;
}

.tgt-search-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tgt-search-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #24a1de;
    background: #f0f7fc;
    user-select: none;
}

.tgt-members-dropdown .tgt-search-avatar-fallback {
    color: #e11d48;
    background: #fff1f2;
}

/* Item Information */
.tgt-search-info {
    flex: 1 1 auto;
    min-width: 0;
}

.tgt-search-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.35;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease;
}

.tgt-search-item:hover .tgt-search-title,
.tgt-search-item.is-selected .tgt-search-title {
    color: #24a1de;
}

.tgt-members-dropdown .tgt-search-item:hover .tgt-search-title,
.tgt-members-dropdown .tgt-search-item.is-selected .tgt-search-title {
    color: #e11d48;
}

/* Matching Highlight */
.tgt-highlight {
    background-color: #e0f2fe;
    color: #0369a1;
    font-weight: 700;
    padding: 1px 3px;
    border-radius: 4px;
}

.tgt-members-dropdown .tgt-highlight {
    background-color: #ffe4e6;
    color: #be123c;
}

/* Item Meta row (Badges + Count) */
.tgt-search-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
    color: #64748b;
    line-height: 1.2;
}

.tgt-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.tgt-badge-type {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.tgt-badge-blog {
    background: #eef2ff;
    color: #4338ca;
    border: 1px solid #c7d2fe;
}

.tgt-badge-cat {
    background: #f0f7fc;
    color: #0284c7;
    border: 1px solid #bae6fd;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tgt-members-dropdown .tgt-badge-cat {
    background: #fff1f2;
    color: #e11d48;
    border-color: #fecdd3;
}

.tgt-meta-count {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: #64748b;
    font-size: 10.5px;
}

.tgt-meta-count svg {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

/* Dropdown Footer ("View all results") */
.tgt-search-footer {
    padding: 10px 14px;
    background: #fafbfc;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
    cursor: pointer;
}

.tgt-search-footer.is-selected {
    background: #f0f7fc;
}

.tgt-members-dropdown .tgt-search-footer.is-selected {
    background: #fff1f2;
}

.tgt-search-view-all {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 700;
    color: #24a1de;
    text-decoration: none;
    width: 100%;
    transition: color 0.15s ease, transform 0.15s ease;
}

.tgt-search-view-all:hover,
.tgt-search-footer.is-selected .tgt-search-view-all {
    color: #1e88be;
}

.tgt-search-view-all .tgt-arrow {
    transition: transform 0.15s ease;
}

.tgt-search-view-all:hover .tgt-arrow,
.tgt-search-footer.is-selected .tgt-arrow {
    transform: translateX(3px);
}

.tgt-members-dropdown .tgt-search-view-all {
    color: #e11d48;
}
.tgt-members-dropdown .tgt-search-view-all:hover,
.tgt-members-dropdown .tgt-search-footer.is-selected .tgt-search-view-all {
    color: #be123c;
}

/* Spinner loader on View All click */
.tgt-view-all-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(36, 161, 222, 0.25);
    border-top-color: #24a1de;
    border-radius: 50%;
    animation: tgtSpin 0.6s linear infinite;
    flex-shrink: 0;
}

.tgt-members-dropdown .tgt-view-all-spinner {
    border-color: rgba(225, 29, 72, 0.25);
    border-top-color: #e11d48;
}

.tgt-search-view-all.is-loading {
    pointer-events: none;
    opacity: 0.85;
}

.tgt-search-view-all.is-loading .tgt-arrow {
    display: none !important;
}

.tgt-search-view-all.is-loading .tgt-view-all-spinner {
    display: inline-block !important;
}

/* Empty / No Results State */
.tgt-search-empty {
    padding: 24px 16px;
    text-align: center;
    color: #64748b;
}

.tgt-search-empty-icon {
    font-size: 26px;
    margin-bottom: 6px;
    display: block;
}

.tgt-search-empty-title {
    font-size: 13.5px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 4px;
}

.tgt-search-empty-hint {
    font-size: 11.5px;
    color: #94a3b8;
    max-width: 260px;
    margin: 0 auto;
    line-height: 1.4;
}

/* Control Icons (Clear Button & Spinner) inside Search Bar */
.tgt-input-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: 8px;
    flex-shrink: 0;
}

/* Suppress duplicate native browser search clear cancel button (Fixes 2 X icons) */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none !important;
    appearance: none !important;
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}
input[type="search"]::-ms-clear,
input[type="search"]::-ms-reveal {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.tgt-search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f1f5f9;
    color: #64748b;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-size: 13px;
    line-height: 1;
}

.tgt-search-clear:hover {
    background: #e2e8f0;
    color: #0f172a;
    transform: scale(1.08);
}

.tgt-search-clear:active {
    transform: scale(0.92);
}

.tgt-search-clear:focus {
    outline: 2px solid #24a1de;
    outline-offset: 1px;
}

.tgt-members-wrapper .tgt-search-clear:focus,
.tgt-members-search-wrapper .tgt-search-clear:focus {
    outline-color: #e11d48 !important;
}

.tgt-search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #24a1de;
    border-radius: 50%;
    animation: tgtSpin 0.6s linear infinite;
    display: inline-block;
    flex-shrink: 0;
}

.tgt-members-wrapper .tgt-search-spinner {
    border-top-color: #e11d48;
}

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

/* Mobile Adjustments */
@media (max-width: 640px) {
    .tgt-search-dropdown {
        border-radius: 14px;
        max-height: min(420px, 68vh);
    }
    .tgt-search-item {
        padding: 8px 8px;
        gap: 10px;
    }
    .tgt-search-avatar {
        width: 38px;
        height: 38px;
    }
    .tgt-search-title {
        font-size: 12.5px;
    }
    .tgt-badge {
        font-size: 9.5px;
        padding: 1px 5px;
    }
}
