/**
 * AI Chat Assistant — Premium Design
 * Inspired by modern chat UIs: clean, airy, professional
 */

#aca-chat-widget *,
#aca-chat-widget *::before,
#aca-chat-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#aca-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

#aca-chat-widget.aca-position-bottom-right { bottom: 24px; right: 24px; }
#aca-chat-widget.aca-position-bottom-left  { bottom: 24px; left: 24px; }

/* ═══════════════════════════
   BUBBLE (FAB)
═══════════════════════════ */
.aca-chat-bubble {
    width: var(--aca-bubble-size, 60px);
    height: var(--aca-bubble-size, 60px);
    border-radius: 50%;
    background: var(--aca-primary, #0055CC);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.22);
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s;
    position: relative;
    opacity: 0;
    transform: scale(0.5);
}
.aca-chat-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.28); }
.aca-chat-bubble:active { transform: scale(0.95); }
.aca-chat-bubble svg { fill: none; stroke: currentColor; }
.aca-chat-bubble img { width: 60%; height: 60%; object-fit: contain; border-radius: 50%; }

.aca-bubble-visible { opacity: 1 !important; transform: scale(1) !important; animation: aca-bubble-in 0.45s cubic-bezier(0.34,1.56,0.64,1); }
.aca-bubble-hidden  { opacity: 0 !important; transform: scale(0.4) !important; pointer-events: none; }

@keyframes aca-bubble-in {
    0%   { opacity: 0; transform: scale(0.3); }
    70%  { opacity: 1; transform: scale(1.07); }
    100% { opacity: 1; transform: scale(1); }
}

.aca-chat-bubble::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid var(--aca-primary, #0055CC);
    opacity: 0;
    animation: aca-pulse-ring 2.5s ease-out infinite;
    animation-delay: 5s;
}
@keyframes aca-pulse-ring {
    0%   { opacity: 0.5; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.5); }
}

/* ═══════════════════════════
   CHAT WINDOW
═══════════════════════════ */
#aca-chat-widget .aca-chat-window {
    position: absolute;
    bottom: 0;
    width: var(--aca-width, 370px);
    height: var(--aca-height, 540px);
    max-height: calc(100vh - 90px);
    background: #ffffff !important;
    border-radius: 16px;
    box-shadow: 0 16px 60px rgba(0,0,0,0.18), 0 4px 20px rgba(0,0,0,0.10);
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
    opacity: 0;
    transform: translateY(14px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.34,1.2,0.64,1);
    border: none;
}
.aca-position-bottom-right .aca-chat-window { right: 0; }
.aca-position-bottom-left  .aca-chat-window { left: 0; }
#aca-chat-widget .aca-chat-window.aca-chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ═══════════════════════════
   HEADER
═══════════════════════════ */
#aca-chat-widget .aca-chat-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--aca-primary, #0055CC) !important;
    color: #fff !important;
    flex-shrink: 0;
}

.aca-chat-header-info { display: flex; align-items: center; gap: 10px; }

