.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 12px;
    max-width: 80%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* Visual Debug Panel */
.debug-panel {
    background-color: #e8f5e8;
    border: 1px solid #a7d7a7;
    border-radius: 4px;
    padding: 8px;
    margin: 8px 0;
    font-size: 0.8em;
    font-family: monospace;
}

.dark-theme .debug-panel {
    background-color: #2a3a2a;
    border-color: #4a6a4a;
    color: #fff;
}

.debug-info {
    line-height: 1.4;
}

.debug-label {
    font-weight: bold;
    color: #2d5a2d;
}

.dark-theme .debug-label {
    color: #90ee90;
}

/* User message styling */
.user-message {
    background-color: #E3F2FD;
    border: 1px solid #BBDEFB;
    margin-left: auto;
    margin-right: 10px;
}

/* AI message styling */
.ai-message {
    background-color: #F3E5F5;
    border: 1px solid #E1BEE7;
    margin-right: auto;
    margin-left: 10px;
}

/* Message header styling */
.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.user-name {
    font-weight: 600;
    color: #474747;
}

.message-time {
    font-size: 0.8em;
    color: #8c8c8c;
}

/* Message actions styling */
.message-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* TTS Button styling */
.tts-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

    .tts-button:hover {
        background-color: rgba(0, 0, 0, 0.1);
        transform: scale(1.1);
    }

    .tts-button.speaking {
        background-color: rgba(0, 123, 255, 0.2);
    }

        .tts-button.speaking .tts-icon {
            animation: pulse 1.5s ease-in-out infinite alternate;
        }

.tts-icon {
    font-size: 14px;
    line-height: 1;
}

/* Sentence highlighting for TTS */
.current-sentence {
    background-color: #e8f5e8 !important;
    padding: 4px 6px;
    border-radius: 4px;
    border-left: 4px solid #4caf50;
    margin: 2px 0;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.2);
}

.dark-theme .current-sentence {
    background-color: #2a4a2a !important;
    border-left-color: #66bb6a;
    box-shadow: 0 2px 4px rgba(102, 187, 106, 0.3);
}

/* make sure to use double @@ in front of keyframes as blazor requires this */
@@keyframes pulse {
    from {
        opacity: 0.7;
    }

    to {
        opacity: 1;
    }
}

/* Message content styling */
.message-content {
    word-wrap: break-word;
    line-height: 1.4;
}

