@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

/* ── Reset scope ─────────────────────────────────────────────────────────────── */
#localai-chat-root *,
#localai-chat-root *::before,
#localai-chat-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── CSS Variables (overridable via inline style on root) ──────────────────── */
#localai-chat-root {
    --lac-accent:       #4ade80;
    --lac-accent-dark:  #16a34a;
    --lac-accent-text:  #052e16;
    --lac-bg:           #ffffff;
    --lac-surface:      #f8fafc;
    --lac-border:       #e8ecf0;
    --lac-text:         #0f1117;
    --lac-text2:        #64748b;
    --lac-user-bg:      var(--lac-accent);
    --lac-user-text:    var(--lac-accent-text);
    --lac-ai-bg:        #ffffff;
    --lac-shadow:       0 12px 40px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.08);
    --lac-radius:       16px;
    --lac-radius-sm:    10px;
    position: fixed;
    z-index: 999999;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    pointer-events: none;
}

#localai-chat-root.lac-pos-left {
    right: auto;
    left: 24px;
    align-items: flex-start;
}

/* ── Launcher button ─────────────────────────────────────────────────────────── */
#lac-launcher {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px 0 16px;
    height: 52px;
    border-radius: 26px;
    background: var(--lac-accent);
    color: var(--lac-accent-text);
    border: none;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -.01em;
    transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
    white-space: nowrap;
}

#lac-launcher:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
}

#lac-launcher:active { transform: scale(.97); }

#lac-launcher .lac-launcher-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(0,0,0,.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* Pulse animation when closed */
@keyframes lac-pulse {
    0%   { box-shadow: 0 4px 16px rgba(0,0,0,.18), 0 0 0 0 color-mix(in srgb, var(--lac-accent) 60%, transparent); }
    70%  { box-shadow: 0 4px 16px rgba(0,0,0,.18), 0 0 0 10px transparent; }
    100% { box-shadow: 0 4px 16px rgba(0,0,0,.18), 0 0 0 0 transparent; }
}
#lac-launcher.lac-pulse { animation: lac-pulse 2.4s ease-out 2; }

/* ── Chat window ─────────────────────────────────────────────────────────────── */
#lac-window {
    width: 340px;
    height: 480px;
    background: var(--lac-bg);
    border-radius: var(--lac-radius);
    box-shadow: var(--lac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: all;
    transform-origin: bottom right;
    transform: scale(.85) translateY(16px);
    opacity: 0;
    transition: transform .28s cubic-bezier(.34,1.36,.64,1), opacity .2s ease;
    border: 1px solid var(--lac-border);
}

#localai-chat-root.lac-pos-left #lac-window {
    transform-origin: bottom left;
}

#lac-window.lac-open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
#lac-header {
    background: var(--lac-accent);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.lac-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0,0,0,.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.lac-header-info { flex: 1; min-width: 0; }
.lac-header-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--lac-accent-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lac-header-status {
    font-size: 11px;
    color: var(--lac-accent-text);
    opacity: .65;
    margin-top: 1px;
}

.lac-header-close {
    width: 28px; height: 28px; border-radius: 50%;
    background: rgba(0,0,0,.1);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; color: var(--lac-accent-text);
    flex-shrink: 0;
    transition: background .15s;
}
.lac-header-close:hover { background: rgba(0,0,0,.2); }

/* ── Messages ────────────────────────────────────────────────────────────────── */
#lac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--lac-surface);
    scroll-behavior: smooth;
}

#lac-messages::-webkit-scrollbar { width: 4px; }
#lac-messages::-webkit-scrollbar-track { background: transparent; }
#lac-messages::-webkit-scrollbar-thumb { background: var(--lac-border); border-radius: 2px; }

.lac-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: lac-msg-in .22s cubic-bezier(.25,.46,.45,.94) both;
}

@keyframes lac-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.lac-msg-ai   { align-self: flex-start; align-items: flex-start; }
.lac-msg-user { align-self: flex-end;   align-items: flex-end; }

.lac-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}

.lac-msg-ai   .lac-bubble {
    background: var(--lac-ai-bg);
    color: var(--lac-text);
    border: 1px solid var(--lac-border);
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.lac-msg-user .lac-bubble {
    background: var(--lac-user-bg);
    color: var(--lac-user-text);
    border-bottom-right-radius: 3px;
}

.lac-msg-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--lac-text2);
    margin-bottom: 3px;
    padding: 0 2px;
}

/* Typing indicator */
.lac-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 11px 14px;
}
.lac-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--lac-text2);
    animation: lac-bounce .9s ease-in-out infinite;
    opacity: .5;
}
.lac-dot:nth-child(2) { animation-delay: .18s; }
.lac-dot:nth-child(3) { animation-delay: .36s; }

@keyframes lac-bounce {
    0%,100% { transform: translateY(0); opacity:.5; }
    40%      { transform: translateY(-5px); opacity:1; }
}

/* Error message */
.lac-error-msg {
    align-self: center;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 12px;
    max-width: 90%;
    text-align: center;
}

/* ── Input area ──────────────────────────────────────────────────────────────── */
#lac-input-area {
    padding: 10px 12px;
    border-top: 1px solid var(--lac-border);
    background: var(--lac-bg);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

#lac-textarea {
    flex: 1;
    border: 1.5px solid var(--lac-border);
    border-radius: 20px;
    padding: 9px 15px;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--lac-text);
    background: var(--lac-surface);
    resize: none;
    outline: none;
    max-height: 110px;
    min-height: 38px;
    overflow-y: auto;
    transition: border-color .15s;
}

#lac-textarea:focus { border-color: var(--lac-accent); background: #fff; }
#lac-textarea::-webkit-scrollbar { width: 3px; }
#lac-textarea::-webkit-scrollbar-thumb { background: var(--lac-border); }

#lac-send-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--lac-accent);
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700;
    color: var(--lac-accent-text);
    flex-shrink: 0;
    transition: transform .15s, opacity .15s;
}
#lac-send-btn:hover  { transform: scale(1.08); }
#lac-send-btn:active { transform: scale(.94); }
#lac-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ── Footer ──────────────────────────────────────────────────────────────────── */
#lac-footer {
    text-align: center;
    font-size: 10px;
    color: var(--lac-text2);
    padding: 5px 12px 8px;
    background: var(--lac-bg);
    opacity: .55;
    letter-spacing: .02em;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
    #localai-chat-root {
        bottom: 0; right: 0; left: 0;
        align-items: stretch;
    }
    #localai-chat-root.lac-pos-left { left: 0; right: 0; }
    #lac-launcher { border-radius: 0; border-top-left-radius: 12px; border-top-right-radius: 12px; width: 100%; justify-content: center; }
    #lac-window { width: 100%; height: 72vh; border-radius: 0; border-top-left-radius: var(--lac-radius); border-top-right-radius: var(--lac-radius); }
}
