/* ==============================================
   logic.ai Chatbot — Frontend Widget
   Developer: Spencer Monteiro
   ============================================== */

#acb-root {
    --acb-primary:  #1a936f;
    --acb-dark:     #114b5f;
    --acb-accent:   #f4a261;
    --acb-white:    #ffffff;
    --acb-gray-50:  #f8fafc;
    --acb-gray-100: #f1f5f9;
    --acb-gray-200: #e2e8f0;
    --acb-gray-400: #94a3b8;
    --acb-gray-800: #1e293b;
    --acb-radius-full: 9999px;
    --acb-radius-lg:   20px;
    --acb-radius-md:   14px;
    --acb-radius-sm:   8px;
    --acb-shadow-xl: 0 20px 60px rgba(0,0,0,0.18);
    --acb-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Launcher ───────────────────────────────── */
.acb-launcher {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: var(--acb-radius-full);
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: transform var(--acb-transition), box-shadow var(--acb-transition);
    color: var(--acb-white);
}

.acb-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(0,0,0,0.28);
}

#acb-root.acb-pos-left .acb-launcher,
#acb-root.acb-pos-left .acb-widget {
    right: auto;
    left: 28px;
}

.acb-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--acb-accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: var(--acb-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: acbPulse 2s infinite;
}

@keyframes acbPulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.15); }
}

/* ── Widget ─────────────────────────────────── */
.acb-widget {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 380px;
    max-height: 620px;
    background: var(--acb-white);
    border-radius: var(--acb-radius-lg);
    box-shadow: var(--acb-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

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

/* ── Header ─────────────────────────────────── */
.acb-header {
    background: linear-gradient(135deg, var(--acb-dark) 0%, var(--acb-primary) 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--acb-white);
    position: relative;
    overflow: hidden;
}

.acb-header::after {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 100px;
    height: 100px;
    background: rgba(255,255,255,0.06);
    border-radius: 50%;
    pointer-events: none;
}

.acb-header-avatar { position: relative; flex-shrink: 0; }

.acb-avatar-ring {
    width: 44px;
    height: 44px;
    border-radius: var(--acb-radius-full);
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.acb-avatar-inner {
    font-weight: 800;
    font-size: 18px;
    color: var(--acb-white);
}

.acb-online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 11px;
    height: 11px;
    background: #4ade80;
    border-radius: 50%;
    border: 2px solid var(--acb-dark);
    animation: acbOnline 2.5s infinite;
}

@keyframes acbOnline {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0.4); }
    50%       { box-shadow: 0 0 0 4px rgba(74,222,128,0); }
}

.acb-header-info { flex: 1; }
.acb-header-info h2 { font-weight: 700; font-size: 15px; margin: 0 0 2px; }
.acb-header-info p  { font-size: 11.5px; opacity: 0.82; margin: 0; }
.acb-status-text    { color: #4ade80; font-weight: 500; }

.acb-header-actions { display: flex; gap: 6px; }

.acb-icon-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 6px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(255,255,255,0.85);
    transition: background var(--acb-transition);
}

.acb-icon-btn:hover { background: rgba(255,255,255,0.22); color: white; }

/* ── Body ───────────────────────────────────── */
.acb-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--acb-gray-50);
}

.acb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.acb-messages::-webkit-scrollbar { width: 4px; }
.acb-messages::-webkit-scrollbar-track { background: transparent; }
.acb-messages::-webkit-scrollbar-thumb { background: var(--acb-gray-200); border-radius: 99px; }

/* ── Messages ───────────────────────────────── */
.acb-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: acbMsgIn 0.3s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes acbMsgIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.acb-msg--user { flex-direction: row-reverse; }

.acb-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    color: white;
    flex-shrink: 0;
}

.acb-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: var(--acb-radius-md);
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.acb-msg--bot .acb-bubble {
    background: var(--acb-white);
    color: var(--acb-gray-800);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid var(--acb-gray-200);
}

