.chatbot-container {
    --cb-dark: #1a1a1a;
    --cb-dark-2: #2d2d2d;
    --cb-dark-3: #111111;
    --cb-accent: #ffff40;
    --cb-accent-warm: #ffd700;
    --cb-accent-glow: rgba(255, 255, 64, 0.22);
    --cb-white: #ffffff;
    --cb-surface: #f7f8fa;
    --cb-border: #e8ecf0;
    --cb-text: #111827;
    --cb-text-sub: #6b7280;
    --cb-text-xs: #9ca3af;
    --cb-online: #22c55e;
    --cb-online-glow: rgba(34, 197, 94, 0.45);
    --cb-error-bg: #fef2f2;
    --cb-error-border: #fecaca;
    --cb-error-text: #b91c1c;
    --cb-shadow-pop: 0 20px 52px rgba(0, 0, 0, 0.15), 0 5px 16px rgba(0, 0, 0, 0.08);
    --cb-shadow-msg: 0 1px 3px rgba(0, 0, 0, 0.07);
    --cb-ease: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    --cb-spring: 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chatbot-container,
.chatbot-container * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: 12px;
    line-height: 1.5;
}

body.chatbot-fullscreen-open {
    overflow: hidden;
}

.chatbot-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.38s ease;
    z-index: 9998;
}

.chatbot-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.chatbot-fab {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 0;
    background: linear-gradient(145deg, var(--cb-dark-3) 0%, var(--cb-dark-2) 100%);
    border: 2px solid var(--cb-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.26);
    transition: transform var(--cb-spring), box-shadow var(--cb-ease);
    animation: cbFabPulse 3.5s ease-in-out infinite;
    flex-shrink: 0;
}

.chatbot-fab::before {
    content: '';
    position: absolute;
    inset: -7px;
    border-radius: 0;
    border: 2px solid var(--cb-accent);
    opacity: 0;
    animation: cbRipple 3.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes cbFabPulse {

    0%,
    100% {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.26), 0 0 0 0 var(--cb-accent-glow);
    }

    50% {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.26), 0 0 0 10px rgba(255, 255, 64, 0);
    }
}

@keyframes cbRipple {
    0% {
        opacity: 0.45;
        transform: scale(0.85);
    }

    100% {
        opacity: 0;
        transform: scale(1.3);
    }
}

.chatbot-fab:hover {
    transform: scale(1.07) translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 0 7px var(--cb-accent-glow);
    animation: none;
}

.chatbot-fab.hidden {
    display: none;
}

.fab-icon {
    width: 26px;
    height: 26px;
    filter: brightness(0) invert(1);
    transition: transform var(--cb-spring);
    pointer-events: none;
}

.chatbot-fab:hover .fab-icon {
    transform: scale(1.08);
}

.fab-tooltip {
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    background: var(--cb-dark);
    color: var(--cb-white);
    font-size: 11px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 0;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--cb-ease), transform var(--cb-ease);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 64, 0.18);
}

.fab-tooltip::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-left-color: var(--cb-dark);
}

.chatbot-fab:hover .fab-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.chatbot-popup {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 300px;
    height: 350px;
    max-height: calc(100vh - 100px);
    background: var(--cb-white);
    border-radius: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-left: 3px solid var(--cb-accent);
    box-shadow: var(--cb-shadow-pop);
    display: none;
    opacity: 0;
    transform: translateY(16px);
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
}

.chatbot-popup.cb-transitioning {
    transition: width 0.42s ease, height 0.42s ease,
        bottom 0.42s ease, right 0.42s ease,
        box-shadow 0.42s ease;
}

.chatbot-popup.open {
    display: flex;
    animation: cbSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.chatbot-popup.fullscreen {
    width: min(760px, 100vw);
    height: min(640px, 100vh);
    bottom: max(0px, calc(50vh - 320px));
    right: max(0px, calc(50vw - 380px));
    max-height: 100vh;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.32), 0 8px 24px rgba(0, 0, 0, 0.14);
}

@keyframes cbSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-header {
    background: linear-gradient(135deg, var(--cb-dark-3) 0%, var(--cb-dark-2) 100%);
    padding: 10px 12px 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
    position: relative;
}

.chatbot-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg,
            transparent 0%, var(--cb-accent) 25%,
            var(--cb-accent-warm) 60%, transparent 100%);
    background-size: 200% 100%;
    animation: cbShimmer 2.8s linear infinite;
}

@keyframes cbShimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.chatbot-header-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
}

.chatbot-avatar-ring {
    position: relative;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
}

