html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    margin: 0;
}

body > .alert {
    flex: 0 0 auto;
}

.chatbot-container {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    background-color: var(--da-surface);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
}

.chatbot-container.chatbot-loading .chatbot-sidebar,
.chatbot-container.chatbot-loading .chatbot-main {
    visibility: hidden;
}


.skeleton-msg {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
}

.skeleton-bubble {
    height: 14px;
    border-radius: 12px;
    background: linear-gradient(90deg, #e6e6e6 25%, #f5f5f5 50%, #e6e6e6 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.chat-skeleton-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--da-border-strong);
}

.chat-skeleton-line {
    height: 10px;
    background: var(--da-surface-alt);
    border-radius: 4px;
    margin: 6px 0;
    animation: shimmer 1.2s infinite linear;
}

.chat-skeleton-line.short {
    width: 40%;
}

.chat-skeleton-line.long {
    width: 80%;
}

@keyframes shimmer {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

.chat-skeleton-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--da-border-strong);
}

.chat-skeleton-line {
    height: 10px;
    background: var(--da-surface-alt);
    border-radius: 4px;
    margin: 6px 0;
    animation: shimmer 1.2s infinite linear;
}

.chat-skeleton-line.short {
    width: 40%;
}

.chat-skeleton-line.long {
    width: 80%;
}

@keyframes shimmer {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

.chatbot-sidebar {
    width: 280px;
    flex: 0 0 280px;
    min-height: 0;
    background-color: var(--da-surface-alt);
    border-right: 1px solid var(--da-border-strong);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatbot-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--da-border-strong);
}

.chatbot-sidebar-header .btn-primary {
    background-color: #0078d4;
    border-color: #0078d4;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 4px;
    white-space: nowrap;
}

.chatbot-sidebar-header .btn-primary:hover {
    background-color: #005a9e;
    border-color: #005a9e;
}

.chatbot-search-box {
    padding: 12px 16px;
    border-bottom: 1px solid var(--da-border-strong);
}

.chatbot-search-box .form-control {
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid var(--da-border-strong);
    padding: 6px 10px;
    height: auto;
}

.chatbot-search-box .form-control::placeholder {
    color: #a8a8a8;
}

.chatbot-search-box .form-control:focus {
    border-color: #0078d4;
    box-shadow: 0 0 0 0.2rem rgba(0, 120, 212, 0.25);
}

.chatbot-chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chatbot-chats-list ul {
    margin: 0;
    padding: 0;
}

.chatbot-chat-item {
    padding: 12px;
    margin-bottom: 6px;
    background-color: var(--da-surface);
    border: 1px solid var(--da-border-strong);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chatbot-chat-item-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.chatbot-chat-item:hover {
    background-color: var(--da-surface-alt);
    border-color: #0078d4;
}

.chatbot-chat-item.active {
    background-color: var(--da-row-selected);
    border-color: #0078d4;
}

.chatbot-chat-item.active .chatbot-chat-item-title,
.chatbot-chat-item.active .chatbot-chat-item-date {
    color: var(--da-text);
}

.chatbot-chat-item-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--da-text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chatbot-chat-item-title-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.chatbot-chat-menu-btn {
    background: none;
    border: none;
    color: #a8a8a8;
    cursor: pointer;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.chatbot-chat-item:hover .chatbot-chat-menu-btn {
    opacity: 1;
}

.chatbot-chat-menu-btn:hover {
    color: #0078d4;
}

.chatbot-context-menu {
    background: var(--da-surface);
    border: 1px solid var(--da-border-strong);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    min-width: 120px;
}

.chatbot-context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    color: var(--da-text);
    transition: background-color 0.2s ease;
}

.chatbot-context-menu-item:hover {
    background-color: var(--da-surface-alt);
}

.chatbot-context-menu-item:first-child {
    border-radius: 4px 4px 0 0;
}

.chatbot-context-menu-item:last-child {
    border-radius: 0 0 4px 4px;
}

.chatbot-chat-item-date {
    font-size: 11px;
    color: #a8a8a8;
}

.chatbot-empty-state {
    padding: 20px;
    text-align: center;
}

.chatbot-empty-state p {
    font-size: 12px;
    margin: 0;
}

.chatbot-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--da-surface);
    overflow: hidden;
}

.chatbot-header {
    padding: 16px;
    border-bottom: 1px solid var(--da-border-strong);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--da-surface);
}

.chatbot-header h5 {
    font-size: 14px;
    font-weight: 600;
    color: var(--da-text);
    margin: 0;
}

.chatbot-header-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chatbot-header-title-wrap h5 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-edit-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    outline: none;
    box-shadow: none;
    background-color: transparent;
    color: var(--da-text);
}

.chatbot-edit-btn:hover {
    background-color: var(--da-surface-alt);
    border: none;
    color: #1f1f1f;
}

