/* ===================================
   Website Agent Chat Widget
   BGNova — Responsive Chat UI
   =================================== */

:root {
    --wa-primary: #5e72e4;
    --wa-primary-dark: #4a5bc7;
    --wa-bubble-size: 60px;
    --wa-window-w: 380px;
    --wa-window-h: 520px;
    --wa-radius: 16px;
    --wa-z: 99999;
}

/* ---- Floating Bubble ---- */
.wa-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--wa-bubble-size);
    height: var(--wa-bubble-size);
    border-radius: 50%;
    background: var(--wa-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: var(--wa-z);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.wa-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
.wa-chat-bubble:active {
    transform: scale(0.95);
}
.wa-chat-bubble svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}
.wa-chat-bubble.wa-open svg {
    transform: rotate(90deg);
}
.wa-chat-bubble .wa-unread {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #f5365c;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ---- Chat Window ---- */
.wa-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: var(--wa-window-w);
    height: var(--wa-window-h);
    background: #fff;
    border-radius: var(--wa-radius);
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.18);
    z-index: var(--wa-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.wa-chat-window.wa-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */
.wa-chat-header {
    background: var(--wa-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.wa-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.wa-chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wa-chat-header-avatar svg {
    width: 22px;
    height: 22px;
}
.wa-chat-header-info {
    flex: 1;
    min-width: 0;
}
.wa-chat-header-name {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
}
.wa-chat-header-status .wa-online-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #2dce89;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.wa-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.wa-chat-close:hover {
    opacity: 1;
}
.wa-chat-close svg {
    width: 20px;
    height: 20px;
}

/* ---- Messages Area ---- */
.wa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f8fc;
    scroll-behavior: smooth;
}
.wa-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.wa-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.wa-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* ---- Message Bubbles ---- */
.wa-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: waFadeIn 0.25s ease;
}
@keyframes waFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.wa-msg-agent {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e8eaf0;
    border-bottom-left-radius: 4px;
}
.wa-msg-visitor {
    align-self: flex-end;
    background: var(--wa-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.wa-msg-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.6;
}
.wa-msg-visitor .wa-msg-time {
    text-align: right;
}

/* ---- Typing Indicator ---- */
.wa-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e8eaf0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.wa-typing-dot {
    width: 8px;
    height: 8px;
    background: #bbb;
    border-radius: 50%;
    animation: waTyping 1.4s infinite ease-in-out;
}
.wa-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes waTyping {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ---- Input Area ---- */
.wa-chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}
.wa-chat-input {
    flex: 1;
    border: 1px solid #e0e3eb;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    background: #f7f8fc;
    transition: border-color 0.2s;
    resize: none;
    min-height: 42px;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
}
.wa-chat-input:focus {
    border-color: var(--wa-primary);
    background: #fff;
}
.wa-chat-input::placeholder {
    color: #aab0c0;
}
.wa-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--wa-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.wa-chat-send:hover {
    background: var(--wa-primary-dark);
}
.wa-chat-send:active {
    transform: scale(0.9);
}
.wa-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.wa-chat-send svg {
    width: 18px;
    height: 18px;
}

/* ---- Lead Form ---- */
.wa-lead-form {
    padding: 16px;
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
    padding-top: 0;
    padding-bottom: 0;
}
.wa-lead-form.wa-lead-visible {
    max-height: 400px;
    opacity: 1;
    padding: 16px;
}
.wa-lead-form h4 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #333;
}
.wa-lead-field {
    margin-bottom: 10px;
}
.wa-lead-field input,
.wa-lead-field select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #e0e3eb;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    background: #fff;
}
.wa-lead-field input:focus,
.wa-lead-field select:focus {
    border-color: var(--wa-primary);
}
.wa-lead-field input::placeholder {
    color: #aab0c0;
}
.wa-lead-submit {
    width: 100%;
    padding: 10px;
    background: var(--wa-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 4px;
}
.wa-lead-submit:hover {
    background: var(--wa-primary-dark);
}
.wa-lead-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.wa-lead-skip {
    display: block;
    text-align: center;
    font-size: 12px;
    color: #999;
    margin-top: 8px;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
}
.wa-lead-skip:hover {
    color: #666;
}
.wa-lead-success {
    text-align: center;
    padding: 16px;
}
.wa-lead-success svg {
    width: 40px;
    height: 40px;
    color: #2dce89;
    margin-bottom: 8px;
}
.wa-lead-success p {
    font-size: 13px;
    color: #666;
    margin: 0;
}

/* ---- Powered By ---- */
.wa-powered {
    text-align: center;
    font-size: 10px;
    color: #bbb;
    padding: 4px 0 6px;
    background: #fff;
    flex-shrink: 0;
}

/* ===================================
   MOBILE RESPONSIVE (≤ 768px)
   =================================== */
@media (max-width: 768px) {
    .wa-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    .wa-chat-bubble svg {
        width: 24px;
        height: 24px;
    }

    .wa-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        transform: translateY(100%);
    }
    .wa-chat-window.wa-visible {
        transform: translateY(0);
    }

    .wa-chat-header {
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top, 12px));
    }

    .wa-chat-input {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .wa-chat-input-area {
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }
}

/* ===================================
   Small phones (≤ 380px)
   =================================== */
@media (max-width: 380px) {
    .wa-msg {
        max-width: 90%;
        font-size: 13px;
    }
    .wa-lead-field input,
    .wa-lead-field select {
        padding: 8px 10px;
        font-size: 14px;
    }
}

/* ===================================
   DARK MODE (optional, respects system preference)
   =================================== */
@media (prefers-color-scheme: dark) {
    /* Only apply if you want dark mode auto-detect in future */
}
