/**
 * Conversation Performance CSS
 * Smooth animations, loading states, and optimizations
 */

/* Scroll optimization */
.tk-conversation-area-list,
#conversations_area_list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    contain: strict;
}

/* During rapid scrolling, reduce visual complexity */
.tk-scrolling .tk-message {
    will-change: auto !important;
}

.tk-scrolling .tk-thumb img {
    opacity: 0.8;
}

/* Message truncation styles */
.tk-message-truncated {
    position: relative;
}

.tk-message-truncated .tk-message-text {
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tk-show-more-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    font-size: 12px;
    color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tk-show-more-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.3);
}

.tk-message-truncated.tk-expanded .tk-show-more-btn {
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
    border-color: rgba(107, 114, 128, 0.2);
}

/* Loading indicator */
.tk-loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-bottom: 1px solid rgba(99, 102, 241, 0.1);
    font-size: 13px;
    color: #6366f1;
}

.tk-loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: tk-spin 0.8s linear infinite;
}

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

/* Lazy loading messages animation */
.tk-loading-older {
    text-align: center;
    padding: 15px;
    color: #9ca3af;
    font-size: 13px;
}

.tk-loading-older::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border: 2px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: tk-spin 0.8s linear infinite;
    vertical-align: middle;
}

/* Smooth message appearance */
.tk-message {
    animation: tk-message-appear 0.2s ease-out;
}

@keyframes tk-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Virtualized messages (out of viewport) */
.tk-virtualized {
    content-visibility: auto;
    contain-intrinsic-size: auto 80px;
}

/* Error message styling */
.tk-message.tk-error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    color: #dc2626 !important;
    padding: 10px 15px !important;
    border-radius: 8px !important;
    font-size: 13px !important;
}

/* Image lazy loading */
.tk-message img:not(.tk-img-loaded) {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: tk-shimmer 1.5s infinite;
    min-height: 100px;
    border-radius: 8px;
}

.tk-message img.tk-img-loaded {
    animation: tk-fade-in 0.3s ease;
}

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

@keyframes tk-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Conversation list item optimization */
.tk-user-conversations li {
    contain: layout style paint;
    will-change: auto;
}

.tk-user-conversations li:hover {
    will-change: background-color;
}

/* Smooth transitions for conversation switching */
.tk-conversation-area-list {
    transition: opacity 0.15s ease;
}

.tk-conversation-area-list.tk-loading-messages {
    opacity: 0.7;
    pointer-events: none;
}

/* Long text optimization */
.tk-message-text {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Pre-formatted text (code blocks) */
.tk-message pre,
.tk-message code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Large attachment optimization */
.tk-message .tk-attachments {
    max-height: 400px;
    overflow-y: auto;
}

/* Skeleton loader for messages */
.tk-skeleton-message {
    padding: 15px;
    display: flex;
    gap: 12px;
}

.tk-skeleton-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: tk-shimmer 1.5s infinite;
    flex-shrink: 0;
}

.tk-skeleton-content {
    flex: 1;
}

.tk-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: tk-shimmer 1.5s infinite;
    margin-bottom: 8px;
}

.tk-skeleton-line:nth-child(1) { width: 80%; }
.tk-skeleton-line:nth-child(2) { width: 60%; }
.tk-skeleton-line:nth-child(3) { width: 40%; }

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .tk-message,
    .tk-loading-spinner,
    .tk-loading-older::before {
        animation: none !important;
    }

    .tk-conversation-area-list {
        scroll-behavior: auto !important;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .tk-message {
        animation: none; /* Disable animations on mobile for performance */
    }

    .tk-virtualized {
        content-visibility: auto;
        contain-intrinsic-size: auto 60px;
    }

    .tk-show-more-btn {
        padding: 6px 14px;
        font-size: 13px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tk-show-more-btn {
        border-width: 2px;
    }

    .tk-message.tk-error {
        border-width: 2px;
    }
}

/* Print styles - don't truncate */
@media print {
    .tk-message-truncated .tk-message-text {
        display: block !important;
    }

    .tk-show-more-btn {
        display: none !important;
    }

    .tk-virtualized {
        content-visibility: visible !important;
    }
}
