/* === Chat Messages — Glassmorphic Design === */

/* TTS buttons */

.tts-button-container {
    position: absolute;
    bottom: 40px;
    right: 8px;
    z-index: 10;
}
.tts-button-container.tts-flow {
    position: static;
    bottom: auto;
    right: auto;
}

.tts-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tts-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tts-button.speaking {
    color: #38a169 !important;
}

.tts-button.speaking:hover {
    color: #2f855a !important;
}

/* Message rendering */
.chat-message pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    background-color: rgba(0, 0, 0, 0.25);
    padding: 1rem;
    border-radius: 10px;
    overflow: auto;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-message img {
    max-width: 100%;
    height: auto;
    margin-top: 5px;
    border-radius: 8px;
}

.chat-message table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1rem;
}

.chat-message th,
.chat-message td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    text-align: left;
}

.chat-message th {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Base message bubble — glassmorphic foundation */
.chat-message {
    white-space: pre-wrap;
    padding: 1rem;
    border-radius: 14px;
    position: relative;
    transition: background-color 200ms ease, box-shadow 200ms ease;
}

/* User message — indigo glass, distinct but not overpowering */
.user-message {
    background: rgba(67, 56, 202, 0.15);
    border: 1px solid rgba(129, 140, 248, 0.16);
    color: #f1f5f9;
    box-shadow:
        0 2px 8px rgba(67, 56, 202, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.user-message:hover {
    background: rgba(67, 56, 202, 0.2);
    box-shadow:
        0 4px 14px rgba(67, 56, 202, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Assistant message — neutral dark glass, no color tint */
.assistant-message {
    background: transparent;
    border: none;
    color: #e2e8f0;
    box-shadow: none;
}

.assistant-message:hover {
    background: rgba(255, 255, 255, 0.02);
}

.message-content {
    min-height: 40px;
}

.text-xs {
    margin-top: 10px;
}

/* Code block buttons */
.copy-button {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 5px;
    transition: color 180ms ease, background-color 180ms ease;
    min-width: 133px;
    z-index: 5;
    white-space: nowrap;
    text-align: center;
}

.copy-button:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
}

/* Prevent the global 24px fa-check from blowing up inside code copy buttons */
.copy-button .fa-check:before,
.play-button .fa-check:before {
    font-size: inherit !important;
}

.play-button {
    position: absolute;
    bottom: 10px;
    right: 155px;
    min-width: 120px;
    z-index: 5;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    transition: color 180ms ease, background-color 180ms ease;
}

.play-button:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
}

.chat-message pre:hover .copy-button {
    display: block;
}

/* Language label — glassmorphic badge */
.language-label {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #64748b !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.06) !important;
    font-size: 11px !important;
}

/* Message action buttons — hidden until message hover, then fade in with color */
.chat-message .edit-buttons {
    opacity: 0;
    transition: opacity 300ms ease;
}

.chat-message:hover .edit-buttons {
    opacity: 1;
}

/* During streaming: suppress all action buttons, even on hover */
.streaming .chat-message .edit-buttons {
    opacity: 0 !important;
    pointer-events: none;
}

.streaming .chat-message .tts-button-container {
    opacity: 0 !important;
    pointer-events: none;
}

.chat-message .edit-buttons button {
    transition: color 200ms ease, filter 200ms ease, transform 200ms ease;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Each button has its own vivid color at rest (visible on message hover) */
.chat-message .edit-buttons .message-action-copy-button { color: #a78bfa !important; }
.chat-message .edit-buttons .download-button { color: #38bdf8 !important; }
.chat-message .edit-buttons .regenerate-button { color: #34d399 !important; }
.chat-message .edit-buttons .edit-button { color: #60a5fa !important; }
.chat-message .edit-buttons .delete-button { color: #f87171 !important; }

/* Button hover — neon glow + lift */
.chat-message .edit-buttons .message-action-copy-button:hover {
    filter: drop-shadow(0 0 10px rgba(167, 139, 250, 0.7));
    transform: scale(1.2);
}
.chat-message .edit-buttons .download-button:hover {
    filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.7));
    transform: scale(1.2);
}
.chat-message .edit-buttons .regenerate-button:hover {
    filter: drop-shadow(0 0 10px rgba(52, 211, 153, 0.7));
    transform: scale(1.2);
}
.chat-message .edit-buttons .edit-button:hover {
    filter: drop-shadow(0 0 10px rgba(96, 165, 250, 0.7));
    transform: scale(1.2);
}
.chat-message .edit-buttons .delete-button:hover {
    filter: drop-shadow(0 0 10px rgba(248, 113, 113, 0.7));
    transform: scale(1.2);
}

/* TTS button — same hidden-until-hover pattern */
.tts-button-container {
    opacity: 0;
    transition: opacity 300ms ease;
}
.chat-message:hover .tts-button-container {
    opacity: 1;
}

.tts-button {
    color: #fb923c !important;
    transition: filter 200ms ease, transform 200ms ease;
}
.tts-button:hover {
    filter: drop-shadow(0 0 10px rgba(251, 146, 60, 0.7));
    transform: scale(1.2);
}

/* Mobile: no hover, always show buttons (muted) */
@media (max-width: 1024px) {
    .chat-message .edit-buttons {
        opacity: 1;
    }
    .chat-message .edit-buttons .message-action-copy-button { color: rgba(167, 139, 250, 0.5) !important; }
    .chat-message .edit-buttons .download-button { color: rgba(56, 189, 248, 0.5) !important; }
    .chat-message .edit-buttons .regenerate-button { color: rgba(52, 211, 153, 0.5) !important; }
    .chat-message .edit-buttons .edit-button { color: rgba(96, 165, 250, 0.5) !important; }
    .chat-message .edit-buttons .delete-button { color: rgba(248, 113, 113, 0.4) !important; }
    .tts-button-container { opacity: 1; }
    .tts-button { color: rgba(251, 146, 60, 0.5) !important; }
}

/* Main content area — deeper dark for chat contrast */
#main-content {
    background-color: rgba(10, 15, 30, 0.95) !important;
}

/* Chat history container — transparent, full width */
#chat-history {
    background-color: transparent;
    margin: 4px 0;
    border-radius: 0;
    padding: 12px 8px;
}

#chat-history::-webkit-scrollbar {
    width: 6px;
}

#chat-history::-webkit-scrollbar-track {
    background-color: transparent;
    border-radius: 10px;
}

#chat-history::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    transition: background-color 200ms ease;
}

#chat-history::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

#chat-history {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* LLM wait timer */
.llm-wait-timer {
    display: inline-block;
    margin-left: 10px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.35);
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
    user-select: none;
}

/* Retry button */
.retry-container {
    display: flex;
    justify-content: flex-end;
    padding: 12px 16px;
}

.retry-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background-color: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 12px;
    color: #93c5fd;
    font-size: 0.875rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 150ms ease;
}

