/* WhatsApp chat assistant */

.wa-chat {
    --wa-green: #25d366;
    --wa-dark: #075e54;
}

.wa-chat [hidden] {
    display: none !important;
}

/* ---------- animated chat icon ---------- */

.wa-launcher {
    position: fixed;
    z-index: 1100;
    right: 20px;
    bottom: calc(20px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
    display: grid;
    width: 62px;
    height: 62px;
    place-items: center;
    color: #ffffff;
    border-radius: 50%;
    background: var(--wa-green);
    box-shadow: 0 12px 28px rgba(7, 94, 84, 0.38);
    animation: waBounce 4s ease-in-out infinite;
}

.wa-launcher:hover {
    color: #ffffff;
    animation-play-state: paused;
    filter: brightness(1.06);
}

.wa-launcher > svg {
    width: 36px;
    height: 36px;
    animation: waWiggle 4s ease-in-out infinite;
}

/* Two rings that spread outwards */
.wa-launcher::before,
.wa-launcher::after {
    position: absolute;
    z-index: -1;
    inset: 0;
    border-radius: 50%;
    background: var(--wa-green);
    content: "";
    animation: waRing 2.4s ease-out infinite;
}

.wa-launcher::after {
    animation-delay: 1.2s;
}

.wa-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: var(--brand-primary);
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1;
}

.wa-open .wa-launcher,
.wa-open .wa-launcher > svg {
    animation: none;
}

.wa-open .wa-launcher::before,
.wa-open .wa-launcher::after {
    display: none;
}

/* ---------- greeting bubble ---------- */

.wa-greeting {
    position: fixed;
    z-index: 1099;
    right: 94px;
    bottom: calc(24px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
    max-width: 270px;
    border: 1px solid var(--neutral-200);
    border-radius: 16px 16px 4px 16px;
    background: #ffffff;
    box-shadow: var(--shadow-md);
    animation: waPop 450ms ease-out;
}

.wa-greeting-text {
    display: block;
    padding: 13px 30px 13px 15px;
    color: var(--neutral-800);
    background: transparent;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.5;
    text-align: left;
}

.wa-greeting-close {
    position: absolute;
    top: 2px;
    right: 4px;
    width: 26px;
    height: 26px;
    color: var(--neutral-500);
    background: transparent;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
}

/* ---------- chat window ---------- */

.wa-window {
    position: fixed;
    z-index: 1101;
    right: 20px;
    bottom: calc(96px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
    display: flex;
    flex-direction: column;
    width: 370px;
    height: 640px;
    max-height: calc(100vh - 116px - var(--footer-menu-space, 0px));
    max-height: calc(100dvh - 116px - var(--footer-menu-space, 0px));
    overflow: hidden;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: var(--shadow-lg);
    animation: waPop 300ms ease-out;
}

.wa-header {
    display: flex;
    gap: 11px;
    align-items: center;
    padding: 13px 14px;
    color: #ffffff;
    background: var(--wa-dark);
}

.wa-avatar {
    display: grid;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 50%;
    background: var(--wa-green);
}

.wa-avatar svg {
    width: 25px;
    height: 25px;
}

.wa-title {
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}

.wa-title strong {
    display: block;
    font-size: 0.92rem;
}

.wa-title small {
    display: block;
    font-size: 0.68rem;
    opacity: 0.85;
}

.wa-icon-button {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    color: #ffffff;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}

.wa-icon-button:hover {
    background: rgba(255, 255, 255, 0.16);
}

.wa-messages {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: 8px;
    min-height: 90px;
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #efe7de;
}

.wa-bubble {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    color: #1f1f1f;
    font-size: 0.85rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: pre-line;
    animation: waPop 250ms ease-out;
}

.wa-bot {
    align-self: flex-start;
    border-top-left-radius: 3px;
    background: #ffffff;
}

.wa-user {
    align-self: flex-end;
    border-top-right-radius: 3px;
    background: #d9fdd3;
}

.wa-typing {
    display: flex;
    gap: 4px;
    padding-block: 13px;
}

.wa-typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8a8a8a;
    animation: waDot 900ms ease-in-out infinite;
}

.wa-typing i:nth-child(2) {
    animation-delay: 150ms;
}

.wa-typing i:nth-child(3) {
    animation-delay: 300ms;
}

.wa-options {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 7px;
    max-height: 42%;
    padding: 0 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #efe7de;
}

.wa-options:not(:empty) {
    padding-block: 6px 12px;
}

.wa-option {
    padding: 8px 13px;
    border: 1px solid var(--wa-dark);
    border-radius: 999px;
    color: var(--wa-dark);
    background: #ffffff;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.3;
}

.wa-option:hover {
    color: #ffffff;
    background: var(--wa-dark);
}

.wa-option-primary {
    border-color: var(--wa-green);
    color: #06372f;
    background: var(--wa-green);
}

.wa-input {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--neutral-200);
}

.wa-input input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--neutral-300);
    border-radius: 999px;
    /* 16px stops phones from zooming in on the box */
    font-size: 16px;
}

.wa-input input:focus {
    border-color: var(--wa-dark);
    outline: 2px solid rgba(7, 94, 84, 0.2);
}