.chatbot-edit-btn:focus,
.chatbot-edit-btn:focus-visible,
.chatbot-edit-btn:active {
    outline: none;
    box-shadow: none;
    border: none;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: var(--da-surface);
}

.chatbot-welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.chatbot-welcome p {
    font-size: 13px;
    color: #a8a8a8;
    margin: 0;
}

.chatbot-messages-loader {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #667085;
}

.chatbot-messages-loader p {
    margin: 0;
    font-size: 13px;
}

.chatbot-messages-loader-spinner {
    width: 26px;
    height: 26px;
    border: 3px solid #e5e7eb;
    border-top-color: #0078d4;
    border-radius: 50%;
    animation: chatbotMessagesLoaderSpin 0.9s linear infinite;
}

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

.chatbot-message {
    display: flex;
    margin-bottom: 0;
    animation: fadeIn 0.3s ease-in;
}

.chatbot-message-wrapper.chatbot-message-active-nav .chatbot-message-content {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 120, 212, 0.15);
}

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

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

.chatbot-message.user {
    justify-content: flex-end;
}

.chatbot-message.user .chatbot-message-content {
    background-color: #0078d4;
    color: #ffffff;
    border-radius: 12px 12px 0 12px;
}

.chatbot-message.assistant {
    justify-content: flex-start;
}

.chatbot-message.assistant .chatbot-message-content {
    background-color: var(--da-surface-alt);
    color: var(--da-text);
    border-radius: 12px 12px 12px 0;
    max-width: 88%;
}

.chatbot-message.error {
    justify-content: flex-start;
}

.chatbot-message.error .chatbot-message-content {
    background-color: #fde7e9;
    color: #a4262c;
    border: 1px solid #f1b2b7;
    border-radius: 12px 12px 12px 0;
    max-width: 88%;
}

.chatbot-message-content {
    max-width: 70%;
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

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

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

.chatbot-message-content pre {
    background: #1f2933;
    color: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.chatbot-message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: Consolas, "Courier New", monospace;
}

.chatbot-message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.chatbot-message-content blockquote {
    margin: 8px 0;
    padding-left: 10px;
    border-left: 3px solid #cbd5e1;
    color: #475569;
}

.chatbot-message-content h1,
.chatbot-message-content h2,
.chatbot-message-content h3,
.chatbot-message-content h4,
.chatbot-message-content h5,
.chatbot-message-content h6 {
    margin: 0 0 8px;
    line-height: 1.3;
}

.chatbot-message-content h1 {
    font-size: 24px;
}

.chatbot-message-content h2 {
    font-size: 20px;
}

.chatbot-message-content h3 {
    font-size: 17px;
}

.chatbot-message-content h4,
.chatbot-message-content h5,
.chatbot-message-content h6 {
    font-size: 14px;
}

.chatbot-message-content hr {
    border: 0;
    border-top: 1px solid #d6d6d6;
    margin: 10px 0;
}

.chatbot-table-wrap {
    width: 100%;
    overflow-x: auto;
    margin: 8px 0;
}

.chatbot-markdown-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
    background: var(--da-surface);
    border: 1px solid var(--da-border-strong);
    border-radius: 8px;
}

.chatbot-markdown-table th,
.chatbot-markdown-table td {
    border: 1px solid #e5e7eb;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
    white-space: normal;
    word-break: break-word;
}

.chatbot-markdown-table th {
    background: var(--da-surface-alt);
    font-weight: 600;
}

.chatbot-message.typing .chatbot-message-content {
    background-color: var(--da-surface-alt);
    color: var(--da-text);
    border-radius: 12px 12px 12px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 40px;
}

.chatbot-typing-text {
    font-size: 12px;
    color: var(--da-text-secondary);
    margin-right: 4px;
}

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

.chatbot-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #0078d4;
    animation: chatbotTypingPulse 1.2s infinite ease-in-out;
}

