/* 1.3 — Message entrance animation */
#ai-chat-history .chat-msg {
    animation: msgFadeInUp 0.2s ease both;
}
@keyframes msgFadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* fadeInUp keyframe for chat-status.js agent rows */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 1.2 — Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
    align-items: center;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    animation: typingBounce 1.2s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* 1.4 — Copy / Feedback action buttons */
.msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}
.chat-msg.ai:hover .msg-actions {
    opacity: 1;
}
.msg-action-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 3px 7px;
    font-size: 11px;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    display: flex;
    align-items: center;
    gap: 3px;
}
.msg-action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}
.msg-action-btn svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
}

/* 1.7 — Scroll-to-bottom floating button */
.scroll-to-bottom-btn {
    position: absolute;
    bottom: 80px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.15s;
    z-index: 10;
}
.scroll-to-bottom-btn.visible {
    opacity: 1;
    pointer-events: auto;
}
.scroll-to-bottom-btn:hover {
    transform: scale(1.1);
}
.scroll-to-bottom-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}




/* ══════════════════════════════════════════════════════════════════════════════
   FASE 4 — Agent Interaction Improvements
   4.1 Mid-flight Interrupt | 4.2 Step Mode | 4.3 Retry | 4.4 Session Context | 4.5 Task History
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── 4.1 Mid-flight Interrupt ─────────────────────────────────────────────── */
.interrupt-btn {
    display: none;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 4px 10px;
    font-size: 10px;
    border-radius: 8px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: #fbbf24;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}
.interrupt-btn:hover {
    background: rgba(251, 191, 36, 0.2);
    border-color: rgba(251, 191, 36, 0.5);
    transform: translateY(-1px);
}
.is-processing .interrupt-btn {
    display: inline-flex;
}
.interrupt-input-container {
    display: none;
    gap: 6px;
    margin-top: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.interrupt-text-input {
    flex: 1;
    min-width: 160px;
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 6px;
    border: 1px solid rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.05);
    color: #f8f8f2;
    outline: none;
    font-family: 'Outfit', sans-serif;
    transition: border-color 0.2s;
}
.interrupt-text-input:focus {
    border-color: rgba(251, 191, 36, 0.6);
}
.interrupt-send-btn,
.interrupt-cancel-btn {
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    transition: all 0.2s;
}
.interrupt-send-btn {
    background: rgba(251, 191, 36, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.4);
    color: #fbbf24;
}
.interrupt-send-btn:hover { background: rgba(251, 191, 36, 0.25); }
.interrupt-cancel-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
}
.interrupt-cancel-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ── 4.2 Step-by-step Mode Toggle ────────────────────────────────────────── */
.step-mode-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #64748b;
    font-size: 13px;
    padding: 4px 7px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}
.step-mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #f8f8f2;
}
.step-mode-btn.step-mode-active {
    background: rgba(139, 233, 253, 0.1);
    border-color: rgba(139, 233, 253, 0.35);
    color: #8be9fd;
    box-shadow: 0 0 8px rgba(139, 233, 253, 0.15);
}

/* ── 4.3 Retry Code Button ────────────────────────────────────────────────── */
.retry-code-btn {
    display: none;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(189, 147, 249, 0.3);
    background: rgba(189, 147, 249, 0.08);
    color: #bd93f9;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}
.retry-code-btn:hover {
    background: rgba(189, 147, 249, 0.18);
    border-color: rgba(189, 147, 249, 0.5);
    transform: translateY(-1px);
}

/* ── 4.4 Session Context Panel ───────────────────────────────────────────── */
.session-context-panel {
    font-size: 11px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(4px);
}
.session-context-summary {
    cursor: pointer;
    font-size: 10px;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: #8be9fd;
    user-select: none;
    list-style: none;
}
.session-context-summary::-webkit-details-marker { display: none; }
.session-context-body {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ctx-item {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    opacity: 0.8;
    font-size: 11px;
    color: #f8f8f2;
    line-height: 1.4;
}
.ctx-item b { flex-shrink: 0; color: #6272a4; }

/* ── 4.5 Task History Timeline ───────────────────────────────────────────── */
.task-history-details {
    font-size: 11px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.02);
}
.task-history-details summary {
    cursor: pointer;
    font-size: 10px;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: #6272a4;
    user-select: none;
    list-style: none;
}
.task-history-details summary::-webkit-details-marker { display: none; }
.task-timeline {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.task-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 10px;
    color: #f8f8f2;
    opacity: 0.75;
}
.task-item:last-child { border-bottom: none; }
.task-icon { flex-shrink: 0; font-size: 11px; }
.task-time {
    flex-shrink: 0;
    color: #6272a4;
    font-family: monospace;
    font-size: 9px;
}
.task-prompt {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.task-running { opacity: 0.6; }
.task-success { opacity: 0.85; }
.task-failed { opacity: 0.75; color: #ff8585; }

/* Premium System Error Card UX/UI */
.chat-msg.ai.system-error-msg {
    background: rgba(239, 83, 80, 0.04) !important;
    border: 1px solid rgba(239, 83, 80, 0.25) !important;
    box-shadow: 0 4px 12px rgba(239, 83, 80, 0.05);
    transition: all 0.25s ease;
}

.chat-msg.ai.system-error-msg:hover {
    border-color: rgba(239, 83, 80, 0.4) !important;
    box-shadow: 0 4px 16px rgba(239, 83, 80, 0.08);
}

.msg-avatar-icon.system-error-icon {
    background: rgba(239, 83, 80, 0.15) !important;
    color: #ef5350 !important;
}

.msg-meta-header.system-error-header {
    color: #ef5350 !important;
    font-weight: 700;
}

.conversational-body.system-error-body {
    color: #ff8a80 !important;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    line-height: 1.5;
    word-break: break-word;
}

.error-details {
    margin-top: 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(239, 83, 80, 0.15);
    overflow: hidden;
    transition: all 0.2s ease;
}

.error-details[open] {
    border-color: rgba(239, 83, 80, 0.25);
}

.error-details-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 10px;
    font-weight: 600;
    color: #ff8a80;
    cursor: pointer;
    user-select: none;
    background: rgba(239, 83, 80, 0.06);
    transition: background 0.15s ease, color 0.15s ease;
}

.error-details-summary:hover {
    background: rgba(239, 83, 80, 0.12);
    color: #ff5252;
}

.error-details-summary::-webkit-details-marker {
    display: none; /* Hide default webkit arrow */
}

.error-details-summary .details-icon {
    font-size: 12px;
}

.error-details-content {
    padding: 8px 10px;
    border-top: 1px solid rgba(239, 83, 80, 0.15);
}

.error-details-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}

.error-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 9.5px;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    transition: all 0.15s ease;
}

.error-copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.error-copy-btn .action-icon {
    font-size: 11px;
}

.error-details-pre {
    margin: 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    overflow-x: auto;
    max-height: 240px;
}

.error-details-pre code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    line-height: 1.4;
    color: #ff8a80;
    white-space: pre-wrap;
    word-break: break-all;
}
