/* conversation.css: Dedicated layout/styles for conversation widget (no colors, no backgrounds, no font colors) */

html {
    scrollbar-color: var(--dim-color) var(--dark-color);
    scrollbar-width: thin;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    /* Prevent the document from scrolling so the conversation container owns scrolling */
    overflow: hidden;
}

* {
    box-sizing: border-box;
    color: #ffffff;
}

#conversation-container {
    width: 100%;
    /* Fill the full viewport available inside the webview and own scrolling */
    height: 100%;
    /* Allow the conversation container to scroll internally. This ensures the
         scrollbar is rendered inside the HTML content (single scrollbar UX). */
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 0;
    scrollbar-width: thin;
    gap: 0;
    border: none;
    border-radius: 0;
    font-family: 'Fira Mono', 'Consolas', 'Segoe UI', Arial, sans-serif;
    font-size: 1.1em;
    box-shadow: none;
}

#conversation-container::-webkit-scrollbar {
    height: 0 !important;
    width: 5px;
}

.message {
    margin: 0;
    padding: 10px 10px 15px 10px;
    width: 100%;
    word-break: break-word;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-radius: 0px;
    position: relative;
    transition: background 0.2s;
    font-size: 1em;
    font-family: 'Fira Mono', 'Consolas', 'Segoe UI', Arial, sans-serif;
    /* Use a simple 1px bottom border for message separation */
    border: none;
    border-bottom: 1px solid var(--line-color-light);
}

.message.user {
    align-self: flex-end;
    border-radius: 0px;
    box-shadow: 0 2px 12px rgba(0, 64, 255, 0.10);
    border: none;
    border-bottom: 1px solid var(--line-color-light);
    transition: border-bottom-color 0.2s, box-shadow 0.2s;
}

.message.user:hover {
    border-bottom: 1px solid var(--primary-color);
}

.message.assistant {
    align-self: flex-start;
    border-radius: 0px;
    box-shadow: 0 2px 12px rgba(0, 255, 128, 0.08);
    border: none;
    border-bottom: 1px solid var(--line-color-light);
    transition: border-bottom-color 0.2s, box-shadow 0.2s;
}

.message.assistant:hover {
    border-bottom: 1px solid var(--primary-color);
}

#conversation-container>.message:nth-child(even) {
    filter: brightness(1.08);
}

.message .header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    margin-bottom: 0;
    gap: 5px;
}

.message .sender {
    font-weight: 600;
    margin-bottom: 0;
    color: var(--dim-color);
    font-size: 0.75em;
    margin-right: 5px;
    display: inline-block;
    flex-shrink: 0;
}

.message.assistant .sender {
    color: var(--dim-color);
}

.message .actions {
    margin-left: auto;
    align-items: center;
    gap: 5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    display: flex;
    justify-content: flex-end;
}

.message:hover .actions {
    opacity: 1;
    pointer-events: auto;
}

.message .content {
    line-height: 1.6em;
    font-size: 0.92em;
    color: var(--light-color);
    margin: 0;
    padding: 10px 12px 0 12px;
    word-wrap: break-word;
    /* Remove pre-wrap to allow proper HTML rendering */
}

/* Markdown element styles */
.message .content p {
    margin: 0.5em 0;
}

.message .content p:first-child {
    margin-top: 0;
}

/* Hide empty paragraphs and divs that can cause unwanted whitespace */
.message .content p:empty,
.message .content div:empty {
    display: none;
}

/* Collapse margins for first visible element */
.message .content>*:first-child {
    margin-top: 0 !important;
}

.message .content p:last-child {
    margin-bottom: 0;
}

.message .content strong {
    font-weight: 700;
    color: var(--primary-color);
}

.message .content em {
    font-style: italic;
}

.message .content code {
    background: var(--dark-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Fira Mono', 'Consolas', monospace;
    font-size: 0.9em;
}

.message .content pre {
    background: var(--dark-color);
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.8em 0;
}

.message .content pre code {
    background: none;
    padding: 0;
}

.message .content ol,
.message .content ul {
    margin: 0.6em 0;
    padding-left: 2em;
    line-height: 1.8em;
}

.message .content ol {
    list-style-type: decimal;
}

.message .content ul {
    list-style-type: disc;
}

.message .content li {
    margin: 0.3em 0;
    padding-left: 0.3em;
}

.message .content li::marker {
    color: var(--primary-color);
}

.message .content h1,
.message .content h2,
.message .content h3,
.message .content h4 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
    color: var(--primary-color);
}

.message .content h1:first-child,
.message .content h2:first-child,
.message .content h3:first-child,
.message .content h4:first-child {
    margin-top: 0;
}

.message .content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1em;
    margin: 0.8em 0;
    color: var(--dim-color);
    font-style: italic;
}

.message .content a {
    color: var(--primary-color);
    text-decoration: underline;
}

.message .content a:hover {
    color: var(--primary-color-light);
}


.message .timestamp {
    font-size: 0.85em;
    color: var(--dim-color);
    margin-top: 2px;
    text-align: right;
    opacity: 0.7;
    padding: 0 12px 4px 12px;
}

.message .delete-button {
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    padding: 0;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}

.message .delete-button:hover {
    opacity: 1;
    background: var(--line-color-light);
}

.message .delete-button svg {
    width: 15px;
    height: 15px;
    display: block;
    pointer-events: none;
    fill: var(--danger-color);
    transition: fill 0.15s;
}

