/**
 * ============================================
 * LUMO CMS - CHATBOT AI CSS
 * Frontend Widget Styles (Sidebar + Bubble)
 * ============================================
 * 
 * Questo file utilizza le CSS Custom Properties
 * definite nel theme per integrarsi perfettamente
 * con il design del template.
 * 
 * @version 2.0 - Bubble layout added
 * @date 2025-12-14
 * ============================================
 */

/* ============================================
   CHATBOT CSS VARIABLES
   ============================================ */

:root {
    --chatbot-width: 420px;
    --chatbot-bg: var(--bg-primary, #ffffff);
    --chatbot-header-bg: var(--primary-color, #0047AB);
    --chatbot-input-bg: var(--bg-secondary, #f8f9fa);
    --chatbot-border: var(--border-color, #dee2e6);
    --chatbot-text: var(--text-primary, #212529);
    --chatbot-text-muted: var(--text-muted, #6c757d);
    --chatbot-accent: var(--primary-color, #0047AB);
    --chatbot-accent-hover: var(--primary-dark, #003388);
    --chatbot-user-bg: var(--primary-color, #0047AB);
    --chatbot-bot-bg: var(--bg-tertiary, #f1f3f5);
    --chatbot-success: var(--success-color, #28a745);
    --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --chatbot-radius: var(--border-radius, 8px);
    --chatbot-font: var(--font-family-base, 'Inter', sans-serif);
}

/* Dark mode support */
[data-theme="dark"],
.dark-mode {
    --chatbot-bg: var(--gray-900, #212529);
    --chatbot-header-bg: var(--primary-color, #0047AB);
    --chatbot-input-bg: var(--gray-800, #343a40);
    --chatbot-border: var(--gray-700, #495057);
    --chatbot-text: var(--gray-100, #f8f9fa);
    --chatbot-text-muted: var(--gray-500, #adb5bd);
    --chatbot-bot-bg: var(--gray-800, #343a40);
    --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ============================================
   TOGGLE BUTTON (shared)
   ============================================ */

.chatbot-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-accent), var(--secondary-color, #FF6B35));
    border: none;
    color: var(--white, #ffffff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    font-family: var(--chatbot-font);
}

.chatbot-toggle-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 28px rgba(0, 71, 171, 0.5);
}

.chatbot-toggle-btn.active {
    transform: scale(0.95);
    background: var(--chatbot-border);
}

.chatbot-toggle-btn svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}

.chatbot-toggle-btn:hover svg {
    transform: scale(1.1);
}

.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger-color, #dc3545);
    color: var(--white, #ffffff);
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* ============================================
   BUBBLE LAYOUT
   ============================================ */

/* Wrapper widget */
.chatbot-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.chatbot-position-br {
    bottom: 20px;
    right: 20px;
}

.chatbot-position-bl {
    bottom: 20px;
    left: 20px;
}

.chatbot-position-tr {
    top: 20px;
    right: 20px;
}

.chatbot-position-tl {
    top: 20px;
    left: 20px;
}

/* Chat Window */
.chatbot-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: var(--chatbot-bg, #ffffff);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
}

.chatbot-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chatbot-position-bl .chatbot-window,
.chatbot-position-tl .chatbot-window {
    right: auto;
    left: 0;
}

.chatbot-position-tr .chatbot-window,
.chatbot-position-tl .chatbot-window {
    bottom: auto;
    top: 70px;
}

/* Message Badges - Icon + Text (on new line) */
.msg-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    padding: 3px 8px;
    border-radius: 6px;
    margin-top: 8px;
    font-weight: 600;
    opacity: 0.85;
    white-space: nowrap;
    clear: both;
}

.msg-badge svg {
    flex-shrink: 0;
}

.msg-badge.ai {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #0d47a1;
    border: 1px solid #90caf9;
}

.msg-badge.faq {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    color: #1b5e20;
    border: 1px solid #a5d6a7;
}

.msg-badge.db {
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    color: #e65100;
    border: 1px solid #ffcc80;
}

.msg-badge.tool {
    background: linear-gradient(135deg, #f3e5f5, #e1bee7);
    color: #7b1fa2;
    border: 1px solid #ce93d8;
}

.msg-badge.fallback {
    background: linear-gradient(135deg, #fafafa, #eeeeee);
    color: #616161;
    border: 1px solid #bdbdbd;
}

/* Overlay - moved to sidebar section below */

/* Responsive Bubble */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: -10px;
        border-radius: 16px;
    }

    .chatbot-position-bl .chatbot-window {
        left: -10px;
    }
}

/* ============================================
   SIDEBAR LAYOUT
   ============================================ */

.chatbot-sidebar {
    position: fixed;
    top: 0;
    right: -420px;
    width: var(--chatbot-width);
    height: 100vh;
    height: 100dvh;
    background: var(--chatbot-bg);
    border-left: 1px solid var(--chatbot-border);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--chatbot-shadow);
    font-family: var(--chatbot-font);
}

.chatbot-sidebar.open {
    right: 0;
}

/* Sidebar Header - uses primary color from template */
.chatbot-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--chatbot-header-bg);
    color: #ffffff;
    min-height: 72px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-sidebar-header .chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chatbot-sidebar-header .chatbot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
}

.chatbot-sidebar-header .chatbot-avatar img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.chatbot-sidebar-header .chatbot-avatar svg {
    width: 24px;
    height: 24px;
    color: #ffffff;
}

.chatbot-sidebar-header .chatbot-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-sidebar-header .chatbot-name {
    font-weight: 600;
    font-size: 16px;
    color: #ffffff;
}

.chatbot-sidebar-header .chatbot-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-sidebar-header .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: statusPulse 2s infinite;
}

/* Sidebar Header Action Buttons - VISIBLE on colored background */
.chatbot-sidebar-header .chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.chatbot-sidebar-header .chatbot-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chatbot-sidebar-header .chatbot-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.chatbot-sidebar-header .chatbot-action-btn svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
}

/* Sidebar Body - Messages area */
.chatbot-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--chatbot-bg);
}

.chatbot-sidebar-body::-webkit-scrollbar {
    width: 6px;
}

.chatbot-sidebar-body::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-sidebar-body::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-sidebar-body::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-muted);
}

/* Sidebar Footer - Input area */
.chatbot-sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--chatbot-border);
    background: var(--chatbot-bg);
    flex-shrink: 0;
}

.chatbot-sidebar-footer .chatbot-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chatbot-sidebar-footer .chatbot-input {
    flex: 1;
    background: var(--chatbot-input-bg);
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    padding: 12px 16px;
    color: var(--chatbot-text);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    font-family: var(--chatbot-font);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    /* Hide scrollbar */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.chatbot-sidebar-footer .chatbot-input::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.chatbot-sidebar-footer .chatbot-input:focus {
    border-color: var(--chatbot-accent);
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb, 0, 71, 171), 0.15);
}

.chatbot-sidebar-footer .chatbot-input::placeholder {
    color: var(--chatbot-text-muted);
}

.chatbot-sidebar-footer .chatbot-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--chatbot-accent);
    color: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-sidebar-footer .chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-accent-hover);
    transform: scale(1.05);
}

.chatbot-sidebar-footer .chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-sidebar-footer .chatbot-send-btn svg {
    width: 20px;
    height: 20px;
}

.chatbot-sidebar-footer .chatbot-footer-info {
    padding-top: 8px;
    text-align: center;
    font-size: 11px;
    color: var(--chatbot-text-muted);
}

/* Sidebar Overlay - Click to close (z-index MUST be lower than sidebar) */
.chatbot-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
    /* MUST be lower than sidebar z-index (10000) */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

.chatbot-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Sidebar Dark Mode */
[data-theme="dark"] .chatbot-sidebar {
    background: var(--chatbot-bg);
    border-left-color: var(--chatbot-border);
}

[data-theme="dark"] .chatbot-sidebar-header {
    background: var(--chatbot-header-bg);
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chatbot-sidebar-header .chatbot-avatar img {
    filter: brightness(0) invert(1);
}

[data-theme="dark"] .chatbot-sidebar-body {
    background: var(--chatbot-bg);
}

[data-theme="dark"] .chatbot-sidebar-footer {
    background: var(--chatbot-bg);
    border-top-color: var(--chatbot-border);
}

[data-theme="dark"] .chatbot-sidebar-footer .chatbot-input {
    background: var(--chatbot-input-bg);
    border-color: var(--chatbot-border);
    color: var(--chatbot-text);
}

/* Sidebar typing indicator specific */
.chatbot-sidebar .chatbot-typing {
    padding: 0 20px 16px;
}

/* ============================================
   HISTORY PANEL
   ============================================ */

.chatbot-history-panel {
    position: absolute;
    top: 72px;
    /* Below header */
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--chatbot-bg);
    z-index: 10;
    display: flex;
    flex-direction: column;
    animation: slideInFromRight 0.2s ease;
}

@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

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

.history-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--chatbot-border);
    background: var(--chatbot-input-bg);
}

