/* ═══════════════════════════════════════════════════════════════
   CHATBOT.CSS — English Academy RVN
   Burbuja flotante + panel de chat contextual
   Usa variables del design system (variables.css)
   ═══════════════════════════════════════════════════════════════ */

/* ── FAB (Floating Action Button) ─────────────────────────────── */
.cb-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 1000;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #2d6fad);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(74, 144, 217, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.cb-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 32px rgba(74, 144, 217, 0.65);
}

.cb-fab:active {
    transform: scale(0.96);
}

.cb-fab-icon {
    width: 26px;
    height: 26px;
    fill: #fff;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    line-height: 1;
}

.cb-fab-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.7);
}

.cb-fab.cb-open .cb-fab-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.7);
}

.cb-fab.cb-open .cb-fab-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Badge de notificación */
.cb-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-darker);
    font-family: 'Poppins', sans-serif;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
}

.cb-fab.cb-open .cb-badge {
    transform: scale(0);
    opacity: 0;
}

/* Tooltip del FAB */
.cb-tooltip {
    position: absolute;
    right: 68px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateX(8px);
    transition: all 0.2s ease;
    font-family: 'Poppins', sans-serif;
}

.cb-tooltip::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right: none;
    border-left-color: var(--border);
}

.cb-fab:hover .cb-tooltip {
    opacity: 1;
    transform: translateX(0);
}

.cb-fab.cb-open .cb-tooltip {
    display: none;
}

/* ── PANEL PRINCIPAL ───────────────────────────────────────────── */
.cb-panel {
    position: fixed;
    bottom: 98px;
    right: 28px;
    z-index: 999;
    width: 370px;
    height: 540px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(74, 144, 217, 0.08);
    transform: scale(0.88) translateY(16px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.22s ease;
}

.cb-panel.cb-visible {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── HEADER ────────────────────────────────────────────────────── */
.cb-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-darker);
    flex-shrink: 0;
}

.cb-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #2d6fad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(74, 144, 217, 0.3);
}

.cb-header-info {
    flex: 1;
    min-width: 0;
}

.cb-header-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.cb-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #4ade80;
    font-family: 'Poppins', sans-serif;
    margin-top: 1px;
}

.cb-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    animation: cbPulse 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes cbPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

.cb-context-pill {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--primary-glow);
    color: var(--primary-light);
    border: 1px solid var(--border);
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all 0.3s ease;
}

.cb-header-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cb-header-close:hover {
    background: rgba(229, 57, 53, 0.1);
    color: #ef4444;
}

/* ── MENSAJES ──────────────────────────────────────────────────── */
.cb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* Mensajes */
.cb-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: cbMsgIn 0.25s ease;
}

@keyframes cbMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.cb-msg.cb-msg-bot { flex-direction: row; }
.cb-msg.cb-msg-user { flex-direction: row-reverse; }

.cb-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #2d6fad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.cb-bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    font-family: 'Poppins', sans-serif;
    max-width: 80%;
    word-break: break-word;
}

.cb-msg-bot .cb-bubble {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-bottom-left-radius: 4px;
}

.cb-msg-user .cb-bubble {
    background: linear-gradient(135deg, var(--primary), #2d6fad);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.cb-bubble strong { color: var(--text-primary); font-weight: 600; }
.cb-bubble em { color: var(--primary-light); font-style: normal; }

/* ── TYPING INDICATOR ──────────────────────────────────────────── */
.cb-typing {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: cbMsgIn 0.2s ease;
}

.cb-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-items: center;
}

.cb-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    animation: cbDot 1.2s ease-in-out infinite;
}
.cb-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.cb-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cbDot {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40%           { opacity: 1;   transform: scale(1); }
}

/* ── TARJETAS DE RESULTADO ─────────────────────────────────────── */
.cb-results-wrap {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 6px;
    max-width: 92%;
}

.cb-result-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
    animation: cbMsgIn 0.25s ease both;
}

.cb-result-card:hover {
    border-color: var(--border-hover);
    transform: translateX(2px);
}

.cb-result-card:nth-child(1) { animation-delay: 0.05s; }
.cb-result-card:nth-child(2) { animation-delay: 0.10s; }
.cb-result-card:nth-child(3) { animation-delay: 0.15s; }
.cb-result-card:nth-child(4) { animation-delay: 0.20s; }
.cb-result-card:nth-child(5) { animation-delay: 0.25s; }

.cb-card-en {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    font-family: 'Poppins', sans-serif;
}

