/* ===================================================================
   BOT IA - Burbuja flotante + ventana de chat del asistente virtual
   =================================================================== */

/* ----- Burbuja del bot -------------------------------------------- */
#bot-bubble {
    position: fixed;
    bottom: 96px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 18px rgba(124, 58, 237, 0.5);
    z-index: 9001;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
#bot-bubble:hover {
    background: linear-gradient(135deg, #6d28d9, #5b21b6);
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(124, 58, 237, 0.65);
}
#bot-bubble-tooltip {
    position: absolute;
    right: 64px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e1b4b;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#bot-bubble-tooltip::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-width: 0;
    border-left-color: #1e1b4b;
}
#bot-bubble:hover #bot-bubble-tooltip {
    opacity: 1;
}

/* ----- Ventana del bot -------------------------------------------- */
#bot-window {
    position: fixed;
    bottom: 164px;
    right: 28px;
    width: 380px;
    height: 490px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 36px rgba(0, 0, 0, 0.18);
    z-index: 9000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: height 0.2s ease, opacity 0.15s ease;
}
#bot-window.bot-abierto {
    display: flex;
}
#bot-window.bot-minimizado {
    height: 52px;
}

/* ----- Header ----------------------------------------------------- */
#bot-header {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    border-radius: 14px 14px 0 0;
}
#bot-header-title {
    font-weight: 600;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
#bot-header-title .bot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.35);
    flex-shrink: 0;
}
#bot-header-title .bot-subtitle {
    font-size: 0.68rem;
    font-weight: 400;
    opacity: 0.8;
    margin-left: -4px;
}
#bot-header-actions {
    display: flex;
    gap: 5px;
}
#bot-header-actions button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
#bot-header-actions button:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* ----- Área de mensajes ------------------------------------------- */
#bot-mensajes-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: #fafafa;
}
#bot-mensajes-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('/assets/images/chat/logo.png') center / contain no-repeat;
    opacity: 0.12;
    z-index: 0;
    pointer-events: none;
}
#bot-mensajes {
    height: 100%;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: transparent;
    background-image: radial-gradient(circle at 20% 50%, rgba(124, 58, 237, 0.03) 0%, transparent 50%),
                      radial-gradient(circle at 80% 20%, rgba(109, 40, 217, 0.03) 0%, transparent 50%);
    position: relative;
    z-index: 1;
    box-sizing: border-box;
}
#bot-mensajes::-webkit-scrollbar { width: 4px; }
#bot-mensajes::-webkit-scrollbar-thumb { background: #d4c4f6; border-radius: 2px; }
#bot-mensajes::-webkit-scrollbar-track { background: transparent; }

/* ----- Burbujas ---------------------------------------------------- */
.bot-msg {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    max-width: 90%;
}
.bot-msg.bot-msg-bot {
    align-self: flex-start;
}
.bot-msg.bot-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.bot-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    color: #fff;
    flex-shrink: 0;
}
.bot-msg-inner {
    max-width: calc(100% - 38px);
}
.bot-msg-burbuja {
    padding: 8px 12px;
    font-size: 0.84rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.bot-msg.bot-msg-bot .bot-msg-burbuja {
    background: #fff;
    color: #333;
    border-radius: 14px 14px 14px 3px;
    border: 1px solid #e9e3fd;
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.08);
}
.bot-msg.bot-msg-user .bot-msg-burbuja {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    border-radius: 14px 14px 3px 14px;
}
.bot-msg-burbuja a {
    color: #7c3aed;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(124, 58, 237, 0.4);
}
.bot-msg.bot-msg-user .bot-msg-burbuja a {
    color: #e9d5ff;
}
.bot-msg-hora {
    font-size: 0.62rem;
    color: #bbb;
    margin-top: 3px;
    padding-left: 3px;
}
.bot-msg.bot-msg-user .bot-msg-hora {
    text-align: right;
    padding-right: 3px;
    padding-left: 0;
}