.history-panel-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 15px;
    color: var(--chatbot-text);
}

.history-panel-header .chatbot-action-btn {
    background: transparent;
    color: var(--chatbot-text-muted);
}

.history-panel-header .chatbot-action-btn:hover {
    background: var(--chatbot-border);
    color: var(--chatbot-text);
}

.history-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--chatbot-text-muted);
    text-align: center;
    padding: 40px 20px;
}

.history-empty svg {
    opacity: 0.4;
    margin-bottom: 16px;
}

.history-empty p {
    margin: 0;
    font-size: 14px;
}

.history-item {
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--chatbot-input-bg);
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    border-color: var(--chatbot-accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.history-item-date {
    font-size: 11px;
    color: var(--chatbot-text-muted);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.5;
    transition: all 0.2s ease;
}

.history-delete-btn:hover {
    opacity: 1;
    background: rgba(220, 53, 69, 0.15);
}

.history-item-preview {
    font-size: 13px;
    color: var(--chatbot-text);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-item-count {
    display: inline-block;
    font-size: 10px;
    background: var(--chatbot-accent);
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 8px;
    margin-top: 6px;
}

.history-item.active {
    border-color: var(--chatbot-accent);
    background: rgba(var(--primary-color-rgb, 0, 71, 171), 0.08);
}

.history-delete-all-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 16px;
    margin-top: 12px;
    background: none;
    border: 1px dashed rgba(220, 53, 69, 0.3);
    border-radius: 10px;
    color: var(--chatbot-text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-delete-all-btn:hover {
    background: rgba(220, 53, 69, 0.08);
    border-color: rgba(220, 53, 69, 0.5);
    color: #dc3545;
}

.history-delete-all-btn svg {
    flex-shrink: 0;
}

/* Dark mode history panel */
[data-theme="dark"] .history-panel-header {
    background: var(--chatbot-input-bg);
    border-bottom-color: var(--chatbot-border);
}

[data-theme="dark"] .history-item {
    background: var(--chatbot-input-bg);
    border-color: var(--chatbot-border);
}

[data-theme="dark"] .history-item:hover {
    background: var(--chatbot-border);
}

[data-theme="dark"] .chatbot-history-panel {
    background: #1f2937;
}

[data-theme="dark"] .history-panel-list {
    background: #1f2937;
}

/* Dark mode for bubble layout window */
[data-theme="dark"] .chatbot-window .chatbot-avatar {
    background: #4b5563;
}

[data-theme="dark"] .chatbot-window .chatbot-messages {
    background: #1f2937;
}

[data-theme="dark"] .chatbot-window .chatbot-input-area {
    background: #1f2937;
    border-top-color: #374151;
}

/* History panel in bubble layout (different header height) */
.chatbot-window .chatbot-history-panel {
    top: 64px;
    /* Bubble header is slightly smaller */
    border-radius: 0 0 16px 16px;
}

/* ============================================
   CONFIRM DIALOG (Custom replacement for browser confirm)
   ============================================ */

.chatbot-confirm-dialog {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.confirm-dialog-content {
    background: var(--chatbot-bg);
    border-radius: 16px;
    padding: 24px;
    max-width: 280px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.confirm-dialog-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--chatbot-accent), var(--secondary-color, #FF6B35));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.confirm-dialog-icon svg {
    width: 24px;
    height: 24px;
}

.confirm-dialog-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--chatbot-text);
}

.confirm-dialog-message {
    margin: 0 0 20px;
    font-size: 13px;
    color: var(--chatbot-text-muted);
    line-height: 1.5;
}

.confirm-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
}

.confirm-btn.cancel {
    background: var(--chatbot-input-bg);
    color: var(--chatbot-text);
    border: 1px solid var(--chatbot-border);
}

.confirm-btn.cancel:hover {
    background: var(--chatbot-border);
}

.confirm-btn.confirm {
    background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-accent-hover, #003388));
    color: #ffffff;
}

.confirm-btn.confirm:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.confirm-btn.confirm:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb, 0, 71, 171), 0.3);
}

