/* PHASE 17 PERFORMANCE CSS */
/* Add these styles to reduce repaint thrash and improve scrolling performance */

/* === 1) Containment for Message Container === */
#chat-messages {
    contain: content; /* Isolate layout, style, and paint */
    overflow-anchor: auto; /* Prevent scroll jumping on new content */
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* === 2) GPU Acceleration for Messages === */
.message {
    will-change: transform; /* Hint browser to optimize */
    transform: translateZ(0); /* Force GPU layer */
    backface-visibility: hidden;
}

/* === 3) Optimize Animations === */
.message-enter {
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === 4) Thinking Indicator === */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: 16px;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    background: #666;
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

.thinking-dot:nth-child(1) { animation-delay: 0s; }
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* === 5) Code Block Optimization === */
pre code {
    display: block;
    padding: 12px;
    overflow-x: auto;
    border-radius: 6px;
    background: #2d2d2d;
    color: #f8f8f2;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    contain: layout style paint; /* Isolate heavy styling */
}

.code-block {
    position: relative;
    margin: 12px 0;
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
}

.code-block:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.code-copy-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

/* === 6) Lazy Loading Images === */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s;
}

img.lazy.loaded {
    opacity: 1;
}

/* === 7) Message Collapse Stub === */
.message-collapse-stub {
    padding: 16px;
    text-align: center;
    border-bottom: 1px solid #e0e0e0;
}

.message-collapse-stub button {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.message-collapse-stub button:hover {
    background: #e8e8e8;
    border-color: #ccc;
}

/* === 8) Tool Output Cards === */
.tool-output {
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-family: monospace;
    font-size: 13px;
    contain: content;
}

.tool-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
}

.tool-output-body {
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}

/* === 9) Loading Skeletons === */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

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

.skeleton-message {
    height: 60px;
    margin: 12px 0;
}

.skeleton-text {
    height: 16px;
    margin: 8px 0;
}

/* === 10) Smooth Transitions === */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === 11) Scroll Performance === */
.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* === 12) Reduce Paint on Hover === */
.message:hover {
    background: rgba(0, 0, 0, 0.02);
    transition: background 0.15s ease;
    will-change: background;
}

/* === 13) File Chips === */
.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 16px;
    font-size: 13px;
    margin: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-chip:hover {
    background: #bbdefb;
    border-color: #64b5f6;
}

.file-chip-icon {
    font-size: 16px;
}

.file-chip-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === 14) Responsive Optimizations === */
@media (max-width: 768px) {
    .message {
        will-change: auto; /* Disable on mobile to save memory */
    }

    #chat-messages {
        contain: layout style; /* Lighter containment on mobile */
    }
}

/* === 15) Prevent Layout Shifts === */
* {
    box-sizing: border-box;
}

.message-content {
    min-height: 40px; /* Prevent height jump during load */
}
