/**
 * WP Ollama Chatbot — Diseño estilo WhatsApp
 */

/* =====================================================================
   Reset
   ===================================================================== */
#ollama-chatbot-container * {
    box-sizing: border-box;
    margin: 0;
}

/* =====================================================================
   Posición bottom-left
   ===================================================================== */
#ollama-chatbot-container.ollama-chatbot-bottom-left {
    align-items: flex-start !important;
}

/* =====================================================================
   BOTÓN FLOTANTE
   ===================================================================== */
#ollama-chatbot-button {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 22px;
    color: #fff;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    user-select: none;
    outline: none;
    box-shadow: 0 4px 20px rgba(0,0,0,.25), 0 2px 6px rgba(0,0,0,.12);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1),
                opacity   .25s ease,
                box-shadow .2s ease;
    transform-origin: bottom right;
}

#ollama-chatbot-container.ollama-chatbot-bottom-left #ollama-chatbot-button {
    transform-origin: bottom left;
}

#ollama-chatbot-button:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 8px 28px rgba(0,0,0,.28), 0 3px 8px rgba(0,0,0,.15);
}
#ollama-chatbot-button:active { transform: scale(.96); }

/* Íconos */
.ollama-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}
.ollama-btn-icon svg { display: block; }

.ollama-btn-close { display: none; opacity: 0; transform: rotate(-90deg) scale(.5); }
.ollama-btn-open  { opacity: 1; transform: rotate(0deg) scale(1); }

#ollama-chatbot-container.chatbot-active #ollama-chatbot-button .ollama-btn-open  { display: none; opacity: 0; }
#ollama-chatbot-container.chatbot-active #ollama-chatbot-button .ollama-btn-close { display: flex; opacity: 1; transform: rotate(0deg) scale(1); }

.ollama-btn-label {
    transition: max-width .3s ease, opacity .2s ease;
    max-width: 200px;
    overflow: hidden;
}
#ollama-chatbot-container.chatbot-active .ollama-btn-label { max-width: 0; opacity: 0; }

/* =====================================================================
   VENTANA DEL CHAT
   ===================================================================== */
#ollama-chatbot-window {
    width: 390px;
    max-width: calc(100vw - 48px);
    height: 580px;
    max-height: calc(100vh - 100px);
    background: #efeae2;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 56px rgba(0,0,0,.22), 0 4px 16px rgba(0,0,0,.1);

    /* Estado cerrado */
    visibility: hidden;
    opacity: 0;
    transform: scale(.92) translateY(18px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s cubic-bezier(.4,0,.2,1), visibility 0s linear .25s;
}

#ollama-chatbot-container.ollama-chatbot-bottom-left #ollama-chatbot-window {
    transform-origin: bottom left;
}

/* Estado abierto */
#ollama-chatbot-container.chatbot-active #ollama-chatbot-window {
    visibility: visible;
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
    transition: opacity .28s ease, transform .28s cubic-bezier(.34,1.2,.64,1), visibility 0s linear 0s;
}

/* =====================================================================
   HEADER — estilo WhatsApp
   ===================================================================== */
#ollama-chatbot-header {
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.ollama-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.ollama-header-avatar svg { width: 26px; height: 26px; }

.ollama-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}
#ollama-chatbot-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ollama-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: rgba(255,255,255,.85);
}
.ollama-status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: waPulse 2.5s ease infinite;
}
@keyframes waPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(74,222,128,.4); }
    50%      { box-shadow: 0 0 0 4px rgba(74,222,128,0); }
}

/* Botón minimizar */
#ollama-chatbot-close {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.9);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .2s ease, transform .15s ease;
}
#ollama-chatbot-close:hover  { background: rgba(255,255,255,.15); transform: scale(1.08); }
#ollama-chatbot-close:active { transform: scale(.92); }

/* =====================================================================
   FONDO DEL CHAT — patrón estilo WhatsApp
   ===================================================================== */
#ollama-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 3px;

    /* Fondo característico de WhatsApp */
    background-color: #efeae2;
    background-image:
        radial-gradient(circle at 1px 1px, rgba(0,0,0,.06) 1px, transparent 0);
    background-size: 20px 20px;
}

/* Scrollbar */
#ollama-chatbot-messages::-webkit-scrollbar       { width: 5px; }
#ollama-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
#ollama-chatbot-messages::-webkit-scrollbar-thumb { background: #c4b9a8; border-radius: 4px; }

/* =====================================================================
   SEPARADOR DE FECHA — "Hoy"
   ===================================================================== */
.ollama-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0 12px;
}
.ollama-date-divider span {
    background: #e1ddd8;
    color: #54656f;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,.08);
}

/* =====================================================================
   MENSAJES
   ===================================================================== */
.ollama-message {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 88%;
    animation: waSlideIn .2s ease both;
}

@keyframes waSlideIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Avatar del bot */
.ollama-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #d1c4e9;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 2px;
}
.ollama-message-avatar svg { width: 17px; height: 17px; color: #6a1b9a; }

/* ── Bot (izquierda) ── */
.ollama-bot-message {
    align-self: flex-start;
    margin-bottom: 2px;
}

.ollama-bot-message .ollama-message-bubble {
    position: relative;
    background: #ffffff;
    border-radius: 0 10px 10px 10px;
    padding: 9px 14px 8px 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,.13);
    min-width: 90px;
    max-width: 100%;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Cola izquierda */
.ollama-bot-message .ollama-message-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -7px;
    width: 7px;
    height: 14px;
    background: #ffffff;
    clip-path: polygon(100% 0, 100% 100%, 0 0);
}

/* ── Usuario (derecha) ── */
.ollama-user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-bottom: 2px;
}

