/* CSS Custom Properties — overridable via wpwa_css_variables filter */
:root {
    --wa-primary: #25d366;
    --wa-dark: #075e54;
    --wa-bg: #e5ddd5;
    --wa-bubble: #dcf8c6;
    --wa-text: #1e293b;
    --wa-white: #ffffff;
    --wa-shadow: 0 10px 30px rgba(0, 10, 30, 0.2);
}

/* Granular Animation Controls */
.wa-no-anim-pulse #wa-t { animation: none !important; }
.wa-no-anim-msg .wa-msg, .wa-no-anim-msg .wa-cs { animation: none !important; opacity: 1 !important; transform: none !important; }
.wa-no-anim-typing .wa-typing span { animation: none !important; transform: scale(1) !important; }
.wa-no-anim-window #wa-w { transition: none !important; transform: none !important; }

/* Reduced Motion — respect user preference */
@media (prefers-reduced-motion: reduce) {
    #wa-w,
    .wa-cta-label,
    .wa-msg,
    .wa-cs,
    .wa-chip,
    .wa-send-btn,
    #wa-t {
        transition: none !important;
        animation: none !important;
    }

    .wa-typing span {
        animation: none !important;
    }
}

#wa-f {
    position: fixed;
    z-index: var(--wa-z-index, 999999);
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    pointer-events: none;
    transition: opacity 0.3s;
}

#wa-f.wa-pos-right {
    align-items: flex-end;
}

#wa-f.wa-pos-left {
    align-items: flex-start;
}

#wa-f * {
    pointer-events: auto;
    box-sizing: border-box;
}

#wa-w {
    width: 315px;
    background: var(--wa-bg);
    color: var(--wa-text);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: var(--wa-shadow);
    margin-bottom: 15px;
    transition: 0.4s ease;
    opacity: 0;
    transform: translateY(40px);
    display: none;
    z-index: 2; /* Above trigger */
}

#wa-w.s {
    opacity: 1;
    transform: translateY(0);
    display: block;
}

#wa-t-c {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1; /* Below window */
    position: relative;
}

.wa-h {
    background: var(--wa-dark);
    color: var(--wa-white);
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.wa-x {
    position: absolute;
    right: 12px;
    top: 12px;
    cursor: pointer;
    opacity: 0.6;
    font-size: 16px;
}

.wa-x:hover,
.wa-x:focus {
    opacity: 1;
    outline: 2px solid var(--wa-white);
    outline-offset: 2px;
    border-radius: 2px;
}

.wa-logo {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--wa-white);
    flex-shrink: 0;
}

.wa-cta-label {
    background: var(--wa-white);
    color: var(--wa-text);
    padding: 8px 15px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    white-space: nowrap;
    opacity: 0;
    transform: translateX(10px);
    transition: all 0.4s ease;
    pointer-events: auto;
    position: relative;
}

.wa-cta-label:after {
    content: "";
    position: absolute;
    top: 50%;
    margin-top: -6px;
    border-width: 6px;
    border-style: solid;
}

.wa-pos-right .wa-cta-label { transform: translateX(10px); margin-right: 5px; }
.wa-pos-right .wa-cta-label:after { right: -12px; border-color: transparent transparent transparent var(--wa-white); }

.wa-pos-left .wa-cta-label { transform: translateX(-10px); margin-left: 5px; }
.wa-pos-left .wa-cta-label:after { left: -12px; border-color: transparent var(--wa-white) transparent transparent; }

.wa-cta-label.s {
    opacity: 1;
    transform: translateX(0);
}

