:root {
    --purple-gradient-from: #8b5cf6;
    --purple-gradient-to: #9333ea;
    --purple-light: #a78bfa;
    --purple-dark: #7c3aed;
    --text-gray-900: #111827;
    --text-gray-700: #374151;
    --text-gray-600: #4b5563;
    --text-gray-500: #6b7280;
    --text-gray-400: #9ca3af;
    --text-gray-300: #d1d5db;
    --bg-gray-50: #f9fafb;
    --border-gray-100: #f3f4f6;
    --border-gray-200: #e5e7eb;
    --placeholder-color: #a2a9b7;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --shadow-purple: 0 4px 20px rgba(139, 92, 246, 0.25);
}

.ai-bot-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.44);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
    z-index: 1050;
}

.ai-bot-overlay.show {
    opacity: 1;
    visibility: visible;
}

.ai-bot-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(50vw, 860px);
    max-width: 100vw;
    height: 100vh;
    background: #fff;
    border-left: 1px solid var(--border-gray-200);
    box-shadow: -14px 0 40px rgba(17, 24, 39, 0.18);
    transform: translateX(100%);
    transition: transform 0.26s ease;
    z-index: 1051;
    display: flex;
    flex-direction: column;
}

.ai-bot-panel.show {
    transform: translateX(0);
}

body.ai-bot-open {
    overflow: hidden;
}

.ai-bot .offcanvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-gray-100);
    padding: 14px 18px;
    flex-shrink: 0;
}

.ai-bot .topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-bot .brand-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-gray-900);
    margin: 0;
    line-height: 1.1;
}

.ai-bot .brand-status {
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-gray-500);
}

.ai-bot .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
}

.ai-bot .topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-bot .topbar-btn {
    border: 1px solid var(--border-gray-200);
    background: #fff;
    color: var(--text-gray-600);
    border-radius: 10px;
    transition: all var(--transition-fast);
}

.ai-bot .topbar-btn.icon-only {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-bot .topbar-btn:hover,
.ai-bot .topbar-btn.active {
    color: var(--purple-dark);
    border-color: var(--purple-light);
    background: rgba(139, 92, 246, 0.08);
}

.ai-bot .offcanvas-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.ai-bot .session-history {
    width: 260px;
    border-right: 1px solid var(--border-gray-100);
    background: #fafafa;
    padding: 14px;
    display: none;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

.ai-bot.history-open .session-history {
    display: flex;
}

.ai-bot .session-history-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--text-gray-400);
}

.ai-bot .session-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-bot .session-history-empty {
    font-size: 12px;
    color: var(--text-gray-500);
}

.ai-bot .history-item {
    width: 100%;
    border: 1px solid var(--border-gray-200);
    border-radius: 10px;
    background: #fff;
    padding: 10px;
    text-align: left;
    transition: all var(--transition-fast);
}

.ai-bot .history-item:hover,
.ai-bot .history-item.active {
    border-color: var(--purple-light);
    background: rgba(139, 92, 246, 0.06);
}

.ai-bot .history-item-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-gray-700);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-bot .history-item-meta {
    font-size: 11px;
    color: var(--text-gray-500);
}

.ai-bot .ai-content-shell {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-bot .initial-state,
.ai-bot .conversation-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 16px 18px 14px;
}

.ai-bot .initial-state {
    overflow: hidden;
}

.ai-bot .conversation-state {
    display: none;
}

.ai-bot .logo-container {
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    box-shadow: var(--shadow-purple);
}

.ai-bot .logo-container.small {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    margin: 0;
}

.ai-bot .brand-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-gray-900);
    margin-bottom: 6px;
}

.ai-bot .subtitle {
    font-size: 14px;
    color: var(--text-gray-500);
    margin-bottom: 4px;
}

.ai-bot .description {
    font-size: 13px;
    color: var(--text-gray-500);
    line-height: 1.55;
    margin-bottom: 20px;
}

.ai-bot .quick-questions-section {
    overflow-y: auto;
    margin-bottom: 12px;
}

.ai-bot .section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-gray-400);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 10px;
}

.ai-bot .question-btn {
    background: var(--bg-gray-50);
    border: 1px solid var(--border-gray-200);
    border-radius: 10px;
    padding: 9px 13px;
    font-size: 12.5px;
    color: var(--text-gray-600);
}

.ai-bot .question-btn:hover {
    border-color: var(--purple-light);
    color: var(--purple-dark);
    background: rgba(139, 92, 246, 0.08);
}

.ai-bot .divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-gray-200), transparent);
    margin-bottom: 10px;
}

.ai-bot .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin-bottom: 8px;
    padding-right: 6px;
}

.ai-bot .message {
    margin-bottom: 14px;
    display: flex;
}

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

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

.ai-bot .message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    margin-right: 8px;
    margin-top: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
}

.ai-bot .message-content {
    max-width: min(88%, 720px);
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.58;
    overflow-wrap: anywhere;
}

.ai-bot .message.user .message-content {
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-purple);
}

.ai-bot .message.assistant .message-content {
    background: #fff;
    border: 1px solid var(--border-gray-200);
    color: var(--text-gray-700);
    border-bottom-left-radius: 4px;
}