.chatbot-avatar-img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: contain;
    background: rgba(255, 255, 64, 0.09);
    border: 2px solid rgba(255, 255, 64, 0.32);
    padding: 6px;
    filter: brightness(0) invert(1);
}

.chatbot-online-ring {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--cb-online);
    border: 2px solid var(--cb-dark-3);
    animation: cbOnlinePing 2.5s ease-in-out infinite;
}

@keyframes cbOnlinePing {

    0%,
    100% {
        box-shadow: 0 0 0 0 var(--cb-online-glow);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

.chatbot-header-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chatbot-bot-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--cb-white);
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.chatbot-header-controls {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-shrink: 0;
}

.chatbot-ctrl-btn {
    width: 28px;
    height: 28px;
    border-radius: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.68);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--cb-ease);
    outline: none;
}

.chatbot-ctrl-btn:hover {
    background: rgba(255, 255, 64, 0.12);
    border-color: rgba(255, 255, 64, 0.32);
    color: var(--cb-accent);
    transform: scale(1.08);
}

.chatbot-close-ctrl:hover {
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.32);
    color: #f87171;
    transform: rotate(90deg) scale(1.08);
}

.ctrl-icon {
    display: block;
    pointer-events: none;
}

.icon-compress {
    display: none;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px 10px;
    background: var(--cb-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    font-size: 12px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 3px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.13);
    border-radius: 0;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.24);
}

.chatbot-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
    animation: cbMsgIn 0.26s ease;
}

.chatbot-message.bot {
    flex-direction: row;
}

.chatbot-message.user {
    flex-direction: row-reverse;
}

@keyframes cbMsgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cb-dark-3), var(--cb-dark-2));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 5px;
}

.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.chatbot-message.bot .msg-body {
    max-width: calc(100% - 36px);
}

.chatbot-message.user .msg-body {
    max-width: 80%;
}

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chatbot-message.user .msg-body {
    align-items: flex-end;
}

.chatbot-message.bot:not(.typing) {
    display: grid;
    grid-template-areas:
        "avatar  bubble"
        ".       footer";
    grid-template-columns: 28px 1fr;
    column-gap: 8px;
    row-gap: 4px;
    align-items: unset;
    width: 100%;
}

.chatbot-message.bot:not(.typing) .msg-body {
    display: contents;
}

.chatbot-message.bot:not(.typing) .msg-avatar {
    grid-area: avatar;
    align-self: end;
}

.chatbot-message.bot:not(.typing) .msg-bubble {
    grid-area: bubble;
}

.chatbot-message.bot:not(.typing) .msg-footer {
    grid-area: footer;
    align-self: start;
}

.chatbot-message.bot.typing {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chatbot-message.bot.typing .msg-body {
    display: flex;
    flex-direction: column;
}

.msg-bubble {
    position: relative;
    padding: 8px 12px;
    border-radius: 0;
    font-size: 12px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    overflow: visible;
}

.chatbot-message.bot .msg-bubble {
    background: var(--cb-white);
    color: var(--cb-text);
    border: 1px solid var(--cb-border);
    box-shadow: var(--cb-shadow-msg);
}

.chatbot-message.user .msg-bubble {
    background: linear-gradient(135deg, var(--cb-dark-3) 0%, var(--cb-dark-2) 100%);
    color: var(--cb-white);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chatbot-message.bot.error .msg-bubble {
    background: var(--cb-error-bg);
    border-color: var(--cb-error-border);
    color: var(--cb-error-text);
}

.message-info {
    margin-top: 8px;
    font-size: 11px;
    color: var(--cb-text-sub);
    line-height: 1.5;
    border-top: 1px solid var(--cb-border);
    padding-top: 7px;
    font-style: italic;
}

.message-reference {
    margin-top: 7px;
}

.message-reference a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--cb-dark);
    background: var(--cb-accent);
    border-radius: 0;
    text-decoration: none;
    transition: all var(--cb-ease);
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.26);
    white-space: nowrap;
}

.message-reference a:hover {
    transform: translateY(-1px);
    background: var(--cb-accent-warm);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.42);
}

.msg-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 18px;
}

.chatbot-message.user .msg-footer {
    flex-direction: row-reverse;
}

.msg-time {
    font-size: 10px;
    color: var(--cb-text-xs);
    white-space: nowrap;
    user-select: none;
    flex-shrink: 0;
}

.message-actions {
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity var(--cb-ease);
}

.chatbot-message:hover .message-actions {
    opacity: 1;
}