.wa-b {
    padding: 15px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.wa-footer {
    padding: 10px 15px;
    background: var(--wa-white);
    border-top: 1px solid #eee;
    display: flex;
    justify-content: center;
}

.wa-send-btn {
    background: var(--wa-primary);
    color: var(--wa-white);
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 700;
    font-size: 14px;
    width: 100%;
    cursor: pointer;
    text-align: center;
    transition: 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.wa-send-btn:hover,
.wa-send-btn:focus {
    background: #128c7e;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    outline: 2px solid var(--wa-primary);
    outline-offset: 2px;
}

.wa-msg {
    background: var(--wa-white);
    color: var(--wa-text);
    padding: 12px;
    border-radius: 0 10px 10px 10px;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
    position: relative;
    opacity: 0;
    transform: translateY(10px);
    animation: wa-fade-in 0.4s ease forwards;
}

@keyframes wa-fade-in {
    to { opacity: 1; transform: translateY(0); }
}

.wa-msg:before {
    content: "";
    position: absolute;
    left: -10px;
    top: 0;
    border-style: solid;
    border-width: 0 12px 12px 0;
    border-color: transparent var(--wa-white) transparent transparent;
}

/* Typing Indicator */
.wa-typing {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 12px;
    background: var(--wa-white);
    color: var(--wa-text);
    border-radius: 0 10px 10px 10px;
    width: fit-content;
    margin-bottom: 12px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.wa-typing:before {
    content: "";
    position: absolute;
    left: -10px;
    top: 0;
    border-style: solid;
    border-width: 0 12px 12px 0;
    border-color: transparent var(--wa-white) transparent transparent;
}

.wa-typing span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    display: inline-block;
    animation: wa-typing-dots 1.4s infinite ease-in-out both;
}

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

@keyframes wa-typing-dots {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.wa-cs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 5px;
    opacity: 0;
    animation: wa-fade-in 0.4s ease 0.3s forwards;
}

.wa-chip {
    background: var(--wa-bubble);
    color: var(--wa-dark);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid #c7e9b4;
    transition: 0.2s;
    white-space: nowrap;
}

.wa-chip:hover,
.wa-chip:focus {
    background: var(--wa-dark);
    color: var(--wa-white);
    outline: 2px solid var(--wa-dark);
    outline-offset: 2px;
}

#wa-f.wa-pos-right #wa-t-c {
    flex-direction: row;
}

#wa-f.wa-pos-left #wa-t-c {
    flex-direction: row-reverse;
}

#wa-t {
    background: var(--wa-primary);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: transform 0.3s;
    animation: wa-pulse 2s infinite;
}

@keyframes wa-pulse {
    0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(37, 211, 102, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

#wa-t:hover,
#wa-t:focus {
    transform: scale(1.05);
    outline: 2px solid var(--wa-primary);
    outline-offset: 2px;
}

#wa-t svg {
    width: 30px;
    height: 30px;
    fill: white;
}

.wa-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    display: none;
}

.wa-badge.s {
    display: block;
}

/* Nudge animation */
.wa-nudge {
    animation: wa-nudge-pulse 0.7s ease;
}

@keyframes wa-nudge-pulse {
    0% { transform: scale(1); }
    30% { transform: scale(1.15); }
    60% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* Social Proof Badge */
#wa-social-proof {
    background: var(--wa-white);
    color: var(--wa-text);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 8px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: wa-fade-in 0.5s ease forwards;
}

#wa-social-proof::before {
    content: "";
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
    animation: wa-pulse-dot 2s infinite;
}

@keyframes wa-pulse-dot {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

@media(max-width:480px) {
    #wa-f {
        bottom: var(--wa-offset, 20px);
        right: 0;
        left: 0;
        width: 100%;
        padding: 0 var(--wa-offset, 20px);
        align-items: flex-end;
        pointer-events: none;
    }

    #wa-f.wa-pos-right {
        align-items: flex-end !important;
    }

    #wa-f.wa-pos-left {
        align-items: flex-start !important;
    }

    #wa-f.wa-pos-right #wa-t-c,
    #wa-f.wa-pos-left #wa-t-c {
        width: auto;
        z-index: 999998;
    }

    #wa-t-c.wa-hidden {
        display: none !important;
    }

    #wa-f.wa-pos-right #wa-t-c {
        flex-direction: row;
    }

    #wa-f.wa-pos-left #wa-t-c {
        flex-direction: row-reverse;
    }

    #wa-w {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0;
        margin-bottom: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(100%);
        height: auto;
        max-height: 80vh;
        display: block !important;
        opacity: 1 !important;
        z-index: var(--wa-z-index, 999999);
        pointer-events: auto;
    }

    #wa-w.s {
        transform: translateY(0);
    }

    .wa-b {
        max-height: 50vh;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }

    .wa-cs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 15px;
        margin-bottom: 0;
        gap: 10px;
        margin-top: auto;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .wa-cs::-webkit-scrollbar {
        display: none;
    }

    .wa-chip {
        flex: 0 0 auto;
    }

    #wa-f.wa-mobile-chips-vertical .wa-cs {
        flex-direction: column;
        flex-wrap: nowrap;
        overflow-x: visible;
        -webkit-overflow-scrolling: auto;
        padding-bottom: 5px;
        margin-top: 0;
    }

    #wa-f.wa-mobile-chips-vertical .wa-chip {
        flex: 0 0 auto;
        width: 100%;
        white-space: normal;
    }
}