.retry-button:hover {
    background-color: rgba(59, 130, 246, 0.22);
    border-color: rgba(59, 130, 246, 0.4);
    color: #bfdbfe;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.15);
}

.retry-button i {
    font-size: 0.75rem;
}

/* Message editing */
.text-red-500 {
    color: rgb(255 127 127) !important;
}

div.message-content[contenteditable="true"] {
    margin-bottom: 20px;
}

div[class^="message-content"][contenteditable="true"] {
    padding: 10px;
}

.fa-check:before {
    font-size: 24px;
}

#applyEdit {
    position: absolute;
    right: 5px;
    bottom: -5px;
}

#applyEdit:before {
    font-size: 24px;
}

.chat-message[editable="true"]>div>button>.fa-trash {
    display: none;
}

.chat-message[data-editing="true"] .absolute.bottom-2.right-2>button>i.fa-trash {
    display: none !important;
}

.chat-message[data-editing="true"] .absolute.bottom-2.right-2>button>i.fa-edit {
    display: none !important;
}

.chat-message[data-editing="true"] .absolute.bottom-2.right-2>button>i.fa-sync {
    display: none !important;
}

/* System messages — frosted panel with muted teal accent */
.system-message-collapsed {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #94a3b8;
}

.system-message-collapsed i {
    margin-right: 5px;
    font-size: 16px;
    vertical-align: middle;
}

.system-message-collapsed:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

