:root {
    --brand: #00d4ff;
    --brand-dark: #008fb3;
    --brand-purple: #6a11cb;
    --grad-blue: linear-gradient(135deg, #00d4ff 0%, #008fb3 100%);
    --grad-royal: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    --bg-glass: rgba(10, 10, 10, 0.75);
    --panel-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --text-dim: #b0b0b0;
    --panel: #121212;
    --panel-soft: rgba(30, 30, 30, 0.6);
    --border: #333333;
    --danger: #ff4d4d;
    --success: #00ff88;
    --glow-brand: rgba(0, 212, 255, 0.3);
}

/* --- Base Layout & Glass --- */
.selection-bar {
    position: absolute;
    display: none;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), inset 0 0 0 1px var(--border-glass);
    z-index: 99999999 !important;
    gap: 8px;
    align-items: center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.selection-bar button {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.selection-bar button:hover {
    background: var(--panel-glass);
    color: var(--brand);
}

.selection-bar button svg {
    width: 16px;
    height: 16px;
}

.search-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20000;
}

.search-popup-window {
    width: 92%;
    max-width: 1000px;
    height: 85vh;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 28px;
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px var(--border-glass);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--text);
    position: relative;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-popup-window.streaming {
    box-shadow: 0 0 30px var(--glow-brand), 0 30px 60px -12px rgba(0, 0, 0, 0.8);
    border-color: rgba(0, 212, 255, 0.4);
}

.search-popup-window.streaming .search-tab:not(.active) {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(50px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Header & Navigation --- */
.search-popup-header {
    padding: 24px 30px;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    flex-shrink: 0;
}

.close-search-popup {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-search-popup:hover {
    background: var(--danger);
    color: #fff;
    transform: rotate(90deg);
}

.search-popup-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(90deg, #fff 0%, #00d4ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.search-popup-tabs {
    display: flex;
    padding: 10px 24px;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
}

.search-tab {
    padding: 12px 24px;
    border-radius: 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-dim);
    transition: all 0.3s;
    user-select: none;
    border: 1px solid transparent;
}

.search-tab:hover {
    background: var(--panel-glass);
    color: var(--text);
}

.search-tab.active {
    background: var(--panel-soft);
    color: var(--brand);
    border-color: var(--border-glass);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* --- Content Content --- */
.search-popup-content {
    flex: 1;
    overflow: hidden;
    padding: 0;
    position: relative;
}

.search-content-pane {
    display: none;
    opacity: 0;
    padding: 30px;
    padding-bottom: 120px;
    transition: opacity 0.4s;
    min-height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.search-content-pane::-webkit-scrollbar {
    width: 8px;
}

.search-content-pane::-webkit-scrollbar-track {
    background: transparent;
}

.search-content-pane::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.search-content-pane::-webkit-scrollbar-thumb:hover {
    background: var(--brand);
}

.search-content-pane.active {
    display: block;
    opacity: 1;
}

#pane-chat {
    padding-bottom: 100px;
}

#pane-images,
#pane-videos {
    padding: 30px;
}

/* --- Chat Section --- */
.chat-streaming-result {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 40px;
    min-height: 200px;
}

/* --- Sources Section --- */
.sources-toggle-area {
    padding: 15px 30px;
}

.toggle-sources-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--panel-soft);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.toggle-sources-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border-color: var(--brand);
}

.toggle-sources-btn.active {
    background: rgba(0, 212, 255, 0.1);
    color: var(--brand);
    border-color: var(--brand);
}

.toggle-sources-btn svg {
    transition: transform 0.3s;
}

.toggle-sources-btn.active svg {
    transform: rotate(180deg);
}

.sources-list {
    padding: 0 30px 20px;
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.4s ease, opacity 0.3s ease;
}

.sources-list.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0 30px;
}

.source-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--panel-glass);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.source-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--brand);
    transform: translateX(5px);
}

.source-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    flex-shrink: 0;
}

