/* Chatbot Widget - Scoped styles */
#chatbot-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3), 0 0 18px rgba(255,255,255,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 2.5px solid #fff;
    outline: none;
}
#chatbot-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
#chatbot-fab svg {
    width: 28px;
    height: 28px;
    fill: #ffffff;
}

#chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
#chatbot-window.chatbot-open {
    display: flex;
}

/* Header */
#chatbot-header {
    padding: 14px 16px;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
/* La imagen conserva su proporción: alto fijo y ancho libre hasta un tope,
   con bordes redondeados. Un logo apaisado sale como rectángulo; una imagen
   cuadrada del asistente, como cuadrado. */
#chatbot-header-logo {
    height: 40px;
    width: auto;
    max-width: 120px;
    border-radius: 9px;
    object-fit: contain;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}
/* Logo de la inmobiliaria (no una imagen del asistente): sobre blanco para
   que un logo con letras oscuras se lea en la cabecera de color. */
#chatbot-header-logo.chatbot-header-logo--fit {
    background: #ffffff;
    padding: 3px 5px;
}
#chatbot-header-info {
    flex: 1;
    min-width: 0;
}
#chatbot-header-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#chatbot-header-status {
    font-size: 12px;
    opacity: 0.85;
}
#chatbot-clear-btn {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chatbot-clear-btn:hover {
    opacity: 1;
}
#chatbot-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 22px;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}
#chatbot-close-btn:hover {
    opacity: 1;
}

/* Messages area */
#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8f9fa;
}
#chatbot-messages::-webkit-scrollbar {
    width: 5px;
}
#chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}
#chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Message bubbles */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chatbot-msg.chatbot-user {
    align-self: flex-end;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}
.chatbot-msg.chatbot-assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #333333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.chatbot-msg a {
    color: inherit;
    text-decoration: underline;
}
.chatbot-msg.chatbot-user a {
    color: #ffffff;
}
.chatbot-msg.chatbot-assistant a {
    color: #1a73e8;
}

/* Typing indicator */
.chatbot-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    align-self: flex-start;
    background: #ffffff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.chatbot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: chatbot-bounce 1.4s infinite ease-in-out;
}
.chatbot-typing-caption {
    display: none;
    font-size: 12px;
    color: #777;
    margin-left: 4px;
    white-space: nowrap;
}
.chatbot-typing.has-caption {
    align-items: center;
}
.chatbot-typing.has-caption .chatbot-typing-caption {
    display: block;
}
.chatbot-typing span:nth-child(1) { animation-delay: 0s; }
.chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input area */
#chatbot-input-area {
    padding: 12px;
    border-top: 1px solid #e8e8e8;
    display: flex;
    gap: 8px;
    background: #ffffff;
    flex-shrink: 0;
}
#chatbot-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}
#chatbot-input:focus {
    border-color: #999;
}
#chatbot-input::placeholder {
    color: #aaa;
}
#chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
#chatbot-send-btn:hover {
    opacity: 0.9;
}
#chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
#chatbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}

/* Todo lo que va dentro de la lista de mensajes conserva su alto: la lista es
   un flex en columna con scroll, y un hijo con `overflow: hidden` (la tarjeta)
   pierde su min-height automático y se aplasta a 2px cuando la lista se
   desborda. Visto en imagen.pixelinmobiliario.red el 10/9/2026. */
#chatbot-messages > * {
    flex-shrink: 0;
}

/* Property cards */
.chatbot-property-card {
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    margin-top: 4px;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    align-self: flex-start;
    width: 85%;
    max-width: 85%;
    text-decoration: none;
    display: flex;
    flex-shrink: 0;
    min-height: 96px;
    overflow: hidden;
}
.chatbot-property-card:hover {
    background: #f0f4ff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.chatbot-property-card-photo {
    position: relative;
    width: 96px;
    flex-shrink: 0;
    background: #eceff3;
    overflow: hidden;
}
.chatbot-property-card-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.chatbot-property-card-photo.is-placeholder::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23b0b6bf'><path d='M12 3L2 12h3v8h6v-6h2v6h6v-8h3L12 3z'/></svg>") no-repeat center / contain;
}
.chatbot-property-card-badge {
    position: absolute;
    left: 6px;
    top: 6px;
    background: rgba(33,33,33,0.85);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 2px 6px;
    border-radius: 6px;
}
.chatbot-property-card-body {
    padding: 10px 12px;
    min-width: 0;
    flex: 1;
}
.chatbot-property-card-title {
    font-weight: 600;
    font-size: 13px;
    color: #333;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.chatbot-property-card-details {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}
.chatbot-property-card-price {
    font-weight: 600;
    font-size: 13px;
    margin-top: 3px;
}

/* "Ver más resultados" */
.chatbot-more-btn {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #ccc;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    margin-top: 2px;
    transition: background 0.2s;
}
.chatbot-more-btn:hover {
    background: #f0f4ff;
}

/* Preguntas sugeridas */
.chatbot-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    max-width: 90%;
}
.chatbot-chip {
    background: #ffffff;
    border: 1px solid #ccc;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-family: inherit;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}
.chatbot-chip:hover {
    background: #f0f4ff;
}

/* Valoración de una respuesta */
.chatbot-rate {
    display: flex;
    gap: 2px;
    margin-top: 4px;
    margin-left: -4px;
}
.chatbot-rate-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 3px 4px;
    border-radius: 8px;
    opacity: 0.35;
    filter: grayscale(1);
    transition: opacity 0.2s, background 0.2s;
}
.chatbot-rate-btn:hover {
    opacity: 0.8;
    background: #f0f0f0;
}
.chatbot-rate-btn.is-active {
    opacity: 1;
    filter: none;
    background: #eef2f7;
}

/* Nota corta debajo de una respuesta (visita pedida) */
.chatbot-note {
    align-self: flex-start;
    font-size: 12px;
    color: #555;
    background: #f1f5ec;
    border: 1px solid #dfe8d5;
    border-radius: 10px;
    padding: 6px 10px;
    max-width: 85%;
}

/* Texto que llega en streaming */
.chatbot-msg.chatbot-streaming::after {
    content: '▍';
    opacity: 0.5;
    animation: chatbot-caret 1s steps(2) infinite;
}
@keyframes chatbot-caret {
    0% { opacity: 0.5; }
    50% { opacity: 0; }
    100% { opacity: 0.5; }
}

/* Mobile responsive */
@media (max-width: 480px) {
    #chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    /* 100dvh sigue al teclado del celular: el input no queda tapado. */
    @supports (height: 100dvh) {
        #chatbot-window {
            top: auto;
            height: 100dvh;
            max-height: 100dvh;
        }
    }
    #chatbot-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    #chatbot-input {
        font-size: 16px; /* iOS hace zoom con menos de 16px */
    }
    .chatbot-property-card {
        width: 100%;
        max-width: 100%;
    }
    .chatbot-msg, .chatbot-note {
        max-width: 92%;
    }
    #chatbot-fab {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }
    #chatbot-fab svg {
        width: 24px;
        height: 24px;
    }
}