.system-message-expanded {
    background: linear-gradient(135deg, rgba(45, 212, 191, 0.06) 0%, rgba(20, 184, 166, 0.04) 100%);
    border: 1px solid rgba(45, 212, 191, 0.12);
    color: #94a3b8;
    font-style: italic;
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 10px;
    transition: max-height 0.3s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.system-message-content {
    display: none;
}

.system-message-expanded .system-message-content {
    display: block;
}

/* Compression messages — frosted violet panel */
.compression-message-collapsed {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #c4b5fd;
}

.compression-message-collapsed i {
    margin-right: 8px;
    font-size: 16px;
    vertical-align: middle;
}

.compression-message-collapsed:hover {
    background-color: rgba(124, 58, 237, 0.1);
}

.compression-toggle-bar {
    margin-bottom: 10px;
}

.compression-toggle-bar + .message-content {
    margin-bottom: 10px;
}

.compression-progress {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1) 0%, rgba(99, 102, 241, 0.06) 100%);
    border-left: 3px solid rgba(124, 58, 237, 0.6);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 10px;
    color: #c4b5fd;
}

.compression-progress-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    margin-bottom: 8px;
}

.compression-progress-header i {
    color: #a78bfa;
}

.compression-progress-label {
    flex: 1;
}

.compression-progress-pct {
    font-weight: bold;
    color: #a78bfa;
}

.compression-progress-bar-bg {
    height: 4px;
    background-color: rgba(124, 58, 237, 0.15);
    border-radius: 2px;
    overflow: hidden;
}

.compression-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #7c3aed, #a78bfa);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.compression-progress-warning {
    font-size: 0.75rem;
    color: #a78bfa;
    margin-top: 6px;
    opacity: 0.8;
}

.compression-message-expanded {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.08) 0%, rgba(99, 102, 241, 0.05) 100%);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-left: 3px solid rgba(124, 58, 237, 0.5);
    color: #e0e7ff;
    font-style: italic;
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 10px;
    transition: max-height 0.3s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* Reasoning container — glassmorphism with gradient fade */
.reasoning-container {
    overflow: hidden;
    transition: max-height 0.45s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.3s ease, border-radius 0.35s ease,
        padding 0.35s ease, margin 0.35s ease,
        border-color 0.3s ease, background 0.3s ease,
        box-shadow 0.3s ease;
    max-height: 0;
    height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
    border: none;
    will-change: max-height, opacity;
    position: relative;
}

/* Collapsed = pill button state */
.reasoning-container.collapsed {
    max-height: 38px;
    height: auto;
    opacity: 1;
    padding: 0;
    margin-bottom: 10px;
    border: 1px solid rgba(139, 92, 246, 0.18);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), rgba(99, 130, 255, 0.08));
    border-radius: 20px;
    cursor: pointer;
}

/* First-appear animation — only on initial creation, not on collapse */
.reasoning-container.reasoning-appear {
    animation: reasoningAppear 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes reasoningAppear {
    from { opacity: 0; transform: translateY(-8px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.reasoning-container.collapsed:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.18), rgba(99, 130, 255, 0.12));
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.12);
}

.reasoning-container.collapsed .reasoning-content,
.reasoning-container.collapsed .reasoning-bottom-fade {
    display: none;
}

.reasoning-container.collapsed .reasoning-header {
    background: none;
    border-bottom: none;
    border-radius: 20px;
    padding: 8px 16px;
}

.reasoning-container.collapsed .reasoning-chevron {
    transform: rotate(180deg);
    opacity: 0.3;
}

/* Streaming collapsed = futuristic pulsing pill */
.reasoning-container.collapsed.streaming {
    animation: thinkingPillPulse 2.5s ease-in-out infinite;
    border-color: rgba(139, 92, 246, 0.3);
}

.reasoning-container.collapsed.streaming .reasoning-header {
    gap: 10px;
}

.reasoning-container.collapsed.streaming .reasoning-header > i.fa-brain {
    font-size: 13px !important;
    opacity: 1 !important;
    animation: brainGlow 2s ease-in-out infinite;
    filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.6));
}

.reasoning-container.collapsed.streaming .reasoning-chevron {
    display: none;
}

