/*
 * Widget CSS
 * CSS Custom Properties mapped to root for pixel-perfect theming.
 * Clean, animated, and responsive chat interface.
 */

:root {
    --widget-primary: #007bff;
    /* Overridden by JS per agent */
    --widget-bg: #ffffff;
    --widget-text: #333333;
    --widget-msg-bg-user: #e3f2fd;
    --widget-msg-bg-bot: #f1f3f4;
    --widget-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --widget-shadow-light: 0 4px 12px rgba(0, 0, 0, 0.1);
    --widget-shadow-heavy: 0 10px 24px rgba(0, 0, 0, 0.15);
    --widget-radius-lg: 16px;
    --widget-radius-sm: 8px;
    --widget-transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
}

/* Base structural elements to avoid conflicting with external sites */
.ai-widget-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: var(--widget-font);
}

/* Floating Toggle Button */
.ai-widget-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--widget-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--widget-shadow-light);
    transition: transform var(--widget-transition), box-shadow var(--widget-transition);
}

.ai-widget-toggle:hover {
    transform: scale(1.05);
    box-shadow: var(--widget-shadow-heavy);
}

.ai-widget-toggle svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
    transition: transform var(--widget-transition);
}

/* Close icon (hidden by default initially handled in JS) */
.ai-widget-toggle .icon-close {
    display: none;
}

.ai-widget-wrapper.open .ai-widget-toggle .icon-chat {
    display: none;
}

.ai-widget-wrapper.open .ai-widget-toggle .icon-close {
    display: block;
    transform: rotate(90deg);
}

/* Chat Window Container */
.ai-widget-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 600px;
    max-height: 80vh;
    background: var(--widget-bg);
    border-radius: var(--widget-radius-lg);
    box-shadow: var(--widget-shadow-heavy);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity var(--widget-transition), transform var(--widget-transition);
    transform-origin: bottom right;
}

.ai-widget-wrapper.open .ai-widget-container {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.ai-widget-header {
    background-color: var(--widget-primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    border-top-left-radius: var(--widget-radius-lg);
    border-top-right-radius: var(--widget-radius-lg);
}

.ai-widget-header-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

/* Chat Body (Messages) */
.ai-widget-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #f9f9f9;
}

/* Webkit Scrollbar styling for a cleaner look */
.ai-widget-body::-webkit-scrollbar {
    width: 6px;
}

.ai-widget-body::-webkit-scrollbar-track {
    background: transparent;
}

.ai-widget-body::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

/* Messages */
.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: fadeInUp 0.3s ease forwards;
}

.ai-msg-user {
    align-self: flex-end;
    background-color: var(--widget-msg-bg-user);
    color: var(--widget-text);
    border-radius: var(--widget-radius-lg) var(--widget-radius-lg) 0 var(--widget-radius-lg);
}

.ai-msg-bot {
    align-self: flex-start;
    background-color: var(--widget-msg-bg-bot);
    color: var(--widget-text);
    border-radius: var(--widget-radius-lg) var(--widget-radius-lg) var(--widget-radius-lg) 0;
}

/* Typing Indicator */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background-color: var(--widget-msg-bg-bot);
    border-radius: var(--widget-radius-lg) var(--widget-radius-lg) var(--widget-radius-lg) 0;
    align-self: flex-start;
    width: fit-content;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #888;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

/* Input Area */
.ai-widget-footer {
    padding: 16px;
    background-color: var(--widget-bg);
    border-top: 1px solid #eee;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ai-widget-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 100px;
    transition: border-color var(--widget-transition);
}

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

.ai-widget-send {
    background-color: var(--widget-primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color var(--widget-transition);
    flex-shrink: 0;
}

.ai-widget-send:hover {
    filter: brightness(0.9);
}

.ai-widget-send svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    margin-left: 2px;
    /* slight visual offset for play icon */
}

.ai-widget-send:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

@keyframes typingBounce {

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

    40% {
        transform: scale(1);
    }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .ai-widget-wrapper {
        bottom: 15px;
        right: 15px;
    }

    .ai-widget-container {
        width: calc(100vw - 30px);
        max-height: calc(100vh - 100px);
    }
}