.chat-container {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 520px;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0.35) 100%);
    border: 1px solid var(--border-color, #d8dee4);
    border-radius: 10px;
    box-shadow: 0 24px 54px rgba(15, 23, 42, 0.18);
    color: var(--main-text-color, #1f2433);
    font-family: var(--default-font, 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif);
    overflow: hidden;
    backdrop-filter: blur(10px) saturate(1.25) brightness(1.02);
    -webkit-backdrop-filter: blur(10px) saturate(1.25) brightness(1.02);
    isolation: isolate;
}

.chat-container::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 10px;
    background: linear-gradient(120deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05) 45%, rgba(255, 255, 255, 0.26));
    pointer-events: none;
    mix-blend-mode: screen;
    z-index: 0;
}

.chat-container > * {
    position: relative;
    z-index: 1;
}

/* Chat header */
.chat-header {
    padding: 14px 18px;
    background: transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.chat-header-left {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.chat-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-text-color, #053295);
    margin: 0;
}

.chat-title sup {
    font-size: 10px;
    font-weight: 400;
    color: #949494;
    position: relative;
    top: -9px;
    left: -35px;
}

.minimized .chat-header h1 > sup {
    top: -7px;
}

.chat-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.chat-button {
    padding: 8px 12px;
    border: 1px solid var(--border-color, #d8dee4);
    border-radius: 8px;
    background: #f8f9fb;
    color: var(--main-text-color, #1f2433);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.chat-button:hover {
    background: #eef2f8;
    border-color: var(--secondary-text-color, #0061c8);
}

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

.chat-button-icon {
    padding: 6px 10px;
    min-width: 36px;
    justify-content: center;
}

.chat-button-primary {
    background: var(--secondary-text-color, #0061c8);
    border-color: var(--secondary-text-color, #0061c8);
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(0, 97, 200, 0.25);
}

.chat-button-primary:hover {
    background: #004a9f;
    border-color: #004a9f;
}

.chat-button-ghost {
    background: #ffffff;
    color: var(--main-text-color, #1f2433);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 800px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
}

.assistant-message {
    align-self: flex-start;
}

.error-message {
    align-self: center;
    max-width: 600px;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #605e5c;
}

.message-role {
    font-weight: 600;
}

.message-time {
    opacity: 0.7;
}

.message-content {
    padding: 12px 16px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid var(--border-color, #d8dee4);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    font-size: 14px;
    line-height: 20px;
    color: var(--main-text-color, #1f2433);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.assistant-disclaimer {
    color: #6a6f7b;
    font-size: 12px;
}

.user-message .message-content {
    background: var(--secondary-text-color, #0061c8);
    color: #ffffff;
}

.error-content {
    background: #fef0f1;
    color: #a4262c;
    border: 1px solid #d13438;
}

/* Markdown content styling */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.message-content h1 { font-size: 24px; }
.message-content h2 { font-size: 20px; }
.message-content h3 { font-size: 18px; }
.message-content h4 { font-size: 16px; }
.message-content h5 { font-size: 14px; }
.message-content h6 { font-size: 12px; }

.message-content p {
    margin: 8px 0;
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content code {
    padding: 2px 6px;
    background: #f6f8fb;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 13px;
    color: #1f2937;
}

.message-content pre {
    padding: 0;
    border: 0;
    background: transparent;
    overflow-x: auto;
    margin: 10px 0;
    box-shadow: none;
}

.message-content pre code {
    display: block;
    padding: 10px 12px;
    border: 1px solid #d0d4da;
    background: #f5f6f8;
    color: #111827;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message-content pre code.hljs {
    background: #f5f6f8;
    color: #111827;
}

[data-theme="dark"] .message-content pre code,
[data-theme="dark"] .message-content pre code.hljs {
    background: #1f2937;
    border-color: #2d3648;
    color: #e5e7eb;
}

.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message-content th, .message-content td {
    border: 1px solid #e1e1e1;
    padding: 8px 12px;
    text-align: left;
}


.message-content th {
    background: #e2e7ec; 
    color: #222; 
    font-weight: 400;
}

[data-theme="dark"] .message-content th {
    background: #3e4650;
    color: #f1f3f5;
}

.message-content a {
    color: var(--secondary-text-color, #0061c8);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content blockquote {
    border-left: 4px solid var(--secondary-text-color, #0061c8);
    margin: 8px 0;
    padding-left: 16px;
    color: #605e5c;
}

/* Citation markers */
.citation-marker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    color: #424242;
    cursor: pointer;
    margin: 0 2px;
    background: #ffffff;
    transition: all 0.2s;
}

.citation-marker:hover {
    background: #f3f2f1;
    border-color: var(--secondary-text-color, #0061c8);
    color: var(--secondary-text-color, #0061c8);
    text-decoration: underline;
}

/* Citations footer */
.citations-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e1e1e1;
}

.citations-title {
    font-size: 12px;
    font-weight: 600;
    color: #616161;
    margin-bottom: 8px;
}

.citations-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.citation-item {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border: 1px solid #d1d1d1;
    border-radius: 4px;
    font-size: 12px;
    color: var(--secondary-text-color, #0061c8);
    cursor: pointer;
    transition: all 0.2s;
    background: #ffffff;
}

.citation-item:hover {
    background: #f3f2f1;
    border-color: var(--secondary-text-color, #0061c8);
    text-decoration: underline;
}

/* Input area */
.chat-input-container {
    padding: 14px 18px 16px;
    border-top: 1px solid var(--border-color, #d8dee4);
}

.chat-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    border: 1px solid var(--border-color, #d8dee4);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1);
}

.chat-input-wrapper:focus-within {
    border-color: var(--secondary-text-color, #0061c8);
    box-shadow: 0 0 0 3px rgba(0, 97, 200, 0.12);
}

#chat-input-field {
    --chat-input-line-height: 22px;
    --chat-input-min-height: 48px;
    --chat-input-padding-inline: 12px;
    flex: 1;
    box-sizing: border-box;
    border: none;
    outline: none;
    font-size: 14px;
    line-height: var(--chat-input-line-height);
    resize: none;
    min-height: var(--chat-input-min-height);
    max-height: 200px;
    font-family: inherit;
    padding: 12px var(--chat-input-padding-inline);
    background: transparent;
    color: var(--main-text-color, #1f2433);
    align-self: center;
}

.chat-input-wrapper #chat-input-field.single-line {
    padding-block: calc((var(--chat-input-min-height, 48px) - var(--chat-input-line-height, 22px)) / 2);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chat-send-button {
    position: relative;
    width: 46px;
    height: 46px;
    padding: 0;
    background: var(--button-primary-color, var(--secondary-text-color, #0061c8));
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.1s, background-color 0.2s, box-shadow 0.2s, color 0.2s;
    box-shadow: 0 10px 22px rgba(0, 97, 200, 0.25);
}

#chat-send-button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: #004a9f;
}

#chat-send-button:active:not(:disabled) {
    transform: translateY(0);
}

#chat-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#chat-send-button::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid transparent;
    opacity: 0;
    pointer-events: none;
}

#chat-send-button.is-loading {
    background: #c53030;
    box-shadow: 0 10px 22px rgba(197, 48, 48, 0.25);
}

#chat-send-button.is-loading:hover {
    background: #b91c1c;
}

#chat-send-button.is-loading::after {
    border-color: rgba(197, 48, 48, 0.2);
    border-top-color: #fca5a5;
    animation: send-ring-spin 1s linear infinite;
    opacity: 1;
}

#chat-send-button .stop-icon {
    display: none;
}

#chat-send-button.is-loading .send-icon {
    display: none;
}

#chat-send-button.is-loading .stop-icon {
    display: inline-flex;
}

#chat-send-button i {
    pointer-events: none;
}

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

/* Loading indicator */
#chat-loading {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    color: #605e5c;
    font-size: 14px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e1e1e1;
    border-top-color: #0078d4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

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

/* Citation panel */
#citation-panel {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    background: #ffffff;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

#citation-panel.open {
    right: 0;
}

.citation-panel-header {
    padding: 16px 24px;
    background: #f3f2f1;
    border-bottom: 1px solid #e1e1e1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.citation-panel-title {
    font-size: 18px;
    font-weight: 600;
    color: #323130;
}

#citation-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #605e5c;
    padding: 4px 8px;
}

#citation-close:hover {
    color: #323130;
}

#citation-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.citation-metadata {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e1e1e1;
}

.citation-title {
    font-size: 16px;
    font-weight: 600;
    color: #323130;
    margin-bottom: 8px;
}

.citation-url {
    font-size: 12px;
    color: #0078d4;
}

.citation-url a {
    color: inherit;
    text-decoration: none;
}

.citation-url a:hover {
    text-decoration: underline;
}

/* Error container */
#chat-error {
    padding: 12px 24px;
    background: #fef0f1;
    color: #a4262c;
    border-left: 4px solid #d13438;
    margin: 16px 24px;
    border-radius: 4px;
    display: none;
}

/* Floating widget variations */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: min(520px, calc(100vw - 48px));
    max-height: calc((100vh - 120px) * 0.75);
    min-height: 420px;
    border-radius: 10px;
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.2);
    z-index: 5000;
    resize: none;
    transition: width 220ms ease, height 220ms ease, transform 220ms ease, box-shadow 220ms ease, opacity 180ms ease;
    transform-origin: bottom right;
}

.chat-widget .chat-header {
    cursor: default;
    user-select: none;
    border-bottom: 1px solid var(--border-color, #d8dee4);
}

.chat-widget .chat-header button#chat-minimize-widget {
    margin-left: -35px;
}

.chat-widget.minimized {
    height: auto;
    min-height: 0;
    max-height: none;
    width: min(408px, calc(100vw - 48px));
}

.chat-widget.minimized .chat-header {
    border-bottom: none;
    padding-block: 10px 6px;
}

.chat-widget.minimized .chat-title {
    font-size: 15px;
}

.chat-widget.minimized .chat-actions {
    gap: 6px;
}

.chat-widget.minimized #chat-expand-widget {
    display: none;
}

.chat-widget.minimized .chat-input-container {
    display: block;
    padding: 10px 14px 14px;
    border-top: none;
}

.chat-widget.minimized .chat-input-wrapper {
    border-radius: 10px;
    padding: 12px 12px 12px 16px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

.chat-widget.minimized #chat-input-field {
    min-height: 36px;
    font-size: 15px;
}

.chat-widget.minimized .input-actions {
    align-items: center;
}

.chat-widget.minimized #chat-send-button {
    background: #002169;
    box-shadow: 0 12px 22px rgba(0, 33, 105, 0.25);
}