.wa-input button {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    color: #ffffff;
    border-radius: 50%;
    background: var(--wa-dark);
    cursor: pointer;
    font-size: 1rem;
}

/* ---------- visitor details form ---------- */

.wa-lead {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #efe7de;
}

.wa-lead > * {
    flex-shrink: 0;
}

.wa-lead > .wa-bubble {
    margin: 0;
}

.wa-lead-form {
    display: flex;
    flex-direction: column;
    padding: 14px;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.wa-lead-form label {
    margin-bottom: 3px;
    color: #333333;
    font-size: 0.76rem;
    font-weight: 700;
}

.wa-lead-form input:not([type="checkbox"]),
.wa-lead-form textarea {
    width: 100%;
    margin-bottom: 9px;
    padding: 8px 11px;
    border: 1px solid var(--neutral-300);
    border-radius: 9px;
    /* 16px stops phones from zooming in on the box */
    font-size: 16px;
}

.wa-lead-form textarea {
    border-radius: 9px;
    resize: vertical;
}

.wa-lead-form input:focus,
.wa-lead-form textarea:focus {
    border-color: var(--wa-dark);
    outline: 2px solid rgba(7, 94, 84, 0.2);
}

.wa-lead-form input[aria-invalid="true"] {
    border-color: var(--error);
}

.wa-lead-form .wa-lead-consent {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-weight: 500;
    line-height: 1.45;
}

.wa-lead-consent input {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    margin-top: 1px;
    accent-color: var(--wa-dark);
}

.wa-lead-consent a {
    color: var(--wa-dark);
    text-decoration: underline;
}

.wa-lead-error {
    margin: 6px 0;
    color: var(--error);
    font-size: 0.76rem;
    font-weight: 700;
}

.wa-lead-error:empty {
    margin: 4px 0;
}

.wa-lead-form button {
    padding: 11px;
    color: #06372f;
    border-radius: 999px;
    background: var(--wa-green);
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 800;
}

/* Keep the "back to top" button above the chat icon */
.back-to-top {
    right: 29px;
    bottom: calc(98px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
}

/* Hide the chat while the phone menu or gallery viewer is open */
body.menu-open .wa-chat,
.wa-open ~ .back-to-top {
    display: none;
}

/* ---------- phones ---------- */

@media (max-width: 575.98px) {
    .wa-launcher {
        right: 14px;
        bottom: calc(14px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
        width: 56px;
        height: 56px;
    }

    .wa-launcher > svg {
        width: 32px;
        height: 32px;
    }

    .wa-greeting {
        right: 80px;
        bottom: calc(17px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
        max-width: calc(100vw - 96px);
    }

    .wa-window {
        right: 8px;
        bottom: calc(80px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
        left: 8px;
        width: auto;
        max-height: calc(100vh - 92px - var(--footer-menu-space, 0px));
        max-height: calc(100dvh - 92px - var(--footer-menu-space, 0px));
    }

    .back-to-top {
        right: 20px;
        bottom: calc(82px + max(env(safe-area-inset-bottom, 0px), var(--footer-menu-space, 0px)));
    }

    /* Room so the chat icon does not cover the last footer line */
    .site-footer .footer-bottom {
        padding-bottom: 130px;
    }
}

/* Short screens, such as a phone held sideways */
@media (max-height: 520px) {
    .wa-window {
        top: 8px;
        bottom: 8px;
        height: auto;
        max-height: none;
    }

    .wa-header {
        padding-block: 7px;
    }

    .wa-messages {
        min-height: 0;
        padding-block: 8px;
    }

    .wa-options {
        max-height: 34%;
    }

    .wa-input {
        padding-block: 6px;
    }
}

/* 16px text stops iPhones from zooming into the enquiry form */
@media (max-width: 767.98px) {
    .enquiry-form input,
    .enquiry-form select,
    .enquiry-form textarea {
        font-size: 16px;
    }
}

/* ---------- phone footer menu (script from work.connecttoindia.net) ---------- */

/* Out of the way while the website's phone menu is open */
body.menu-open cti-footer-menu {
    display: none !important;
}

/* On short screens the open chat needs the whole height */
@media (max-height: 520px) {
    body:has(.wa-open) cti-footer-menu {
        display: none !important;
    }
}

/* ---------- animations ---------- */

@keyframes waRing {
    0% {
        opacity: 0.55;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(1.75);
    }
}

@keyframes waBounce {
    0%,
    70%,
    100% {
        transform: translateY(0);
    }

    78% {
        transform: translateY(-10px);
    }

    86% {
        transform: translateY(0);
    }

    92% {
        transform: translateY(-4px);
    }
}

@keyframes waWiggle {
    0%,
    70%,
    100% {
        transform: rotate(0);
    }

    76% {
        transform: rotate(-14deg);
    }

    82% {
        transform: rotate(12deg);
    }

    88% {
        transform: rotate(-7deg);
    }

    94% {
        transform: rotate(4deg);
    }
}

@keyframes waPop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes waDot {
    0%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    50% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .wa-launcher::before,
    .wa-launcher::after {
        display: none;
    }
}
