:root {
    --chatbot-nav-height: 60px;
    --chatbot-top-margin: 25px;
    --chatbot-side-gap: 20px;
    --chatbot-bottom-gap: 12px;
    --chatbot-mobile-max-width: 400px;
    --chatbot-desktop-width: 500px;
}

html.chatbot-scroll-lock,
body.chatbot-scroll-lock {
    overflow: hidden;
    overscroll-behavior: none;
}

body.chatbot-scroll-lock {
    position: fixed;
    width: 100%;
    left: 0;
    right: 0;
}

.chatbot-backdrop {
    position: fixed;
    top: var(--chatbot-nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    touch-action: none;
}

.chatbot-backdrop[hidden] {
    display: none !important;
}

[data-theme="dark"] .chatbot-backdrop {
    background: rgba(2, 6, 23, 0.55);
}

.chatbot-widget[hidden] {
    display: none !important;
}

.chatbot-widget {
    position: fixed;
    z-index: 1001;
    top: calc(var(--chatbot-nav-height) + var(--chatbot-top-margin));
    bottom: calc(var(--chatbot-bottom-gap) + env(safe-area-inset-bottom, 0px));
    right: var(--chatbot-side-gap);
    left: var(--chatbot-side-gap);
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.chatbot-widget-panel {
    pointer-events: auto;
    width: 100%;
    max-width: var(--chatbot-mobile-max-width);
    height: 100%;
    max-height: none;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22), 0 4px 12px rgba(15, 23, 42, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatbotWidgetIn 0.25s ease-out;
}

.chatbot-widget.is-minimized .chatbot-widget-body {
    display: none;
}

.chatbot-widget.is-minimized {
    top: auto;
    bottom: calc(var(--chatbot-bottom-gap) + env(safe-area-inset-bottom, 0px));
    left: auto;
    right: var(--chatbot-side-gap);
    width: min(var(--chatbot-mobile-max-width), calc(100vw - (var(--chatbot-side-gap) * 2)));
    height: auto;
    max-height: none;
}

.chatbot-widget.is-minimized .chatbot-widget-panel {
    height: auto;
    max-height: none;
}

@keyframes chatbotWidgetIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chatbot-widget-header {
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

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

.chatbot-widget-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-widget-avatar-text {
    font-size: 1.1rem;
    font-weight: 700;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

.chatbot-widget-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chatbot-widget-name {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-widget-status {
    font-size: 0.75rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chatbot-widget-status::before {
    content: '';
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    animation: chatbotPulse 2s infinite;
}

@keyframes chatbotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-widget-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chatbot-widget-control-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chatbot-widget-control-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

.chatbot-widget-control-btn svg {
    width: 18px;
    height: 18px;
}

.chatbot-widget-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.chatbot-widget .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f8fafc;
    min-height: 0;
}

.chatbot-widget .message {
    margin-bottom: 12px;
    animation: chatbotFadeIn 0.3s ease;
}

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

.chatbot-widget .message-content {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 0.9rem;
}

.chatbot-widget .bot-message .message-content {
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #1e293b;
}

.chatbot-widget .bot-message .message-content em {
    font-style: italic;
}

.chatbot-widget .message-content a.chatbot-link {
    color: #6366f1;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chatbot-widget .message-content a.chatbot-link:hover {
    color: #4f46e5;
}

[data-theme="dark"] .chatbot-widget .message-content a.chatbot-link {
    color: #818cf8;
}

[data-theme="dark"] .chatbot-widget .message-content a.chatbot-link:hover {
    color: #a5b4fc;
}

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

.chatbot-widget .user-message .message-content {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
}

.chatbot-widget .quick-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chatbot-widget .quick-options .quick-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 6px 12px;
    min-height: 32px;
    border: 1px solid #6366f1;
    background: #fff;
    color: #6366f1;
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chatbot-widget .quick-options .quick-btn:hover {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

.chatbot-widget .chat-input-container {
    flex-shrink: 0;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
}

.chatbot-widget .chat-input-wrapper {
    display: flex;
    gap: 8px;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 4px;
}

.chatbot-widget #userInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 14px;
    font-size: 0.95rem;
    outline: none;
    min-width: 0;
}

.chatbot-widget .send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.chatbot-widget .send-btn:hover {
    transform: scale(1.05);
}

.chatbot-widget .send-btn svg {
    width: 18px;
    height: 18px;
}

.chatbot-widget .typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
}

.chatbot-widget .typing-indicator span {
    width: 7px;
    height: 7px;
    background: #6366f1;
    border-radius: 50%;
    animation: chatbotBounce 1.4s infinite ease-in-out;
}

.chatbot-widget .typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.chatbot-widget .typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatbotBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}


[data-theme="dark"] .chatbot-widget-panel {
    background: #1e293b;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .chatbot-widget-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

[data-theme="dark"] .chatbot-widget .chat-messages {
    background: #0f172a;
}

[data-theme="dark"] .chatbot-widget .bot-message .message-content {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .chatbot-widget .quick-options .quick-btn {
    background: #1e293b;
    border-color: #6366f1;
    color: #818cf8;
}

[data-theme="dark"] .chatbot-widget .quick-options .quick-btn:hover {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

[data-theme="dark"] .chatbot-widget .chat-input-container {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .chatbot-widget .chat-input-wrapper {
    background: #0f172a;
}

[data-theme="dark"] .chatbot-widget #userInput {
    color: #e2e8f0;
}

[data-theme="dark"] .chatbot-widget #userInput::placeholder {
    color: #64748b;
}

@media (min-width: 768px) {
    .chatbot-widget {
        left: auto;
        width: var(--chatbot-desktop-width);
        justify-content: flex-end;
    }

    .chatbot-widget-panel {
        max-width: var(--chatbot-desktop-width);
        width: var(--chatbot-desktop-width);
    }

    .chatbot-widget.is-minimized {
        width: var(--chatbot-desktop-width);
    }
}

@media (max-width: 767px) {
    .chatbot-widget:not(.is-minimized) {
        top: calc(var(--chatbot-nav-height) + var(--chatbot-top-margin));
        bottom: calc(var(--chatbot-bottom-gap) + env(safe-area-inset-bottom, 0px));
        max-height: calc(100dvh - var(--chatbot-nav-height) - var(--chatbot-top-margin) - var(--chatbot-bottom-gap) - env(safe-area-inset-bottom, 0px));
    }

    .chatbot-widget:not(.is-minimized) .chatbot-widget-panel {
        max-height: calc(100dvh - var(--chatbot-nav-height) - var(--chatbot-top-margin) - var(--chatbot-bottom-gap) - env(safe-area-inset-bottom, 0px));
    }
}

@supports not (height: 100dvh) {
    @media (max-width: 767px) {
        .chatbot-widget:not(.is-minimized) {
            max-height: calc(100vh - var(--chatbot-nav-height) - var(--chatbot-top-margin) - var(--chatbot-bottom-gap) - env(safe-area-inset-bottom, 0px));
        }

        .chatbot-widget:not(.is-minimized) .chatbot-widget-panel {
            max-height: calc(100vh - var(--chatbot-nav-height) - var(--chatbot-top-margin) - var(--chatbot-bottom-gap) - env(safe-area-inset-bottom, 0px));
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-widget-panel {
        animation: none;
    }

    .chatbot-widget .message,
    .chatbot-widget-status::before,
    .chatbot-widget .typing-indicator span {
        animation: none;
    }
}
