/**
 * Widget de chat de TravelBot AI — estilos del front-end (visitantes).
 *
 * Todo el color viene de UNA variable CSS (--travelbot-color), fijada
 * en línea por WidgetRenderer según lo que el administrador eligió en
 * Configuración. El resto de la paleta (grises, fondos) es neutra a
 * propósito: el widget debe verse nativo en cualquier sitio, tema o
 * builder (Elementor/Gutenberg/lo que sea) — no impone una identidad
 * visual propia, se adapta a la del sitio donde vive.
 *
 * Tipografía: se usa el stack de fuentes del sistema del visitante
 * (misma razón: encajar con cualquier sitio) en vez de una fuente
 * propia del plugin.
 */

#travelbot-widget-root {
    --travelbot-color: #25D366;
    --travelbot-color-dark: color-mix(in srgb, var(--travelbot-color) 80%, black);
    --travelbot-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    position: fixed;
    z-index: 999999;
    right: 20px;
    bottom: 20px;
    font-family: var(--travelbot-font);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

#travelbot-widget-root *,
#travelbot-widget-root *::before,
#travelbot-widget-root *::after {
    box-sizing: border-box;
}

/**
 * Reset defensivo de <button>.
 *
 * Muchos temas y Elementor definen estilos globales de "button" (padding
 * ancho, radios grandes, colores de marca, y en varios casos un
 * ::before/::after decorativo para la animación de hover) que se
 * filtran a CUALQUIER <button> de la página, incluidos los del widget.
 * Se resetean propiedades puntuales (no `all: unset`, que en algunos
 * temas dejaba pasar justamente esos pseudo-elementos decorativos) y
 * se anulan explícitamente ::before/::after, que es de donde suele
 * salir esa "mancha" de color de más.
 */
#travelbot-widget-root button {
    box-sizing: border-box;
    cursor: pointer;
    font-family: var(--travelbot-font);
    font-size: 14px;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    text-shadow: none;
    background-image: none !important;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

#travelbot-widget-root button::before,
#travelbot-widget-root button::after {
    content: none !important;
    display: none !important;
}

/* ---------- Burbuja flotante ---------- */

.travelbot-bubble {
    position: relative;
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    max-width: 60px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    background: var(--travelbot-color) !important;
    color: #fff !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.travelbot-bubble:hover {
    background: var(--travelbot-color) !important;
    transform: scale(1.06);
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.26);
}

.travelbot-bubble:focus-visible {
    outline: 3px solid var(--travelbot-color-dark);
    outline-offset: 3px;
}

.travelbot-bubble svg {
    width: 26px;
    height: 26px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.travelbot-bubble .travelbot-icon-close {
    position: absolute;
}

/* Cruza los íconos abrir/cerrar con un pequeño giro, en vez de un
   simple corte — el detalle de movimiento que distingue al widget. */
#travelbot-widget-root:not(.is-open) .travelbot-icon-close,
#travelbot-widget-root.is-open .travelbot-icon-chat {
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}

#travelbot-widget-root.is-open .travelbot-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.travelbot-bubble-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ff4757;
    border: 2px solid #fff;
}

/* ---------- Panel del chat ---------- */

.travelbot-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 372px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

#travelbot-widget-root.is-open .travelbot-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */

.travelbot-header {
    background: linear-gradient(135deg, var(--travelbot-color), var(--travelbot-color-dark));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.travelbot-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

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

.travelbot-avatar svg {
    width: 20px;
    height: 20px;
}

.travelbot-header-text {
    flex: 1;
    min-width: 0;
}

.travelbot-header-title {
    font-weight: 600;
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.travelbot-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.travelbot-header-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6bffb0;
    display: inline-block;
}

.travelbot-header-close {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    max-width: 30px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    background: transparent !important;
    color: #fff !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.travelbot-header-close:hover {
    background: rgba(255, 255, 255, 0.18) !important;
}

.travelbot-header-close svg {
    width: 16px;
    height: 16px;
}

/* Mensajes */

.travelbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f7f8;
    scroll-behavior: smooth;
}

.travelbot-message {
    max-width: 82%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    word-wrap: break-word;
    animation: travelbot-msg-in 0.18s ease;
}

@keyframes travelbot-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.travelbot-message.is-bot {
    align-self: flex-start;
    background: #fff;
    color: #202124;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.travelbot-message.is-user {
    align-self: flex-end;
    background: var(--travelbot-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.travelbot-message a {
    color: inherit;
    text-decoration: underline;
}

/* Indicador "escribiendo..." */

.travelbot-typing {
    align-self: flex-start;
    background: #fff;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 12px 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    display: inline-flex;
    gap: 4px;
}

.travelbot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b0b3b8;
    animation: travelbot-typing-bounce 1.1s infinite ease-in-out;
}

.travelbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.travelbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes travelbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Botón de WhatsApp, inyectado dentro de un mensaje del bot */

.travelbot-whatsapp-cta {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 9px;
    padding: 8px 14px;
    background: #25D366;
    color: #fff;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: filter 0.15s ease;
}

.travelbot-whatsapp-cta:hover {
    filter: brightness(0.94);
}

.travelbot-whatsapp-cta svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Fuentes citadas */

.travelbot-sources {
    margin-top: 8px;
    font-size: 11.5px;
    opacity: 0.75;
}

.travelbot-sources a {
    display: block;
}

/* Input */

.travelbot-input-row {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #ececec;
    background: #fff;
}

.travelbot-input-row textarea {
    box-sizing: border-box;
    flex: 1;
    width: 100%;
    resize: none;
    border: 1px solid #dcdcde !important;
    border-radius: 20px !important;
    padding: 10px 14px !important;
    margin: 0 !important;
    font-family: var(--travelbot-font);
    font-size: 13.5px;
    min-height: 38px;
    max-height: 90px;
    line-height: 1.35;
    background: #fff;
    box-shadow: none !important;
    outline: none;
    transition: border-color 0.15s ease;
}

.travelbot-input-row textarea:focus {
    border-color: var(--travelbot-color) !important;
}

.travelbot-send-btn {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    background: var(--travelbot-color) !important;
    color: #fff !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.12s ease, opacity 0.12s ease;
}

.travelbot-send-btn:hover:not(:disabled) {
    background: var(--travelbot-color) !important;
    transform: scale(1.05);
}

.travelbot-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.travelbot-send-btn svg {
    width: 16px;
    height: 16px;
}

.travelbot-footer-note {
    text-align: center;
    font-size: 10.5px;
    color: #9a9a9a;
    padding: 6px 0 10px;
    background: #fff;
}

/* ---------- Responsive: pantalla completa en móvil ---------- */

@media (max-width: 480px) {
    #travelbot-widget-root {
        right: 16px;
        bottom: 16px;
    }

    .travelbot-panel {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    /* En pantalla completa la burbuja quedaría flotando encima del
       propio panel (tapando el input, como reportado) — el panel ya
       tiene su botón de cerrar en el header, así que la ocultamos. */
    #travelbot-widget-root.is-open .travelbot-bubble {
        display: none !important;
    }
}

/* Respeta la preferencia de menos animaciones del sistema operativo. */
@media (prefers-reduced-motion: reduce) {
    #travelbot-widget-root * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