.message-copy {
    width: 22px;
    height: 22px;
    border-radius: 0;
    border: 1px solid var(--cb-border);
    background: var(--cb-white);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--cb-ease);
    padding: 0;
    flex-shrink: 0;
}

.message-copy img {
    width: 11px;
    height: 11px;
    pointer-events: none;
}

.message-copy:hover {
    background: #fff7c2;
    border-color: var(--cb-accent-warm);
    transform: scale(1.08);
}

.chatbot-message.typing {
    align-items: flex-end;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 8px;
    background: var(--cb-white);
    border-radius: 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #c4c9d4;
    animation: cbTyping 1.4s ease-in-out infinite;
    flex-shrink: 0;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes cbTyping {

    0%,
    60%,
    100% {
        transform: translateY(0);
        background: #c4c9d4;
    }

    30% {
        transform: translateY(-7px);
        background: var(--cb-dark-2);
    }
}

.chatbot-composer {
    padding: 10px 12px;
    background: var(--cb-white);
    border-top: 1px solid var(--cb-border);
    flex-shrink: 0;
}

.chatbot-input-wrap {
    position: relative;
    width: 100%;
}

#chatbotInput {
    width: 100%;
    border: 1.5px solid var(--cb-border);
    background: var(--cb-surface);
    padding: 8px 40px 8px 12px;
    font-size: 12px;
    font-family: inherit;
    border-radius: 0;
    color: var(--cb-text);
    outline: none;
    transition: border-color var(--cb-ease), background var(--cb-ease);
    line-height: 1.4;
    display: block;
}

#chatbotInput::placeholder {
    color: var(--cb-text-xs);
}

#chatbotInput:focus {
    background: var(--cb-white);
}

.chatbot-send {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cb-dark-2);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--cb-ease);
    outline: none;
}

.chatbot-send:hover:not(:disabled) {
    background: var(--cb-dark);
}

.chatbot-send:active:not(:disabled) {
    opacity: 0.8;
}

.chatbot-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.chatbot-send-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1);
    pointer-events: none;
}

.chatbot-status {
    padding: 6px 12px;
    border-radius: 0;
    font-size: 11px;
    align-self: center;
    max-width: 90%;
    text-align: center;
    animation: cbMsgIn 0.28s ease;
    flex-shrink: 0;
}

.chatbot-status.success {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.chatbot-status.error {
    background: var(--cb-error-bg);
    color: var(--cb-error-text);
    border: 1px solid var(--cb-error-border);
}

.chatbot-status.info {
    background: #f0f9ff;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.chatbot-banner {
    background: #fffbeb;
    border-left: 3px solid var(--cb-accent);
    color: var(--cb-text);
    padding: 8px 12px;
    margin: 6px 12px 0;
    font-size: 11px;
    border-radius: 0;
    display: flex;
    align-items: flex-start;
    gap: 7px;
    animation: cbMsgIn 0.28s ease;
    flex-shrink: 0;
    line-height: 1.5;
}

.chatbot-ctrl-btn:focus-visible,
.chatbot-fab:focus-visible,
.chatbot-send:focus-visible,
.message-copy:focus-visible {
    outline: 2px solid var(--cb-accent);
    outline-offset: 2px;
}

#chatbotInput:focus-visible {
    outline: 2px solid var(--cb-dark-2);
    outline-offset: 0;
}

.chatbot-message.bot .msg-bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -9px;
    width: 0;
    height: 0;
    border-right: 9px solid var(--cb-border);
    border-top: 9px solid transparent;
    pointer-events: none;
}

.chatbot-message.bot .msg-bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -6px;
    width: 0;
    height: 0;
    border-right: 7px solid var(--cb-white);
    border-top: 7px solid transparent;
    pointer-events: none;
}

.chatbot-message.bot.error .msg-bubble::after {
    border-right-color: var(--cb-error-bg);
}

.chatbot-message.user .msg-bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -6px;
    width: 0;
    height: 0;
    border-left: 7px solid #2d2d2d;
    border-top: 7px solid transparent;
    pointer-events: none;
}

@media (max-width: 480px) {
    .chatbot-container {
        bottom: 14px;
        right: 14px;
    }

    .chatbot-popup {
        position: fixed;
        inset: 0;
        width: 100% !important;
        height: 100% !important;
        max-height: 100%;
        bottom: 0 !important;
        right: 0 !important;
        border-left: none;
        transition: none !important;
        animation: cbMobileUp 0.28s ease;
    }

    @keyframes cbMobileUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .chatbot-backdrop {
        display: none;
    }

    .chatbot-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .chatbot-composer {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .fab-tooltip {
        display: none;
    }
}