/* INAPTIC V102 — Chat Styles (Revamped)
   Copyright (c) 2026 INAPTIC. Proprietary.
   Cohesive spacing, premium typography, and unified component styling */

/* ═══════════════════════════════════════════════════════════════
   Message Containers & Layout
   ═══════════════════════════════════════════════════════════════ */

.message {
    display: flex;
    gap: var(--space-xl);
    padding: var(--space-xl) clamp(16px, 4vw, 32px);
    max-width: 900px;
    margin: 0 auto;
    animation: msg-appear 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast), border-color var(--transition-fast);
    border: 1px solid transparent;
}

.message:hover {
    background: rgba(255, 255, 255, 0.012);
}
[data-theme="light"] .message:hover {
    background: rgba(0, 0, 0, 0.01);
}

@keyframes msg-appear {
    from { opacity: 0; transform: translateY(16px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.message + .message {
    border-top: 1px solid var(--border);
}

.message-avatar {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: 800;
    flex-shrink: 0;
    margin-top: 2px;
    transition: all var(--transition-fast);
}

.message.user .message-avatar {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.message.user .message-avatar:hover {
    border-color: var(--border-hover);
    transform: scale(1.05);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent), var(--purple), var(--accent2));
    color: white;
    box-shadow: var(--shadow-glow), 0 0 20px var(--purple-glow);
    animation: avatar-glow 3s ease-in-out infinite;
}

@keyframes avatar-glow {
    0%, 100% { box-shadow: 0 0 10px var(--accent-glow); }
    50% { box-shadow: 0 0 18px var(--accent-glow), 0 0 30px var(--purple-glow); }
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.message-role {
    font-family: var(--font-heading);
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.message-time {
    font-size: var(--font-size-xs);
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.message-content {
    font-family: var(--font-sans);
    font-size: var(--font-size-md);
    line-height: 1.65;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Typography styles inside messages */
.message-content p { margin-bottom: var(--space-md); }
.message-content p:last-child { margin-bottom: 0; }

.message-content a {
    color: var(--accent-hover);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-dim);
    transition: all var(--transition-fast);
}
.message-content a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.message-content strong { color: var(--text-primary); font-weight: 700; }
.message-content em { color: var(--text-secondary); }
.message-content ul, .message-content ol { margin: var(--space-md) 0; padding-left: var(--space-xl); }
.message-content li { margin-bottom: var(--space-xs); }

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding: var(--space-sm) var(--space-lg);
    margin: var(--space-lg) 0;
    background: var(--bg-primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.message-content code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    padding: 2px 6px;
    background: var(--bg-primary);
    border-radius: var(--radius-xs);
    color: var(--accent-hover);
    border: 1px solid var(--border);
}

.message-content pre {
    margin: var(--space-lg) 0;
    padding: var(--space-lg);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.message-content pre code {
    padding: 0; background: none; color: var(--text-primary); border: none;
    font-size: var(--font-size-sm); line-height: 1.6;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-lg) 0;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.message-content th, .message-content td {
    padding: var(--space-md);
    border: 1px solid var(--border);
    text-align: left;
}

.message-content th {
    background: var(--bg-primary);
    font-weight: 700;
    color: var(--text-secondary);
}

.message-content h1, .message-content h2, .message-content h3 {
    font-family: var(--font-heading);
    margin: var(--space-xl) 0 var(--space-md);
    color: var(--text-primary);
    line-height: 1.2;
}
.message-content h1 { font-size: 1.5em; font-weight: 800; }
.message-content h2 { font-size: 1.3em; font-weight: 700; }
.message-content h3 { font-size: 1.15em; font-weight: 700; }
.message-content hr { border: none; border-top: 1px solid var(--border); margin: var(--space-xl) 0; }
.message-content img { max-width: 100%; border-radius: var(--radius-md); margin: var(--space-lg) 0; }

/* ═══════════════════════════════════════════════════════════════
   Streaming Cursor & Typing Indicator
   ═══════════════════════════════════════════════════════════════ */

.streaming-cursor {
    display: inline-block;
    width: 2px; height: 1.1em;
    background: linear-gradient(to bottom, var(--accent), var(--purple));
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s step-end infinite;
    box-shadow: 0 0 8px var(--accent-glow);
    border-radius: 1px;
}

@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.typing-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    max-width: 900px;
    margin: 0 auto;
    color: var(--text-dim);
    font-size: var(--font-size-sm);
    animation: msg-appear 0.3s ease;
}

.typing-dots { display: flex; gap: 4px; }

.typing-dots span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    animation: typing-bounce 1.2s ease-in-out infinite;
    box-shadow: 0 0 6px var(--accent-glow);
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════
   Tool Call Blocks (Cohesive Support for .tool-call & .tool-call-block)
   ═══════════════════════════════════════════════════════════════ */

.tool-calls-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin: var(--space-md) 0;
}

/* Match both class names to prevent style gaps during dynamic mounts */
.tool-call,
.tool-call-block {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.tool-call.running,
.tool-call-block.running {
    border-color: var(--accent);
    box-shadow: 0 0 14px var(--accent-dim);
}

.tool-call.success,
.tool-call-block.success {
    border-color: var(--success-dim);
    box-shadow: 0 0 8px var(--success-dim);
}

.tool-call.error,
.tool-call-block.error {
    border-color: var(--error-dim);
    box-shadow: 0 0 8px var(--error-dim);
}

.tool-call-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: rgba(0,0,0,0.1);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
}

.tool-call-header:hover {
    background: var(--bg-hover);
}

.tool-call-icon,
.tool-icon {
    width: 20px; height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
}

.tool-call-name {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--text-primary);
}

.tool-call-status {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: var(--radius-full);
}

.tool-call-status.running { background: var(--accent-dim); color: var(--accent-hover); }
.tool-call-status.success { background: var(--success-dim); color: var(--success); }
.tool-call-status.error { background: var(--error-dim); color: var(--error); }

.tool-call-chevron {
    color: var(--text-dim);
    font-size: 10px;
    transition: transform var(--transition-fast);
}

/* Expanded state rotation */
.tool-call.expanded .tool-call-chevron,
.tool-call-block.expanded .tool-call-chevron {
    transform: rotate(90deg);
}

.tool-call-body {
    display: none;
    padding: var(--space-md);
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.05);
}

/* Support expanded toggle */
.tool-call.expanded .tool-call-body,
.tool-call-block.expanded .tool-call-body {
    display: block;
}

/* Handle fallback toggling (if JS uses .collapsed on body instead) */
.tool-call-body.collapsed {
    display: none !important;
}

.tool-call-section-label,
.tool-call-label {
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: var(--space-xs);
}

.tool-call-input,
.tool-call-output,
.tool-call-code {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-input);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: var(--space-sm);
    border: 1px solid var(--border);
}

.tool-call-input:last-child,
.tool-call-output:last-child {
    margin-bottom: 0;
}

.tool-spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid var(--accent-dim);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: tool-spin 0.6s linear infinite;
}

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

