:root {
    --ai-chatbot-accent: #2563eb;
}

#ai-chatbot-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--ai-chatbot-accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    z-index: 99998;
    transition: transform 0.2s, box-shadow 0.2s;
}

#ai-chatbot-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

#ai-chatbot-bubble svg {
    width: 28px;
    height: 28px;
}

#ai-chatbot-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#ai-chatbot-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#ai-chatbot-container {
    width: 100%;
    max-width: 480px;
    height: 85vh;
    max-height: 700px;
    background: #fff;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin: 20px;
}

/* Header */
#ai-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--ai-chatbot-accent);
    color: #fff;
    gap: 12px;
    flex-shrink: 0;
}

#ai-chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#ai-chatbot-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}

#ai-chatbot-header-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ai-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

#ai-chatbot-clear,
#ai-chatbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

#ai-chatbot-clear:hover,
#ai-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

#ai-chatbot-close {
    font-size: 24px;
    line-height: 1;
}

#ai-chatbot-clear svg {
    width: 18px;
    height: 18px;
}

/* Messages */
#ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
    min-height: 0;
    scroll-behavior: smooth;
}

.ai-chatbot-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: aiChatbotFadeIn 0.2s ease;
}

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

.ai-chatbot-user {
    align-self: flex-end;
    background: var(--ai-chatbot-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-chatbot-user p:first-child,
.ai-chatbot-assistant p:first-child {
    margin-top: 0;
}

.ai-chatbot-user p:last-child,
.ai-chatbot-assistant p:last-child {
    margin-bottom: 0;
}

.ai-chatbot-assistant {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* Markdown-rendered content styling */
.ai-chatbot-assistant h1,
.ai-chatbot-assistant h2,
.ai-chatbot-assistant h3,
.ai-chatbot-assistant h4 {
    margin-top: 12px;
    margin-bottom: 8px;
    font-weight: 600;
    line-height: 1.3;
}

.ai-chatbot-assistant h1 { font-size: 1.3em; }
.ai-chatbot-assistant h2 { font-size: 1.2em; }
.ai-chatbot-assistant h3 { font-size: 1.1em; }
.ai-chatbot-assistant h4 { font-size: 1em; }

.ai-chatbot-assistant p {
    margin-top: 8px;
    margin-bottom: 8px;
}

.ai-chatbot-assistant ul,
.ai-chatbot-assistant ol {
    margin-top: 8px;
    margin-bottom: 8px;
    padding-left: 20px;
}

.ai-chatbot-assistant li {
    margin-bottom: 4px;
}

.ai-chatbot-assistant li > ul,
.ai-chatbot-assistant li > ol {
    margin-top: 2px;
    margin-bottom: 2px;
}

.ai-chatbot-assistant a {
    color: var(--ai-chatbot-accent);
    text-decoration: underline;
}

.ai-chatbot-assistant a:hover {
    opacity: 0.8;
}

.ai-chatbot-assistant code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: #e11d48;
}

.ai-chatbot-assistant pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85em;
    line-height: 1.5;
}

.ai-chatbot-assistant pre code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.ai-chatbot-assistant blockquote {
    border-left: 3px solid var(--ai-chatbot-accent);
    margin: 8px 0;
    padding-left: 12px;
    color: #64748b;
    font-style: italic;
}

.ai-chatbot-assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.9em;
}

.ai-chatbot-assistant th,
.ai-chatbot-assistant td {
    border: 1px solid #e2e8f0;
    padding: 6px 10px;
    text-align: left;
}

.ai-chatbot-assistant th {
    background: #f1f5f9;
    font-weight: 600;
}

.ai-chatbot-assistant hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 12px 0;
}

.ai-chatbot-assistant strong {
    font-weight: 600;
}

.ai-chatbot-assistant em {
    font-style: italic;
}

.ai-chatbot-assistant del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Typing indicator */
.ai-chatbot-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 16px;
    width: 60px;
}

.ai-chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: aiChatbotBounce 1.4s infinite ease-in-out both;
}

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

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

/* Footer */
#ai-chatbot-footer {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    align-items: flex-end;
    flex-shrink: 0;
}

#ai-chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    min-height: 44px;
    outline: none;
    box-sizing: border-box;
}

#ai-chatbot-input:focus {
    border-color: var(--ai-chatbot-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#ai-chatbot-send {
    width: 44px;
    height: 44px;
    background: var(--ai-chatbot-accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.1s;
}

#ai-chatbot-send:hover {
    opacity: 0.9;
}

#ai-chatbot-send:active {
    transform: scale(0.95);
}

#ai-chatbot-send svg {
    width: 20px;
    height: 20px;
}

/* Mobile - accurate full screen with safe areas and keyboard handling */
@media (max-width: 640px) {
    #ai-chatbot-overlay {
        padding: 0;
        align-items: flex-end;
    }
    
    #ai-chatbot-container {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    #ai-chatbot-header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        min-height: 56px;
    }
    
    #ai-chatbot-messages {
        padding: 16px;
        padding-bottom: 8px;
    }
    
    #ai-chatbot-footer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    #ai-chatbot-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    #ai-chatbot-header-name {
        font-size: 14px;
    }
    
    .ai-chatbot-message {
        font-size: 13px;
        padding: 10px 14px;
    }
    
    #ai-chatbot-clear,
    #ai-chatbot-close {
        width: 32px;
        height: 32px;
    }
}
