/* --- CHAT FLOTANTE --- */
/* En móvil, espacio extra por encima de la barra inferior del iframe (jugamos.lat) */
:root {
    --chat-embed-tab-bar-offset: 0px;
}

/* Teléfonos y vistas estrechas: el chat sube para no tapar la barra del casino (iframe) */
@media (max-width: 640px) {
    :root {
        --chat-embed-tab-bar-offset: 58px;
    }

    /* registro.html: no hay iframe del casino; bajar la burbuja para no tapar “¿Ya tenés cuenta? Entrar” */
    body.smartplay-page-registro {
        --chat-embed-tab-bar-offset: 0px;
    }

    body.smartplay-page-registro .chat-widget {
        bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }
}

.chat-widget {
    position: fixed;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px) + var(--chat-embed-tab-bar-offset, 0px));
    /* Margen extra respecto al safe-area para que el badge no quede pegado al borde físico */
    right: max(20px, env(safe-area-inset-right, 0px) + 12px);
    width: 300px;
    height: 400px;
    max-height: calc(100dvh - 2rem - env(safe-area-inset-bottom, 0px) - var(--chat-embed-tab-bar-offset, 0px));
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    z-index: 2100; /* por encima del iframe; la intro (.casino-intro) va z-index 2000 */
    overflow: hidden; /* el scroll va dentro de .chat-body / .auth-container */
    transition: height 0.25s ease, width 0.3s ease, box-shadow 0.3s ease;
}

/* Login / registro: más alto para que entren todos los campos alineados */
.chat-widget.chat-widget--auth:not(.minimized) {
    height: min(540px, calc(100dvh - 2rem - env(safe-area-inset-bottom, 0px) - var(--chat-embed-tab-bar-offset, 0px)));
}

/* Estado minimizado (Botón pequeño) */
.chat-widget.minimized {
    width: 200px; /* Un poco más ancho para que entre el subtítulo */
    height: 50px; /* Ajustado a la nueva altura del header */
    border-radius: 25px; /* Forma de píldora */
    background-color: transparent; /* Evita que se vea el fondo blanco del contenedor */
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); /* Sombra ajustada para la píldora */
    /* El badge (#userUnreadBadge) sobresale con right negativo; overflow:hidden lo recortaba a la mitad en móvil */
    overflow: visible;
}

.chat-header {
    background-color: #075e54; /* Verde oscuro WhatsApp */
    color: white;
    padding: 10px 15px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px; /* Un poco más alto para la foto */
    box-sizing: border-box;
    border-radius: 10px 10px 0 0;
    position: relative; /* Necesario para posicionar el badge absolutamente relativo a este contenedor */
}

.chat-widget.minimized .chat-header {
    border-radius: 25px; /* Bordes totalmente redondeados cuando está minimizado */
    height: 50px;
    position: relative;
    z-index: 3; /* Por encima del cuerpo: los toques abren el chat */
    flex-shrink: 0;
    touch-action: manipulation;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 15px; /* Aumentado de 10px a 15px para más separación */
}

#logoutBtnHeader {
    background: transparent;
    color: white;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px; /* Agregado padding para que el área táctil sea más grande */
    display: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

#toggleIcon {
    padding: 5px; /* Agregado padding para que el área táctil sea más grande */
}

#logoutBtnHeader:hover {
    opacity: 1;
}

.chat-header-img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #fff;
}

.chat-header span {
    font-size: 0.95rem;
    white-space: nowrap;
}

/* Ocultar el texto si se requiere más espacio */
.chat-widget.minimized .chat-header span:first-child {
    font-size: 0.85rem;
}

.chat-widget.minimized .chat-header span:last-child {
    font-size: 0.7rem; /* Icono de flecha más chico también */
}

.chat-body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0; /* clave: el flex hijo puede encogerse y hacer scroll interno */
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 8px;
    overflow: hidden;
    background-color: #efeae2; /* Fondo estilo WhatsApp */
    opacity: 1;
    transition: opacity 0.2s ease;
    border-radius: 0 0 10px 10px;
}

