/* ============================================================ */
/* CHAT INTERFACE                                               */
/* ============================================================ */

.gw-chat-container {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 500px;
    height: 650px;
    /* Never overflow the viewport on smaller screens */
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    border: none;

    /* Fixed size, no resize */
    border-radius: 25px;
    border-bottom-left-radius: 25px;
    /* Ensure round */
    border-bottom-right-radius: 5px;
    /* Tail origin */
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.25);
    overflow: visible;
    /* Important for tail! */
}

/* Speech Bubble Tail */
.gw-chat-container::before {
    content: '';
    position: absolute;
    bottom: -18px;
    right: 0px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 20px 20px 0 0;
    border-color: white transparent transparent transparent;
    z-index: 10000;
}

/* Handle removed */
.gw-resize-handle {
    display: none;
}


.gw-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 1000;
}

/* Visual cue for the handle (corner bracket) */
.gw-resize-handle::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-top: 2px solid rgba(255, 255, 255, 0.6);
    border-left: 2px solid rgba(255, 255, 255, 0.6);
    pointer-events: none;
}


.gw-chat-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.gw-chat-header {
    background: linear-gradient(135deg, #b90e2b, #900b22);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.gw-chat-title {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.gw-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gw-chat-close:hover {
    opacity: 1;
    transform: rotate(90deg) scale(1.1);
}

/* Messages Area */
.gw-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.gw-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    animation: message-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes message-pop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.gw-message.bot {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    align-self: flex-start;
}

.gw-message.user {
    background: #b90e2b;
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(185, 14, 43, 0.3);
    align-self: flex-end;
}

/* Ejemplos de pregunta bajo el saludo */
.gw-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-self: stretch;
}

.gw-chat-suggestions button {
    background: white;
    color: #333;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 10px 14px;
    min-height: 44px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.gw-chat-suggestions button:hover,
.gw-chat-suggestions button:focus-visible {
    border-color: #b90e2b;
    color: #b90e2b;
}

.gw-message.loading-msg {
    font-style: italic;
    color: #888;
    background: #f0f0f0;
}

/* Input Area */
.gw-chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 10px;
}

.gw-chat-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #eee;
    border-radius: 25px;
    outline: none;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.gw-chat-input:focus {
    border-color: #b90e2b;
}

.gw-chat-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #b90e2b;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s, background 0.3s;
    box-shadow: 0 4px 10px rgba(185, 14, 43, 0.3);
}

.gw-chat-send:hover {
    background: #900b22;
    transform: scale(1.05);
}

.gw-chat-send:active {
    transform: scale(0.95);
}

/* Scrollbar */
.gw-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.gw-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.gw-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}


/* Source Link Styling */
.gw-source-container {
    margin-top: 10px;
    margin-bottom: 5px;
    text-align: right;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 8px;
}

.gw-source-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #b90e2b;
    background-color: rgba(185, 14, 43, 0.1);
    padding: 6px 12px;
    border-radius: 15px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.gw-source-link:hover {
    background-color: #b90e2b;
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(185, 14, 43, 0.2);
}

/* Updated Source Link Text Styling */
.gw-source-link-text {
    color: #b90e2b;
    text-decoration: underline;
    font-weight: 600;
    cursor: pointer;
}

.gw-source-link-text:hover {
    color: #900b22;
    text-decoration: none;
}

/* Mobile Chat Experience Improvements */
@media (max-width: 768px) {
    /* A pantalla completa de lo que se ve: gestito.js pone --chat-alto y --chat-arriba con el
       visualViewport, que es lo que encoge cuando sale el teclado (90vh y 100dvh no). Antes era
       una tarjeta del 90vh que, con la barra del navegador y el teclado, quedaba cortada. */
    .gw-chat-container {
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        bottom: auto !important;
        top: var(--chat-arriba, 0px) !important;
        height: var(--chat-alto, 100dvh) !important;
        max-height: none !important;
        border-radius: 0 !important;
    }

    /* La página de detrás, quieta mientras el chat está abierto */
    html.gw-chat-abierto,
    html.gw-chat-abierto body {
        overflow: hidden;
    }

    /* Keep the speech-bubble tail from poking out off-screen */
    .gw-chat-container::before {
        display: none;
    }

    /* Con el chat a pantalla completa, Gestito anclado en la esquina tapaba la flecha de enviar
       (29-10-2026): mientras el chat está abierto en el móvil, se esconde. La cabecera ya dice
       «Chat con Gestito». */
    .gw-mascot.chat-anchored {
        display: none !important;
    }

    /* Cerrar y conversación nueva, a 44px para el dedo (eran del tamaño de su icono) */
    .gw-chat-close,
    .gw-chat-reset {
        min-width: 44px;
        min-height: 44px;
        display: inline-grid;
        place-items: center;
    }

    .gw-chat-messages {
        font-size: 1rem;
        /* Slightly larger text for readability */
    }

    .gw-chat-input {
        /* 16px: con menos, el iPhone amplía la página al tocar la caja. La regla general de
           los campos (tema/css/default.css) ya lo pone; esta se queda por si cambia. */
        font-size: 16px;
    }
}

/* Controls Container */
.gw-chat-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Reset Button */
.gw-chat-reset {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.2s;
    font-weight: bold;
}

.gw-chat-reset:hover {
    opacity: 1;
    transform: rotate(45deg);
}

/* Message Timestamp */
.gw-message-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.7);
    float: right;
    margin-top: 5px;
    margin-left: 10px;
    line-height: 1;
}

.gw-message.bot .gw-message-time {
    color: rgba(0, 0, 0, 0.4);
}

/* Fix: Do not show last message on hover when chat is open */
.gw-mascot.chat-anchored:not(.showing-message):hover .mascot-message {
    opacity: 0 !important;
    transform: translateY(15px) scale(0.8) rotate(-5deg) !important;
    pointer-events: none !important;
}