/* Markdown specific styling */
.markdown-content pre {
    /*background-color: #f5f5f5;*/
    background: radial-gradient(circle at top left, #0d182b, #050a14);
    border-radius: 4px;
    overflow-x: auto;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.markdown-content code {
    background-color: #f5f5f5;
    /*background: radial-gradient(circle at top left, #0d182b, #050a14);*/
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.markdown-content p {
    margin: 8px 0;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.markdown-content ul, .markdown-content ol {
    padding-left: 20px;
}

/* Dark theme styling - with high contrast colors */
.dark-theme.user-message {    
    background: radial-gradient(circle at top left, #020617, #1e293b);
    /*border-color: #0D47A1;*/
    border-color: blue;
    color: #FFFFFF;
}

.dark-theme.ai-message {
    background: radial-gradient(circle at top left, #1e293b, #020617);
    /*border-color: #4A148C;*/
    border-color: coral;
    color: lightgreen;
}

.dark-theme .user-name {
    color: #FFFFFF;
    font-weight: 600;
}

.dark-theme .message-time {
    color: #E0E0E0;
}

.dark-theme .tts-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.dark-theme .tts-button.speaking {
    background-color: rgba(100, 181, 246, 0.3);
}

.dark-theme .markdown-content pre, .dark-theme .markdown-content code {
    background-color: rgba(0, 0, 0, 0.3);
    color: #E0E0E0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}  

/* Override inline styles emitted by Markdig SyntaxHighlighting (editor-colors) */
.dark-theme .markdown-content .editor-colors,
.dark-theme .markdown-content .editor-colors div,
.dark-theme .markdown-content .editor-colors pre,
.dark-theme .markdown-content .editor-colors code {
   background-color: #00001A !important;
   color: #E0E0E0 !important;
}

/* Table styling for markdown */
.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
}

.markdown-content th,
.markdown-content td {
    padding: 8px;
    text-align: left;
    border: 1px solid #ddd;
}

.markdown-content th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.dark-theme .markdown-content th {
    background-color: #333;
    color: white;
}

.dark-theme .markdown-content th,
.dark-theme .markdown-content td {
    border-color: #444;
    color: white;
}

/* Links styling */
.markdown-content a {
    color: #0066cc;
    text-decoration: none;
}

    .markdown-content a:hover {
        text-decoration: underline;
    }

.dark-theme .markdown-content a {
    color: #64B5F6;
}

/* Make Prism recognize the lang-python class */
div.lang-python {
    display: block;
    overflow-x: auto;
    padding: 1em;
    margin: .5em 0;
    background-color: #080808;
    border-radius: 0.3em;
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    white-space: pre;
}

    /* Syntax highlighting for Python in the alternative class format */
    div.lang-python .keyword {
        color: #07a;
    }

    div.lang-python .function {
        color: #DD4A68;
    }

    div.lang-python .string {
        color: #690;
    }

    div.lang-python .number {
        color: #905;
    }

    div.lang-python .comment {
        color: #998;
        font-style: italic;
    }

    div.lang-python .punctuation {
        color: #999;
    }

div[class^="lang-"] {
    display: block;
    overflow-x: auto;
    padding: 1em;
    background-color: #000025;
    color: #DAFC00;
    border-radius: 0.3em;
    font-family: monospace;
    white-space: pre;
}

/* Image thumbnails styling */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.image-thumbnail {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid #ccc;
    transition: transform 0.2s ease;
}

    .image-thumbnail:hover {
        transform: scale(1.1);
    }

    .image-thumbnail img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

/* Image popup styling */
.image-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.image-popup-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background-color: white;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

    .image-popup-content img {
        max-width: 100%;
        max-height: calc(90vh - 40px);
        display: block;
    }

.close-button {
    position: absolute;
    top: -15px;
    right: -15px;
    background-color: #444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

    .close-button:hover {
        background-color: #666;
    }

.dark-theme .image-popup-content {
    background-color: #333;
}

.dark-theme .close-button {
    background-color: #666;
}

/* Bubble footer. Home's conversation-link rules supply both actions' colors and hover. */
.message-footer {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-block-end: 6px;
}

.message-footer-share {
    margin-inline-start: auto;
}

.message-footer .conversation-link {
    box-sizing: border-box;
    line-height: normal;
}

.message-footer .fork-menu-toggle {
    appearance: none;
    border: 0;
    font-family: inherit;
    font-weight: inherit;
    text-align: start;
    cursor: pointer;
}

@media (pointer: coarse) {
    .message-footer .conversation-link {
        min-block-size: 44px;
    }
}

/* Native popover is above the transcript's scroll clip and outside its layout. */
.fork-menu-options {
    display: none;
    position: fixed;
    inset: auto auto max(1rem, env(safe-area-inset-bottom)) 1rem;
    box-sizing: border-box;
    inline-size: max-content;
    max-inline-size: min(15rem, calc(100% - 2rem));
    margin: 0;
    padding: .25rem;
    border: 1px solid #c4cdd8;
    border-radius: .5rem;
    background: #fff;
    color: #202124;
    box-shadow: 0 4px 16px #0003;
    font-size: .875rem;
}

.fork-menu-options:popover-open {
    display: block;
}

@supports (position-area: block-start span-inline-end) {
    .fork-menu-options {
        inset: auto;
        position-area: block-start span-inline-end;
        position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
        justify-self: start;
        margin-block: .25rem;
    }
}

.dark-theme .fork-menu-options {
    border-color: #52617a;
    background: #172235;
    color: #e9edef;
}

.fork-menu-options button {
    display: block;
    inline-size: 100%;
    min-block-size: 44px;
    padding: .4rem .65rem;
    border: 0;
    border-radius: .25rem;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}

.fork-menu-options button:hover,
.fork-menu-options button:focus-visible {
    background: #edf3fa;
}

.dark-theme .fork-menu-options button:hover,
.dark-theme .fork-menu-options button:focus-visible {
    background: #2b3c55;
}

.message-footer .conversation-link:focus-visible,
.fork-menu-options button:focus-visible {
    outline: 2px solid #4185d7;
    outline-offset: -2px;
}

/* Per-block code copy. The control sits outside the code's scrolling surface. */
.markdown-content chat-code-block {
    display: block;
    position: relative;
}

.markdown-content chat-code-block::part(copy),
.markdown-content chat-code-block::part(feedback) {
    position: absolute;
    inset-block-start: .25rem;
    z-index: 1;
    border: 1px solid #718096;
    border-radius: .375rem;
    background: #172334;
    color: #fff;
}

.markdown-content chat-code-block::part(copy) {
    inset-inline-end: .25rem;
    display: grid;
    place-items: center;
    inline-size: 2rem;
    block-size: 2rem;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    cursor: pointer;
}

.markdown-content chat-code-block:is(:hover, :focus-within)::part(copy),
.markdown-content chat-code-block::part(copy-feedback) {
    opacity: 1;
    pointer-events: auto;
}

.markdown-content chat-code-block::part(copy):focus-visible {
    outline: 2px solid #83d6ff;
    outline-offset: 2px;
}

.markdown-content chat-code-block::part(feedback) {
    inset-inline-end: 2.5rem;
    max-inline-size: calc(100% - 3rem);
    padding: .3rem .5rem;
    font-size: .8rem;
    pointer-events: none;
}

.markdown-content chat-code-block::part(feedback):empty {
    opacity: 0;
}

@media (hover: none), (any-pointer: coarse) {
    .markdown-content chat-code-block::part(copy) {
        inline-size: 2.75rem;
        block-size: 2.75rem;
        opacity: 1;
        pointer-events: auto;
    }

    .markdown-content chat-code-block::part(feedback) {
        inset-inline-end: 3.25rem;
        max-inline-size: calc(100% - 3.75rem);
    }
}
