/**
 * ================================================================================
 * CO-READIT - AI Post Context CSS
 * ================================================================================
 * 
 * Collapsible/expandable post context for AI chat
 * IMPORTANT: This is NOT a modal like Komico - it's a collapsible section
 * Uses 16x16 brain icon + 12px text as trigger
 * 
 * @author      Edu Brazeal
 * @version     1.0.0
 * ================================================================================
 */

/* ===== Context Trigger Button ===== */
.ai-post-context-trigger {
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--primary-color);
}

.ai-post-context-trigger:hover {
    background: var(--hover-bg);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.ai-post-context-trigger.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Brain icon - 16x16px as specified */
.ai-post-context-trigger__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Text - 12px as specified */
.ai-post-context-trigger__text {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

/* Chevron for expand/collapse indicator */
.ai-post-context-trigger__chevron {
    width: 12px;
    height: 12px;
    margin-left: 2px;
    transition: transform 0.2s ease;
}

.ai-post-context-trigger.active .ai-post-context-trigger__chevron {
    transform: rotate(180deg);
}

/* ===== Collapsible Context Panel ===== */
.ai-post-context {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.2s ease;
    opacity: 0;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin: 8px 0;
}

.ai-post-context.expanded {
    max-height: 400px;
    opacity: 1;
    overflow-y: auto;
}

/* Scrollbar styling for context panel */
.ai-post-context::-webkit-scrollbar {
    width: 4px;
}

.ai-post-context::-webkit-scrollbar-track {
    background: transparent;
}

.ai-post-context::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

/* ===== Context Content ===== */
.ai-post-context__content {
    padding: 12px;
}

/* Post Header */
.ai-post-context__header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.ai-post-context__circle-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

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

.ai-post-context__circle-icon svg {
    width: 16px;
    height: 16px;
    color: #ffffff;
}

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

.ai-post-context__circle-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.ai-post-context__author {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Post Title */
.ai-post-context__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: 8px;
}

/* Post Body Preview */
.ai-post-context__body {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    max-height: 150px;
    overflow: hidden;
    position: relative;
}

.ai-post-context__body--truncated::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to bottom, transparent, var(--bg-secondary));
    pointer-events: none;
}

/* Post Stats */
.ai-post-context__stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-post-context__stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-post-context__stat svg {
    width: 12px;
    height: 12px;
}

/* ===== Media Preview ===== */
.ai-post-context__media {
    margin-top: 10px;
    border-radius: 6px;
    overflow: hidden;
    max-height: 120px;
}

.ai-post-context__media img {
    width: 100%;
    height: auto;
    max-height: 120px;
    object-fit: cover;
}

/* ===== Link Preview ===== */
.ai-post-context__link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-top: 10px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.ai-post-context__link:hover {
    border-color: var(--primary-color);
}

.ai-post-context__link-icon {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.ai-post-context__link-text {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Context Loading State ===== */
.ai-post-context--loading .ai-post-context__content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-post-context__skeleton {
    background: linear-gradient(
        90deg, 
        var(--border-color) 25%, 
        var(--hover-bg) 50%, 
        var(--border-color) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.ai-post-context__skeleton--header {
    height: 32px;
    width: 60%;
}

.ai-post-context__skeleton--title {
    height: 20px;
    width: 90%;
}

.ai-post-context__skeleton--body {
    height: 60px;
    width: 100%;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ===== Context Error State ===== */
.ai-post-context--error .ai-post-context__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    text-align: center;
}

.ai-post-context__error-icon {
    width: 32px;
    height: 32px;
    color: var(--error-color);
    margin-bottom: 8px;
}

.ai-post-context__error-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.ai-post-context__retry {
    padding: 6px 12px;
    background: var(--primary-color);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-post-context__retry:hover {
    background: var(--primary-hover);
}

/* ===== Login Required State ===== */
.ai-post-context--login-required .ai-post-context__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.ai-post-context__login-icon {
    width: 40px;
    height: 40px;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.ai-post-context__login-icon svg {
    width: 100%;
    height: 100%;
}

.ai-post-context__login-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.ai-post-context__login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    background: var(--primary-color);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-post-context__login-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

/* ===== Inline Context (for chat messages) ===== */
.ai-message__context-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
    font-size: 11px;
    color: var(--primary-color);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-message__context-badge:hover {
    background: rgba(59, 130, 246, 0.2);
}

.ai-message__context-badge svg {
    width: 12px;
    height: 12px;
}

/* ===== Context Toggle in Chat Input ===== */
.ai-chatbox__context-toggle {
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
}

/* ===== Responsive Design ===== */
@media (max-width: 767px) {
    .ai-post-context-trigger {
        padding: 4px 8px;
    }
    
    .ai-post-context-trigger__icon {
        width: 14px;
        height: 14px;
    }
    
    .ai-post-context-trigger__text {
        font-size: 11px;
    }
    
    .ai-post-context.expanded {
        max-height: 300px;
    }
    
    .ai-post-context__content {
        padding: 10px;
    }
    
    .ai-post-context__title {
        font-size: 13px;
    }
    
    .ai-post-context__body {
        font-size: 12px;
        max-height: 100px;
    }
}

/* ===== Dark Mode Support ===== */
[data-theme="dark"] .ai-post-context-trigger {
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ai-post-context-trigger:hover,
[data-theme="dark"] .ai-post-context-trigger.active {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.15);
}

[data-theme="dark"] .ai-post-context {
    background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-post-context__body--truncated::after {
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.3));
}

[data-theme="dark"] .ai-post-context__link {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ai-post-context__skeleton {
    background: linear-gradient(
        90deg, 
        rgba(255, 255, 255, 0.05) 25%, 
        rgba(255, 255, 255, 0.1) 50%, 
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
}

/* ===== AI Analysis Section Styles ===== */
.ai-post-context__section {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.ai-post-context__section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.ai-post-context__section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.ai-post-context__section-header svg {
    width: 14px;
    height: 14px;
}

.ai-post-context__summary {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
}

.ai-post-context__key-points {
    margin: 0;
    padding-left: 18px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.ai-post-context__key-points li {
    margin-bottom: 4px;
}

.ai-post-context__key-points li:last-child {
    margin-bottom: 0;
}

.ai-post-context__row {
    display: flex;
    gap: 12px;
}

.ai-post-context__section--half {
    flex: 1;
    min-width: 0;
}

.ai-post-context__sentiment {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.ai-post-context__sentiment--positive {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.ai-post-context__sentiment--negative {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.ai-post-context__sentiment--neutral {
    background: rgba(156, 163, 175, 0.15);
    color: var(--text-secondary);
}

.ai-post-context__topics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-post-context__topic {
    display: inline-block;
    padding: 3px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-post-context__section--fact-check {
    background: rgba(59, 130, 246, 0.05);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    margin-top: 12px;
}

.ai-post-context__section--fact-check .ai-post-context__section-header {
    color: #3b82f6;
}

.ai-post-context__fact-check {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
}

.ai-post-context__section--insights {
    background: rgba(168, 85, 247, 0.05);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    margin-top: 12px;
}

.ai-post-context__section--insights .ai-post-context__section-header {
    color: #a855f7;
}

.ai-post-context__insights {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
}

/* Wrapper for proper positioning */
.ai-post-context-wrapper {
    margin: -10px 0 2px 0;
}

/* Dark mode for new styles */
[data-theme="dark"] .ai-post-context__section {
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ai-post-context__topic {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ai-post-context__section--fact-check {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] .ai-post-context__section--insights {
    background: rgba(168, 85, 247, 0.1);
    border-color: rgba(168, 85, 247, 0.3);
}
