/* ==========================================================================
   Mellio AI — frontend-widget
   Färger, typsnitt och launcher-storlek kommer från CSS-variabler som
   sätts i wp_head (se class-widget.php).
   ========================================================================== */

#mellio-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: var(--mellio-font, inherit);
}

/*
 * Knappar, fält och textareor ärver INTE typsnitt av sig själva — utan detta
 * får de webbläsarens systemfont oavsett vad temat använder.
 */
#mellio-root button,
#mellio-root input,
#mellio-root textarea,
#mellio-root a {
    font-family: var(--mellio-font, inherit);
}

#mellio-root.mellio-pos-left {
    right: auto;
    left: 24px;
}

/* ---------- Launcher ---------- */

#mellio-launcher {
    width: var(--mellio-launcher-size, 64px);
    height: var(--mellio-launcher-size, 64px);
    border-radius: 50%;
    background: var(--mellio-primary);
    border: none;
    cursor: pointer;
    position: relative;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    transition: transform 0.15s ease;
    color: var(--mellio-text);
}

#mellio-launcher:hover { transform: scale(1.06); }

#mellio-launcher-face {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

#mellio-launcher img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#mellio-launcher .mellio-launcher-symbol {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56%;
    height: 56%;
    color: var(--mellio-text);
}

#mellio-launcher .mellio-launcher-symbol svg {
    width: 100%;
    height: 100%;
}

#mellio-launcher-badge {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 40%;
    height: 40%;
    min-width: 20px;
    min-height: 20px;
    border-radius: 50%;
    border: 2px solid var(--mellio-bg, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    box-sizing: border-box;
}

#mellio-launcher-badge.mellio-badge-bubble {
    background: var(--mellio-primary);
    color: var(--mellio-text);
}

#mellio-launcher-badge.mellio-badge-bubble svg {
    width: 58%;
    height: 58%;
}

#mellio-launcher-badge.mellio-badge-avatar {
    background: var(--mellio-bg, #fff);
}

#mellio-launcher-badge.mellio-badge-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#mellio-root.mellio-pos-left #mellio-launcher-badge {
    right: auto;
    left: -2px;
}

/* ---------- Teaserbubbla ----------
 * Ligger vid sidan om launchern. Utan width: max-content ärver en
 * absolutpositionerad ruta launcherns bredd som tillgängligt utrymme
 * och radbryter efter varje ord.
 */

#mellio-teaser {
    position: absolute;
    bottom: 6px;
    right: calc(var(--mellio-launcher-size, 64px) + 12px);
    display: flex;
    align-items: flex-start;
    gap: 2px;
    width: max-content;
    max-width: min(280px, calc(100vw - var(--mellio-launcher-size, 64px) - 60px));
    background: var(--mellio-bg, #fff);
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    padding: 2px 4px 2px 6px;
    animation: mellio-teaser-in 0.35s ease both;
}

#mellio-root.mellio-pos-left #mellio-teaser {
    right: auto;
    left: calc(var(--mellio-launcher-size, 64px) + 12px);
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
    animation-name: mellio-teaser-in-left;
}

#mellio-teaser[hidden] { display: none; }

#mellio-teaser-open {
    background: none;
    border: none;
    padding: 9px 4px 9px 8px;
    text-align: left;
    font-size: 13.5px;
    line-height: 1.45;
    color: inherit;
    cursor: pointer;
}

#mellio-teaser-close {
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    margin-top: 6px;
    cursor: pointer;
    color: inherit;
    opacity: 0.45;
    flex-shrink: 0;
}

#mellio-teaser-close:hover { opacity: 0.9; }

@keyframes mellio-teaser-in {
    from { opacity: 0; transform: translateX(8px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes mellio-teaser-in-left {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---------- Chattfönster ---------- */

#mellio-window {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: calc(var(--mellio-launcher-size, 64px) + 12px);
    right: 0;
    width: 340px;
    height: 500px;
    max-height: calc(100vh - 120px);
    background: var(--mellio-bg);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    overflow: hidden;
}

#mellio-root.mellio-pos-left #mellio-window {
    right: auto;
    left: 0;
}

#mellio-root.mellio-open #mellio-window {
    display: flex;
}

#mellio-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--mellio-primary);
    color: var(--mellio-text);
    flex-shrink: 0;
}

