/* ============================================================
   AUDIO ASSISTANT V2 - Hub Academia Premium
   Estilos para el botón flotante y el panel de voz
   ============================================================ */

/* ─── VARIABLES LOCALES ─────────────────────────────── */
:root {
    --audio-primary: #8b5cf6;
    --audio-secondary: #06b6d4;
    --audio-bg: rgba(8, 8, 12, 0.97);
    --audio-surface: rgba(255, 255, 255, 0.04);
    --audio-border: rgba(255, 255, 255, 0.08);
    --audio-text: #f1f5f9;
    --audio-muted: #64748b;
}

/* ─── BOTÓN FLOTANTE (FAB) ───────────────────────────── */
.audio-assistant-fab {
    position: fixed;
    bottom: 96px; /* Stacked above chat toggle (24px + 60px + gap) */
    right: 24px;
    width: 60px; /* Matched with chatbot-toggle */
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    border: none;
    cursor: pointer;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.45);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    overflow: visible;
}

.audio-assistant-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(139, 92, 246, 0.65);
}

.audio-assistant-fab.panel-open {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.45);
}

/* Cuando está minimizado: pulsación suave violeta */
.audio-assistant-fab.minimized-mode {
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    animation: fab-minimized-pulse 2s ease-in-out infinite;
}

@keyframes fab-minimized-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4); transform: scale(1); }
    50%      { box-shadow: 0 6px 35px rgba(139, 92, 246, 0.7); transform: scale(1.06); }
}

.audio-fab-icon {
    font-size: 1.4rem; /* Slightly larger to match chat icon */
    color: white;
    z-index: 2;
    position: relative;
}

/* Badge de bloqueo (corona dorada) */
.audio-fab-lock {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #fbbf24, #d97706);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    color: #000;
    border: 2px solid #0a0a0f;
    z-index: 3;
}

/* Ondas en el FAB — SOLO visibles cuando la IA habla (.speaking) */
.audio-fab-waves {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
}

.audio-fab-waves span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(139, 92, 246, 0.5);
    opacity: 0;
    /* Sin animación por defecto */
}

/* ✅ Ondas SOLO cuando la IA está hablando */
.audio-assistant-fab.speaking .audio-fab-waves span {
    animation: audio-fab-pulse 2.5s ease-out infinite;
}
.audio-assistant-fab.speaking .audio-fab-waves span:nth-child(2) { animation-delay: 0.8s; }
.audio-assistant-fab.speaking .audio-fab-waves span:nth-child(3) { animation-delay: 1.6s; }

@keyframes audio-fab-pulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(2.2); opacity: 0;   }
}

/* ─── PANEL PRINCIPAL ────────────────────────────────── */
.audio-assistant-panel {
    position: fixed;
    bottom: 170px;
    right: 24px;
    width: 400px; /* Incrementado para mejor lectura de listas */
    /* ✅ FIX: Altura máxima fija para evitar que se estire o tape el nav */
    max-height: 520px;
    background: var(--audio-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--audio-border);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    z-index: 1049;
    box-shadow:
        0 0 0 1px rgba(139, 92, 246, 0.15),
        0 25px 60px rgba(0, 0, 0, 0.7),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.audio-assistant-panel.active {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Estado minimizado: colapsar completamente */
.audio-assistant-panel.minimized {
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
}

/* ─── HEADER ─────────────────────────────────────────── */
.audio-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--audio-border);
    background: rgba(255,255,255,0.02);
    flex-shrink: 0;
}

.audio-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.audio-title-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.audio-panel-title h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--audio-text);
    margin: 0;
}

