/* ===================================================================
   🌐 MentorSync — CORE LAYOUT (Optimized for Light/Dark via data-theme)
   - Estructura del panel
   - Layout (sin colores)
   - Tooltip base
   - Responsive general
=================================================================== */

/* ------------------------------
   PANEL PRINCIPAL
------------------------------ */
.mentorsync-ai-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;

    width: min(360px, calc(100% - 2.6rem));
    max-height: min(520px, 80vh);

    display: none;
    flex-direction: column;

    border-radius: 1.35rem;
    overflow: hidden;

    z-index: 2147483647;
    box-sizing: border-box;
}

.mentorsync-ai-panel.is-open {
    display: flex;
}

.mentorsync-ai-panel * {
    box-sizing: border-box;
}

/* ------------------------------
   HEADER (estructura)
------------------------------ */
.mentorsync-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.mentorsync-ai-header-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.mentorsync-ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;
}

/* Imagen SVG dentro del avatar */
.mentorsync-ai-avatar-img,
.mentorsync-sidebar-avatar-img {
    width: 100%;
    height: 100%;
    display: block;
}

.mentorsync-ai-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.mentorsync-ai-subtitle {
    font-size: 0.78rem;
    line-height: 1.25;
}

/* Botón cerrar */
.mentorsync-ai-close {
    width: 26px;
    height: 26px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 999px;
    border: none;
    cursor: pointer;

    background: transparent;
    font-size: 14px;
}

/* ------------------------------
   MENSAJES (estructura)
------------------------------ */
.mentorsync-ai-messages {
    flex: 1;
    padding: 1rem 0.95rem;
    overflow-y: auto;

    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.mentorsync-ai-messages::-webkit-scrollbar {
    width: 6px;
}
.mentorsync-ai-messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
}

/* Cada mensaje */
.mentorsync-ai-message {
    display: flex;
    gap: 0.55rem;
}

.mentorsync-ai-message-assistant {
    justify-content: flex-start;
}

.mentorsync-ai-message-user {
    justify-content: flex-end;
}

/* Avatar de mensaje */
.mentorsync-ai-message-avatar {
    width: 26px;
    height: 26px;
    border-radius: 999px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;
}

/* Burbuja */
.mentorsync-ai-message-bubble {
    padding: 0.6rem 0.75rem;
    border-radius: 0.9rem;

    font-size: 0.85rem;
    line-height: 1.45;

    white-space: pre-wrap;
    word-break: break-word;
}

/* ------------------------------
   INPUT DEL CHAT (estructura)
------------------------------ */
.mentorsync-ai-input {
    display: flex;
    align-items: flex-end;
    gap: 0.65rem;

    padding: 0.8rem 1rem;
    border-top: 1px solid transparent;
}

.mentorsync-ai-input-text {
    flex: 1;
    min-height: 38px;
    max-height: 110px;

    padding: 0.55rem 0.7rem;
    border-radius: 0.9rem;

    border: 1px solid transparent;
    resize: none;
    outline: none;
}

.mentorsync-ai-input-send {
    padding: 0.55rem 0.9rem;
    border-radius: 999px;

    border: none;
    cursor: pointer;
}

/* ------------------------------
   TOOLTIP BASE
------------------------------ */
.mentorsync-ai-tooltip {
    position: relative;
    cursor: default;
}

.mentorsync-ai-tooltip::before {
    content: attr(data-tooltip);

    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);

    opacity: 0;
    pointer-events: none;

    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;

    background: var(--msync-tooltip-bg);
    color: var(--msync-tooltip-text);
    box-shadow: 0 4px 12px var(--msync-tooltip-shadow);

    transition: opacity .18s ease, transform .18s ease;
}

.mentorsync-ai-tooltip::after {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);

    border-width: 6px;
    border-style: solid;
    border-color: var(--msync-tooltip-bg) transparent transparent transparent;

    opacity: 0;
    transition: opacity .18s ease;
}

.mentorsync-ai-tooltip:hover::before,
.mentorsync-ai-tooltip:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Variables por defecto */
:root {
    --msync-tooltip-bg: rgba(0, 0, 0, 0.80);
    --msync-tooltip-text: #fff;
    --msync-tooltip-shadow: rgba(0, 0, 0, 0.25);
}

/* Light mode */
html[data-theme="light"] {
    --msync-tooltip-bg: rgba(255, 255, 255, 0.90);
    --msync-tooltip-text: #111;
    --msync-tooltip-shadow: rgba(255, 255, 255, 0.18);
}

/* ------------------------------
   RESPONSIVE
------------------------------ */
@media (max-width: 768px) {
    .mentorsync-ai-panel {
        left: 1.3rem;
        right: 1.3rem;
        bottom: 1.3rem;

        width: auto;
        max-height: 78vh;
    }
}

/* =====================================
   MENTORSYNC — Z-INDEX MASTER FIX
===================================== */

/* Contenedor principal del panel */
.mentorsync-ai-panel {
    position: fixed !important;
    bottom: 90px;
    right: 30px;

    z-index: 999999999 !important; /* más alto que cualquier overlay */
    pointer-events: auto !important;
}

/* Sidebar/burbuja flotante */
.mentorsync-sidebar {
    position: fixed !important;
    top: 50%;
    right: 1.5rem;

    transform: translateY(-50%);
    z-index: 999999999 !important;
}

/* ===============================================
   FIX DEFINITIVO PARA EL MENÚ ⋮ DE MENTORSYNC
   Se asegura de que:
   - aparezca arriba de los mensajes
   - tenga z-index superior
   - se posicione correctamente
   - se muestre al abrirlo
================================================ */

.mentorsync-ai-menu {
    position: absolute !important;
    top: 55px; /* debajo del header */
    right: 12px;

    min-width: 160px;
    padding: 10px 0;
    border-radius: 10px;

    background: var(--msync-menu-bg, rgba(0,0,0,0.85));
    backdrop-filter: blur(8px);

    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity .25s ease, transform .25s ease,
                visibility .25s ease;

    z-index: 9999999999 !important;
}

/* Cuando se abre */
.mentorsync-ai-panel.mentorsync-menu-open .mentorsync-ai-menu {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0);
}

/* Estilos de ítems del menú */
.mentorsync-ai-menu button {
    display: block;
    width: 100%;
    background: transparent;
    color: white;
    text-align: left;
    padding: 10px 15px;
    border: none;
    font-size: 14px;
    cursor: pointer;
}

.mentorsync-ai-menu button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Permitir que el menú pueda expandirse fuera del header */
.mentorsync-ai-header {
    overflow: visible !important;
    position: relative;
    z-index: 1000;
}

.mentorsync-ai-menu {
    max-height: none !important;
    overflow: visible !important;
    padding-bottom: 10px;
}

/* ============================================================
   FIX DEFINITIVO — Mostrar SIEMPRE todas las opciones del menú
============================================================ */

.mentorsync-ai-menu {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    padding-bottom: 12px !important;
}

.mentorsync-ai-panel.mentorsync-menu-open .mentorsync-ai-menu {
    display: block !important;
}

/* ============================================================
   OCULTAR BOTÓN FLOTANTE EN MÓVIL
============================================================ */
@media (max-width: 768px) {
    .mentorsync-sidebar {
        display: none !important;
    }
}