/* Dark mode confirm dialog */
[data-theme="dark"] .confirm-dialog-content {
    background: var(--chatbot-bg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .confirm-btn.cancel {
    background: var(--gray-700, #495057);
    border-color: var(--gray-600, #6c757d);
}

/* ============================================
   HEADER (shared)
   ============================================ */

.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--chatbot-header-bg);
    color: var(--white, #ffffff);
    min-height: 72px;
    flex-shrink: 0;
}

.chatbot-window .chatbot-header {
    border-radius: 16px 16px 0 0;
    padding: 12px 16px;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chatbot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white, #ffffff);
    flex-shrink: 0;
}

.chatbot-window .chatbot-avatar {
    width: 40px;
    height: 40px;
    background: var(--chatbot-bg, #ffffff);
    padding: 6px;
}

.chatbot-avatar svg {
    width: 24px;
    height: 24px;
}

.chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chatbot-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--white, #ffffff);
}

.chatbot-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-success);
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
    }

    50% {
        opacity: 0.8;
        box-shadow: 0 0 0 4px rgba(40, 167, 69, 0);
    }
}

.chatbot-header-actions {
    display: flex;
    gap: 4px;
}

.chatbot-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--white, #ffffff);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chatbot-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

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

.chatbot-window .chatbot-action-btn {
    width: 32px;
    height: 32px;
}

