/* ==========================================================================
   WAP2 Chat – WhatsApp Chat Button & Popup
   ========================================================================== */

/* --- CSS Custom Properties (set inline from PHP) --- */
.wap2-widget {
    --wap2-btn-color: #25D366;
    --wap2-hdr-color: #075E54;
}

/* --- Overlay --- */
.wap2-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 400ms ease, visibility 400ms ease;
}

.wap2-overlay.wap2-show {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

/* --- Widget wrapper (fixed positioning) --- */
.wap2-widget {
    position: fixed;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: none; /* container never intercepts events */
}

/* Position variants */
.wap2-pos-bottom-right {
    bottom: 24px;
    right: 24px;
    align-items: flex-end;
}

.wap2-pos-bottom-left {
    bottom: 24px;
    left: 24px;
    align-items: flex-start;
}

.wap2-pos-middle-right {
    bottom: 50%;
    right: 24px;
    transform: translateY(50%);
    align-items: flex-end;
}

.wap2-pos-middle-left {
    bottom: 50%;
    left: 24px;
    transform: translateY(50%);
    align-items: flex-start;
}

/* --- Floating Button --- */
.wap2-btn {
    width: 60px !important;
    min-width: 60px !important;
    max-width: 60px !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
    border-radius: 50% !important;
    background: var(--wap2-btn-color) !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 250ms ease, box-shadow 250ms ease;
    order: 2;
    position: relative;
    z-index: 2;
    pointer-events: auto; /* re-enable on the actual button */
}

.wap2-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.wap2-btn:focus-visible {
    outline: 3px solid var(--wap2-hdr-color);
    outline-offset: 3px;
}

.wap2-btn svg {
    pointer-events: none;
}

/* --- Popup --- */
.wap2-popup {
    width: 360px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    order: 1;
    margin-bottom: 16px;
    pointer-events: auto; /* re-enable on the actual popup */

    /* Hidden state */
    visibility: hidden;
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    transform-origin: bottom center;
    transition: opacity 500ms cubic-bezier(.215, .61, .355, 1),
                transform 500ms cubic-bezier(.215, .61, .355, 1),
                visibility 500ms;
}

.wap2-popup.wap2-show {
    visibility: visible;
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Popup for left-aligned positions */
.wap2-pos-bottom-left .wap2-popup,
.wap2-pos-middle-left .wap2-popup {
    transform-origin: bottom left;
}

.wap2-pos-bottom-right .wap2-popup,
.wap2-pos-middle-right .wap2-popup {
    transform-origin: bottom right;
}

/* --- Popup Header --- */
.wap2-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--wap2-hdr-color) !important;
    color: #fff !important;
}

.wap2-popup-title {
    font-weight: 600;
    line-height: 1.3;
}

.wap2-popup-close {
    background: none !important;
    border: none;
    color: #fff !important;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 12px;
    opacity: 0.8;
    transition: opacity 200ms;
}

.wap2-popup-close:hover {
    opacity: 1;
}

/* --- Popup Message --- */
.wap2-popup-msg {
    padding: 16px 20px 8px;
    color: #555;
    line-height: 1.5;
}

/* --- Agent Card --- */
.wap2-agent {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    text-align: left;
}

.wap2-agent-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.wap2-agent-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--wap2-hdr-color) !important;
}

.wap2-agent-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
}

.wap2-agent-name {
    font-weight: 600;
    color: #222;
}

.wap2-agent-subtitle {
    color: #777;
}

.wap2-agent-hours {
    color: #999;
}

/* --- Textarea --- */
.wap2-popup-input {
    display: block;
    width: calc(100% - 40px);
    margin: 12px 20px;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
    resize: vertical;
    color: #333;
    line-height: 1.4;
    box-sizing: border-box;
}

.wap2-popup-input:focus {
    outline: none;
    border-color: var(--wap2-hdr-color);
    box-shadow: 0 0 0 2px rgba(7, 94, 84, 0.15);
}

.wap2-popup-input.wap2-input-invalid {
    border-color: #d93025;
    box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.15);
}

.wap2-input-error {
    margin: -4px 20px 8px;
    font-size: 12px;
    color: #d93025;
    line-height: 1.4;
}

/* --- Send Button --- */
.wap2-popup-send {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 20px 16px;
    padding: 12px 20px;
    background: var(--wap2-hdr-color) !important;
    color: #fff !important;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 200ms ease;
    text-align: center;
}

.wap2-popup-send:hover {
    opacity: 0.9;
    color: #fff !important;
}

.wap2-popup-send:focus-visible {
    outline: 3px solid var(--wap2-btn-color);
    outline-offset: 2px;
}

.wap2-popup-send svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Responsive — Mobile
   ========================================================================== */
@media (max-width: 480px) {
    .wap2-popup {
        width: calc(100vw - 32px);
        max-width: 360px;
    }

    .wap2-overlay.wap2-show {
        opacity: 0.25;
    }

    .wap2-pos-bottom-right,
    .wap2-pos-bottom-left {
        left: 16px;
        right: 16px;
    }

    .wap2-pos-bottom-right .wap2-btn {
        align-self: flex-end;
    }

    .wap2-pos-bottom-left .wap2-btn {
        align-self: flex-start;
    }

    .wap2-popup {
        width: 100%;
        max-width: none;
    }
}