.message .delete-button:hover svg {
    fill: var(--danger-color);
}

/* Copy button - icon only */
.message .copy-button {
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    padding: 0;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
}

.message .copy-button svg {
    width: 16px;
    height: 16px;
    display: block;
    pointer-events: none;
    fill: var(--dim-color);
    transition: fill 0.15s;
}

.message .copy-button:hover svg {
    fill: var(--light-color);
}

.message .content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--primary-color);
    transition: color 0.15s, border-bottom 0.15s;
    word-break: break-all;
}

.message .content a:hover {
    color: var(--light-color);
    border-bottom: 1px solid var(--light-color);
    text-decoration: underline;
}

pre,
code {
    color: var(--primary-color) !important;
    font-size: 0.98em;
    line-height: 1.5;
    padding: 5px 12px;
    overflow-x: auto;
    max-width: 100%;
    box-sizing: border-box;
    font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'monospace';
    background-color: var(--darksecondary-color) !important;
    border-radius: 2px;
}

pre {
    margin: 10px 0;
    white-space: pre;
}

code:not(pre code) {
    padding: 2px 5px;
    white-space: pre-wrap;
    background-color: var(--line-color-light);
}

.MathJax {
    color: var(--light-color) !important;
}

.MathJax_Display {
    margin: 1em 0 !important;
}

mjx-container {
    color: var(--light-color) !important;
}

mjx-container[display="true"] {
    margin: 1em 0 !important;
}

/* Unified Status Widget - combines thinking and tool status */
.unified-status-widget {
    margin: 8px 0 12px 0;
    border-radius: 6px;
    font-size: 0.85em;
    background: var(--line-color);
    border-left: 3px solid var(--primary-color);
    overflow: hidden;
    /* Ensure the widget displays in the flex flow properly */
    flex-shrink: 0;
    /* Ensure proper stacking */
    z-index: 1;
}

/* Ensure messages following status widgets have proper spacing */
.unified-status-widget+.message {
    margin-top: 0;
}

.unified-status-widget.has-thinking {
    border-left-color: #9333ea;
}

.unified-status-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    background: rgba(0, 0, 0, 0.1);
}

.unified-status-header:hover {
    background: rgba(0, 0, 0, 0.2);
}

.unified-status-icon {
    font-size: 0.9em;
}

.unified-status-title {
    color: var(--light-color);
    font-weight: 500;
    font-size: 0.9em;
}

.unified-status-count {
    color: var(--dim-color);
    font-size: 0.8em;
    margin-left: auto;
}

.unified-status-expand {
    color: var(--dim-color);
    font-size: 0.7em;
    transition: transform 0.2s;
}

.unified-status-widget.expanded .unified-status-expand {
    transform: rotate(90deg);
}

/* Visible items container - hidden by default, only header shows */
.unified-status-visible {
    display: none;
}

.unified-status-widget.expanded .unified-status-visible {
    display: block;
    position: relative;
    overflow: hidden;
}

/* History container - shown when expanded */
.unified-status-history {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.unified-status-history:empty {
    display: none;
}

.unified-status-widget.expanded .unified-status-history {
    max-height: 400px;
    overflow-y: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Individual status item */
.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.status-item.new-item {
    animation: slideIn 0.3s ease;
}

.status-item:last-child {
    border-bottom: none;
}

.status-item.exiting {
    animation: slideOut 0.3s ease forwards;
}

.status-item-icon {
    font-size: 1em;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
    display: none;
    /* Hide individual item icons - header shows the main icon */
}

.status-item-icon.spinning {
    animation: iconPulse 1.2s ease-in-out infinite;
}

.status-item-text {
    color: var(--light-color);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-item.thinking-item {
    background: rgba(147, 51, 234, 0.05);
}

.status-item.tool-item {
    background: rgba(59, 130, 246, 0.05);
}

.status-item.completed {
    opacity: 0.7;
}

.status-item.completed .status-item-icon {
    animation: none;
}

/* Slide animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes iconPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.15);
    }
}

/* Header icon pulsing */
.unified-status-icon.pulsing {
    animation: iconPulse 1.2s ease-in-out infinite;
}

/* Animated dots for "Thinking" text */
.unified-status-title.animated-dots::after {
    content: '';
    animation: dotPulse 1.5s infinite;
}

@keyframes dotPulse {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }

    100% {
        content: '';
    }
}

/* Thinking preview line - shows streaming content */
.thinking-preview-line {
    display: none;
    padding: 4px 12px 8px 12px;
    font-size: 0.8em;
    color: var(--dim-color);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    border-top: 1px solid rgba(147, 51, 234, 0.2);
    background: rgba(147, 51, 234, 0.03);
    animation: fadeSlideIn 0.2s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Thinking content expandable */
.thinking-content-wrapper {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

/* Show thinking content when widget is expanded */
.unified-status-widget.expanded .thinking-content-wrapper {
    max-height: 300px;
    overflow-y: auto;
}

.thinking-content-inner {
    padding: 8px 12px;
    border-top: 1px solid rgba(147, 51, 234, 0.2);
    color: var(--dim-color);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Droid Sans Mono', monospace;
    font-size: 0.85em;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 180px;
    overflow-y: auto;
}

/* Legacy support - keep old classes working */
.tool-status,
.thinking-block {
    display: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    background: var(--dark-color);
}

::-webkit-scrollbar-thumb {
    background: var(--dim-color);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

::-webkit-scrollbar-track {
    background: var(--dark-color);
}