@keyframes thinkingPillPulse {
    0%, 100% {
        border-color: rgba(139, 92, 246, 0.2);
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0), 0 0 12px rgba(139, 92, 246, 0.05);
        background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(99, 130, 255, 0.06));
    }
    50% {
        border-color: rgba(139, 92, 246, 0.4);
        box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.06), 0 0 20px rgba(139, 92, 246, 0.1);
        background: linear-gradient(135deg, rgba(139, 92, 246, 0.18), rgba(99, 130, 255, 0.1));
    }
}

@keyframes brainGlow {
    0%, 100% {
        color: #a78bfa;
        filter: drop-shadow(0 0 4px rgba(167, 139, 250, 0.3));
        transform: scale(1);
    }
    50% {
        color: #c4b5fd;
        filter: drop-shadow(0 0 10px rgba(167, 139, 250, 0.7));
        transform: scale(1.15);
    }
}

/* Expanded = glass card state */
.reasoning-container.visible {
    max-height: 320px;
    height: auto;
    opacity: 1;
    padding: 0;
    margin-bottom: 1rem;
    border: 1px solid rgba(139, 92, 246, 0.12);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.06) 0%, rgba(99, 130, 255, 0.04) 50%, rgba(52, 211, 153, 0.02) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-radius: 14px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.reasoning-container.visible .reasoning-chevron {
    transform: rotate(0deg);
    opacity: 0.4;
}

.reasoning-container.visible .reasoning-header:hover .reasoning-chevron {
    opacity: 0.7;
}

/* Bottom fade — sticky element inside the scrollable container */
.reasoning-bottom-fade {
    position: sticky;
    bottom: 0;
    height: 80px;
    margin-top: -80px;
    background: linear-gradient(to top,
        rgba(22, 20, 40, 0.9) 0%,
        rgba(22, 20, 40, 0.5) 30%,
        rgba(22, 20, 40, 0.15) 60%,
        transparent 100%);
    pointer-events: none;
    z-index: 10;
    flex-shrink: 0;
}

/* Header — sticky, transparent with fade below so text dissolves under it */
.reasoning-header {
    position: sticky;
    top: 0;
    z-index: 15;
    padding: 10px 16px 44px;
    font-size: 12px !important;
    letter-spacing: 0.01em;
    color: #a78bfa !important;
    font-weight: 600 !important;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(to bottom,
        rgba(24, 22, 40, 1) 0%,
        rgba(24, 22, 40, 0.95) 30%,
        rgba(24, 22, 40, 0.5) 60%,
        rgba(24, 22, 40, 0.15) 80%,
        transparent 100%);
    margin: 0;
    border-radius: 14px 14px 0 0;
}

.reasoning-header span {
    font-weight: 500 !important;
    font-size: 12px !important;
    color: #a78bfa !important;
}

/* Streaming expanded — brain glows + pulse dot */
.reasoning-container.visible.streaming .reasoning-header > i.fa-brain {
    animation: brainGlow 2s ease-in-out infinite;
    filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.6));
    opacity: 1 !important;
}

.reasoning-container.visible.streaming .reasoning-header::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #a78bfa;
    animation: reasoningPulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes reasoningPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

.reasoning-content {
    transition: opacity 0.3s ease;
    opacity: 0;
    padding: 4px 16px 16px;
    font-size: 13px;
    line-height: 1.65;
    color: #94a3b8;
    overflow-wrap: break-word;
}

.reasoning-container.visible .reasoning-content {
    opacity: 1;
    transition-delay: 0.1s;
}

/* Smooth scrollbar inside reasoning */
.reasoning-container::-webkit-scrollbar {
    width: 3px;
}
.reasoning-container::-webkit-scrollbar-track {
    background: transparent;
}
.reasoning-container::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
    border-radius: 2px;
}
.reasoning-container::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.35);
}

/* Chat title fade */
#chat-title.fade-out {
    animation: fadeOutOpacity 3s 10s forwards, fadeOutHeight 3s 13s forwards, fadeOutMargin 3s 13s forwards;
}

/* Chat responsive */
@media (min-width: 1200px) {
    .max-w-lg {
        max-width: 80%;
    }
}

@media (min-width: 600px) {
    .chat-message img {
        max-width: 580px !important;
    }
}

@media (max-width: 600px) {
    div.message-content>div.text-xs {
        max-width: 75%;
    }
}
