/* Simulación de chat estilo WhatsApp — popup inferior derecho */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.wa-chat-root {
    --wa-green: #075e54;
    --wa-green-light: #128c7e;
    --wa-header: #075e54;
    --wa-bubble-in: #ffffff;
    --wa-bubble-out: #dcf8c6;
    --wa-bg: #e5ddd5;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: none;
}

.wa-chat-root * {
    pointer-events: auto;
    box-sizing: border-box;
}

.wa-chat-toggle-wrap {
    position: relative;
    display: inline-block;
}

.wa-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #25d366;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wa-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.wa-chat-toggle:focus-visible {
    outline: 2px solid #25d366;
    outline-offset: 3px;
}

.wa-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #e53935;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.2s;
}

.wa-chat-root.wa-has-unread .wa-chat-badge {
    opacity: 1;
    transform: scale(1);
}

.wa-chat-panel {
    position: absolute;
    right: 0;
    bottom: 68px;
    width: min(100vw - 2rem, 360px);
    height: min(70vh, 480px);
    max-height: calc(100vh - 120px);
    background: var(--wa-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.wa-chat-root.wa-open .wa-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.wa-chat-header {
    background: var(--wa-header);
    color: #fff;
    padding: 0.65rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.wa-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.wa-chat-header-text {
    flex: 1;
    min-width: 0;
}

.wa-chat-header-text strong {
    display: block;
    font-size: 1rem;
    font-weight: 600;
}

.wa-chat-header-text small {
    opacity: 0.9;
    font-size: 0.8rem;
}

.wa-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 50%;
    line-height: 1;
    font-size: 1.1rem;
}

.wa-chat-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.wa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background-color: var(--wa-bg);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23d4ccc4' fill-opacity='0.25' d='M0 0h30v30H0zm30 30h30v30H30z'/%3E%3C/svg%3E");
}

.wa-msg {
    max-width: 88%;
    padding: 0.45rem 0.65rem 0.35rem;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.wa-msg-in {
    align-self: flex-start;
    background: var(--wa-bubble-in);
    border-top-left-radius: 2px;
}

.wa-msg-out {
    align-self: flex-end;
    background: var(--wa-bubble-out);
    border-top-right-radius: 2px;
}

.wa-msg time {
    display: block;
    text-align: right;
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 0.2rem;
}

.wa-msg-in time {
    text-align: left;
}

.wa-typing {
    align-self: flex-start;
    background: var(--wa-bubble-in);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    border-top-left-radius: 2px;
    font-size: 0.85rem;
    color: #111111;
    display: none;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.wa-typing.wa-visible {
    display: block;
}

.wa-typing span {
    animation: wa-blink 1.2s infinite;
}

.wa-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.wa-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wa-blink {
    0%,
    60%,
    100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

.wa-chat-footer {
    background: #f0f0f0;
    padding: 0.5rem 0.5rem 0.5rem 0.65rem;
    display: flex;
    align-items: flex-end;
    gap: 0.35rem;
    flex-shrink: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.wa-chat-input {
    flex: 1;
    border: none;
    border-radius: 20px;
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.35;
}

.wa-chat-input:focus {
    outline: none;
}

.wa-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #25d366;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wa-chat-send:hover {
    filter: brightness(1.05);
}

.wa-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .wa-chat-root {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .wa-chat-panel {
        width: calc(100vw - 1.5rem);
        height: min(75vh, 520px);
    }
}
