/* WhatsApp chat widget */

.wa-widget {
    --wa-green: #25d366;
    --wa-green-dark: #1da851;
    --wa-teal: #075e54;
    --wa-teal-light: #128c7e;
    --wa-chat-bg: #efeae2;
    --wa-bubble: #ffffff;
    --wa-offset: 24px;
    --wa-z: 990;
    position: fixed;
    bottom: var(--wa-offset);
    z-index: var(--wa-z);
    font-family: var(--font-body, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 14px;
}

.wa-pos-right { right: var(--wa-offset); }
.wa-pos-left  { left: var(--wa-offset); align-items: flex-start; }

/* ---------- Launcher ---------- */
.wa-launcher {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px 8px 10px;
    border: 0;
    border-radius: 999px;
    background: var(--wa-green);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(37, 211, 102, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
    position: relative;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.wa-launcher:hover {
    background: var(--wa-green-dark);
    transform: translateY(-2px);
    box-shadow: 0 14px 34px rgba(37, 211, 102, 0.4), 0 3px 8px rgba(0, 0, 0, 0.14);
}

.wa-launcher:focus-visible {
    outline: 3px solid rgba(37, 211, 102, 0.45);
    outline-offset: 3px;
}

.wa-launcher-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wa-launcher-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    white-space: nowrap;
}

.wa-launcher-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.85;
}

.wa-launcher-status {
    font-size: 0.9rem;
    font-weight: 600;
}

.wa-launcher-dot {
    position: absolute;
    top: 6px;
    left: 42px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4ade80;
    border: 2px solid var(--wa-green);
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
    animation: wa-pulse 2s infinite;
}

.wa-widget.is-offline .wa-launcher {
    background: #4b5563;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.wa-widget.is-offline .wa-launcher:hover { background: #374151; }
.wa-widget.is-offline .wa-launcher-dot,
.wa-widget.is-offline .wa-avatar-dot {
    background: #9ca3af;
    border-color: #4b5563;
    animation: none;
}

/* open state: launcher becomes the close button */
.wa-widget.is-open .wa-launcher-text { display: none; }
.wa-widget.is-open .wa-launcher {
    padding: 8px;
}
.wa-widget.is-open .wa-launcher-dot { display: none; }
.wa-widget.is-open .wa-launcher-icon svg { transform: rotate(90deg); }
.wa-launcher-icon svg { transition: transform 0.3s ease; }

@keyframes wa-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
    70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

/* ---------- Chat panel ---------- */
.wa-panel {
    width: 360px;
    max-width: calc(100vw - 2 * var(--wa-offset));
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    pointer-events: none;
}
.wa-pos-left .wa-panel { transform-origin: bottom left; }

.wa-widget.is-open .wa-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.wa-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--wa-teal) 0%, var(--wa-teal-light) 100%);
    color: #fff;
}

.wa-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    color: var(--wa-teal);
    font-family: var(--font-heading, 'Playfair Display', Georgia, serif);
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wa-avatar-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--wa-green);
    border: 2px solid var(--wa-teal-light);
}

.wa-panel-heading {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    line-height: 1.25;
}

.wa-panel-heading strong {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-status {
    font-size: 0.78rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease;
}
.wa-close:hover { background: rgba(255, 255, 255, 0.24); }

.wa-panel-body {
    background-color: var(--wa-chat-bg);
    background-image:
        radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px),
        radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px);
    background-size: 18px 18px;
    background-position: 0 0, 9px 9px;
    padding: 18px 14px;
    min-height: 180px;
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wa-msg {
    display: flex;
}
.wa-msg-in  { justify-content: flex-start; }
.wa-msg-out { justify-content: flex-end; }

.wa-msg-bubble {
    position: relative;
    max-width: 86%;
    background: var(--wa-bubble);
    border-radius: 12px;
    padding: 8px 12px 6px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
    font-size: 0.875rem;
    line-height: 1.5;
    color: #111;
    animation: wa-bubble-in 0.25s ease;
}
.wa-msg-in .wa-msg-bubble { border-top-left-radius: 4px; }
.wa-msg-out .wa-msg-bubble { background: #dcf8c6; border-top-right-radius: 4px; }

.wa-msg-bubble p { margin: 0; }

.wa-msg-name {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--wa-teal-light);
    margin-bottom: 2px;
}

.wa-msg-time {
    display: block;
    text-align: right;
    font-size: 0.68rem;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 4px;
}

@keyframes wa-bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wa-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 2px;
}
.wa-typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    animation: wa-typing 1.2s infinite;
}
.wa-typing i:nth-child(2) { animation-delay: 0.2s; }
.wa-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes wa-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.wa-panel-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: #f0f2f5;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.wa-panel-footer textarea {
    flex: 1;
    resize: none;
    border: 1px solid transparent;
    border-radius: 22px;
    padding: 10px 16px;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    background: #fff;
    color: #111;
    outline: none;
    max-height: 110px;
    min-height: 42px;
    transition: border-color 0.2s ease;
}
.wa-panel-footer textarea:focus { border-color: var(--wa-green); }

.wa-send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 0;
    border-radius: 50%;
    background: var(--wa-green);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}
.wa-send:hover { background: var(--wa-green-dark); transform: scale(1.05); }
.wa-send svg { margin-left: 2px; }

.wa-panel-note {
    padding: 6px 12px 8px;
    background: #f0f2f5;
    font-size: 0.68rem;
    text-align: center;
    color: rgba(0, 0, 0, 0.45);
}

/* ---------- Mobile: compact launcher + bottom sheet ---------- */
@media (max-width: 767px) {
    .wa-widget {
        --wa-offset: 16px;
        gap: 0;
    }

    .wa-launcher {
        padding: 0;
        width: 54px;
        height: 54px;
        justify-content: center;
    }
    .wa-launcher-text { display: none; }
    .wa-launcher-icon {
        width: 54px;
        height: 54px;
        background: transparent;
    }
    .wa-launcher-dot {
        top: 2px;
        left: auto;
        right: 2px;
    }
    .wa-widget.is-open .wa-launcher { padding: 0; }

    .wa-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        max-height: 82vh;
        border-radius: 18px 18px 0 0;
        transform: translateY(100%);
        transform-origin: bottom center;
    }
    .wa-widget.is-open .wa-panel { transform: translateY(0); }

    .wa-panel-body {
        max-height: none;
        flex: 1;
    }

    .wa-panel-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    /* sheet open: hide the launcher */
    .wa-widget.is-open .wa-launcher {
        opacity: 0;
        pointer-events: none;
    }
}

/* Backdrop for the mobile sheet */
.wa-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 989;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s;
}
.wa-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
}
@media (min-width: 768px) {
    .wa-backdrop { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .wa-launcher, .wa-panel, .wa-msg-bubble, .wa-launcher-icon svg { transition: none; animation: none; }
    .wa-launcher-dot { animation: none; }
}