.ollama-user-message .ollama-message-bubble {
    position: relative;
    background: #d9fdd3;
    border-radius: 10px 0 10px 10px;
    padding: 9px 14px 8px 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,.13);
    min-width: 90px;
    max-width: 100%;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Cola derecha */
.ollama-user-message .ollama-message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    right: -7px;
    width: 7px;
    height: 14px;
    background: #d9fdd3;
    clip-path: polygon(0 0, 0 100%, 100% 0);
}

/* Texto */
.ollama-message-text {
    font-size: 14.2px;
    line-height: 1.52;
    color: #111b21;
    display: block;
}

.ollama-bot-message .ollama-message-text a {
    color: #0073aa;
    text-decoration: underline;
}

/* Timestamp — flujo normal, alineado a la derecha debajo del texto */
.ollama-message-time {
    font-size: 11px;
    color: #667781;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    line-height: 1;
    align-self: flex-end;
    margin-top: -2px;
}

/* Doble tilde para mensajes del usuario */
.ollama-user-message .ollama-message-time {
    color: #53bdeb;
}
.ollama-tick {
    display: inline-flex;
}
.ollama-tick svg { width: 16px; height: 16px; }

/* Mensaje de error */
.ollama-error-message .ollama-message-bubble {
    background: #fff5f5 !important;
    border: 1px solid #fecaca;
}
.ollama-error-message .ollama-message-text { color: #dc2626 !important; }

/* =====================================================================
   INDICADOR DE ESCRITURA — estilo WhatsApp
   ===================================================================== */
#ollama-chatbot-typing {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 0 10px 8px;
    background: transparent;

    visibility: hidden;
    opacity: 0;
    max-height: 0;
    transition: opacity .2s ease, max-height .25s ease, visibility 0s linear .25s;
}
#ollama-chatbot-typing.is-visible {
    visibility: visible;
    opacity: 1;
    max-height: 60px;
    transition: opacity .2s ease, max-height .25s ease, visibility 0s linear 0s;
}

.ollama-typing-bubble {
    background: #ffffff;
    border-radius: 0 10px 10px 10px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.13);
    display: flex;
    gap: 5px;
    align-items: center;
    position: relative;
}
.ollama-typing-bubble::before {
    content: '';
    position: absolute;
    top: 0; left: -7px;
    width: 7px; height: 14px;
    background: #ffffff;
    clip-path: polygon(100% 0, 100% 100%, 0 0);
}

.ollama-typing-bubble span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8696a0;
    display: inline-block;
    animation: waBounce 1.3s ease infinite;
}
.ollama-typing-bubble span:nth-child(2) { animation-delay: .18s; }
.ollama-typing-bubble span:nth-child(3) { animation-delay: .36s; }

@keyframes waBounce {
    0%,60%,100% { transform: translateY(0);   opacity: .5; }
    30%          { transform: translateY(-6px); opacity: 1;  }
}

/* =====================================================================
   BARRA DE INPUT — estilo WhatsApp
   ===================================================================== */
#ollama-chatbot-input-area {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 8px;
    background: #f0f2f5;
    border-top: 1px solid #e9edef;
    flex-shrink: 0;
}

#ollama-chatbot-input {
    flex: 1;
    padding: 11px 16px;
    background: #ffffff;
    border: none;
    border-radius: 24px;
    font-size: 14.5px;
    font-family: inherit;
    color: #111b21;
    outline: none;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    transition: box-shadow .2s ease;
    resize: none;
    line-height: 1.4;
}
#ollama-chatbot-input:focus        { box-shadow: 0 1px 4px rgba(0,0,0,.15); }
#ollama-chatbot-input::placeholder { color: #8696a0; }

#ollama-chatbot-send {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: transform .2s ease, filter .2s ease;
}
#ollama-chatbot-send:hover:not(:disabled)  { transform: scale(1.08); filter: brightness(1.08); }
#ollama-chatbot-send:active:not(:disabled) { transform: scale(.94); }
#ollama-chatbot-send:disabled { opacity: .4; cursor: not-allowed; }
#ollama-chatbot-send svg { width: 20px; height: 20px; margin-left: 2px; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 480px) {
    #ollama-chatbot-window {
        width: 100vw !important;
        max-width: 100vw !important;
        height: calc(100vh - 80px) !important;
        max-height: calc(100vh - 80px) !important;
        border-radius: 18px 18px 0 0 !important;
        position: fixed !important;
        bottom: 80px !important;
        left: 0 !important;
        right: 0 !important;
        transform-origin: bottom center !important;
    }
    #ollama-chatbot-container.ollama-chatbot-bottom-right,
    #ollama-chatbot-container.ollama-chatbot-bottom-left {
        bottom: 16px !important;
        right: 16px !important;
        left: auto !important;
        align-items: flex-end !important;
    }
    .ollama-btn-label { display: none; }
    #ollama-chatbot-button {
        width: 54px; height: 54px;
        border-radius: 50%; padding: 0; justify-content: center;
    }
}

/* =====================================================================
   ACCESIBILIDAD
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    #ollama-chatbot-window,
    #ollama-chatbot-button,
    .ollama-message,
    .ollama-typing-bubble span {
        transition-duration: .01ms !important;
        animation-duration:  .01ms !important;
    }
}
#ollama-chatbot-send:focus-visible,
#ollama-chatbot-close:focus-visible,
#ollama-chatbot-input:focus-visible,
#ollama-chatbot-button:focus-visible {
    outline: 2px solid rgba(255,255,255,.6);
    outline-offset: 2px;
}
@media print { #ollama-chatbot-container { display: none !important; } }