#mellio-header img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

#mellio-header span {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
}

#mellio-close {
    background: none;
    border: none;
    color: var(--mellio-text);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
}

#mellio-close:hover { opacity: 1; }

/* ---------- Meddelanden ---------- */

#mellio-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mellio-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.mellio-msg-bot {
    align-self: flex-start;
    background: var(--mellio-bubble);
    border-bottom-left-radius: 4px;
}

.mellio-msg-user {
    align-self: flex-end;
    background: var(--mellio-primary);
    color: var(--mellio-text);
    border-bottom-right-radius: 4px;
}

.mellio-msg-bot .mellio-link {
    color: var(--mellio-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}

.mellio-msg-bot .mellio-link:hover {
    text-decoration-thickness: 2px;
}

.mellio-msg-user .mellio-link {
    color: inherit;
    text-decoration: underline;
}

.mellio-typing {
    display: flex;
    gap: 5px;
    padding: 12px 14px;
    align-items: center;
}

.mellio-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--mellio-primary);
    opacity: 0.4;
    animation: mellio-pulse 1.2s ease-in-out infinite;
}

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

@keyframes mellio-pulse {
    0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* ---------- Snabbsvar ---------- */

#mellio-quick-replies {
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.mellio-qr-btn {
    background: transparent;
    border: 1.5px solid var(--mellio-primary);
    color: var(--mellio-primary);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mellio-qr-btn:hover {
    background: var(--mellio-primary);
    color: var(--mellio-text);
}

/* ---------- Inmatning ---------- */

#mellio-input-row {
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(0,0,0,0.08);
    padding: 8px 12px;
    gap: 8px;
    flex-shrink: 0;
}

#mellio-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    outline: none;
    padding: 6px 4px;
    color: inherit;
}

#mellio-send {
    background: var(--mellio-primary);
    color: var(--mellio-text);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

#mellio-send:hover { opacity: 0.85; }

/* ---------- Små skärmar ---------- */

@media (max-width: 480px) {
    #mellio-window {
        width: calc(100vw - 32px);
    }

    #mellio-teaser {
        max-width: calc(100vw - var(--mellio-launcher-size, 64px) - 48px);
    }

    #mellio-teaser-open {
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #mellio-teaser { animation: none; }
    #mellio-launcher { transition: none; }
}

/* ---------- Kontaktformulär ---------- */

.mellio-lead {
    background: var(--mellio-bubble);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.mellio-lead label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    opacity: 0.85;
}

.mellio-lead .mellio-optional {
    opacity: 0.6;
}

.mellio-lead input,
.mellio-lead textarea {
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 13px;
    background: var(--mellio-bg, #fff);
    color: inherit;
    width: 100%;
    box-sizing: border-box;
}

.mellio-lead input:focus,
.mellio-lead textarea:focus {
    outline: 2px solid var(--mellio-primary);
    outline-offset: -1px;
}

.mellio-lead button {
    background: var(--mellio-primary);
    color: var(--mellio-text);
    border: none;
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 13px;
    cursor: pointer;
    align-self: flex-start;
}

.mellio-lead button[disabled] {
    opacity: 0.6;
    cursor: default;
}

.mellio-lead-status:empty { display: none; }

.mellio-lead-status {
    margin: 0;
    font-size: 12px;
    color: #b32d2e;
}

/* ---------- Integritetsrad ---------- */

#mellio-privacy {
    margin: 0;
    padding: 0 14px 8px;
    font-size: 10.5px;
    line-height: 1.4;
    opacity: 0.6;
    text-align: center;
}

#mellio-privacy a {
    color: inherit;
    text-decoration: underline;
}
