/* AI Avatar Widget Styles */
:root {
    --ai-widget-primary: #667eea;
    --ai-widget-bg: #1e293b;
    --ai-widget-card: #0f172a;
    --ai-widget-text: #e2e8f0;
    --ai-widget-border: #334155;
}

.ai-widget-container {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.ai-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Toggle button — hidden when chat is open */
.ai-widget-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-widget-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.ai-widget-toggle-hidden {
    opacity: 0;
    pointer-events: none;
}

/* Chat panel — fixed, full viewport height with margins */
.ai-widget-chat {
    position: fixed;
    top: 20px;
    bottom: 20px;
    right: 20px;
    width: min(480px, 33vw);
    background-color: var(--ai-widget-card);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s, transform 0.3s;
}

.ai-widget-hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Header */
.ai-widget-header {
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 48px 14px 16px; /* right padding reserves space for close btn */
}

.ai-widget-header h3 {
    margin: 0 2px 0 0;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.2;
}

.ai-widget-subtitle {
    margin: 2px 0 6px 0;
    font-size: 11px;
    opacity: 0.75;
    font-weight: 400;
}

/* Status row: AI indicator + DB indicator side by side */
.ai-widget-status {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 11px;
    opacity: 0.9;
}

.ai-widget-status-connected { color: #10b981; }
.ai-widget-status-offline    { color: #f59e0b; }
.ai-widget-status-error      { color: #ef4444; }
.ai-widget-status-connecting { color: #94a3b8; }

.ai-widget-status-divider {
    color: rgba(255, 255, 255, 0.3);
    font-size: 10px;
}

/* Close button — top-right corner of header */
.ai-widget-close-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: opacity 0.2s, background 0.2s;
}

.ai-widget-close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
}

/* Messages */
.ai-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: var(--ai-widget-bg);
}

.ai-widget-message {
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 80%;
    margin-bottom: 12px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.ai-widget-message-bot {
    background-color: #334155;
    color: var(--ai-widget-text);
    align-self: flex-start;
}

.ai-widget-message-user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.ai-widget-message strong {
    font-weight: 600;
    color: #e2e8f0;
}

.ai-widget-message a {
    color: #60a5fa;
    text-decoration: underline;
}

.ai-widget-message a:hover {
    color: #93c5fd;
}

.ai-widget-message ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style-type: disc;
}

.ai-widget-message li {
    margin: 2px 0;
}

/* Input area */
.ai-widget-input-area {
    display: flex;
    gap: 8px;
    padding: 16px;
    background-color: var(--ai-widget-card);
    border-top: 1px solid var(--ai-widget-border);
}

.ai-widget-input-area input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--ai-widget-border);
    border-radius: 24px;
    background-color: var(--ai-widget-bg);
    color: var(--ai-widget-text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.ai-widget-input-area input:focus {
    border-color: var(--ai-widget-primary);
}

.ai-widget-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

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

/* Mobile */
@media (max-width: 480px) {
    .ai-widget-chat {
        top: 10px;
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
    }
}

/* ------------------------------------------------------------------
   Inline mode — widget mounted in-flow inside a page section.
   Activated when widget.js finds #ai-widget-inline-mount on the page.
   Overrides the fixed/floating positioning so the chat sits as a
   normal block element (e.g. on the home page "Ask my assistant"
   section), taking the full content width up to a reasonable cap.
   ------------------------------------------------------------------ */
.ai-widget-container.ai-widget-inline {
    position: static;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.ai-widget-container.ai-widget-inline .ai-widget-chat {
    position: static;
    top: auto;
    bottom: auto;
    right: auto;
    left: auto;
    width: 100%;
    height: 560px;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

@media (max-width: 600px) {
    .ai-widget-container.ai-widget-inline .ai-widget-chat {
        height: 480px;
    }
}