.ai-bot .typing-indicator { display: none; align-items: center; gap: 5px; }
.ai-bot .typing-indicator.show { display: flex; }
.ai-bot .typing-dot { width: 7px; height: 7px; background: var(--purple-light); border-radius: 50%; animation: typing 1.2s infinite ease-in-out; }
.ai-bot .typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-bot .typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }

.ai-bot .input-section {
    margin-top: auto;
    border-top: 1px solid var(--border-gray-100);
    padding-top: 10px;
    background: #fff;
}

.ai-bot .input-section.initial {
    border-top: none;
}

.ai-bot .input-container { position: relative; }

.ai-bot .message-input {
    width: 100%;
    min-height: 44px;
    overflow-y: auto;
    padding: 11px 50px 11px 14px;
    background: var(--bg-gray-50);
    border: 1.5px solid var(--border-gray-200);
    border-radius: 12px;
    resize: none;
    font-size: 14px;
    color: var(--text-gray-700);
    line-height: 1.44;
}

.ai-bot .message-input:focus {
    outline: none;
    border-color: var(--purple-gradient-from);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
    background: #fff;
}

.ai-bot .message-input::placeholder { color: var(--placeholder-color); }

.ai-bot .send-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(calc(-50% - 3px));
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--text-gray-300), var(--text-gray-400));
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-bot .send-button.active,
.ai-bot .send-button:hover {
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
}

.ai-bot .send-icon { width: 15px; height: 15px; color: #fff; }

.ai-bot .powered-by {
    margin-top: 8px;
    text-align: center;
    color: var(--text-gray-400);
    font-size: 11px;
}

.ai-bot .suggested-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.ai-bot .suggested-action {
    padding: 7px 12px;
    border-radius: 18px;
    border: 1px solid var(--border-gray-200);
    background: #fff;
    font-size: 12px;
    color: var(--text-gray-600);
}

.ai-bot .suggested-action:hover {
    border-color: var(--purple-light);
    color: var(--purple-dark);
    background: rgba(139, 92, 246, 0.06);
}

.ai-bot .message-content h1,
.ai-bot .message-content h2,
.ai-bot .message-content h3,
.ai-bot .message-content h4 { color: var(--text-gray-900); line-height: 1.3; margin: 0 0 7px; font-weight: 700; }
.ai-bot .message-content h1 { font-size: 1.2rem; }
.ai-bot .message-content h2 { font-size: 1.08rem; }
.ai-bot .message-content h3 { font-size: 0.98rem; }
.ai-bot .message-content p { margin: 0 0 7px; }
.ai-bot .message-content strong { font-weight: 700; color: var(--text-gray-900); }
.ai-bot .message-content ul,
.ai-bot .message-content ol { margin: 0 0 7px 18px; padding: 0; }
.ai-bot .message-content li { margin-bottom: 4px; }
.ai-bot .message-content code { background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 5px; padding: 1px 5px; font-size: 0.86em; }
.ai-bot .message-content pre { background: #111827; color: #f3f4f6; border-radius: 10px; padding: 10px; overflow-x: auto; margin: 0 0 10px; }
.ai-bot .message-content pre code { background: transparent; border: 0; color: inherit; padding: 0; }

.ai-bot .chat-messages { position: relative; }

.ai-bot .ai-error-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    border-radius: 12px;
    z-index: 5;
}

.ai-bot .ai-error-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 20px;
}

.ai-bot .ai-error-title { font-size: 16px; font-weight: 700; color: var(--text-gray-900); }
.ai-bot .ai-error-description { font-size: 13px; color: var(--text-gray-500); max-width: 280px; }

.ai-bot .ai-error-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 9px;
    padding: 9px 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
}

.ai-bot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--purple-gradient-from), var(--purple-gradient-to));
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.35), 0 2px 8px rgba(0, 0, 0, 0.1);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1060;
}

.ai-bot-fab.hide { opacity: 0; pointer-events: none; }

.ai-bot-fab-tooltip {
    position: absolute;
    right: 64px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(31, 41, 55, 0.92);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ai-bot-fab:hover .ai-bot-fab-tooltip { opacity: 1; }

.ai-bot-fab-notification {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 10px;
    height: 10px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #ef4444;
    display: none;
}

.ai-bot-fab-notification.active { display: block; }

@media (max-width: 1200px) {
    .ai-bot-panel { width: min(62vw, 860px); }
}

@media (max-width: 992px) {
    .ai-bot-panel { width: 100vw; max-width: 100vw; }
    .ai-bot .session-history {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        border-right: 1px solid var(--border-gray-200);
        box-shadow: 8px 0 24px rgba(17, 24, 39, 0.14);
        z-index: 2;
    }
}

@media (max-width: 768px) {
    .ai-bot .offcanvas-header { padding: 12px 14px; }
    .ai-bot .initial-state,
    .ai-bot .conversation-state { padding: 12px 14px; }
    .ai-bot .topbar-btn.icon-only { width: 32px; height: 32px; }
    .ai-bot .brand-title { font-size: 22px; }
    .ai-bot .message-content { max-width: 94%; font-size: 13.5px; }
    .ai-bot-fab { width: 52px; height: 52px; right: 18px; bottom: 18px; }
    .ai-bot-fab-tooltip { display: none; }
}