/* ==========================================================================
   CHAT WIDGET — AI Assistant
   ========================================================================== */
#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: var(--font-sans);
}

/* Trigger Button */
.chat-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background: var(--card);
    border: 1px solid var(--border);
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}
.chat-trigger-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-xl);
}

/* Container */
.chatbox-container {
    width: 360px;
    height: 540px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: none;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 15px;
}
.chatbox-container.active { display: flex; }

/* Header */
.chatbox-header {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #f8fafc;
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-title {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
}
#close-chat-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
}
#close-chat-btn:hover { color: #f8fafc; }

.model-selector {
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
    padding: 5px 10px;
    border-radius: var(--radius-md);
    font-size: 12px;
    outline: none;
    cursor: pointer;
    width: 100%;
    font-family: var(--font-sans);
}
.model-selector option { background: #0f172a; }

/* Body */
.chatbox-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.message.user {
    background: var(--primary);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.message.ai {
    background: var(--card);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    border: 1px solid var(--border);
}

/* Loading */
.message.loading {
    background: var(--card);
    align-self: flex-start;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 18px;
    min-width: 50px;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    display: inline-block;
    animation: waveAnimation 1.3s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes waveAnimation {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.5; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* Footer */
.chatbox-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    border-top: 1px solid var(--border);
    background: var(--card);
}

.file-upload-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}
.file-upload-btn:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}
.upload-icon {
    width: 20px;
    height: 20px;
    color: var(--text);
    display: block;
}
.file-upload-btn.file-selected {
    background: var(--primary-soft);
    border-color: var(--primary);
}
.file-upload-btn.file-selected .upload-icon { color: var(--primary); }

.chatbox-footer input[type="text"] {
    flex: 1;
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--radius-full);
    outline: none;
    font-size: 13.5px;
    height: 40px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast);
}
.chatbox-footer input[type="text"]:focus { border-color: var(--primary); }

#send-btn {
    background: var(--primary);
    color: #ffffff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background var(--transition-fast), transform var(--transition-fast);
}
#send-btn:hover { background: var(--primary-dark); }
#send-btn:active { transform: scale(0.95); }

/* ===== RESPONSIVE — FULLSCREEN MOBILE ===== */
@media screen and (max-width: 480px) {
    #ai-chat-widget {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
    }
    .chatbox-container {
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
        margin-bottom: 0;
        border: none;
    }
    #ai-chat-widget:has(.chatbox-container.active) .chat-trigger-btn {
        display: none;
    }
    .chatbox-footer {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }
}