/**
 * BWF LiveChat Widget — Styles
 * Design moderno tipo WhatsApp/Intercom. Dark mode auto.
 */

:root {
    --bwf-accent: #4f46e5;
    --bwf-accent-hover: #4338ca;
    --bwf-bubble-size: 56px;
    --bwf-window-w: 380px;
    --bwf-window-h: 560px;
    --bwf-radius: 16px;
    --bwf-radius-sm: 10px;
    --bwf-radius-msg: 18px;
    --bwf-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    --bwf-shadow-bubble: 0 4px 20px rgba(0, 0, 0, 0.15);
    --bwf-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --bwf-bg: #ffffff;
    --bwf-bg-secondary: #f7f7f8;
    --bwf-text: #1a1a2e;
    --bwf-text-muted: #6b7280;
    --bwf-border: #e5e7eb;
    --bwf-msg-visitor-bg: var(--bwf-accent);
    --bwf-msg-visitor-text: #ffffff;
    --bwf-msg-ai-bg: #f0f0f5;
    --bwf-msg-ai-text: #1a1a2e;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bwf-bg: #1e1e2e;
        --bwf-bg-secondary: #2a2a3d;
        --bwf-text: #e4e4e8;
        --bwf-text-muted: #9ca3af;
        --bwf-border: #3f3f5a;
        --bwf-msg-ai-bg: #2a2a3d;
        --bwf-msg-ai-text: #e4e4e8;
        --bwf-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
    }
}

/* ━━━ CONTAINER ━━━ */
.bwf-chat {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: var(--bwf-font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.bwf-chat--right {
    right: 20px;
}

.bwf-chat--left {
    left: 20px;
}

/* ━━━ BUBBLE ━━━ */
.bwf-chat__bubble {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bwf-accent);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4), 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    outline: none;
    position: relative;
    animation: bwf-bounce-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s both;
}

.bwf-chat__bubble svg {
    width: 28px;
    height: 28px;
}

.bwf-chat__bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(79, 70, 229, 0.5), 0 2px 12px rgba(0, 0, 0, 0.15);
}

.bwf-chat__bubble:active {
    transform: scale(0.92);
}

/* Pulse ring */
.bwf-chat__bubble::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--bwf-accent);
    opacity: 0;
    animation: bwf-pulse 2.5s ease-out infinite 2s;
    z-index: -1;
}

/* Greeting tooltip */
.bwf-chat__greeting {
    position: absolute;
    bottom: 8px;
    right: 76px;
    background: var(--bwf-bg);
    color: var(--bwf-text);
    padding: 10px 16px;
    border-radius: 12px 12px 4px 12px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    opacity: 0;
    transform: translateX(10px) scale(0.95);
    animation: bwf-greeting-in 0.4s ease-out 4s forwards;
    pointer-events: none;
    max-width: 260px;
}

.bwf-chat--left .bwf-chat__greeting {
    right: auto;
    left: 76px;
    border-radius: 12px 12px 12px 4px;
    transform: translateX(-10px) scale(0.95);
}

.bwf-chat__greeting-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bwf-text-muted);
    color: #fff;
    border: none;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    line-height: 1;
}

.bwf-chat__greeting.bwf-hidden {
    display: none;
}

/* Animations */
@keyframes bwf-pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

@keyframes bwf-bounce-in {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    60% {
        transform: scale(1.15);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes bwf-greeting-in {
    0% {
        opacity: 0;
        transform: translateX(10px) scale(0.95);
    }

    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.bwf-chat__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: bwf-badge-bounce 2s infinite;
}

@keyframes bwf-badge-bounce {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* ━━━ WINDOW ━━━ */
.bwf-chat__window {
    width: var(--bwf-window-w);
    height: var(--bwf-window-h);
    max-height: calc(100vh - 100px);
    background: var(--bwf-bg);
    border-radius: var(--bwf-radius);
    box-shadow: var(--bwf-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--bwf-border);
    animation: bwf-slide-up 0.25s ease;
}

@keyframes bwf-slide-up {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ━━━ HEADER ━━━ */
.bwf-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bwf-accent);
    color: #ffffff;
    flex-shrink: 0;
}

.bwf-chat__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bwf-chat__header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.bwf-chat__header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.bwf-chat__header-subtitle {
    font-size: 12px;
    opacity: 0.85;
}

.bwf-chat__close {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.bwf-chat__close:hover {
    opacity: 1;
}

/* ━━━ MESSAGES ━━━ */
.bwf-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bwf-bg-secondary);
    scroll-behavior: smooth;
}

.bwf-chat__messages::-webkit-scrollbar {
    width: 4px;
}

.bwf-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}

.bwf-chat__messages::-webkit-scrollbar-thumb {
    background: var(--bwf-border);
    border-radius: 4px;
}

.bwf-chat__welcome {
    text-align: center;
    padding: 20px 10px;
    color: var(--bwf-text-muted);
    font-size: 13px;
}

/* ━━━ MESSAGE BUBBLES ━━━ */
.bwf-chat__msg {
    display: flex;
    max-width: 85%;
}

.bwf-chat__msg--visitor {
    align-self: flex-end;
}

.bwf-chat__msg--ai {
    align-self: flex-start;
}