.source-card span {
    flex: 1;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-bubble {
    max-width: 80%;
    padding: 20px 24px;
    border-radius: 24px;
    font-size: 16px;
    line-height: 1.7;
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    animation: bubbleSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes bubbleSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message-bubble.ai {
    align-self: flex-start;
    background: rgba(40, 40, 40, 0.5);
    border-bottom-left-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.message-bubble.ai::before {
    content: 'FELO AI';
    display: block;
    font-size: 11px;
    font-weight: 900;
    color: var(--brand);
    margin-bottom: 10px;
    letter-spacing: 0.1em;
}

.message-bubble.user {
    align-self: flex-end;
    background: var(--grad-royal);
    border: none;
    border-bottom-right-radius: 6px;
    box-shadow: 0 15px 35px rgba(37, 117, 252, 0.3);
    color: #fff;
}

.message-bubble.user::before {
    content: 'YOU';
    display: block;
    font-size: 11px;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 10px;
    letter-spacing: 0.1em;
    text-align: right;
}

/* --- Images Tab (Professional Grid) --- */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.image-item {
    background: var(--panel-glass);
    border: 1px solid var(--border-glass);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    position: relative;
    aspect-ratio: 4/3;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: block;
}

.image-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0) 0%, rgba(0, 0, 0, 0.3) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.image-item:hover {
    transform: scale(1.03) translateY(-5px);
    border-color: var(--brand);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.image-item:hover::before {
    opacity: 1;
}

.image-item:hover img {
    transform: scale(1.1);
}

/* --- Videos Tab (Cinematic) --- */
.video-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.video-item {
    background: var(--panel-soft);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.video-item:hover {
    transform: translateY(-8px);
    border-color: var(--brand);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.video-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-thumb .no-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: var(--text-dim);
    width: 100%;
    height: 100%;
    background: var(--panel);
}

.video-thumb::after {
    content: '▶';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 54px;
    height: 54px;
    background: var(--grad-blue);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    padding-left: 4px;
    box-shadow: 0 0 25px rgba(0, 212, 255, 0.5);
    opacity: 0.9;
    transition: transform 0.3s;
    z-index: 2;
}

.video-item:hover .video-thumb::after {
    transform: translate(-50%, -50%) scale(1.15);
}

.video-info {
    padding: 18px 20px;
}

.video-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 8px;
    color: #fff;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-meta {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 10px;
}

.video-meta::before {
    content: '•';
    color: var(--brand);
}

/* Empty state for images/videos */
.image-grid > div:not(.image-item),
.video-list > div:not(.video-item) {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
    font-size: 16px;
}

/* --- Follow-up Area --- */
.chat-followup-area {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    max-width: 1000px;
    display: flex;
    gap: 12px;
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 14px 18px;
    border-radius: 24px;
    border: 1px solid var(--border-glass);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.chat-followup-area input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    outline: none;
    font-size: 15px;
    padding: 12px 8px;
}

.chat-followup-area input::placeholder {
    color: var(--text-dim);
}

.chat-followup-area button {
    background: var(--grad-blue);
    border: none;
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-followup-area button:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}

.chat-followup-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* --- Media Preview --- */
.media-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 30000;
}

.media-preview-window {
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    background: rgba(18, 18, 18, 0.95);
    border: 1px solid var(--border-glass);
    border-radius: 32px;
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.close-media-preview {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 32px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.close-media-preview:hover {
    background: var(--danger);
    color: #fff;
    transform: rotate(90deg);
}

.media-preview-target {
    flex: 1;
    min-height: 400px;
    max-height: 60vh;
    border-radius: 24px 24px 0 0;
    overflow: hidden;
    border: 1px solid var(--border-glass);
    margin: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-preview-target img,
.media-preview-target iframe {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: none;
}

.media-preview-target iframe {
    width: 100%;
    height: 100%;
}

.media-preview-info {
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.03);
    border-top: 1px solid var(--border-glass);
}

.media-preview-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.media-preview-footer {
    display: flex;
    gap: 12px;
}

.media-original-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--panel-soft);
    color: var(--text);
    text-decoration: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid var(--border-glass);
    transition: all 0.2s;
}

.media-original-link:hover {
    background: var(--brand);
    color: #000;
    border-color: var(--brand);
}

/* Loader Styles */
.tab-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    gap: 16px;
    color: var(--text-dim);
    font-size: 15px;
}

.tab-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(0, 212, 255, 0.1);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Animations */
@keyframes blink {
    from {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.cursor-blink {
    display: inline-block;
    width: 3px;
    height: 1.2em;
    background: var(--brand);
    vertical-align: middle;
    margin-left: 2px;
    animation: blink 1s step-end infinite;
}