.aca-header-avatar,
.aca-header-avatar-default {
    width: 38px; height: 38px;
    border-radius: 50%;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.35);
}
.aca-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aca-header-avatar-default { color: #fff; }
.aca-header-avatar-default svg { fill: none; stroke: currentColor; }

.aca-header-title    { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.25; }
.aca-header-subtitle {
    font-size: 11px; color: rgba(255,255,255,0.82); line-height: 1.3;
    display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.aca-header-subtitle::before {
    content: '';
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; display: inline-block; flex-shrink: 0;
}

.aca-chat-header-actions { display: flex; gap: 2px; }
.aca-header-btn {
    width: 32px; height: 32px; border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.9);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.aca-header-btn:hover { background: rgba(255,255,255,0.28); }
.aca-header-btn svg { fill: none; stroke: currentColor; }

/* ═══════════════════════════
   MESSAGES AREA
═══════════════════════════ */
#aca-chat-widget .aca-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px;
    background: #ffffff !important;
    scroll-behavior: smooth;
}
#aca-chat-widget .aca-chat-messages::-webkit-scrollbar { width: 4px; }
#aca-chat-widget .aca-chat-messages::-webkit-scrollbar-track { background: transparent; }
#aca-chat-widget .aca-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 4px; }

/* ═══════════════════════════
   MESSAGES
═══════════════════════════ */
.aca-message {
    display: flex;
    max-width: 82%;
    animation: aca-msg-in 0.22s ease-out;
}
@keyframes aca-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.aca-message-user {
    align-self: flex-end;
    justify-content: flex-end;
}
.aca-message-bot {
    align-self: flex-start;
}
.aca-message-system {
    align-self: center;
    max-width: 88%;
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    padding: 4px 0;
}

/* ── Bubbles ── */
.aca-message-bubble {
    padding: 11px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.6;
    font-size: 13.5px;
}

/* User bubble — solid primary, pill right corner squared */
.aca-bubble-user {
    background: var(--aca-user-bubble, #0055CC) !important;
    color: var(--aca-user-text, #ffffff) !important;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,85,204,0.25);
}

/* Bot bubble — white card with subtle shadow, left corner squared */
.aca-bubble-bot {
    background: #f0f4f9 !important;
    color: #1a1a2e !important;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.aca-bubble-bot a { color: var(--aca-primary, #0055CC); text-decoration: underline; text-underline-offset: 2px; }
.aca-bubble-bot a:hover { opacity: 0.8; }
.aca-bubble-bot strong { font-weight: 600; color: #0f172a; }
.aca-bubble-bot ul, .aca-bubble-bot ol { padding-left: 18px; margin: 6px 0; }
.aca-bubble-bot li { margin: 4px 0; }
.aca-bubble-bot p { margin: 0 0 6px; }
.aca-bubble-bot p:last-child { margin: 0; }
.aca-bubble-bot code {
    background: rgba(0,0,0,0.06); padding: 1px 5px;
    border-radius: 3px; font-size: 0.88em;
    font-family: 'SF Mono', 'Cascadia Code', monospace;
}

/* ── Typing ── */
.aca-typing-dots {
    display: flex; align-items: center; gap: 5px;
    padding: 13px 16px !important;
    background: #f0f4f9 !important;
}
.aca-typing-dots span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #94a3b8;
    animation: aca-typing 1.2s ease-in-out infinite;
}
.aca-typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.aca-typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes aca-typing {
    0%,60%,100% { opacity: 0.25; transform: translateY(0); }
    30%          { opacity: 1;    transform: translateY(-4px); }
}

/* ═══════════════════════════
   INPUT AREA
═══════════════════════════ */
#aca-chat-widget .aca-chat-input-area {
    padding: 12px 14px 14px;
    border-top: 1px solid #eef0f4;
    background: #ffffff !important;
    flex-shrink: 0;
}
.aca-chat-input-wrapper {
    display: flex; align-items: flex-end; gap: 8px;
    background: #f0f4f9;
    border: 1.5px solid transparent;
    border-radius: 26px;
    padding: 5px 5px 5px 16px;
    transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.aca-chat-input-wrapper:focus-within {
    border-color: var(--aca-primary, #0055CC);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0,85,204,0.10);
}
#aca-chat-input {
    flex: 1; border: none; outline: none; background: transparent;
    resize: none; font-family: inherit; font-size: 13.5px;
    line-height: 1.5; color: #1e293b;
    padding: 7px 0; max-height: 100px; overflow-y: auto;
}
#aca-chat-input::placeholder { color: #a0aec0; }

.aca-chat-send-btn {
    width: 36px; height: 36px; min-width: 36px;
    border-radius: 50%;
    background: var(--aca-primary, #0055CC);
    color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), background 0.15s;
    box-shadow: 0 2px 8px rgba(0,85,204,0.30);
}
.aca-chat-send-btn:hover:not(:disabled)  { transform: scale(1.1); }
.aca-chat-send-btn:active:not(:disabled) { transform: scale(0.94); }
.aca-chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.aca-chat-send-btn svg { fill: none; stroke: currentColor; }

.aca-powered-by { text-align: center; font-size: 10px; color: #c4cdd6; margin-top: 8px; }

/* ═══════════════════════════
   HANDOFF CARD
═══════════════════════════ */
.aca-handoff-card {
    background: #fff; border: 1.5px solid #e8edf4;
    border-radius: 14px; padding: 16px;
    align-self: flex-start; max-width: 92%;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
    animation: aca-msg-in 0.22s ease-out;
}
.aca-handoff-title    { font-weight: 700; font-size: 14px; color: #0f172a; margin-bottom: 4px; }
.aca-handoff-subtitle { font-size: 12px; color: #64748b; margin-bottom: 12px; }
.aca-handoff-actions  { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 4px; }
.aca-handoff-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 7px 14px; border-radius: 100px;
    font-size: 12px; font-weight: 600;
    cursor: pointer; text-decoration: none; border: none;
    transition: filter 0.15s; font-family: inherit;
}
.aca-handoff-btn:hover { filter: brightness(0.93); }
.aca-btn-call   { background: #dcfce7; color: #15803d; }
.aca-btn-email  { background: #eff6ff; color: #1d4ed8; }
.aca-btn-notify { background: #fef9c3; color: #a16207; }
.aca-handoff-form { margin-top: 12px; display: flex; flex-direction: column; gap: 7px; }
.aca-handoff-form input {
    border: 1.5px solid #e2e8f0; border-radius: 8px;
    padding: 8px 12px; font-size: 13px; color: #1e293b;
    outline: none; font-family: inherit; background: #f8fafc;
    transition: border-color 0.18s;
}
.aca-handoff-form input:focus { border-color: var(--aca-primary, #0055CC); background: #fff; }
.aca-handoff-send-btn {
    background: var(--aca-primary, #0055CC); color: #fff;
    border: none; border-radius: 8px; padding: 9px 16px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity 0.15s; font-family: inherit;
}
.aca-handoff-send-btn:hover:not(:disabled) { opacity: 0.88; }
.aca-handoff-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.aca-handoff-success {
    background: #f0fdf4; color: #166534;
    border: 1px solid #bbf7d0; border-radius: 8px;
    padding: 10px 14px; font-size: 13px; font-weight: 500;
}

/* ═══════════════════════════
   MOBILE
═══════════════════════════ */
@media (max-width: 480px) {
    #aca-chat-widget.aca-position-bottom-right,
    #aca-chat-widget.aca-position-bottom-left {
        bottom: 12px; right: 12px; left: 12px;
    }
    #aca-chat-widget .aca-chat-window {
        width: calc(100vw - 24px) !important;
        height: calc(100vh - 80px) !important;
        border-radius: 14px;
        right: 0 !important; left: 0 !important;
    }
    .aca-chat-bubble { position: fixed; bottom: 12px; right: 12px; }
    .aca-position-bottom-left .aca-chat-bubble { right: auto; left: 12px; }
}