/* ----- Typing indicator ------------------------------------------- */
#bot-typing {
    display: none;
    align-self: flex-start;
    align-items: flex-end;
    gap: 7px;
}
#bot-typing.visible {
    display: flex;
}
.bot-typing-dots {
    background: #fff;
    border: 1px solid #e9e3fd;
    border-radius: 14px 14px 14px 3px;
    padding: 10px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.08);
}
.bot-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9c73f0;
    animation: bot-dot-bounce 1.2s infinite ease-in-out both;
}
.bot-typing-dots span:nth-child(1) { animation-delay: 0s; }
.bot-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.bot-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bot-dot-bounce {
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ----- Input ------------------------------------------------------- */
#bot-input-area {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 7px;
    border-top: 1px solid #ede9fe;
    flex-shrink: 0;
    background: #fff;
}
#bot-input {
    flex: 1;
    border: 1px solid #ddd6fe;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 0.84rem;
    outline: none;
    background: #fafafa;
    height: 36px;
    line-height: 1.3;
    font-family: inherit;
    color: #333;
    transition: border-color 0.2s;
}
#bot-input:focus {
    border-color: #7c3aed;
    background: #fff;
}
#bot-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
#bot-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    transition: opacity 0.2s, transform 0.15s;
    flex-shrink: 0;
}
#bot-send-btn:hover:not(:disabled) {
    opacity: 0.88;
    transform: scale(1.08);
}
#bot-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ----- Footer powered-by ------------------------------------------ */
#bot-powered {
    text-align: center;
    font-size: 0.62rem;
    color: #bbb;
    padding: 3px 0 5px;
    background: #fff;
    border-top: 1px solid #f3f0ff;
    letter-spacing: 0.02em;
}

/* ----- Dark theme -------------------------------------------------- */
/* html.dark-theme cubre el FOUC (clase en <html> desde el inline script del head)
   body.dark-theme cubre el estado normal tras DOMContentLoaded */
html.dark-theme #bot-window,
body.dark-theme #bot-window {
    background: var(--dark-bg-secondary);
    box-shadow: 0 8px 36px rgba(0, 0, 0, 0.45);
}
html.dark-theme #bot-mensajes-wrap,
body.dark-theme #bot-mensajes-wrap {
    background: var(--dark-bg-primary);
}
html.dark-theme #bot-mensajes,
body.dark-theme #bot-mensajes {
    background: var(--dark-bg-primary);
    background-image: none;
}
html.dark-theme .bot-msg.bot-msg-bot .bot-msg-burbuja,
body.dark-theme .bot-msg.bot-msg-bot .bot-msg-burbuja {
    background: var(--dark-bg-tertiary);
    color: var(--dark-text-primary);
    border-color: #4c1d95;
}
html.dark-theme .bot-msg.bot-msg-bot .bot-msg-burbuja a,
body.dark-theme .bot-msg.bot-msg-bot .bot-msg-burbuja a {
    color: #c4b5fd;
}
html.dark-theme .bot-typing-dots,
body.dark-theme .bot-typing-dots {
    background: var(--dark-bg-tertiary);
    border-color: #4c1d95;
}
html.dark-theme .bot-typing-dots span,
body.dark-theme .bot-typing-dots span {
    background: #a78bfa;
}
html.dark-theme #bot-input-area,
body.dark-theme #bot-input-area {
    background: var(--dark-bg-secondary);
    border-top-color: #4c1d95;
}
html.dark-theme #bot-input,
body.dark-theme #bot-input {
    background: var(--dark-bg-tertiary);
    border-color: #4c1d95;
    color: var(--dark-text-primary);
}
html.dark-theme #bot-input:focus,
body.dark-theme #bot-input:focus {
    border-color: #7c3aed;
    background: var(--dark-bg-card);
}
html.dark-theme #bot-powered,
body.dark-theme #bot-powered {
    background: var(--dark-bg-secondary);
    border-top-color: #4c1d95;
    color: var(--dark-text-muted);
}
html.dark-theme .bot-msg-hora,
body.dark-theme .bot-msg-hora {
    color: var(--dark-text-muted);
}

/* ----- Responsive -------------------------------------------------- */
@media (max-width: 480px) {
    #bot-window {
        right: 8px;
        width: calc(100vw - 16px);
        bottom: 154px;
        height: 420px;
    }
    #bot-bubble {
        bottom: 96px;
        right: 18px;
    }
}