/* ═══════════════════════════════════════════════════════════════
   Thinking Block
   ═══════════════════════════════════════════════════════════════ */

.thinking-block {
    margin: var(--space-md) 0;
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-left: 3px solid var(--purple);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: box-shadow var(--transition-normal), border var(--transition-normal);
}

.thinking-block.expanded {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 3px solid var(--purple);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.thinking-header,
.thinking-block-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    user-select: none;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.thinking-header:hover,
.thinking-block-header:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.thinking-icon {
    font-size: 11px;
    animation: thinking-pulse 1.8s ease-in-out infinite;
    color: var(--purple);
    display: inline-block;
}

.thinking-chevron {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    transition: transform var(--transition-fast);
}

.thinking-chevron::after {
    content: "▼";
    font-size: 8px;
    color: var(--text-dim);
    transition: color var(--transition-fast);
}

.thinking-header:hover .thinking-chevron::after {
    color: var(--text-primary);
}

.thinking-block:not(.expanded) .thinking-chevron {
    transform: rotate(-90deg);
}

@keyframes thinking-pulse {
    0%, 100% { opacity: 0.5; transform: scale(0.92); }
    50% { opacity: 1; transform: scale(1.08); }
}

.thinking-content {
    display: none;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: 1.6;
    background: rgba(0, 0, 0, 0.15);
    font-style: italic;
    white-space: pre-wrap;
}

.thinking-block.expanded .thinking-content {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════
   Proof Chain Display & Stats Bar
   ═══════════════════════════════════════════════════════════════ */

.proof-chain {
    margin: var(--space-md) 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.proof-chain-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.proof-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}
.proof-badge.verified { background: var(--success-dim); color: var(--success); }
.proof-badge.unverified { background: var(--warning-dim); color: var(--warning); }

.proof-step {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 6px 0;
    font-size: var(--font-size-sm);
    border-top: 1px solid var(--border);
}

.proof-step-num {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent-hover);
    width: 20px;
}

.proof-step-type {
    flex: 1;
    font-weight: 500;
}

.proof-step-hash {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-dim);
}