.bwf-chat__msg--system {
    align-self: center;
    max-width: 100%;
}

.bwf-chat__msg-bubble {
    padding: 10px 14px;
    border-radius: var(--bwf-radius-msg);
    word-break: break-word;
}

.bwf-chat__msg--visitor .bwf-chat__msg-bubble {
    background: var(--bwf-msg-visitor-bg);
    color: var(--bwf-msg-visitor-text);
    border-bottom-right-radius: 4px;
}

.bwf-chat__msg--ai .bwf-chat__msg-bubble {
    background: var(--bwf-msg-ai-bg);
    color: var(--bwf-msg-ai-text);
    border-bottom-left-radius: 4px;
}

.bwf-chat__msg-text {
    font-size: 14px;
    line-height: 1.5;
}

.bwf-chat__msg-text a {
    color: inherit;
    text-decoration: underline;
}

.bwf-chat__msg-time {
    font-size: 10px;
    opacity: 0.6;
    text-align: right;
    margin-top: 4px;
}

.bwf-chat__msg-system {
    font-size: 12px;
    color: var(--bwf-text-muted);
    background: var(--bwf-bg);
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid var(--bwf-border);
}

/* ━━━ TYPING INDICATOR ━━━ */
.bwf-chat__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    background: var(--bwf-bg-secondary);
}

.bwf-chat__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bwf-text-muted);
    animation: bwf-typing 1.2s infinite;
}

.bwf-chat__typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.bwf-chat__typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bwf-typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ━━━ INPUT ━━━ */
.bwf-chat__input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bwf-bg);
    border-top: 1px solid var(--bwf-border);
    flex-shrink: 0;
}

.bwf-chat__input {
    flex: 1;
    border: 1px solid var(--bwf-border);
    border-radius: var(--bwf-radius-sm);
    padding: 10px 14px;
    font-family: var(--bwf-font);
    font-size: 14px;
    line-height: 1.4;
    color: var(--bwf-text);
    background: var(--bwf-bg-secondary);
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 120px;
    transition: border-color 0.15s;
}

.bwf-chat__input:focus {
    border-color: var(--bwf-accent);
}

.bwf-chat__input::placeholder {
    color: var(--bwf-text-muted);
}

.bwf-chat__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bwf-accent);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.bwf-chat__send:hover:not(:disabled) {
    background: var(--bwf-accent-hover);
}

.bwf-chat__send:active:not(:disabled) {
    transform: scale(0.92);
}

.bwf-chat__send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ━━━ POWERED BY ━━━ */
.bwf-chat__powered {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: var(--bwf-text-muted);
    background: var(--bwf-bg);
}

.bwf-chat__powered a {
    color: var(--bwf-accent);
    text-decoration: none;
    font-weight: 600;
}

/* ━━━ MOBILE ━━━ */
@media (max-width: 480px) {
    .bwf-chat__window {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .bwf-chat {
        bottom: 16px;
    }

    .bwf-chat--right {
        right: 16px;
    }

    .bwf-chat--left {
        left: 16px;
    }
}

/* ━━━ PRE-CHAT FORM ━━━ */
.bwf-chat__prechat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 24px 24px;
    flex: 1;
    overflow-y: auto;
    background: var(--bwf-bg);
}

.bwf-prechat__icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--bwf-accent), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    opacity: 0.9;
}

.bwf-prechat__icon svg {
    stroke: #fff;
}

.bwf-prechat__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--bwf-text);
    margin: 0 0 6px;
    text-align: center;
}

.bwf-prechat__subtitle {
    font-size: 13px;
    color: var(--bwf-text-muted);
    margin: 0 0 24px;
    text-align: center;
    line-height: 1.5;
}

.bwf-prechat__form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bwf-prechat__field {
    width: 100%;
}

.bwf-prechat__input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--bwf-border);
    border-radius: var(--bwf-radius-sm);
    font-family: var(--bwf-font);
    font-size: 14px;
    color: var(--bwf-text);
    background: var(--bwf-bg-secondary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.bwf-prechat__input:focus {
    border-color: var(--bwf-accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.bwf-prechat__input::placeholder {
    color: var(--bwf-text-muted);
}

.bwf-prechat__input--error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
    animation: bwf-shake 0.4s ease;
}

@keyframes bwf-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.bwf-prechat__submit {
    width: 100%;
    padding: 13px 20px;
    margin-top: 6px;
    background: var(--bwf-accent);
    color: #fff;
    border: none;
    border-radius: var(--bwf-radius-sm);
    font-family: var(--bwf-font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s, transform 0.1s;
}

.bwf-prechat__submit:hover:not(:disabled) {
    background: var(--bwf-accent-hover);
}

.bwf-prechat__submit:active:not(:disabled) {
    transform: scale(0.98);
}

.bwf-prechat__submit:disabled {
    opacity: 0.6;
    cursor: default;
}

.bwf-prechat__privacy {
    text-align: center;
    font-size: 11px;
    color: var(--bwf-text-muted);
    margin: 12px 0 0;
    line-height: 1.5;
}

.bwf-prechat__privacy a {
    color: var(--bwf-accent);
    text-decoration: none;
}