.chat-widget.minimized .chat-messages,
.chat-widget.minimized #chat-loading {
    display: none;
}

.chat-widget.expanded {
    top: auto;
    bottom: 24px;
    right: 24px;
    left: auto;
    width: min(1040px, calc((100vw - 48px) * 2), calc(100vw - 58px));
    max-width: min(1040px, calc((100vw - 48px) * 2), calc(100vw - 58px));
    max-height: calc((100vh - 34px) * 0.86);
    resize: none;
}

.chat-widget.expanded .chat-header {
    cursor: default;
}

.chat-widget + #citation-panel {
    display: none;
}

.chat-widget.expanding {
    animation: chat-expand 220ms ease-out;
}

.chat-widget.collapsing {
    animation: chat-collapse 200ms ease-in;
}

#chat-clear-button {
    transition: opacity 140ms ease, transform 140ms ease;
}

.chat-widget.minimized #chat-clear-button {
    display: none;
}

.chat-empty-state {
    padding: 16px 18px;
    border-radius: 10px;
    border: 1px solid var(--border-color, #d8dee4);
    background: rgba(255, 255, 255, 0.4);
    color: var(--main-text-color, #1f2433);
    line-height: 1.5;
    font-size: 14px;
    box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.06);
}

@keyframes chat-expand {
    0% {
        transform: scale(0.94);
        opacity: 0.92;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes chat-collapse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(0.97);
        opacity: 0.92;
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .chat-container {
        border-radius: 0;
        box-shadow: none;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-container {
        padding: 12px 16px;
    }

    #citation-panel {
        width: 100%;
        right: -100%;
    }

    #citation-panel.open {
        right: 0;
    }

    .message-content {
        max-width: 100%;
    }

    .chat-widget {
        bottom: 16px;
        right: 16px;
        left: auto;
        width: min(460px, calc(100vw - 32px));
        max-height: calc((100vh - 120px) * 0.75);
        min-height: 300px;
        border-radius: 10px;
    }

    .chat-widget.expanded {
        top: auto;
        right: 16px;
        bottom: 16px;
        left: auto;
        width: min(460px, calc(100vw - 50px));
        max-width: min(460px, calc(100vw - 50px));
        max-height: calc((100vh - 120px) * 0.75);
        min-height: 600px;
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles */
*:focus-visible {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
}
