/**
 * BFI AI Chatbot Widget - Styles
 *
 * CSS custom properties (--ai-chatbot-primary, --ai-chatbot-primary-dark)
 * are set dynamically from the WordPress admin settings.
 *
 * ============================================================================
 *  CUSTOMER CAN OVERRIDE these styles via:
 *  - WordPress Admin → Design → Customizer → Additional CSS
 *  - Or a child theme stylesheet
 * ============================================================================
 */

/* CSS Variables for theming */
:root {
    --ai-chatbot-primary: #667eea;
    --ai-chatbot-primary-dark: #764ba2;
    --ai-chatbot-text: #333333;
    --ai-chatbot-bg: #ffffff;
    --ai-chatbot-border: #e2e8f0;
    --ai-chatbot-shadow: rgba(0, 0, 0, 0.15);
}

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

.ai-chatbot-widget.bottom-right {
    bottom: 24px;
    right: 24px;
}

.ai-chatbot-widget.bottom-left {
    bottom: 24px;
    left: 24px;
}

/* Toggle Button */
.ai-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-primary-dark) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px var(--ai-chatbot-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px var(--ai-chatbot-shadow);
}

.ai-chatbot-toggle svg {
    width: 28px;
    height: 28px;
    color: white;
}

.ai-chatbot-toggle .close-icon {
    display: none;
}

.ai-chatbot-toggle.active .chat-icon {
    display: none;
}

.ai-chatbot-toggle.active .close-icon {
    display: block;
}

/* Screen-reader-only text */
.ai-chatbot-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Chat Window */
.ai-chatbot-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 550px;
    background: var(--ai-chatbot-bg);
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--ai-chatbot-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: ai-chatbot-slideUp 0.3s ease;
}

.bottom-right .ai-chatbot-window {
    right: 0;
}

.bottom-left .ai-chatbot-window {
    left: 0;
}

.ai-chatbot-window.open {
    display: flex;
}

@keyframes ai-chatbot-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.ai-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-primary-dark) 100%);
    color: white;
}

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

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

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

.ai-chatbot-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.ai-chatbot-status {
    font-size: 0.75rem;
    opacity: 0.9;
}

.ai-chatbot-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: white;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.ai-chatbot-close:hover {
    opacity: 1;
}

.ai-chatbot-close svg {
    width: 20px;
    height: 20px;
}

/* Messages Area */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
}

.ai-chatbot-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}

.ai-chatbot-message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-chatbot-message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.ai-chatbot-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.ai-chatbot-message-time {
    margin-top: 3px;
    font-size: 0.68rem;
    color: #9ca3af;
    text-align: right;
}

.ai-chatbot-message.user .ai-chatbot-message-content {
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-primary-dark) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-chatbot-message.assistant .ai-chatbot-message-content {
    background: white;
    color: var(--ai-chatbot-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-chatbot-message.error .ai-chatbot-message-content {
    background: #fee2e2;
    color: #991b1b;
}

.ai-chatbot-message-content p {
    margin: 0;
}

.ai-chatbot-message-content strong {
    font-weight: 700;
}

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

.ai-chatbot-message-content a {
    color: var(--ai-chatbot-primary);
    text-decoration: underline;
}

.ai-chatbot-message.user .ai-chatbot-message-content a {
    color: white;
}

/* Sources */
.ai-chatbot-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 0.75rem;
    color: #666;
}

.ai-chatbot-sources-toggle {
    cursor: pointer;
    color: #666;
}

.ai-chatbot-sources-list {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-chatbot-sources a {
    display: inline-block;
    color: var(--ai-chatbot-primary);
    text-decoration: none;
}

.ai-chatbot-sources a:hover {
    text-decoration: underline;
}

/* Quick Action Buttons */
.ai-chatbot-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
    align-self: flex-start;
    max-width: 95%;
    margin-top: -12px;
}

.ai-chatbot-quick-btn {
    padding: 8px 16px;
    border: 1.5px solid var(--ai-chatbot-primary);
    border-radius: 20px;
    background: white;
    color: var(--ai-chatbot-primary);
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s;
    white-space: nowrap;
}

.ai-chatbot-quick-btn:hover:not(.disabled) {
    background: var(--ai-chatbot-primary);
    color: white;
}

.ai-chatbot-quick-btn.selected {
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-primary-dark) 100%);
    color: white;
    border-color: var(--ai-chatbot-primary-dark);
}

.ai-chatbot-quick-btn.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* Typing Indicator */
.ai-chatbot-typing {
    padding: 0 20px 10px;
    background: #f8f9fa;
    display: none;
}

.ai-chatbot-typing.visible {
    display: block;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--ai-chatbot-primary);
    border-radius: 50%;
    animation: ai-chatbot-typing 1.4s ease-in-out infinite;
}

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

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

@keyframes ai-chatbot-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Form */
.ai-chatbot-form {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 8px 16px;
    border: 1px solid var(--ai-chatbot-border);
    transition: border-color 0.2s;
}

.ai-chatbot-input-wrapper:focus-within {
    border-color: var(--ai-chatbot-primary);
}

.ai-chatbot-input {
    flex: 1;
    border: none;
    background: none;
    font-size: 0.9rem;
    outline: none;
    color: var(--ai-chatbot-text);
}

.ai-chatbot-input::placeholder {
    color: #999;
}

.ai-chatbot-submit {
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-primary-dark) 100%);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.ai-chatbot-submit:hover {
    transform: scale(1.1);
}

.ai-chatbot-submit svg {
    width: 18px;
    height: 18px;
    color: white;
}

.ai-chatbot-disclaimer {
    margin-top: 8px;
    font-size: 0.7rem;
    line-height: 1.3;
    color: #6b7280;
}

/* Footer */
.ai-chatbot-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: white;
    font-size: 0.7rem;
    color: #9ca3af;
    border-top: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-clear-link {
    color: #003770;
    text-decoration: underline;
    cursor: pointer;
    font-weight: bold;
}

.ai-chatbot-privacy-link {
    color: #9ca3af;
    text-decoration: none;
    cursor: pointer;
}

.ai-chatbot-clear-link:hover {
    color: #003770;
    text-decoration: underline;
}

.ai-chatbot-privacy-link:hover {
    color: #6b7280;
    text-decoration: underline;
}

.ai-chatbot-char-count {
    font-variant-numeric: tabular-nums;
    color: #999;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-chatbot-widget {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }

    .ai-chatbot-widget.bottom-left {
        right: 16px;
    }

    .ai-chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}
