:root {
    --chat-accent: #ff7a00;
    --chat-accent-hover: #e06b00;
    --chat-bg: #e5eaf2;
    --chat-surface: #e5eaf2;
    --chat-border: #ffffff;
    --chat-text: #1e293b;
    --chat-text-muted: #6b7280;
    --chat-user-bg: #e5eaf2;
    --chat-user-text: #ff7a00;
    --chat-bot-bg: #e5eaf2;
    --chat-bot-text: #1f2937;
    --chat-shadow: 8px 8px 18px rgba(150, 168, 196, 0.45), -8px -8px 18px #ffffff;
}

#rag-chatbot-root *, #rag-chatbot-root *::before, #rag-chatbot-root *::after {
    border-color: transparent !important;
}

body.dark-mode {
    --chat-bg: #1e2025;
    --chat-surface: #1e2025;
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-text: #f9fafb;
    --chat-text-muted: #9ca3af;
    --chat-bot-bg: #1e2025;
    --chat-bot-text: #e5e7eb;
    --chat-shadow: 12px 12px 24px #14161a, -12px -12px 24px #282a30;
}

.chatbot-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--chat-bg);
    color: var(--chat-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        4px 4px 10px rgba(165, 177, 198, 0.22),
        -4px -4px 10px rgba(255, 255, 255, 0.95);
    z-index: 99999;
    transition:
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.25s ease,
        color 0.2s ease;
    outline: none;
    pointer-events: auto;
}

.chatbot-trigger:hover {
    transform: scale(1.06);
    color: var(--chat-accent-hover);
    box-shadow:
        6px 6px 14px rgba(165, 177, 198, 0.28),
        -6px -6px 14px rgba(255, 255, 255, 1),
        0 0 12px rgba(255, 122, 0, 0.25);
}

.chatbot-trigger:active {
    box-shadow:
        inset 4px 4px 8px rgba(165, 177, 198, 0.35),
        inset -4px -4px 8px rgba(255, 255, 255, 0.95);
    transform: scale(0.96);
}

.chatbot-trigger svg {
    pointer-events: none;
    position: absolute;
    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
}

