/* ===================================================================
   🌐 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(400px, calc(100% - 2rem));
    max-height: min(580px, 86vh);

    display: none;
    flex-direction: column;

    border-radius: 1.35rem;
    overflow: hidden;

    z-index: 2147483647;
    box-sizing: border-box;
    background: var(--ms-ink, #0c0a14);
}

.mentorsync-ai-panel.is-open {
    display: flex;
    height: min(580px, calc(100vh - 2.5rem));
}

.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.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    opacity: 0.82;
}

/* 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 — posición unificada (no duplicar en otros CSS) */
.mentorsync-ai-panel {
    z-index: 2147483647 !important;
    pointer-events: auto !important;
}

/* Sidebar flotante: debajo del panel */
.mentorsync-sidebar {
    position: fixed;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    z-index: 2147483646;
    transition: opacity 0.22s ease, visibility 0.22s ease, transform 0.22s ease;
}

/* ===============================================
   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:not(.mentorsync-header) {
        top: auto;
        bottom: 1.25rem;
        right: 1rem;
        transform: none;
        width: 52px;
        height: 52px;
    }

    body.mentorsync-panel-open .mentorsync-ai-panel {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
    }
}

.mentorsync-ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.mentorsync-ai-action-btn {
    border: 1px solid rgba(124, 58, 237, 0.35);
    background: rgba(124, 58, 237, 0.1);
    color: inherit;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
}

/* 🔥 HEADER MODE */
.mentorsync-header {
    position: relative;
    display: flex;
    align-items: center;
    top: auto;
    right: auto;
    transform: none;
    z-index: 10;
}

/* Avatar del panel — fallback si la imagen CDN falla */
.mentorsync-ai-avatar-ring {
    display: grid;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--ms-violet-deep, #6e5ce6), var(--ms-violet, #9b8cff), var(--ms-rose, #e8789a));
}

.mentorsync-ai-avatar-ring .mentorsync-ai-avatar-img {
    width: calc(100% - 4px);
    height: calc(100% - 4px);
    border-radius: 50%;
    object-fit: cover;
    background: #1c1929;
}

.mentorsync-ai-avatar-ring.is-fallback .mentorsync-ai-avatar-img,
.mentorsync-ai-avatar-img.is-broken {
    display: none !important;
}

.mentorsync-ai-avatar-ring.is-fallback::after {
    content: "✦";
    font-size: 1.35rem;
    line-height: 1;
    color: #fff;
    grid-area: 1 / 1;
}

.mentorsync-ai-message-avatar {
    overflow: hidden;
    background: linear-gradient(135deg, var(--ms-violet-deep, #6e5ce6), var(--ms-rose, #e8789a));
}

.mentorsync-ai-message-avatar .mentorsync-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.mentorsync-ai-message-avatar.is-fallback .mentorsync-avatar-img {
    display: none;
}

.mentorsync-ai-message-avatar.is-fallback::after {
    content: "✦";
    font-size: 14px;
    line-height: 1;
    color: #fff;
}

.mentorsync-ai-message-avatar.mentorsync-ai-message-avatar--user.is-fallback::after {
    content: "Tú";
    font-size: 9px;
    font-weight: 800;
}

.mentorsync-ai-feedback {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(155, 140, 255, 0.14);
}

.mentorsync-ai-message-footer .mentorsync-ai-feedback {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.mentorsync-ai-fb-up,
.mentorsync-ai-fb-down {
    border: 1px solid rgba(155, 140, 255, 0.28);
    background: rgba(155, 140, 255, 0.08);
    border-radius: 10px;
    min-width: 36px;
    height: 32px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.mentorsync-ai-fb-up span,
.mentorsync-ai-fb-down span {
    pointer-events: none;
}

.mentorsync-ai-fb-up:hover,
.mentorsync-ai-fb-down:hover {
    background: rgba(155, 140, 255, 0.2);
    border-color: rgba(155, 140, 255, 0.45);
    transform: translateY(-1px);
}

.mentorsync-ai-copy-btn {
    opacity: 0.75;
}

.mentorsync-ai-voice-btn {
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    padding: 6px 8px;
    line-height: 1;
    transition: background 0.2s ease;
}

.mentorsync-ai-voice-btn:hover {
    background: rgba(155, 140, 255, 0.15);
}

.mentorsync-ai-voice-btn.is-listening {
    opacity: 0.6;
    background: rgba(232, 120, 154, 0.2);
}