.agent-stats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
    margin-top: var(--space-lg);
    border-top: 1px solid var(--border);
}

.agent-stat {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-dim);
    padding: 4px 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   Error & Usage Blocks
   ═══════════════════════════════════════════════════════════════ */

.message-error {
    max-width: 900px;
    margin: var(--space-md) auto;
    padding: var(--space-md) var(--space-lg);
    background: var(--error-dim);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-md);
    color: var(--error);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    animation: msg-appear 0.3s ease;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.05);
}

.usage-bar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-xs) 0;
    font-size: var(--font-size-xs);
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.usage-bar-track {
    flex: 1; height: 4px;
    background: var(--bg-primary);
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 1px solid var(--border);
}

.usage-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--purple));
    border-radius: var(--radius-full);
    transition: width var(--transition-normal);
    box-shadow: 0 0 6px var(--accent-glow);
}

/* ═══════════════════════════════════════════════════════════════
   Premium Revamp — Chat & Metrix Overrides
   ═══════════════════════════════════════════════════════════════ */

/* Welcome Screen Glow ambient effect */
.welcome-glow {
    animation: welcome-ambient-glow 8s ease-in-out infinite;
}

/* Staggered load for cards in Welcome page */
.welcome-message h2 {
    animation: premium-fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.welcome-subtitle {
    animation: premium-fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: 0.1s;
}
.welcome-desc {
    animation: premium-fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: 0.15s;
}
.welcome-capabilities .cap-card {
    animation: premium-fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.welcome-capabilities .cap-card:nth-child(1) { animation-delay: 0.2s; }
.welcome-capabilities .cap-card:nth-child(2) { animation-delay: 0.25s; }
.welcome-capabilities .cap-card:nth-child(3) { animation-delay: 0.3s; }
.welcome-capabilities .cap-card:nth-child(4) { animation-delay: 0.35s; }

/* Active Tool Pulse */
.tool-item.active .tool-dot {
    animation: ring-pulse-success 2s infinite;
}
.status-dot.online {
    animation: ring-pulse-success 2s infinite;
}

/* Typing bounce micro-scaling */
.typing-dots span {
    animation: typing-bounce 1s cubic-bezier(0.25, 0.8, 0.25, 1) infinite;
}

/* Interactive Input Container glowing overlay */
#input-container {
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast), background var(--transition-fast);
}
#input-container:focus-within {
    background: var(--bg-glass-hover);
    box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-glow), 0 0 30px var(--purple-glow);
}

/* ═══════════════════════════════════════════════════════════════
   Light Theme — Thinking Block Overrides
   ═══════════════════════════════════════════════════════════════ */

[data-theme="light"] .thinking-block {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .thinking-content {
    color: var(--text-secondary, #555);
}