/* ============================================
   MESSAGES AREA (shared)
   ============================================ */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chatbot-window .chatbot-messages {
    padding: 16px;
}

/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-muted);
}

/* ============================================
   MESSAGES (shared)
   ============================================ */

.chatbot-message {
    display: flex;
    gap: 12px;
    max-width: 88%;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

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

.chatbot-message.user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.chatbot-message.bot {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-message.bot .message-avatar {
    background: #f3f4f6;
    color: var(--chatbot-accent);
    padding: 6px;
}

.chatbot-message.user .message-avatar {
    background: var(--chatbot-user-bg);
    color: var(--white, #ffffff);
    display: none;
}

.message-avatar svg {
    width: 16px;
    height: 16px;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Badge on new line */
.message-content .msg-badge {
    display: flex;
    width: fit-content;
}

.chatbot-message.bot .message-content {
    background: #f3f4f6;
    color: var(--chatbot-text);
    border-bottom-left-radius: 4px;
}

.chatbot-message.user .message-content {
    background: var(--chatbot-user-bg);
    color: var(--white, #ffffff);
    border-bottom-right-radius: 4px;
}

.chatbot-window .chatbot-message.bot .message-content {
    background: var(--chatbot-bot-bg);
}

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

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

/* Message Feedback Buttons */
.message-feedback {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.message-feedback:hover {
    opacity: 1;
}

.feedback-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--chatbot-text-muted);
    transition: all 0.2s;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--chatbot-text);
}

.feedback-btn.active {
    color: var(--chatbot-accent);
}

.feedback-btn svg {
    width: 12px;
    height: 12px;
    stroke-width: 2;
}

/* Action buttons (copy / regenerate) */
.msg-action-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--chatbot-text-muted);
    transition: all 0.2s;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--chatbot-text);
}

.msg-action-btn.active {
    color: var(--chatbot-accent);
}

.msg-action-btn svg {
    width: 12px;
    height: 12px;
    stroke-width: 2;
}

/* Toast (copy notification) */
.chatbot-toast {
    position: absolute;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%) translateY(8px);
    background: rgba(20, 20, 20, 0.92);
    color: #fff;
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 0.78rem;
    font-weight: 500;
    z-index: 10001;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.chatbot-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Error + retry pill */
.chatbot-error-msg {
    margin: 12px 16px;
    padding: 10px 14px;
    background: rgba(220, 53, 69, 0.08);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.18);
    border-radius: 12px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.chatbot-error-msg .error-text {
    flex: 1;
    min-width: 0;
}

.chatbot-retry-btn {
    background: var(--chatbot-accent, #667eea);
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
}

.chatbot-retry-btn:hover {
    opacity: 0.88;
}

/* ============================================
   TYPING INDICATOR (shared)
   ============================================ */

.chatbot-typing {
    display: flex;
    gap: 12px;
    padding: 0 20px 16px;
    align-items: flex-start;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: #f3f4f6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chatbot-window .typing-indicator {
    background: var(--chatbot-bot-bg);
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

@keyframes pulse-mic {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* ============================================
   INPUT AREA (shared)
   ============================================ */

.chatbot-input-area {
    padding: 16px 20px 20px;
    border-top: 1px solid #e5e7eb;
    background: var(--chatbot-bg);
    flex-shrink: 0;
}

.chatbot-window .chatbot-input-area {
    padding: 12px 16px;
}

.chatbot-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    background: var(--chatbot-input-bg);
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 12px 16px;
    color: var(--chatbot-text);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    font-family: var(--chatbot-font);
    transition: border-color 0.2s;
    outline: none;
    /* Hide scrollbar */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.chatbot-input::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.chatbot-input:focus {
    border-color: var(--chatbot-accent);
}

.chatbot-input::placeholder {
    color: var(--chatbot-text-muted);
}

.chatbot-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--chatbot-accent);
    color: var(--white, #ffffff);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-window .chatbot-send-btn {
    width: 40px;
    height: 40px;
}

.chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-accent-hover);
    transform: scale(1.05);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Microphone Button */
.chatbot-mic-btn {
    width: 40px;
    height: 40px;
    border: 1px solid #e0e0e0;
    background: transparent;
    color: #666;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-mic-btn:hover {
    background: #f5f5f5;
    color: var(--chatbot-accent);
    border-color: var(--chatbot-accent);
}

.chatbot-mic-btn.listening {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: #ef4444;
    animation: pulse-mic 1.5s infinite;
}

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

/* ============================================
   SUGGESTIONS (shared)
   ============================================ */

.chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
}

