/**
 * AI Overview Component Styles
 * Displays AI-generated trending summary on search page
 */

/* ============================================
   AI Overview Card
   ============================================ */

#ai-overview-wrapper,
.ai-overview-wrapper {
    max-width: 100%;
    margin-bottom: 1.5rem;
    display: block;
}

.ai-overview-card {
    background: var(--card-bg, #fff);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.ai-overview-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ============================================
   Header - Icon, Label, and Avatars
   ============================================ */

.ai-overview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.ai-overview-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-overview-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-overview-icon img {
    width: 18px;
    height: 18px;
    filter: none;
}

/* Primary color for sparkle icon */
.ai-overview-icon img {
    color: var(--primary-color, #6366f1);
}

/* For SVG icons that use currentColor */
.ai-overview-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--primary-color, #6366f1);
}

.ai-overview-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1a1a1a);
}

/* ============================================
   Contributors - Overlapping Avatars (Right side)
   ============================================ */

.ai-overview-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-overview-avatars {
    display: flex;
    align-items: center;
    flex-direction: row-reverse; /* Stack from right */
}

.ai-overview-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--card-bg, #fff);
    object-fit: cover;
    margin-left: -8px;
    background: var(--bg-secondary, #f0f0f0);
    flex-shrink: 0;
}

.ai-overview-avatar:last-child {
    margin-left: 0;
}