.acb-msg--user .acb-bubble {
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-dark));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.acb-msg--bot .acb-bubble a {
    color: var(--acb-primary);
    font-weight: 600;
    text-decoration: underline;
}

.acb-msg--error .acb-bubble {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.acb-msg-time {
    font-size: 10px;
    color: var(--acb-gray-400);
    margin-top: 4px;
    padding: 0 4px;
}

/* ── Typing ─────────────────────────────────── */
.acb-typing {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.acb-typing-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    color: white;
    flex-shrink: 0;
}

.acb-typing-dots {
    background: var(--acb-white);
    border: 1px solid var(--acb-gray-200);
    padding: 12px 16px;
    border-radius: var(--acb-radius-md);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.acb-typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--acb-primary);
    border-radius: 50%;
    opacity: 0.5;
    animation: acbTyping 1.4s infinite;
}

.acb-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.acb-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes acbTyping {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.5; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Quick replies ──────────────────────────── */
.acb-quick-replies {
    padding: 8px 16px 12px;
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    background: var(--acb-gray-50);
    border-top: 1px solid var(--acb-gray-100);
}

.acb-quick-btn {
    padding: 6px 12px;
    background: var(--acb-white);
    border: 1.5px solid var(--acb-gray-200);
    border-radius: var(--acb-radius-full);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--acb-dark);
    cursor: pointer;
    transition: all var(--acb-transition);
    white-space: nowrap;
    font-family: inherit;
}

.acb-quick-btn:hover {
    background: var(--acb-gray-50);
    border-color: var(--acb-primary);
    color: var(--acb-primary);
    transform: translateY(-1px);
}

/* ── Input ──────────────────────────────────── */
.acb-input-area {
    padding: 12px 16px 14px;
    background: var(--acb-white);
    border-top: 1px solid var(--acb-gray-200);
}

.acb-input-wrap {
    display: flex;
    align-items: center;
    background: var(--acb-gray-50);
    border: 1.5px solid var(--acb-gray-200);
    border-radius: var(--acb-radius-full);
    padding: 6px 8px 6px 16px;
    transition: border-color var(--acb-transition), box-shadow var(--acb-transition);
}

.acb-input-wrap:focus-within {
    border-color: var(--acb-primary);
    box-shadow: 0 0 0 3px rgba(26,147,111,0.1);
    background: var(--acb-white);
}

#acb-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13.5px;
    color: var(--acb-gray-800);
    outline: none;
    padding: 4px 0;
    font-family: inherit;
}

#acb-input::placeholder { color: var(--acb-gray-400); }

#acb-send {
    width: 36px;
    height: 36px;
    border-radius: var(--acb-radius-full);
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: transform var(--acb-transition), box-shadow var(--acb-transition), opacity var(--acb-transition);
    flex-shrink: 0;
}

#acb-send:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#acb-send:disabled { opacity: 0.5; cursor: not-allowed; }

.acb-powered {
    text-align: center;
    font-size: 10.5px;
    color: var(--acb-gray-400);
    margin-top: 8px;
    margin-bottom: 0;
}

.acb-powered a { color: var(--acb-primary); text-decoration: none; font-weight: 500; }
.acb-powered a:hover { text-decoration: underline; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 480px) {
    .acb-widget {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border-top-left-radius: var(--acb-radius-lg);
        border-top-right-radius: var(--acb-radius-lg);
    }
    .acb-launcher { bottom: 20px; right: 20px; }
}

/* ── Avatar image support ───────────────────────────────────────── */
.acb-avatar-ring {
    overflow: hidden;
    padding: 4px;
    background: white;
}

.acb-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 50%;
}

.acb-typing-avatar .acb-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* When avatar is an image, override gradient background */
.acb-header-avatar .acb-avatar-ring:has(.acb-avatar-img) {
    background: white;
    border-color: rgba(255,255,255,0.35);
}
