/* ── LI Aftercare AI Chat Widget ─────────────────────────────────────────── */

:root {
    --liac-primary:      #0d6b6e;   /* Deep teal */
    --liac-primary-light:#12898d;
    --liac-accent:       #e8f7f7;
    --liac-accent2:      #00b4b8;
    --liac-text:         #1a2b2b;
    --liac-text-muted:   #5a7070;
    --liac-bubble-user:  #0d6b6e;
    --liac-bubble-ai:    #f4fafa;
    --liac-border:       #d0e8e8;
    --liac-bg:           #ffffff;
    --liac-shadow:       0 8px 32px rgba(13,107,110,.18), 0 2px 8px rgba(0,0,0,.08);
    --liac-radius:       16px;
    --liac-font:         'Georgia', 'Times New Roman', serif;
    --liac-font-ui:      -apple-system, 'Segoe UI', sans-serif;
    --liac-z:            99999;
}

/* ── Floating bubble ─────────────────────────────────────────────────────── */
#liac-float-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--liac-z);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--liac-primary), var(--liac-accent2));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(13,107,110,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    color: #fff;
}

#liac-float-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(13,107,110,.5);
}

#liac-float-btn svg { transition: transform .3s ease; }
#liac-float-btn.liac-open svg { transform: rotate(45deg); }

/* Pulse ring */
#liac-float-btn::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(13,107,110,.3);
    animation: liac-pulse 2.5s ease-out infinite;
}

@keyframes liac-pulse {
    0%   { transform: scale(1);   opacity: .8; }
    70%  { transform: scale(1.3); opacity: 0;  }
    100% { transform: scale(1.3); opacity: 0;  }
}

/* Badge */
#liac-float-btn .liac-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #e74c3c;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}
#liac-float-btn .liac-badge.visible { display: block; }

/* ── Floating panel ───────────────────────────────────────────────────────── */
#liac-float-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: var(--liac-z);
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    border-radius: var(--liac-radius);
    box-shadow: var(--liac-shadow);
    background: var(--liac-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--liac-border);
    transform-origin: bottom right;
    transform: scale(.85) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}

#liac-float-panel.liac-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Inline container ─────────────────────────────────────────────────────── */
.liac-inline-wrapper {
    border-radius: var(--liac-radius);
    overflow: hidden;
    box-shadow: var(--liac-shadow);
    border: 1px solid var(--liac-border);
}

.liac-chat-container.liac-inline {
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    border: none;
}

/* ── Shared container ─────────────────────────────────────────────────────── */
.liac-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--liac-bg);
    font-family: var(--liac-font-ui);
    color: var(--liac-text);
    -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.liac-chat-header {
    background: linear-gradient(135deg, var(--liac-primary) 0%, #0a5558 100%);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.liac-header-icon {
    font-size: 22px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.liac-header-text {
    flex: 1;
    min-width: 0;
}

.liac-header-title {
    display: block;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .01em;
}

.liac-header-status {
    display: block;
    color: rgba(255,255,255,.7);
    font-size: 11px;
    margin-top: 1px;
}

.liac-header-close {
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
    padding: 0;
}
.liac-header-close:hover { background: rgba(255,255,255,.25); }

/* ── Messages area ───────────────────────────────────────────────────────── */
.liac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.liac-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: liac-slide-in .2s ease;
}

@keyframes liac-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.liac-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--liac-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    border: 1px solid var(--liac-border);
}

.liac-msg.liac-user .liac-msg-avatar {
    background: var(--liac-primary);
    color: #fff;
    font-size: 12px;
    border-color: var(--liac-primary);
}

.liac-msg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
}

.liac-msg.liac-ai .liac-msg-bubble {
    background: var(--liac-bubble-ai);
    color: var(--liac-text);
    border: 1px solid var(--liac-border);
    border-bottom-left-radius: 4px;
}