.chat-widget.minimized .chat-body {
    opacity: 0;
    visibility: hidden;
    /* Colapsar por completo: si el cuerpo ocupa espacio, en iOS/Android los hijos
       pueden seguir recibiendo toques aunque el padre tenga pointer-events: none */
    flex: 0 0 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    pointer-events: none;
}

/* Ningún control del panel puede “robar” el toque cuando la burbuja está cerrada */
.chat-widget.minimized .chat-body * {
    pointer-events: none !important;
}

/* Formularios (Auth) — columna alineada, ancho completo del panel */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    justify-content: flex-start;
    padding-top: 4px;
    padding-bottom: 8px; /* espacio al hacer scroll hasta “Ingresar” en pantallas chicas */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y manipulation;
    position: relative;
    z-index: 1;
}

.auth-container h3 {
    font-size: 1rem;
    flex-shrink: 0;
}

.auth-container input[type="text"],
.auth-container input[type="email"],
.auth-container input[type="password"],
.auth-container input[type="tel"] {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.85rem;
}

.auth-container .phone-row {
    display: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    align-items: stretch;
    gap: 6px;
}

.auth-container .phone-row.phone-row--visible {
    display: flex !important;
}

.auth-container #countryCode {
    flex: 0 0 34%;
    width: auto !important;
    min-width: 0;
    box-sizing: border-box;
    padding: 8px 4px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.8rem;
}

.auth-container #phoneInput {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
}

.auth-container #authBtn {
    width: 100%;
    box-sizing: border-box;
    margin-top: 4px;
    padding: 12px 10px;
    min-height: 44px; /* área táctil cómoda en celular */
    background-color: #1a1a1a;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    touch-action: manipulation; /* menos retraso / gestos raros en iOS */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 2;
}

.auth-container button {
    padding: 8px;
    background-color: #1a1a1a;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
}

.auth-container button:hover {
    background-color: #333;
}

.auth-toggle {
    text-align: center;
    font-size: 0.8rem;
    color: #666;
    cursor: pointer;
    margin-top: 5px;
}

.auth-toggle:hover {
    text-decoration: underline;
}

#registerHint {
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

#authError {
    flex-shrink: 0;
}

#quickQuestions {
    flex-shrink: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    padding: 6px 4px !important;
    gap: 4px !important;
}

/* Mensajes (Chat) */
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: none; /* Oculto hasta login */
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.message {
    position: relative;
    padding: 6px 10px;
    border-radius: 8px;
    max-width: 92%;
    width: fit-content;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 0.72rem;
    line-height: 1.35;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1); /* Sombra suave WhatsApp */
}

.message img {
    max-width: 100% !important;
    height: auto;
    box-sizing: border-box;
}

.message a {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    box-sizing: border-box;
}

.message-pdf-link {
    display: inline-block;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 5px;
    text-decoration: none;
    color: inherit;
    font-size: 0.68rem;
    line-height: 1.3;
    max-width: 100%;
}

.message-receipt-ok {
    margin-top: 8px;
    padding: 6px 8px;
    background: #dcf8c6;
    border-radius: 5px;
    font-size: 0.68rem;
    color: #075e54;
    border: 1px solid #c3e6cb;
    text-align: center;
    line-height: 1.35;
}

.message.self {
    background-color: #dcf8c6; /* Verde claro WhatsApp */
    color: #1a1a1a;
    align-self: flex-end;
    border-top-right-radius: 0; /* Cola del globo */
}

.message.self::after {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-top: 10px solid #dcf8c6;
    border-right: 10px solid transparent;
}

.message.other, .message.admin {
    background-color: #ffffff; /* Blanco WhatsApp */
    color: #1a1a1a;
    align-self: flex-start;
    border-top-left-radius: 0; /* Cola del globo */
}

.message.other::before, .message.admin::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-top: 10px solid #ffffff;
    border-left: 10px solid transparent;
}

.message .meta {
    font-size: 0.58rem;
    color: #999; /* Gris sutil para la hora */
    margin-top: 3px;
    display: block;
    text-align: right; /* Hora a la derecha como en WA */
}

.message strong {
    font-weight: 700;
}

.message.admin strong {
    color: #075e54; /* Nombre de Pame en verde oscuro WhatsApp */
}