.ai-overview-contributor-count {
    font-size: 13px;
    color: var(--text-secondary, #666);
    font-weight: 500;
}

/* ============================================
   Content Area
   ============================================ */

.ai-overview-content {
    padding: 16px;
    position: relative;
    overflow: hidden;
    max-height: 200px; /* Collapsed state - ~4 lines */
    transition: max-height 0.3s ease;
}

.ai-overview-content.expanded {
    max-height: 2000px;
}

.ai-overview-content p {
    margin: 0 0 12px 0;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary, #1a1a1a);
}

.ai-overview-content p:last-child {
    margin-bottom: 0;
}

/* Highlighted terms (like Google's bold keywords) */
.ai-overview-content strong,
.ai-overview-content b {
    color: var(--primary-color, #6366f1);
    font-weight: 600;
}

/* Circle and User links (c/community, u/username, @username) */
.ai-overview-content .ai-overview-link {
    color: var(--primary-color, #6366f1);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.ai-overview-content .ai-overview-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Highlighted text (from **bold**) - Google-style blue highlight */
.ai-overview-content .ai-overview-highlight {
    background: linear-gradient(to bottom, transparent 60%, rgba(99, 102, 241, 0.15) 60%);
    color: var(--text-primary, #1a1a1a);
    font-weight: 600;
}

/* Headers */
.ai-overview-content .ai-overview-h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-color, #6366f1);
    margin: 16px 0 8px 0;
    line-height: 1.4;
}

.ai-overview-content .ai-overview-h3:first-child {
    margin-top: 0;
}

.ai-overview-content .ai-overview-h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1a1a1a);
    margin: 12px 0 6px 0;
    line-height: 1.4;
}

/* Lists */
.ai-overview-content .ai-overview-list {
    margin: 8px 0 12px 0;
    padding-left: 20px;
}

.ai-overview-content .ai-overview-list li {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary, #1a1a1a);
    margin-bottom: 6px;
}

.ai-overview-content .ai-overview-list li:last-child {
    margin-bottom: 0;
}

/* Ordered list numbers styling */
.ai-overview-content ol.ai-overview-list {
    list-style-type: decimal;
}

.ai-overview-content ul.ai-overview-list {
    list-style-type: disc;
}

/* ============================================
   Sources Section - Referenced Posts
   ============================================ */

.ai-overview-sources {
    padding: 12px 0 0 0;
    margin-top: 12px;
    border-top: 1px solid var(--border-color, #e0e0e0);
}

.ai-overview-sources-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-overview-sources-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-overview-source-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--card-bg, #fff);
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.ai-overview-source-item:hover {
    background: var(--bg-hover, #f0f0f0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ai-overview-source-number {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: var(--primary-color, #6366f1);
    border-radius: 50%;
}

.ai-overview-source-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1a1a1a);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-overview-source-item:hover .ai-overview-source-title {
    color: var(--primary-color, #6366f1);
}

.ai-overview-source-circle {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-secondary, #666);
    background: var(--bg-secondary, #f0f0f0);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ============================================
   Footer - Timestamp
   ============================================ */

.ai-overview-footer {
    padding: 2px 16px 2px;
    display: flex;
    justify-content: flex-end;
}

.ai-overview-timestamp {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary, #666);
}

/* Gradient fade overlay when collapsed */
.ai-overview-fade {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to bottom, transparent, var(--card-bg, #fff));
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-overview-content.expanded + .ai-overview-fade,
.ai-overview-fade.hidden {
    opacity: 0;
}

/* ============================================
   Expand/Collapse Button
   ============================================ */

.ai-overview-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 2px 16px;
    background: transparent;
    border: none;
    border-top: 1px solid var(--border-color, #e0e0e0);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary, #666);
    transition: background 0.2s ease, color 0.2s ease;
}

.ai-overview-expand-btn:hover {
    background: var(--bg-hover, #f5f5f5);
    color: var(--primary-color, #6366f1);
}

.ai-overview-expand-btn img {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.ai-overview-expand-btn.expanded img {
    transform: rotate(180deg);
}

/* ============================================
   Skeleton Loading State
   ============================================ */

.ai-overview-skeleton {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    overflow: hidden;
}

.ai-overview-skeleton-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.ai-overview-skeleton-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-overview-skeleton-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: var(--skeleton-bg, #e0e0e0);
    animation: shimmer 1.5s infinite;
}

.ai-overview-skeleton-label {
    width: 80px;
    height: 14px;
    border-radius: 4px;
    background: var(--skeleton-bg, #e0e0e0);
    animation: shimmer 1.5s infinite;
}

.ai-overview-skeleton-avatars {
    display: flex;
    flex-direction: row-reverse;
}

.ai-overview-skeleton-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--skeleton-bg, #e0e0e0);
    margin-left: -8px;
    border: 2px solid var(--card-bg, #fff);
    animation: shimmer 1.5s infinite;
}

.ai-overview-skeleton-avatar:last-child {
    margin-left: 0;
}

.ai-overview-skeleton-content {
    padding: 16px;
}

.ai-overview-skeleton-line {
    height: 14px;
    border-radius: 4px;
    background: var(--skeleton-bg, #e0e0e0);
    margin-bottom: 10px;
    animation: shimmer 1.5s infinite;
}

.ai-overview-skeleton-line:nth-child(1) { width: 100%; animation-delay: 0s; }
.ai-overview-skeleton-line:nth-child(2) { width: 95%; animation-delay: 0.1s; }
.ai-overview-skeleton-line:nth-child(3) { width: 85%; animation-delay: 0.2s; }
.ai-overview-skeleton-line:nth-child(4) { width: 70%; animation-delay: 0.3s; }

.ai-overview-skeleton-btn {
    height: 44px;
    border-top: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-overview-skeleton-btn-inner {
    width: 100px;
    height: 14px;
    border-radius: 4px;
    background: var(--skeleton-bg, #e0e0e0);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* ============================================
   Error/Empty State
   ============================================ */

.ai-overview-error,
.ai-overview-empty {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-secondary, #666);
}

.ai-overview-error-icon,
.ai-overview-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.5;
}

/* ============================================
   Dark Mode
   ============================================ */

[data-theme="dark"] .ai-overview-card {
    background: var(--card-bg, #1e1e1e);
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-overview-header {
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-icon img {
    filter: brightness(1.2);
}

[data-theme="dark"] .ai-overview-avatar {
    border-color: var(--card-bg, #1e1e1e);
}

[data-theme="dark"] .ai-overview-fade {
    background: linear-gradient(to bottom, transparent, var(--card-bg, #1e1e1e));
}

[data-theme="dark"] .ai-overview-expand-btn {
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-expand-btn:hover {
    background: var(--bg-hover, #2a2a2a);
}

[data-theme="dark"] .ai-overview-skeleton {
    background: var(--card-bg, #1e1e1e);
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-skeleton-header {
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-skeleton-icon,
[data-theme="dark"] .ai-overview-skeleton-label,
[data-theme="dark"] .ai-overview-skeleton-avatar,
[data-theme="dark"] .ai-overview-skeleton-line,
[data-theme="dark"] .ai-overview-skeleton-btn-inner {
    background: var(--skeleton-bg, #333);
}

[data-theme="dark"] .ai-overview-skeleton-btn {
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-sources {
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .ai-overview-source-item {
    background: var(--card-bg, #252525);
}

[data-theme="dark"] .ai-overview-source-item:hover {
    background: var(--bg-hover, #2a2a2a);
}

[data-theme="dark"] .ai-overview-source-circle {
    background: var(--bg-secondary, #333);
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 768px) {
    .ai-overview-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .ai-overview-header {
        padding: 10px 12px;
    }
    
    .ai-overview-content {
        padding: 7px;
        max-height: 190px; /* Smaller on mobile */
    }
    
    .ai-overview-content p {
        font-size: 16px;
    }
    
    .ai-overview-avatar {
        width: 22px;
        height: 22px;
        margin-left: -6px;
    }
    
    .ai-overview-expand-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .ai-overview-sources {
        padding: 8px 0 0 0;
        margin-top: 8px;
    }
    
    .ai-overview-source-item {
        padding: 6px 8px;
    }
    
    .ai-overview-source-title {
        font-size: 12px;
    }
    
    .ai-overview-source-circle {
        display: none; /* Hide circle on mobile for space */
    }
}

/* ============================================
   RTL Support
   ============================================ */

[dir="rtl"] .ai-overview-avatars {
    flex-direction: row;
}

[dir="rtl"] .ai-overview-avatar {
    margin-left: 0;
    margin-right: -8px;
}

[dir="rtl"] .ai-overview-avatar:last-child {
    margin-right: 0;
}

[dir="rtl"] .ai-overview-skeleton-avatars {
    flex-direction: row;
}

[dir="rtl"] .ai-overview-skeleton-avatar {
    margin-left: 0;
    margin-right: -8px;
}

[dir="rtl"] .ai-overview-skeleton-avatar:last-child {
    margin-right: 0;
}

/* ============================================
   Trending Fallback (When AI is disabled)
   ============================================ */

.trending-card .ai-overview-header {
    border-bottom: none;
    padding-bottom: 8px;
}

.trending-icon img {
    filter: none;
}

.trending-list {
    display: flex;
    flex-direction: column;
}

.trending-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.15s ease;
    border-top: 1px solid var(--border-color, #e5e5e5);
}

.trending-item:first-child {
    border-top: none;
}

.trending-item:hover {
    background-color: var(--hover-bg, #f5f5f5);
}

.trending-rank {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary, #666);
    background: var(--bg-secondary, #f0f0f0);
    border-radius: 6px;
}

.trending-item:nth-child(1) .trending-rank {
    background: var(--primary-color, #6366f1);
    color: #fff;
}

.trending-item:nth-child(2) .trending-rank {
    background: var(--primary-color-light, rgba(99, 102, 241, 0.15));
    color: var(--primary-color, #6366f1);
}

.trending-item:nth-child(3) .trending-rank {
    background: var(--primary-color-light, rgba(99, 102, 241, 0.1));
    color: var(--primary-color, #6366f1);
}

.trending-content {
    flex: 1;
    min-width: 0;
}

.trending-title {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #1a1a1a);
    line-height: 1.4;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.trending-item:hover .trending-title {
    color: var(--primary-color, #6366f1);
}

.trending-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.trending-circle {
    color: var(--text-secondary, #666);
}

.trending-stats {
    display: flex;
    align-items: center;
    gap: 4px;
}

.trending-stat-icon {
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

/* ============================================
   Dark Mode - Trending
   ============================================ */

@media (prefers-color-scheme: dark) {
    .trending-item:hover {
        background-color: var(--hover-bg, #2a2a2a);
    }
    
    .trending-rank {
        background: var(--bg-secondary, #333);
        color: var(--text-secondary, #999);
    }
    
    .trending-item:nth-child(1) .trending-rank {
        background: var(--primary-color, #818cf8);
        color: #fff;
    }
    
    .trending-item:nth-child(2) .trending-rank,
    .trending-item:nth-child(3) .trending-rank {
        background: var(--primary-color-light, rgba(129, 140, 248, 0.2));
        color: var(--primary-color, #818cf8);
    }
}

/* Mobile - Trending */
@media (max-width: 480px) {
    .trending-item {
        padding: 10px 12px;
    }
    
    .trending-rank {
        width: 22px;
        height: 22px;
        font-size: 11px;
    }
    
    .trending-title {
        font-size: 13px;
    }
    
    .trending-meta {
        font-size: 11px;
    }
}