.cb-card-es {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 3px;
    line-height: 1.4;
    font-family: 'Poppins', sans-serif;
}

.cb-card-meta {
    display: flex;
    gap: 5px;
    margin-top: 7px;
    flex-wrap: wrap;
    align-items: center;
}

.cb-tag {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--primary-glow);
    color: var(--primary-light);
    border: 1px solid var(--border);
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
}

.cb-tag-nivel {
    background: rgba(76, 175, 80, 0.08);
    color: #69db7c;
    border-color: rgba(76, 175, 80, 0.2);
}

.cb-tag-cat {
    background: rgba(255, 193, 7, 0.08);
    color: #ffd54f;
    border-color: rgba(255, 193, 7, 0.15);
}

/* Botón de audio en card */
.cb-card-audio {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    font-size: 12px;
    transition: color 0.2s;
    flex-shrink: 0;
}
.cb-card-audio:hover { color: var(--primary-light); }

/* ── SUGERENCIAS RÁPIDAS ───────────────────────────────────────── */
.cb-suggestions {
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid var(--border);
    background: var(--bg-darker);
    flex-shrink: 0;
}

.cb-sug-label {
    width: 100%;
    font-size: 10px;
    color: var(--text-muted);
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    margin-bottom: 2px;
}

.cb-sug-btn {
    font-size: 11px;
    padding: 5px 11px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--primary-glow);
    color: var(--primary-light);
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
}

.cb-sug-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

/* ── INPUT ÁREA ────────────────────────────────────────────────── */
.cb-input-area {
    padding: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    border-top: 1px solid var(--border);
    background: var(--bg-darker);
    flex-shrink: 0;
}

.cb-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 9px 15px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Poppins', sans-serif;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    line-height: 1.4;
}

.cb-input::placeholder { color: var(--text-muted); }
.cb-input:focus { border-color: var(--border-hover); }

.cb-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #2d6fad);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.15s;
    box-shadow: 0 2px 10px rgba(74, 144, 217, 0.3);
}

.cb-send-btn:hover { opacity: 0.85; transform: scale(1.06); }
.cb-send-btn:active { transform: scale(0.95); }

.cb-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

/* ── ESTADO DE CARGA ───────────────────────────────────────────── */
.cb-loading-msg {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'Poppins', sans-serif;
    padding: 4px 0;
}

.cb-loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: cbSpin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes cbSpin {
    to { transform: rotate(360deg); }
}

/* ── ESTADO VACÍO / SIN RESULTADOS ────────────────────────────── */
.cb-empty {
    text-align: center;
    padding: 20px 16px;
    color: var(--text-muted);
    font-size: 13px;
    font-family: 'Poppins', sans-serif;
    line-height: 1.6;
}

.cb-empty-icon {
    font-size: 28px;
    margin-bottom: 8px;
    display: block;
}

/* ── NOTIFICACIÓN DE CAMBIO DE CONTEXTO ────────────────────────── */
.cb-context-change {
    text-align: center;
    padding: 6px 12px;
    font-size: 11px;
    color: var(--primary-light);
    font-family: 'Poppins', sans-serif;
    background: var(--primary-glow);
    border: 1px solid var(--border);
    border-radius: 20px;
    margin: 0 auto;
    max-width: 85%;
    animation: cbMsgIn 0.25s ease;
}

/* ── RESPONSIVE MÓVIL ──────────────────────────────────────────── */
@media (max-width: 600px) {
    .cb-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 120px);
        bottom: 84px;
        right: 12px;
        border-radius: 20px;
    }

    .cb-fab {
        bottom: 20px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .cb-tooltip { display: none; }
}

/* ── CARDS NAVEGABLES ──────────────────────────────────────────── */
.cb-card-clickable {
    cursor: pointer;
    border-color: rgba(74, 144, 217, 0.25);
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.cb-card-clickable:hover {
    border-color: var(--primary);
    transform: translateX(3px);
    box-shadow: 0 2px 12px rgba(74, 144, 217, 0.2);
}

.cb-goto-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    padding: 3px 9px;
    border-radius: 20px;
    border: 1px solid var(--primary);
    background: var(--primary-glow);
    color: var(--primary-light);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
    margin-left: auto;
    white-space: nowrap;
}

.cb-goto-btn:hover {
    background: var(--primary);
    color: #fff;
}

.cb-card-hint {
    font-size: 10px;
    color: var(--primary-light);
    margin-top: 6px;
    font-family: 'Poppins', sans-serif;
    opacity: 0.7;
}