.audio-context-label {
    font-size: 0.7rem;
    color: var(--audio-muted);
    display: block;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.audio-panel-controls {
    display: flex;
    gap: 6px;
}

.audio-panel-ctrl-btn {
    background: var(--audio-surface);
    border: 1px solid var(--audio-border);
    border-radius: 8px;
    width: 30px;
    height: 30px;
    color: var(--audio-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.audio-panel-ctrl-btn:hover {
    color: white;
    background: rgba(255,255,255,0.08);
}

/* ─── VISUALIZADOR DE ONDAS ──────────────────────────── */
.audio-waveform-container {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.audio-waveform {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 40px;
}

.audio-bar {
    width: 4px;
    height: 8px;
    background: rgba(139, 92, 246, 0.3);
    border-radius: 2px;
    transition: height 0.15s ease;
}

/* Estado: escuchando */
.audio-waveform.waveform-listening .audio-bar {
    background: #22c55e;
    animation: bar-bounce-listen 0.8s ease-in-out infinite alternate;
}

/* Estado: pensando */
.audio-waveform.waveform-thinking .audio-bar {
    background: #f59e0b;
    animation: bar-thinking 1.2s ease-in-out infinite;
}

/* Estado: hablando */
.audio-waveform.waveform-speaking .audio-bar {
    background: linear-gradient(180deg, var(--audio-primary), var(--audio-secondary));
    animation: bar-speaking 0.6s ease-in-out infinite alternate;
}

@keyframes bar-bounce-listen {
    0%   { height: 8px; }
    100% { height: 36px; }
}

@keyframes bar-thinking {
    0%, 100% { height: 8px;  opacity: 0.5; }
    50%       { height: 28px; opacity: 1;   }
}

@keyframes bar-speaking {
    0%   { height: 6px;  }
    100% { height: 38px; }
}

.audio-waveform.waveform-speaking .audio-bar,
.audio-waveform.waveform-listening .audio-bar {
    animation-delay: calc(var(--i, 0) * 0.04s);
}

.audio-status-text {
    font-size: 0.75rem;
    color: var(--audio-muted);
    margin: 0;
    min-height: 16px;
}

.audio-transcript-text {
    font-size: 0.78rem;
    color: #94a3b8;
    margin: 0;
    font-style: italic;
    text-align: center;
    min-height: 14px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── ÁREA DE RESPUESTA (FORMATO RICO) ───────────────── */
.audio-response-area {
    padding: 10px 14px;
    /* ✅ FIX: Limitar el tamaño con scroll interno, no empujar el panel */
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 80px;
    max-height: 200px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.audio-response-bubble {
    background: var(--audio-surface);
    border: 1px solid var(--audio-border);
    border-radius: 16px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.audio-response-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--audio-primary);
}

.audio-response-header i {
    font-size: 0.85rem;
}

/* ✅ Contenido con formato Markdown rico */
.audio-response-content {
    font-size: 0.85rem;
    line-height: 1.5; /* Reducido de 1.65 */
    color: var(--audio-text);
    word-break: break-word;
}

.audio-response-content .audio-bold {
    color: #c4b5fd; /* Violeta claro */
    font-weight: 700;
}

.audio-response-content .audio-h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: white;
    margin: 6px 0 2px; /* Reducido de 10px 0 4px */
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding-bottom: 2px;
}

.audio-response-content .audio-h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #e2e8f0;
    margin: 4px 0 2px; /* Reducido de 8px */
}

.audio-response-content .audio-list {
    margin: 2px 0 4px; /* Reducido para evitar gaps */
    padding-left: 18px;
    list-style: none;
}

.audio-response-content .audio-list li {
    position: relative;
    padding-left: 14px;
    margin-bottom: 3px;
    font-size: 0.83rem;
    color: #cbd5e1;
}

/* Soporte para listas anidadas (hasta 3 niveles) */
.audio-response-content .audio-list .audio-list {
    margin: 4px 0 6px 12px;
}

.audio-response-content .audio-list .audio-list .audio-list {
    margin: 4px 0 6px 12px;
}

.audio-response-content .audio-list .audio-list li::before {
    content: '○';
    font-size: 0.7rem;
    top: 1px;
}

.audio-response-content .audio-list .audio-list .audio-list li::before {
    content: '▪';
    font-size: 0.6rem;
    top: 2px;
}

.audio-response-content .audio-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--audio-primary);
    font-weight: bold;
}

.audio-response-content .audio-quote {
    border-left: 3px solid var(--audio-primary);
    padding: 6px 12px;
    margin: 6px 0;
    background: rgba(139, 92, 246, 0.06);
    color: #94a3b8;
    font-style: italic;
    border-radius: 0 8px 8px 0;
    font-size: 0.82rem;
}

/* ─── ACCIONES DE RESPUESTA (Guardar nota) ───────────── */
.audio-response-actions {
    display: flex;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.audio-save-note-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--audio-border);
    border-radius: 8px;
    padding: 5px 12px;
    color: var(--audio-muted);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.audio-save-note-btn:hover {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.06);
}