.liac-msg.liac-user .liac-msg-bubble {
    background: var(--liac-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Markdown-like formatting inside AI bubbles */
.liac-msg-bubble strong { font-weight: 700; }
.liac-msg-bubble a { color: var(--liac-primary); }
.liac-msg.liac-user .liac-msg-bubble a { color: #a8e8ea; }
.liac-msg-bubble ul, .liac-msg-bubble ol { margin: 6px 0 6px 18px; padding: 0; }
.liac-msg-bubble li { margin-bottom: 3px; }
.liac-msg-bubble p { margin: 0 0 6px; }
.liac-msg-bubble p:last-child { margin-bottom: 0; }
.liac-msg-bubble h3, .liac-msg-bubble h4 { margin: 8px 0 4px; font-size: 14px; }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.liac-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--liac-bubble-ai);
    border: 1px solid var(--liac-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.liac-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--liac-text-muted);
    animation: liac-bounce .9s infinite;
}
.liac-typing span:nth-child(2) { animation-delay: .15s; }
.liac-typing span:nth-child(3) { animation-delay: .3s; }

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

/* ── Quick replies — flat mode ───────────────────────────────────────────── */
.liac-quick-replies {
    padding: 0 12px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.liac-quick-btn {
    background: var(--liac-accent);
    border: 1px solid var(--liac-border);
    color: var(--liac-primary);
    font-size: 12px;
    font-family: var(--liac-font-ui);
    padding: 5px 11px;
    border-radius: 20px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    line-height: 1.4;
    font-weight: 500;
}

.liac-quick-btn:hover {
    background: #d0f0f0;
    border-color: var(--liac-primary);
    transform: translateY(-1px);
}

/* ── Quick replies — topic group mode ───────────────────────────────────── */
.liac-quick-replies.liac-topic-mode {
    flex-direction: column;
    padding: 8px 12px;
    max-height: 220px;
    overflow-y: auto;
    border-top: 1px solid var(--liac-border);
    background: #f9fefe;
    gap: 4px;
}

.liac-quick-replies.liac-topic-mode::-webkit-scrollbar { width: 3px; }
.liac-quick-replies.liac-topic-mode::-webkit-scrollbar-thumb { background: var(--liac-border); border-radius: 3px; }

.liac-topic-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--liac-text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 4px;
    padding: 2px 0;
}

.liac-topic-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.liac-topic-btn {
    background: #fff;
    border: 1px solid var(--liac-border);
    color: var(--liac-primary);
    font-size: 12px;
    font-family: var(--liac-font-ui);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: background .15s, border-color .15s, box-shadow .15s;
    white-space: nowrap;
}

.liac-topic-btn:hover {
    background: var(--liac-accent);
    border-color: var(--liac-primary);
    box-shadow: 0 2px 6px rgba(13,107,110,.12);
}

.liac-back-btn {
    background: none;
    border: none;
    color: var(--liac-primary);
    font-size: 11px;
    font-family: var(--liac-font-ui);
    font-weight: 600;
    cursor: pointer;
    padding: 2px 0 4px;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.liac-back-btn:hover { color: var(--liac-primary-light); }

.liac-question-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.liac-question-btn {
    background: #fff;
    border: 1px solid var(--liac-border);
    color: var(--liac-text);
    font-size: 12.5px;
    font-family: var(--liac-font-ui);
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    line-height: 1.4;
    transition: background .15s, border-color .15s;
}

.liac-question-btn:hover {
    background: var(--liac-accent);
    border-color: var(--liac-primary);
    color: var(--liac-primary);
}

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

.liac-input {
    flex: 1;
    border: 1px solid var(--liac-border);
    border-radius: 12px;
    padding: 9px 13px;
    font-size: 14px;
    font-family: var(--liac-font-ui);
    line-height: 1.4;
    resize: none;
    background: #fff;
    color: var(--liac-text);
    transition: border-color .15s, box-shadow .15s;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
}

.liac-input:focus {
    border-color: var(--liac-primary);
    box-shadow: 0 0 0 3px rgba(13,107,110,.12);
}

.liac-input::placeholder { color: #9ab8b8; }

.liac-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--liac-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}

.liac-send-btn:hover { background: var(--liac-primary-light); transform: scale(1.05); }
.liac-send-btn:disabled { background: #b0cece; cursor: not-allowed; transform: none; }

/* ── Footer disclaimer ───────────────────────────────────────────────────── */
.liac-footer {
    padding: 6px 14px 8px;
    font-size: 10px;
    color: var(--liac-text-muted);
    text-align: center;
    line-height: 1.4;
    border-top: 1px solid var(--liac-border);
    background: #f9fefe;
    flex-shrink: 0;
}

/* ── Error messages ──────────────────────────────────────────────────────── */
.liac-error {
    background: #fff5f5 !important;
    border-color: #ffcdd2 !important;
    color: #c62828 !important;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #liac-float-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 88vh;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
    #liac-float-btn {
        bottom: 16px;
        right: 16px;
    }
    .liac-msg-bubble {
        max-width: 88%;
        font-size: 15px;
    }
    .liac-input {
        font-size: 16px; /* prevents iOS zoom on focus */
    }
    .liac-chat-header {
        padding: 16px 20px;
    }
    .liac-messages {
        padding: 16px 14px;
    }
    .liac-input-area {
        padding: 12px 14px;
    }
    .liac-quick-replies.liac-topic-mode {
        max-height: 240px;
    }
}
