/* ==========================================================================
   Asistente Institucional, Guía Interactiva, Smart Hover Tooltips & ScrollLock
   Biblioteca Híbrida — IESTP Chivay (v2.0)
   ========================================================================== */

:root {
    --avatar-size: 58px;
    --avatar-size-min: 50px;
    --avatar-glow: rgba(0, 201, 167, 0.45);
    --avatar-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --avatar-border: linear-gradient(135deg, #00c9a7, #6366f1, #f59e0b);
    --tooltip-bg: rgba(13, 18, 34, 0.96);
    --tooltip-text: #f8fafc;
    --z-index-backdrop: 9990;
    --z-index-avatar: 9995;
    --z-index-tooltip: 10000;
    --z-index-smart-tip: 10050;
}

/* ─── 1. ANTI-INTERFERENCIA DE INTERFACES Y BLOQUEO DE SCROLL (Scroll Bleed Fix) ─── */
body.ui-scroll-locked {
    overflow: hidden !important;
    overscroll-behavior: none !important;
}

.modal-overlay,
.pwa-modal-backdrop,
.avatar-tour-backdrop-global {
    overscroll-behavior: contain;
}

.modal,
.pwa-modal-card,
.avatar-tooltip,
.tour-floating-tooltip,
.sidebar,
.tabla-container {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* Evitar que el orbe del asistente o el FAB PWA interfieran cuando hay un modal abierto */
body.ui-modal-active .avatar-orb-container,
body.ui-modal-active .pwa-fab {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(16px) scale(0.9);
}

/* Posicionar el FAB PWA encima del asistente en móviles para que jamás se superpongan */
.pwa-fab {
    bottom: 88px !important;
    right: 20px !important;
    z-index: 9980 !important;
    transition: opacity 0.25s ease, transform 0.25s ease !important;
}

/* En escritorio el botón "Instalar App" ya vive en la barra superior, ocultamos el FAB inferior para limpieza visual */
@media (min-width: 900px) {
    .pwa-fab {
        display: none !important;
    }
}

/* Toasts en esquina superior derecha (bajo el header) para no chocar con el Asistente inferior */
.toast-container {
    top: calc(var(--header-height, 68px) + 14px) !important;
    bottom: auto !important;
    right: 20px !important;
    z-index: 10020 !important;
}

/* ─── 2. SMART HOVER TOOLTIPS (Indicaciones instantáneas al pasar el mouse) ─── */
.smart-hover-tooltip {
    position: fixed;
    z-index: var(--z-index-smart-tip);
    max-width: 290px;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    background: rgba(11, 16, 30, 0.96);
    border: 1px solid rgba(0, 201, 167, 0.38);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: #f1f5f9;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.78rem;
    line-height: 1.45;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px) scale(0.98);
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.smart-hover-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.smart-hover-tooltip . sht-title {
    display: block;
    font-weight: 700;
    color: #34d399;
    margin-bottom: 2px;
    font-size: 0.76rem;
    letter-spacing: 0.01em;
}

/* ─── 3. BACKDROP Y FOCUS BOX DE LA GUÍA INTERACTIVA ─── */
.avatar-tour-backdrop-global {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 9, 20, 0.72);
    backdrop-filter: blur(3px);
    z-index: var(--z-index-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.avatar-tour-backdrop-global.active {
    opacity: 1;
    pointer-events: auto;
}

.avatar-focus-box {
    position: fixed;
    z-index: var(--z-index-backdrop);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(5, 9, 20, 0.75), 0 0 28px rgba(0, 201, 167, 0.55);
    border: 2.5px solid #00c9a7;
    pointer-events: none;
    opacity: 0;
    transition: all 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.avatar-focus-box.active {
    opacity: 1;
}

/* ─── 4. ORBE DEL ASISTENTE INSTITUCIONAL ─── */
.avatar-orb-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--z-index-avatar);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.avatar-orb-wrap {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    pointer-events: auto;
}

.avatar-orb-pill {
    background: rgba(13, 18, 34, 0.92);
    border: 1px solid rgba(0, 201, 167, 0.35);
    color: #e2e8f0;
    padding: 0.42rem 0.85rem;
    border-radius: 999px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(12px);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.avatar-orb-pill:hover {
    border-color: #00c9a7;
    color: #ffffff;
    transform: translateX(-2px);
}

.avatar-orb-pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.avatar-orb {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    background: var(--avatar-bg);
    position: relative;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55), 0 0 18px var(--avatar-glow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 2.5px;
}

.avatar-orb::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: var(--avatar-border);
    z-index: -1;
    animation: spin-gradient 6s linear infinite;
}

.avatar-graphic {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 25%, #1e293b, #090d1a);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #00c9a7;
    font-size: 1.4rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.avatar-graphic svg {
    width: 56%;
    height: 56%;
    fill: currentColor;
}

.avatar-orb:hover {
    transform: translateY(-2px) scale(1.06);
    box-shadow: 0 12px 30px rgba(0, 201, 167, 0.55);
}

.avatar-orb.minimized {
    width: var(--avatar-size-min);
    height: var(--avatar-size-min);
    opacity: 0.95;
}

/* ─── 5. VENTANA PRINCIPAL DEL ASISTENTE (Guías + Consultor IA) ─── */
.avatar-tooltip {
    position: absolute;
    bottom: calc(100% + 14px);
    right: 0;
    width: 375px;
    max-height: min(620px, calc(100vh - 110px));
    overflow-y: auto;
    background: var(--tooltip-bg);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    color: var(--tooltip-text);
    padding: 1.15rem;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
    border: 1px solid rgba(0, 201, 167, 0.35);
    pointer-events: none;
    opacity: 0;
    transform: translateY(12px) scale(0.96);
    visibility: hidden;
    transition: all 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    transform-origin: bottom right;
}

.avatar-tooltip.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    pointer-events: auto;
}

.avatar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.avatar-head-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.avatar-head-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #00c9a7, #4f46e5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 0.95rem;
    box-shadow: 0 4px 12px rgba(0, 201, 167, 0.35);
}

.avatar-head-title {
    font-family: 'Outfit', sans-serif;
    font-size: 0.94rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.15;
}

.avatar-head-sub {
    font-size: 0.72rem;
    color: #94a3b8;
}

.avatar-head-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.avatar-icon-btn {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cbd5e1;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.18s ease;
}

.avatar-icon-btn:hover {
    background: rgba(0, 201, 167, 0.18);
    border-color: #00c9a7;
    color: #fff;
}

.avatar-tabs {
    display: flex;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.04);
    padding: 0.28rem;
    border-radius: 11px;
    margin-bottom: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.avatar-tab {
    flex: 1;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}

.avatar-tab.active {
    background: linear-gradient(135deg, #00c9a7, #059669);
    color: #06131f;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 201, 167, 0.28);
}

.avatar-tooltip-content {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    line-height: 1.55;
    color: #e2e8f0;
    margin-bottom: 0.85rem;
}

.avatar-menu-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.avatar-menu-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
    padding: 0.68rem 0.85rem;
    border-radius: 11px;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.avatar-menu-btn:hover {
    background: rgba(0, 201, 167, 0.12);
    border-color: rgba(0, 201, 167, 0.5);
    transform: translateX(2px);
}

.avatar-menu-btn::after {
    content: '➔';
    color: #00c9a7;
    font-size: 0.8rem;
}

/* Mini-chat consultor dentro del asistente */
.avatar-chat-box {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.avatar-chat-messages {
    max-height: 235px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.55rem;
    border-radius: 12px;
    background: rgba(6, 10, 22, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.avatar-chat-msg {
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    font-size: 0.8rem;
    line-height: 1.45;
}

.avatar-chat-msg.bot {
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(0, 201, 167, 0.22);
    color: #f1f5f9;
    align-self: flex-start;
}

.avatar-chat-msg.user {
    background: linear-gradient(135deg, #4f46e5, #00c9a7);
    color: #fff;
    align-self: flex-end;
    font-weight: 500;
}

.avatar-quick-chips {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.avatar-chip {
    background: rgba(0, 201, 167, 0.11);
    border: 1px solid rgba(0, 201, 167, 0.3);
    color: #6ee7b7;
    padding: 0.28rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.16s ease;
}

.avatar-chip:hover {
    background: rgba(0, 201, 167, 0.24);
    color: #fff;
}

.avatar-chat-input-row {
    display: flex;
    gap: 0.4rem;
}

.avatar-chat-input {
    flex: 1;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 10px;
    padding: 0.52rem 0.75rem;
    color: #fff;
    font-size: 0.8rem;
    outline: none;
}

.avatar-chat-input:focus {
    border-color: #00c9a7;
}

/* ─── 6. TOOLTIP FLOTANTE DURANTE EL RECORRIDO GUIADO ─── */
.tour-floating-tooltip {
    position: fixed;
    z-index: var(--z-index-tooltip);
    width: 340px;
    max-height: 82vh;
    overflow-y: auto;
    background: var(--tooltip-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    color: var(--tooltip-text);
    padding: 1.15rem 1.25rem;
    border-radius: 16px;
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(0, 201, 167, 0.45);
    border-left: 4px solid #00c9a7;
    pointer-events: none;
    opacity: 0;
    transform: translateY(12px);
    visibility: hidden;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.tour-floating-tooltip.active {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
}

.tour-step-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #34d399;
    background: rgba(16, 185, 129, 0.14);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    margin-bottom: 0.55rem;
}

.avatar-tooltip-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.75rem;
}

.avatar-btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    padding: 0.48rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    font-weight: 600;
    transition: all 0.18s ease;
}

.avatar-btn-skip {
    background: rgba(255, 255, 255, 0.07);
    color: #cbd5e1;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.avatar-btn-skip:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
}

.avatar-btn-next {
    background: linear-gradient(135deg, #00c9a7, #10b981);
    color: #04131a;
    font-weight: 700;
}

.avatar-btn-next:hover {
    box-shadow: 0 4px 14px rgba(0, 201, 167, 0.45);
    transform: translateY(-1px);
}

@keyframes spin-gradient {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    .tour-floating-tooltip {
        width: calc(100vw - 2rem);
        left: 1rem !important;
        right: 1rem !important;
        padding: 1rem;
    }
    .avatar-orb-container {
        bottom: 14px;
        right: 14px;
    }
    .avatar-orb-pill {
        display: none;
    }
    .avatar-tooltip {
        width: calc(100vw - 2rem);
        max-height: 74vh;
        right: 0;
        padding: 1rem;
    }
    .smart-hover-tooltip {
        display: none !important;
    }
}