.audio-save-note-btn.saved {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.3);
}

/* ─── ACCIONES RÁPIDAS ───────────────────────────────── */
.audio-quick-actions {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    overflow-x: auto;
    scrollbar-width: none;
    border-top: 1px solid var(--audio-border);
    flex-shrink: 0;
}

.audio-quick-actions::-webkit-scrollbar { display: none; }

.audio-quick-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    padding: 6px 14px;
    background: var(--audio-surface);
    border: 1px solid var(--audio-border);
    border-radius: 20px;
    color: #94a3b8;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.audio-quick-btn:hover {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.4);
    color: white;
    transform: translateY(-1px);
}

.audio-quick-btn i {
    font-size: 0.75rem;
    color: var(--audio-primary);
}

/* ─── CONTROL DEL MICRÓFONO ──────────────────────────── */
.audio-mic-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px;
    border-top: 1px solid var(--audio-border);
    background: rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.audio-mic-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: white;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    position: relative;
}

.audio-mic-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(139, 92, 246, 0.3);
    opacity: 0;
    transition: opacity 0.3s;
}

.audio-mic-btn.listening {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    box-shadow: 0 4px 25px rgba(34, 197, 94, 0.5);
    animation: mic-pulse 1s ease-in-out infinite;
}

.audio-mic-btn.listening::after {
    opacity: 1;
    border-color: rgba(34, 197, 94, 0.5);
}

@keyframes mic-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.audio-stop-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
    transition: transform 0.2s ease;
}

.audio-stop-btn:hover { transform: scale(1.05); }

.audio-mic-hint {
    font-size: 0.7rem;
    color: var(--audio-muted);
    margin: 0;
    text-align: center;
}

/* ─── MINI PLAYER BAR (Tipo flotante compacto) ──────── */
.audio-mini-player {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 320px; /* Ancho fijo para no chocar con botones de la derecha */
    max-width: calc(100vw - 110px); /* Evitar solape con FABs */
    height: 64px;
    background: linear-gradient(135deg, rgba(15, 15, 20, 0.95), rgba(30, 20, 50, 0.95));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1060;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    transform: translateY(30px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.audio-mini-player.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

.mini-player-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.mini-player-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.mini-player-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mini-player-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--audio-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-player-status {
    font-size: 0.7rem;
    color: var(--audio-muted);
}

.mini-player-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mini-ctrl-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.mini-ctrl-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.4);
    transform: scale(1.05);
}

.mini-ctrl-btn:first-child {
    /* Mic button: violeta */
    background: linear-gradient(135deg, var(--audio-primary), var(--audio-secondary));
    border: none;
    box-shadow: 0 2px 10px rgba(139, 92, 246, 0.4);
}

.mini-ctrl-btn.listening {
    background: linear-gradient(135deg, #22c55e, #16a34a) !important;
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.4);
    animation: mic-pulse 1s ease-in-out infinite;
}

.mini-ctrl-btn.mini-stop {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border: none;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.3);
}

.mini-ctrl-btn.mini-close {
    background: transparent;
    border: none;
    color: var(--audio-muted);
    font-size: 0.8rem;
}

.mini-ctrl-btn.mini-close:hover {
    color: #ef4444;
    background: transparent;
}

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 480px) {
    .audio-assistant-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: 150px;
        border-radius: 20px;
        max-height: 60vh;
    }

    .audio-assistant-fab {
        right: 20px;
        bottom: 84px; /* Stacked */
        width: 56px;
        height: 56px;
    }

    .audio-response-area {
        max-height: 150px;
    }

    .audio-mini-player {
        left: 10px;
        bottom: 10px;
        width: calc(100% - 90px);
        padding: 0 10px;
        height: 60px;
    }

    .mini-player-title {
        max-width: 100px;
    }

    .mini-player-icon {
        width: 32px;
        height: 32px;
    }
}
