/* =========================================================
   Lila chatbot widget — frontend styles.
   Scoped to #lila-root so they don't leak into the host theme.
   ========================================================= */

#lila-root {
    --lila-accent: #5d5dff;
    --lila-surface: #16161A;
    --lila-text: #e4e1ee;
    --lila-muted: #908fa1;
    --lila-bg-user: rgba(93, 93, 255, 0.18);
    --lila-bg-bot: #1f1f28;
    --lila-border: #2a2a36;
    position: fixed;
    z-index: 2147483600;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Manrope, Inter, Roboto, sans-serif;
    color: var(--lila-text);
}

#lila-root.lila-pos-bottom-right { right: 20px; bottom: 20px; }
#lila-root.lila-pos-bottom-left  { left:  20px; bottom: 20px; }

/* FAB */
#lila-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--lila-accent);
    color: #fff;
    box-shadow: 0 10px 25px rgba(93, 93, 255, 0.35), 0 4px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
#lila-fab:hover  { transform: scale(1.05); }
#lila-fab:active { transform: scale(0.96); }
#lila-root.is-open #lila-fab { display: none; }

/* Panel */
#lila-panel {
    position: absolute;
    bottom: 0;
    width: min(380px, calc(100vw - 32px));
    height: min(580px, calc(100dvh - 40px));
    background: var(--lila-surface);
    color: var(--lila-text);
    border: 1px solid var(--lila-border);
    border-radius: 16px;
    box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.5), 0 8px 16px -8px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: lila-pop 0.18s ease-out;
}
#lila-root.lila-pos-bottom-right #lila-panel { right: 0; }
#lila-root.lila-pos-bottom-left  #lila-panel { left:  0; transform-origin: bottom left; }

@keyframes lila-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* Mobile: fullscreen panel + small icon-only FAB matching the LYB scroll-up button. */
@media (max-width: 480px) {
    #lila-root.lila-pos-bottom-right,
    #lila-root.lila-pos-bottom-left { right: 16px; left: 16px; bottom: 16px; }

    /* FAB sized + spaced to match .lyb-scrolltop (48×48 with 24px icon).
       Absolutely positioned within the full-width root so it stays in the
       corner while the panel can still stretch when open. */
    #lila-fab {
        width: 48px;
        height: 48px;
        position: absolute;
        bottom: 0;
    }
    #lila-root.lila-pos-bottom-right #lila-fab { right: 0; }
    #lila-root.lila-pos-bottom-left  #lila-fab { left:  0; }
    #lila-fab svg { width: 24px; height: 24px; }

    #lila-panel {
        width: auto;
        right: 0; left: 0;
        height: calc(100dvh - 24px);
        border-radius: 14px;
    }
}

/* Header */
#lila-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--lila-accent), color-mix(in srgb, var(--lila-accent) 55%, #000));
    color: #fff;
    flex-shrink: 0;
}
#lila-title    { font-size: 15px; font-weight: 600; line-height: 1.2; }
#lila-subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }
#lila-close {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
#lila-close:hover { background: rgba(255,255,255,0.22); }

/* Messages */
#lila-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
#lila-messages::-webkit-scrollbar         { width: 8px; }
#lila-messages::-webkit-scrollbar-thumb   { background: #2f2f3c; border-radius: 4px; }
#lila-messages::-webkit-scrollbar-track   { background: transparent; }

.lila-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.lila-bubble--bot {
    background: var(--lila-bg-bot);
    border: 1px solid var(--lila-border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.lila-bubble--user {
    background: var(--lila-bg-user);
    border: 1px solid color-mix(in srgb, var(--lila-accent) 40%, transparent);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Markdown-rendered inline elements inside bot bubbles */
.lila-bubble--bot strong { font-weight: 700; color: #fff; }
.lila-bubble--bot em     { font-style: italic; }
.lila-bubble--bot code   {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
}

/* Typing indicator */
.lila-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}
.lila-typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--lila-muted);
    animation: lila-blink 1.2s infinite ease-in-out;
}
.lila-typing span:nth-child(2) { animation-delay: 0.15s; }
.lila-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes lila-blink {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40%           { opacity: 1;   transform: translateY(-2px); }
}

/* Input form */
#lila-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--lila-border);
    background: var(--lila-surface);
    flex-shrink: 0;
}
#lila-input {
    flex: 1;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--lila-border);
    border-radius: 10px;
    background: #1b1b24;
    color: var(--lila-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease;
}
#lila-input:focus { border-color: var(--lila-accent); }
#lila-input::placeholder { color: var(--lila-muted); }

/* Prevent iOS zoom on focus */
@media (max-width: 768px) {
    #lila-input { font-size: 16px; }
}

#lila-send {
    width: 40px; height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--lila-accent);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}
#lila-send:hover  { background: color-mix(in srgb, var(--lila-accent) 90%, #fff); }
#lila-send:active { transform: scale(0.95); }
#lila-send:disabled {
    background: #3a3a48;
    cursor: not-allowed;
}

/* Disclaimer */
#lila-disclaimer {
    padding: 8px 14px 12px;
    font-size: 11px;
    color: var(--lila-muted);
    line-height: 1.4;
    text-align: center;
    background: var(--lila-surface);
    border-top: 1px solid var(--lila-border);
    flex-shrink: 0;
}
#lila-disclaimer a { color: var(--lila-accent); text-decoration: underline; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    #lila-panel,
    .lila-typing span { animation: none !important; }
    #lila-fab,
    #lila-send,
    #lila-close { transition: none !important; }
}
