/**
 * WA Chat Widget – Front-end Styles
 * ----------------------------------
 * Pure CSS, zero dependencies.
 * Uses CSS custom properties for easy theming.
 */

/* ── Design tokens ───────────────────────────── */
:root {
    --wacw-green:        #25D366;
    --wacw-green-dark:   #128C7E;
    --wacw-green-darker: #075E54;
    --wacw-bubble-bg:    #DCF8C6;
    --wacw-text:         #303030;
    --wacw-text-muted:   #667781;
    --wacw-white:        #ffffff;
    --wacw-shadow:       0 4px 24px rgba(0, 0, 0, .18);
    --wacw-radius:       16px;
    --wacw-btn-size:     60px;
    --wacw-z:            99999;
    --wacw-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                         Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue",
                         sans-serif;
}

/* ── Container ───────────────────────────────── */
#wacw-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--wacw-z);
    font-family: var(--wacw-font);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ── Device visibility helpers ───────────────── */
#wacw-container.wacw-hide-desktop {
    /* hide on screens wider than 768px */
}
@media (min-width: 769px) {
    #wacw-container.wacw-hide-desktop { display: none !important; }
}
#wacw-container.wacw-hide-mobile {
    /* hide on screens narrower than 768px */
}
@media (max-width: 768px) {
    #wacw-container.wacw-hide-mobile { display: none !important; }
}

/* ───────────────────────────────────────────────
   Floating Action Button (FAB)
   ─────────────────────────────────────────────── */
.wacw-fab {
    position: relative;
    width: var(--wacw-btn-size);
    height: var(--wacw-btn-size);
    border-radius: 50%;
    background: var(--wacw-green);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--wacw-shadow);
    transition: transform .3s cubic-bezier(.4,0,.2,1),
                background .25s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.wacw-fab:hover {
    transform: scale(1.08);
    background: var(--wacw-green-dark);
}

.wacw-fab:active {
    transform: scale(.95);
}

/* WhatsApp icon inside FAB */
.wacw-fab svg {
    width: 32px;
    height: 32px;
    fill: var(--wacw-white);
    transition: transform .3s ease;
}

/* Close icon (X) – shown when popup is open */
.wacw-fab .wacw-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(.5);
    transition: opacity .25s ease, transform .3s ease;
}
.wacw-fab.is-active .wacw-icon-wa {
    opacity: 0;
    transform: rotate(90deg) scale(.5);
}
.wacw-fab.is-active .wacw-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ── Pulse ring ──────────────────────────────── */
.wacw-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 3px solid var(--wacw-green);
    opacity: 0;
    animation: wacw-pulse-ring 2.2s cubic-bezier(.4,0,.6,1) infinite;
    pointer-events: none;
}

@keyframes wacw-pulse-ring {
    0%   { transform: scale(.85); opacity: .7; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* Hide pulse when popup is open */
.wacw-fab.is-active .wacw-pulse {
    animation: none;
    opacity: 0;
}

/* ── Tooltip ("Chat with us!") ───────────────── */
.wacw-tooltip {
    position: absolute;
    right: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    white-space: nowrap;
    background: var(--wacw-white);
    color: var(--wacw-text);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
}

/* Small triangle pointing right */
.wacw-tooltip::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right: none;
    border-left-color: var(--wacw-white);
}

.wacw-fab:hover .wacw-tooltip,
.wacw-fab:focus .wacw-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Hide tooltip when popup is open */
.wacw-fab.is-active .wacw-tooltip {
    opacity: 0 !important;
    pointer-events: none;
}

/* ───────────────────────────────────────────────
   Chat Popup
   ─────────────────────────────────────────────── */
.wacw-popup {
    position: absolute;
    bottom: calc(var(--wacw-btn-size) + 16px);
    right: 0;
    width: 340px;
    border-radius: var(--wacw-radius);
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,.22);
    transform-origin: bottom right;
    /* Hidden by default */
    opacity: 0;
    transform: scale(.7) translateY(10px);
    pointer-events: none;
    transition: opacity .3s cubic-bezier(.4,0,.2,1),
                transform .35s cubic-bezier(.4,0,.2,1);
}

.wacw-popup.is-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ── Popup Header ────────────────────────────── */
.wacw-popup-header {
    background: linear-gradient(135deg, var(--wacw-green-darker), var(--wacw-green-dark));
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--wacw-white);
}

/* Avatar */
.wacw-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.wacw-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Default avatar SVG fallback */
.wacw-avatar svg {
    width: 28px;
    height: 28px;
    fill: var(--wacw-white);
}

/* Online dot */
.wacw-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4ADE80;
    border: 2.5px solid var(--wacw-green-darker);
    box-sizing: border-box;
}

.wacw-agent-info {
    display: flex;
    flex-direction: column;
}

.wacw-agent-name {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .02em;
}

.wacw-agent-status {
    font-size: 12.5px;
    opacity: .85;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.wacw-agent-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
}

/* Close button inside header */
.wacw-popup-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: .7;
    transition: opacity .2s;
}

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

.wacw-popup-close svg {
    width: 18px;
    height: 18px;
    fill: var(--wacw-white);
}

/* ── Popup Body ──────────────────────────────── */
.wacw-popup-body {
    background: #E5DDD5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0l30 30-30 30L0 30z' fill='%23d4cdc3' fill-opacity='.08'/%3E%3C/svg%3E");
    padding: 20px 16px;
    min-height: 100px;
}

/* Chat bubble */
.wacw-bubble {
    background: var(--wacw-white);
    padding: 12px 16px;
    border-radius: 0 12px 12px 12px;
    max-width: 85%;
    font-size: 14px;
    color: var(--wacw-text);
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    position: relative;
    animation: wacw-bubble-in .4s cubic-bezier(.4,0,.2,1) both;
    animation-delay: .15s;
}

/* Bubble tail */
.wacw-bubble::before {
    content: "";
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: var(--wacw-white);
    border-left: none;
}

.wacw-bubble-time {
    display: block;
    text-align: right;
    font-size: 11px;
    color: var(--wacw-text-muted);
    margin-top: 6px;
}

@keyframes wacw-bubble-in {
    from { opacity: 0; transform: translateY(8px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Popup Footer / Start Chat ───────────────── */
.wacw-popup-footer {
    background: var(--wacw-white);
    padding: 14px 16px;
}

.wacw-start-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--wacw-green);
    color: var(--wacw-white);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background .25s ease, transform .2s ease;
    letter-spacing: .02em;
    -webkit-tap-highlight-color: transparent;
}

.wacw-start-chat:hover {
    background: var(--wacw-green-dark);
    transform: translateY(-1px);
}

.wacw-start-chat:active {
    transform: translateY(0) scale(.98);
}

.wacw-start-chat svg {
    width: 20px;
    height: 20px;
    fill: var(--wacw-white);
}

/* ───────────────────────────────────────────────
   Responsive tweaks
   ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    #wacw-container {
        bottom: 16px;
        right: 16px;
    }

    .wacw-popup {
        width: calc(100vw - 32px);
        right: 0;
    }

    :root {
        --wacw-btn-size: 54px;
    }

    .wacw-fab svg {
        width: 28px;
        height: 28px;
    }
}