.chatbot-trigger .trigger-icon-open {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chatbot-trigger .trigger-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

.chatbot-trigger.active .trigger-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

.chatbot-trigger.active .trigger-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chatbot-window {
    position: fixed;
    bottom: 88px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 110px);
    background: var(--chat-bg);
    border: none;
    border-radius: 24px;
    box-shadow:
        10px 10px 24px rgba(145, 163, 190, 0.35),
        -10px -10px 24px rgba(255, 255, 255, 0.65);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition:
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0.3s ease;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-header {
    padding: 14px 18px;
    background: var(--chat-surface);
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

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

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--chat-bg);
    box-shadow:
        4px 4px 8px #a3b1c6,
        -4px -4px 8px #ffffff;
    color: var(--chat-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    border: none;
}

.chat-title-group h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--chat-text);
    margin: 0;
    line-height: 1.2;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--chat-text-muted);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.chat-close-btn {
    background: var(--chat-bg);
    box-shadow:
        3px 3px 6px #a3b1c6,
        -3px -3px 6px #ffffff;
    border: none;
    color: var(--chat-text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        color 0.2s ease,
        box-shadow 0.2s ease;
}

.chat-close-btn:hover {
    color: var(--chat-accent);
    box-shadow:
        inset 3px 3px 6px #a3b1c6,
        inset -3px -3px 6px #ffffff;
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: var(--chat-bg);
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(163, 177, 198, 0.6);
    border-radius: 4px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeInMsg 0.25s ease-out forwards;
}

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

.chat-msg.user {
    align-self: flex-end;
}

.chat-msg.bot {
    align-self: flex-start;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg.user .msg-bubble {
    background: var(--chat-bg);
    color: var(--chat-accent);
    font-weight: 600;
    box-shadow:
        inset 4px 4px 8px #a3b1c6,
        inset -4px -4px 8px #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-msg.bot .msg-bubble {
    background: var(--chat-bg);
    color: var(--chat-text);
    box-shadow:
        6px 6px 12px #a3b1c6,
        -6px -6px 12px #ffffff;
    border-bottom-left-radius: 4px;
    border: none;
}

.chat-msg.bot .msg-bubble p {
    margin: 0 0 6px 0;
    text-align: left;
    line-height: 1.5;
}

.chat-msg.bot .msg-bubble p:last-child {
    margin-bottom: 0;
}

.chat-heading {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--chat-text);
    margin: 10px 0 4px 0;
    line-height: 1.3;
}

.chat-heading:first-child {
    margin-top: 0;
}

.chat-list {
    margin: 6px 0 8px 18px;
    padding: 0;
    list-style-type: disc;
}

.chat-list li {
    margin-bottom: 4px;
    line-height: 1.45;
}

.chat-list li:last-child {
    margin-bottom: 0;
}

.chat-msg.bot .msg-bubble a {
    color: var(--chat-accent);
    text-decoration: underline;
    font-weight: 600;
    word-break: break-all;
    transition: color 0.2s ease;
}

.chat-msg.bot .msg-bubble a:hover {
    color: var(--chat-accent-hover);
}

.chat-msg.bot .msg-bubble code {
    background: var(--chat-bg);
    box-shadow:
        inset 2px 2px 4px #a3b1c6,
        inset -2px -2px 4px #ffffff;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "Consolas", "Fira Code", monospace;
    font-size: 0.82rem;
    color: var(--chat-accent);
}

.chat-msg.bot .msg-bubble pre {
    background: var(--chat-bg);
    box-shadow:
        inset 4px 4px 8px #a3b1c6,
        inset -4px -4px 8px #ffffff;
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: "Consolas", "Fira Code", monospace;
    font-size: 0.8rem;
    margin: 8px 0;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--chat-bg);
    box-shadow:
        4px 4px 8px #a3b1c6,
        -4px -4px 8px #ffffff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    border: none;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-accent);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}
.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px 16px;
    background: var(--chat-bg);
}

.suggestion-chip {
    background: var(--chat-bg);
    box-shadow:
        4px 4px 8px #a3b1c6,
        -4px -4px 8px #ffffff;
    border: none;
    color: var(--chat-text);
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.suggestion-chip:hover {
    box-shadow:
        inset 3px 3px 6px #a3b1c6,
        inset -3px -3px 6px #ffffff;
    color: var(--chat-accent);
}

.chat-input-form {
    padding: 12px 14px;
    background: var(--chat-bg);
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-input {
    flex: 1;
    background: var(--chat-bg);
    box-shadow:
        inset 3px 3px 8px rgba(145, 163, 190, 0.35),
        inset -3px -3px 8px rgba(255, 255, 255, 0.5);
    border: none;
    color: var(--chat-text);
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 0.88rem;
    outline: none;
    transition: all 0.2s ease;
}

.chat-input:focus {
    box-shadow:
        inset 2px 2px 4px rgba(165, 177, 198, 0.1),
        inset -2px -2px 4px #ffffff,
        0 0 0 2px rgba(255, 122, 0, 0.35);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--chat-bg);
    box-shadow:
        4px 4px 8px #a3b1c6,
        -4px -4px 8px #ffffff;
    border: none;
    color: var(--chat-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    box-shadow:
        inset 3px 3px 6px #a3b1c6,
        inset -3px -3px 6px #ffffff;
    color: var(--chat-accent-hover);
    transform: scale(0.96);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 480px) {
    .chatbot-trigger {
        bottom: 18px;
        right: 18px;
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }

    .chatbot-window {
        bottom: 76px;
        right: 14px;
        left: 14px;
        width: auto;
        max-width: none;
        height: 75vh;
        max-height: 520px;
    }
}