.chatbot-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatbotTypingPulse {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chatbot-input-area {
    padding: 16px;
    border-top: 1px solid var(--da-border-strong);
    background-color: var(--da-surface);
}

.chatbot-input-area .input-group {
    display: flex;
    gap: 8px;
}

.chatbot-input-area .form-control {
    font-size: 12px;
    border: 1px solid var(--da-border-strong);
    border-radius: 4px;
    padding: 8px 12px;
    height: auto;
    min-height: 38px;
    max-height: 200px;
    resize: none;
    overflow-y: hidden;
}

.chatbot-input-area .form-control::placeholder {
    color: #a8a8a8;
}

.chatbot-input-area .form-control:focus {
    border-color: #0078d4;
    box-shadow: 0 0 0 0.2rem rgba(0, 120, 212, 0.25);
}

.chatbot-input-area .btn-primary {
    background-color: #0078d4;
    border-color: #0078d4;
    font-size: 12px;
    padding: 8px 16px;
    border-radius: 4px;
    white-space: nowrap;
    height: fit-content;
    align-self: center;
}

.chatbot-input-area .btn-primary:hover {
    background-color: #005a9e;
    border-color: #005a9e;
}

.chatbot-input-area .btn-primary:disabled {
    background-color: #c8c6c4;
    border-color: var(--da-border-strong);
    cursor: not-allowed;
}

.chatbot-messages::-webkit-scrollbar,
.chatbot-chats-list::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track,
.chatbot-chats-list::-webkit-scrollbar-track {
    background: var(--da-surface-alt);
}

.chatbot-messages::-webkit-scrollbar-thumb,
.chatbot-chats-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover,
.chatbot-chats-list::-webkit-scrollbar-thumb:hover {
    background: #888;
}

.chatbot-message-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 0;
}

.chatbot-message-wrapper .chatbot-message {
    flex: 1;
    margin-bottom: 0;
}

.chatbot-message-content.error-message {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.chatbot-message-content.error-message span {
    flex: 1;
}

.chatbot-retry-btn {
    background: none;
    border: none;
    color: #a4262c;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.chatbot-retry-btn:hover {
    color: #752b2f;
    background-color: rgba(164, 38, 44, 0.1);
    border-radius: 4px;
}

.chatbot-retry-btn:active {
    transform: scale(0.9);
}

@media (max-width: 768px) {
    .chatbot-container {
        flex-direction: column;
    }

    .chatbot-sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--da-border-strong);
    }

    .chatbot-messages {
        padding: 14px 12px;
    }

    .chatbot-message-content {
        max-width: 92%;
        padding: 11px 13px;
        font-size: 12.5px;
    }
}

/* --- Staged attachments (composer) ------------------------------ */
.chatbot-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.chatbot-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 220px;
    padding: 2px 4px 2px 8px;
    border: 1px solid var(--da-border-strong);
    border-radius: 14px;
    background: var(--da-surface-alt);
    color: var(--da-text);
    font-size: 12px;
}

.chatbot-chip i {
    color: var(--da-primary-text);
    font-size: 12px;
    flex-shrink: 0;
}

.chatbot-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatbot-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--da-text-secondary);
    cursor: pointer;
    padding: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chatbot-chip-remove:hover {
    background: var(--da-row-hover);
    color: var(--da-text);
}

#attachFileBtn {
    flex: 0 0 auto;
}

#attachFileBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-message-stack {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 70%;
    min-width: 0;
}

.chatbot-message.user .chatbot-message-stack {
    align-items: flex-end;
}

.chatbot-message.assistant .chatbot-message-stack,
.chatbot-message.error .chatbot-message-stack {
    align-items: flex-start;
}

/* The stack already carries the width cap the bubble would otherwise apply to itself. */
.chatbot-message-stack .chatbot-message-content {
    max-width: 100%;
}

.chatbot-attachment-grid {
    display: grid;
    gap: 4px;
    max-width: 320px;
}

/* One image gets the full bubble width; two or three share a row, as in the composer preview. */
.chatbot-attachment-grid.count-1 { grid-template-columns: 1fr; }
.chatbot-attachment-grid.count-2 { grid-template-columns: repeat(2, 1fr); }
.chatbot-attachment-grid.count-3 { grid-template-columns: repeat(3, 1fr); }

.chatbot-attachment-tile {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 1px solid var(--da-border-strong);
    border-radius: 8px;
    overflow: hidden;
    background: var(--da-surface-alt);
    cursor: pointer;
    aspect-ratio: 1 / 1;
}

.chatbot-attachment-grid.count-1 .chatbot-attachment-tile {
    aspect-ratio: 4 / 3;
    max-height: 320px;
}

.chatbot-attachment-tile:not(.loaded)::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
            var(--da-surface-alt) 25%,
            var(--da-row-hover) 50%,
            var(--da-surface-alt) 75%);
    background-size: 200% 100%;
    animation: chatbot-attachment-shimmer 1.2s ease-in-out infinite;
}

@keyframes chatbot-attachment-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.chatbot-attachment-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 0.15s ease-in;
}

.chatbot-attachment-tile.loaded img {
    opacity: 1;
}

.chatbot-attachment-tile.failed::after {
    content: "\F33A";
    font-family: "bootstrap-icons";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--da-text-disabled);
    font-size: 20px;
}

.chatbot-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--da-border-strong);
    border-radius: 8px;
    background: var(--da-surface-alt);
    color: var(--da-text);
    font-size: 12px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Lightbox --------------------------------------------------- */
.chatbot-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.75);
    cursor: zoom-out;
}

.chatbot-lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}