.message.admin .meta-admin-sub {
    font-size: 0.62rem !important;
    font-weight: 400 !important;
}

#userUnreadBadge {
    background-color: #ff3b30; /* Rojo más intenso y moderno */
    color: white;
    border-radius: 50%;
    min-width: 22px; /* Ancho mínimo para que sea un círculo perfecto */
    height: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Sombra para darle relieve */
    position: absolute; /* Posicionamiento absoluto */
    top: -5px; /* Sobresale un poco por arriba */
    right: -5px; /* Sobresale un poco por la derecha */
    border: 2px solid white; /* Borde blanco para separarlo del fondo verde */
    z-index: 10;
}
#userUnreadBadge.show {
    display: flex;
}

.chat-input-container {
    display: none; /* Oculto hasta login */
    flex-shrink: 0;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    gap: 6px;
    border-top: 1px solid #eee;
    padding-top: 6px;
    align-items: center;
}

/* Popup flotante periódico: “adjuntá comprobante” (encima de la barra de envío) */
.attach-float-hint {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 46px;
    z-index: 20;
    display: flex;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px) scale(0.96);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.attach-float-hint.attach-float-hint--visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.attach-float-hint__inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin: 0;
    padding: 9px 12px;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 0.68rem;
    line-height: 1.3;
    font-weight: 700;
    color: #0f766e;
    text-align: center;
    background: linear-gradient(180deg, #f0fdfa 0%, #ccfbf1 100%);
    border: 1px solid #2dd4bf;
    border-radius: 12px;
    box-shadow: 0 6px 22px rgba(13, 148, 136, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

.attach-float-hint__inner::after {
    content: '';
    position: absolute;
    left: 22px;
    bottom: -7px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ccfbf1;
    filter: drop-shadow(0 1px 0 #2dd4bf);
}

.attach-float-hint__icon {
    font-size: 1rem;
    line-height: 1;
}

.chat-widget.minimized .attach-float-hint {
    visibility: hidden;
    opacity: 0 !important;
    pointer-events: none;
}

#attachBtn {
    background-color: transparent;
    color: #128c7e;
    border: none;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-container input[type="text"] {
    flex-grow: 1;
    min-width: 0;
    max-width: 100%;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 15px;
    outline: none;
    font-size: 0.75rem;
}

/* --- PREGUNTAS RÁPIDAS --- */
.quick-btn {
    background-color: #ffffff;
    color: #075e54;
    border: 1px solid #075e54;
    border-radius: 12px;
    padding: 4px 8px;
    font-size: 0.65rem;
    line-height: 1.25;
    cursor: pointer;
    transition: all 0.2s;
    white-space: normal;
    text-align: center;
    max-width: 100%;
    box-sizing: border-box;
}

.quick-btn:hover {
    background-color: #075e54;
    color: white;
}

.chat-input-container button {
    background-color: #128c7e; /* Verde WhatsApp para el botón de enviar */
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

/* --- TOAST: instalación app + bono (index / registro) --- */
.install-promo-toast {
    position: fixed;
    left: 50%;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px) + var(--chat-embed-tab-bar-offset, 0px));
    transform: translateX(-50%) translateY(14px);
    max-width: min(22rem, calc(100vw - 1.5rem));
    box-sizing: border-box;
    padding: 0.85rem 2.25rem 0.85rem 0.95rem;
    border-radius: 0.85rem;
    background: linear-gradient(145deg, #1e0a3a 0%, #2d0f4a 50%, #1a0630 100%);
    border: 1px solid rgba(167, 139, 250, 0.45);
    box-shadow:
        0 8px 28px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(0, 0, 0, 0.2);
    color: #f3f4f6;
    font-size: 0.82rem;
    line-height: 1.45;
    z-index: 2120; /* sobre el chat (2100); bajo popup global admin */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.38s ease,
        transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.38s ease;
}

.install-promo-toast.install-promo-toast--visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.install-promo-toast__text {
    margin: 0 0 0.65rem;
    padding: 0;
}

.install-promo-toast__text strong {
    color: #fde68a;
    font-weight: 800;
    text-shadow: 0 0 12px rgba(250, 204, 21, 0.35);
}

.install-promo-toast__close {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 1.85rem;
    height: 1.85rem;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.install-promo-toast__close:hover,
.install-promo-toast__close:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    outline: none;
}

.install-promo-toast__cta {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    color: #1a0a2e;
    background: linear-gradient(180deg, #fde68a 0%, #f59e0b 100%);
    border: none;
    border-radius: 0.55rem;
    cursor: pointer;
}

.install-promo-toast__cta:hover {
    filter: brightness(1.06);
}

@media (max-width: 480px) {
    .install-promo-toast {
        left: 0.75rem;
        right: 0.75rem;
        max-width: none;
        transform: translateY(14px);
    }

    .install-promo-toast.install-promo-toast--visible {
        transform: translateY(0);
    }

    /* Chat flotante: cabe en el ancho útil + margen safe-area */
    .chat-widget {
        right: max(14px, env(safe-area-inset-right, 0px) + 14px);
        width: min(
            300px,
            calc(100vw - max(16px, env(safe-area-inset-left, 0px)) - max(16px, env(safe-area-inset-right, 0px)))
        );
    }

    .chat-widget.minimized {
        width: min(
            200px,
            calc(100vw - max(20px, env(safe-area-inset-left, 0px)) - max(20px, env(safe-area-inset-right, 0px)) - 12px)
        );
    }

    /* Píldora: texto largo no desborda ni empuja el badge fuera de pantalla */
    .chat-widget.minimized .chat-header {
        padding-left: 8px;
        padding-right: 8px;
        gap: 4px;
    }

    .chat-widget.minimized .chat-header-info {
        min-width: 0;
        flex: 1 1 auto;
    }

    .chat-widget.minimized .chat-header-info > div {
        min-width: 0;
        overflow: hidden;
    }

    .chat-widget.minimized .chat-header-info > div span {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-widget.minimized .chat-header-actions {
        flex-shrink: 0;
        gap: 8px;
    }

    #userUnreadBadge {
        right: -2px;
        top: -3px;
    }

    /* iOS: evita zoom al tocar inputs del login en el chat */
    .auth-container input[type="text"],
    .auth-container input[type="email"],
    .auth-container input[type="password"],
    .auth-container input[type="tel"],
    .auth-container #countryCode {
        font-size: 16px;
    }

    .chat-popup {
        right: max(12px, env(safe-area-inset-right, 0px) + 8px);
        max-width: calc(100vw - 1.5rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    }
}

/* --- POPUP DE RECORDATORIO --- */
.chat-popup {
    position: fixed;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px) + var(--chat-embed-tab-bar-offset, 0px)); /* encima del chat minimizado */
    right: 20px;
    background-color: #ffcc00; /* Amarillo llamativo */
    color: #1a1a1a;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); /* Animación con rebote */
    pointer-events: none; /* Para que no interfiera con clics */
    z-index: 2110; /* por encima del chat flotante */
}

.chat-popup.show {
    opacity: 1;
    transform: translateY(0);
}

/* Triangulito apuntando hacia abajo */
.chat-popup::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 20px;
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #ffcc00 transparent transparent transparent;
}

/* --- POPUP GLOBAL (ENVIADO POR ADMIN) --- */
.global-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85); /* Fondo más oscuro para que resalte más */
    z-index: 2147483647; /* Z-index MÁXIMO ABSOLUTO permitido por los navegadores */
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.global-popup-overlay.show {
    display: flex;
    opacity: 1;
}

.global-popup-box {
    background: white;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

.global-popup-overlay.show .global-popup-box {
    transform: scale(1);
}

.global-popup-title {
    color: #9b4dca;
    font-size: 1.5rem;
    font-weight: 900;
    margin-top: 0;
    margin-bottom: 15px;
    text-transform: uppercase;
}

.global-popup-message {
    color: #333;
    font-size: 1.1rem;
    line-height: 1.5;
    margin-bottom: 25px;
}

.global-popup-close {
    background: #075e54;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    transition: background 0.2s;
}

.global-popup-close:hover {
    background: #128c7e;
}
