/* ═══════════════════════════════════════════════════════════
   AI Help Widget - Styles
   Drop-in chat widget for any web application
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS Variables (override via ai-config.php accent_color) ─── */
:root {
    --ai-accent: #2563eb;
    --ai-accent-hover: #1d4ed8;
    --ai-accent-light: #eff6ff;
    --ai-bg: #ffffff;
    --ai-bg-chat: #f8fafc;
    --ai-text: #1e293b;
    --ai-text-light: #64748b;
    --ai-border: #e2e8f0;
    --ai-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 4px 20px rgba(0, 0, 0, 0.08);
    --ai-radius: 16px;
    --ai-font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Launcher Button ─── */
.ai-widget-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ai-accent);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
    z-index: 99998;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.ai-widget-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(37, 99, 235, 0.5);
    background: var(--ai-accent-hover);
}

.ai-widget-launcher svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}

.ai-widget-launcher.active svg.ai-icon-chat { display: none; }
.ai-widget-launcher.active svg.ai-icon-close { display: block; }
.ai-widget-launcher:not(.active) svg.ai-icon-chat { display: block; }
.ai-widget-launcher:not(.active) svg.ai-icon-close { display: none; }

/* Pulse animation on first load */
.ai-widget-launcher:not(.active)::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--ai-accent);
    animation: ai-pulse 2s ease-out 3;
}

@keyframes ai-pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ─── Left position variant ─── */
.ai-widget-launcher.ai-pos-left { right: auto; left: 24px; }
.ai-widget-window.ai-pos-left { right: auto; left: 24px; }

/* ─── Chat Window ─── */
.ai-widget-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--ai-bg);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--ai-font);
}

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

/* ─── Header ─── */
.ai-widget-header {
    background: var(--ai-accent);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.ai-widget-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ai-widget-header-text h4 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.ai-widget-header-text p {
    font-size: 11px;
    opacity: 0.8;
    margin: 0;
    line-height: 1.3;
}

.ai-widget-header-actions {
    display: flex;
    gap: 4px;
}

.ai-widget-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

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

.ai-widget-header-btn svg {
    width: 16px;
    height: 16px;
}

/* ─── Messages Area ─── */
.ai-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--ai-bg-chat);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.ai-widget-messages::-webkit-scrollbar {
    width: 5px;
}

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

.ai-widget-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* ─── Message Bubbles ─── */
.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ai-text);
    word-wrap: break-word;
    animation: ai-fadeIn 0.25s ease;
}

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

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

.ai-msg-bot {
    background: var(--ai-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ai-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ─── Bot message content formatting ─── */
.ai-msg-bot p {
    margin: 0 0 8px 0;
}

.ai-msg-bot p:last-child {
    margin-bottom: 0;
}

.ai-msg-bot strong, .ai-msg-bot b {
    font-weight: 600;
    color: var(--ai-text);
}

.ai-msg-bot ol, .ai-msg-bot ul {
    margin: 6px 0;
    padding-left: 20px;
}

.ai-msg-bot li {
    margin-bottom: 4px;
}

.ai-msg-bot code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
}

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

/* ─── Typing Indicator ─── */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--ai-bg);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ai-border);
}

.ai-typing-dot {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: ai-bounce 1.4s ease-in-out infinite;
}

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

@keyframes ai-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ─── Input Area ─── */
.ai-widget-input {
    padding: 12px 16px;
    background: var(--ai-bg);
    border-top: 1px solid var(--ai-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.ai-widget-input textarea {
    flex: 1;
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13.5px;
    font-family: var(--ai-font);
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 42px;
    line-height: 1.4;
    color: var(--ai-text);
    background: var(--ai-bg-chat);
    transition: border-color 0.2s;
}

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

.ai-widget-input textarea::placeholder {
    color: #94a3b8;
}

.ai-widget-send {
    width: 42px;
    height: 42px;
    border: none;
    background: var(--ai-accent);
    color: white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.ai-widget-send:hover:not(:disabled) {
    background: var(--ai-accent-hover);
    transform: scale(1.05);
}

.ai-widget-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-widget-send svg {
    width: 18px;
    height: 18px;
}

/* ─── Powered By ─── */
.ai-widget-powered {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #94a3b8;
    background: var(--ai-bg);
    border-top: 1px solid #f1f5f9;
}

.ai-widget-powered a {
    color: #64748b;
    text-decoration: none;
}

/* ─── Quick Actions (suggested questions) ─── */
.ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
    background: var(--ai-bg-chat);
}

.ai-quick-btn {
    padding: 6px 12px;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--ai-accent);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--ai-font);
}

.ai-quick-btn:hover {
    background: var(--ai-accent-light);
    border-color: var(--ai-accent);
}

/* ─── Error message ─── */
.ai-msg-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    font-size: 13px;
}

/* ─── Mobile Responsive ─── */
@media (max-width: 480px) {
    .ai-widget-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        max-height: calc(100vh - 80px);
        bottom: 72px;
        right: 8px;
        border-radius: 14px;
    }

    .ai-widget-window.ai-pos-left {
        left: 8px;
    }

    .ai-widget-launcher {
        width: 54px;
        height: 54px;
        bottom: 16px;
        right: 16px;
    }

    .ai-widget-launcher.ai-pos-left {
        left: 16px;
    }
}