.suggestion-btn {
    padding: 6px 12px;
    background: #e5e7eb;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: var(--chatbot-accent);
    color: white;
    border-color: var(--chatbot-accent);
}

/* ============================================
   DARK THEME (shared)
   ============================================ */

[data-theme="dark"] .chatbot-window,
[data-theme="dark"] .chatbot-sidebar {
    background: #1f2937;
    color: #f9fafb;
}

[data-theme="dark"] .chatbot-sidebar-header {
    background: var(--primary-color, #0047AB);
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chatbot-sidebar-body {
    background: #1f2937;
}

[data-theme="dark"] .chatbot-sidebar-footer {
    background: #1f2937;
    border-top-color: #374151;
}

[data-theme="dark"] .chatbot-message .message-content {
    background: #374151;
    color: #f9fafb;
}

/* Specific dark mode for bot messages (higher specificity to override base styles) */
[data-theme="dark"] .chatbot-message.bot .message-content {
    background: #374151;
    color: #f9fafb;
}

[data-theme="dark"] .chatbot-message.bot .message-avatar {
    background: #4b5563;
    color: var(--chatbot-accent);
}

[data-theme="dark"] .typing-indicator {
    background: #374151;
}

[data-theme="dark"] .chatbot-input {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

[data-theme="dark"] .chatbot-input::placeholder {
    color: #9ca3af;
}

[data-theme="dark"] .suggestion-btn {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

[data-theme="dark"] .history-panel-header {
    background: #111827;
    border-bottom-color: #374151;
}

[data-theme="dark"] .history-item {
    background: #374151;
    border-color: #4b5563;
}

[data-theme="dark"] .history-item:hover {
    background: #4b5563;
}

/* Footer Info */
.chatbot-footer-info {
    padding: 4px 16px 8px;
    text-align: center;
    font-size: 11px;
    color: var(--chatbot-text-muted);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .chatbot-sidebar {
        width: 100%;
        right: -100%;
        border-left: none;
    }

    .chatbot-toggle-btn {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }

    .chatbot-toggle-btn svg {
        width: 24px;
        height: 24px;
    }

    .chatbot-messages {
        padding: 16px;
    }

    .chatbot-input-area {
        padding: 12px 16px 16px;
    }

    .chatbot-toggle-btn.active {
        opacity: 0;
        pointer-events: none;
    }
}

@media (max-width: 480px) {
    .chatbot-header {
        padding: 14px 16px;
        min-height: 64px;
    }

    .chatbot-avatar {
        width: 40px;
        height: 40px;
    }

    .chatbot-name {
        font-size: 15px;
    }

    .message-content {
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {

    .chatbot-toggle-btn,
    .chatbot-sidebar,
    .chatbot-window,
    .chatbot-overlay {
        display: none !important;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {

    .chatbot-toggle-btn,
    .chatbot-sidebar,
    .chatbot-window,
    .chatbot-message,
    .chatbot-action-btn,
    .chatbot-send-btn,
    .typing-indicator span {
        transition: none;
        animation: none;
    }

    .status-dot,
    .chatbot-badge {
        animation: none;
    }
}

/* @keyframes fadeIn - required by some animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ============================================
   GO-TO-TOP COORDINATION
   Prevent overlap with go-to-top button
   ============================================ */

.chatbot-toggle-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When go-to-top is visible, shift chatbot up */
.chatbot-toggle-btn.shifted-for-gototop {
    bottom: 90px;
    /* 24px + 60px (gototop height) + 6px gap */
}

/* On mobile, use less space */
@media (max-width: 768px) {
    .chatbot-toggle-btn.shifted-for-gototop {
        bottom: 85px;
    }
}