/* ============================================
   TUTOR OFFLINE - SOPORTE PARA TECLADO EN MÓVIL
   ============================================ */

/* Panel del tutor - CON AJUSTE PARA TECLADO */
.tutor-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    max-width: 90vw;
    max-height: 500px;
    min-height: 300px;  /* ← NUEVO: altura mínima */
    background: var(--tutor-bg, #1A1A2E);
    border-radius: var(--tutor-radius, 16px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    z-index: 999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(108, 99, 255, 0.3);
    animation: slideUpTutor 0.3s ease;
    transition: max-height 0.3s ease, bottom 0.3s ease;  /* ← NUEVO: transición suave */
}

/* Contenedor de mensajes - CON SCROLL Y FLEX */
.tutor-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 350px;
    min-height: 150px;  /* ← NUEVO: altura mínima */
    background: #16213E;
    -webkit-overflow-scrolling: touch;  /* ← NUEVO: scroll suave en iOS */
}

/* Input area - SIEMPRE VISIBLE */
.tutor-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    background: #1A1A2E;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;  /* ← IMPORTANTE: no se encoge */
    min-height: 60px;  /* ← NUEVO: altura mínima */
}

/* Input - SIEMPRE VISIBLE */
.tutor-input-area input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    background: #2A2A4A;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    min-height: 44px;  /* ← NUEVO: altura táctil */
}

/* ============================================
   RESPONSIVE - TECLADO EN MÓVIL Y TABLET
   ============================================ */

/* Pantallas pequeñas (móviles) */
@media (max-width: 768px) {
    .tutor-panel {
        bottom: 80px;
        right: 15px;
        width: calc(100% - 30px);
        max-height: 60vh;  /* ← CAMBIADO: usa viewport height */
        min-height: 300px;
        max-width: 100%;
        border-radius: 16px;
    }

    .tutor-messages {
        max-height: 40vh;
        min-height: 120px;
        padding: 12px;
    }

    .tutor-input-area {
        padding: 10px 12px;
        min-height: 54px;
    }

    .tutor-input-area input {
        font-size: 16px;  /* ← NUEVO: evita zoom en iOS */
        padding: 10px 14px;
        min-height: 40px;
    }

    .tutor-send {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

/* Pantallas muy pequeñas (altura < 600px) */
@media (max-height: 600px) {
    .tutor-panel {
        max-height: 70vh;
        min-height: 250px;
        bottom: 70px;
    }

    .tutor-messages {
        max-height: 45vh;
        min-height: 100px;
        padding: 10px;
    }

    .tutor-messages .tutor-msg {
        font-size: 13px;
        padding: 8px 12px;
    }

    .tutor-input-area {
        padding: 8px 10px;
        min-height: 48px;
    }

    .tutor-input-area input {
        font-size: 14px;
        padding: 8px 12px;
        min-height: 36px;
    }

    .tutor-send {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .tutor-header {
        padding: 10px 15px;
        font-size: 13px;
    }

    .tutor-header span {
        font-size: 13px;
    }
}

/* Pantallas EXTREMADAMENTE pequeñas (altura < 400px) */
@media (max-height: 400px) {
    .tutor-panel {
        max-height: 75vh;
        min-height: 200px;
        bottom: 60px;
        border-radius: 12px;
    }

    .tutor-messages {
        max-height: 50vh;
        min-height: 80px;
        padding: 8px;
        gap: 6px;
    }

    .tutor-messages .tutor-msg {
        font-size: 12px;
        padding: 6px 10px;
        max-width: 90%;
    }

    .tutor-input-area {
        padding: 6px 8px;
        min-height: 40px;
        gap: 6px;
    }

    .tutor-input-area input {
        font-size: 12px;
        padding: 6px 10px;
        min-height: 30px;
        border-radius: 20px;
    }

    .tutor-send {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .tutor-header {
        padding: 6px 12px;
        font-size: 12px;
    }

    .tutor-header span {
        font-size: 12px;
    }

    .tutor-close {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .tutor-status {
        font-size: 9px;
        padding: 4px 10px;
    }

    .status-dot {
        width: 6px;
        height: 6px;
    }
}

/* Landscape en móvil */
@media (max-width: 768px) and (orientation: landscape) {
    .tutor-panel {
        max-height: 80vh;
        min-height: 200px;
        bottom: 60px;
        width: calc(100% - 40px);
        max-width: 500px;
        right: 20px;
    }

    .tutor-messages {
        max-height: 50vh;
        min-height: 100px;
        padding: 10px;
    }

    .tutor-messages .tutor-msg {
        font-size: 13px;
        padding: 8px 12px;
        max-width: 80%;
    }

    .tutor-input-area {
        padding: 8px 12px;
        min-height: 48px;
    }

    .tutor-input-area input {
        font-size: 14px;
        padding: 8px 12px;
        min-height: 36px;
    }

    .tutor-send {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
}

/* ============================================
   PARA CUANDO EL TECLADO ESTÁ ABIERTO
   ============================================ */

/* Clase que se añade cuando el teclado está visible */
.tutor-panel.keyboard-open {
    min-height: 200px !important;
    bottom: 10px !important;
    right: 10px !important;
    width: calc(100% - 20px) !important;
    border-radius: 12px !important;

    /* La altura la controla JavaScript */
    height: auto !important;
    max-height: none !important;
}

.tutor-panel.keyboard-open .tutor-messages {
    max-height: 30vh !important;
    min-height: 80px !important;
}

.tutor-panel.keyboard-open .tutor-input-area {
    min-height: 50px !important;
}

.tutor-panel.keyboard-open .tutor-header {
    padding: 8px 12px !important;
}

.tutor-panel.keyboard-open .tutor-header span {
    font-size: 13px !important;
}

.tutor-panel.keyboard-open .tutor-status {
    display: none !important;  /* ← NUEVO: oculta el estado para ahorrar espacio */
}

/* ============================================
   BOTÓN FLOTANTE - NO SE SUPERPONE AL TECLADO
   ============================================ */
.tutor-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #6C63FF, #4A3FBF);
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(108, 99, 255, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Cuando el teclado está abierto, el botón sube */
.tutor-btn.keyboard-open {
    bottom: 80px !important;
    right: 15px !important;
    width: 50px !important;
    height: 50px !important;
    font-size: 22px !important;
}

/* ============================================
   SCROLLBAR PERSONALIZADA (para móvil)
   ============================================ */
.tutor-messages::-webkit-scrollbar {
    width: 4px;
}

.tutor-messages::-webkit-scrollbar-track {
    background: transparent;
}

.tutor-messages::-webkit-scrollbar-thumb {
    background: #6C63FF;
    border-radius: 4px;
}

.tutor-messages::-webkit-scrollbar-thumb:hover {
    background: #8B83FF;
}

/* ============================================
   ANIMACIONES DE MENSAJES
   ============================================ */
@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tutor-msg {
    animation: msgIn 0.25s ease forwards;
}

/* ============================================
   INDICADOR DE ESCRITURA
   ============================================ */
.tutor-writing {
    background: #2A2A4A;
    color: #FFFFFF;
    align-self: flex-start;
    padding: 12px 18px;
    display: flex;
    gap: 5px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    border-left: 3px solid #6C63FF;
}

.tutor-writing span {
    width: 8px;
    height: 8px;
    background: #6C63FF;
    border-radius: 50%;
    display: inline-block;
    animation: writingDot 1.2s infinite;
}

.tutor-writing span:nth-child(1) { animation-delay: 0s; }
.tutor-writing span:nth-child(2) { animation-delay: 0.2s; }
.tutor-writing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes writingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}


/* ============================================
   TUTOR OFFLINE
   ============================================ */
:root {
    --tutor-primary: #6C63FF;
    --tutor-secondary: #4A3FBF;
    --tutor-bg: #1A1A2E;
    --tutor-card: #16213E;
    --tutor-text: #FFFFFF;
    --tutor-input: #2A2A4A;
    --tutor-bot: #6C63FF;
    --tutor-user: #00D4FF;
    --tutor-radius: 16px;
}

/* Botón flotante */
.tutor-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #6C63FF, #4A3FBF);
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(108, 99, 255, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tutor-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(108, 99, 255, 0.6);
}

.tutor-btn .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #FF6B6B;
    color: white;
    font-size: 10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Panel del tutor */
.tutor-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    max-width: 90vw;
    max-height: 500px;
    background: var(--tutor-bg);
    border-radius: var(--tutor-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    z-index: 999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(108, 99, 255, 0.3);
    animation: slideUpTutor 0.3s ease;
}

.tutor-panel.open {
    display: flex;
}

@keyframes slideUpTutor {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.tutor-header {
    background: linear-gradient(135deg, #6C63FF, #4A3FBF);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 15px;
}

.tutor-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tutor-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Mensajes */
.tutor-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 350px;
    min-height: 200px;
}

.tutor-messages::-webkit-scrollbar {
    width: 4px;
}
.tutor-messages::-webkit-scrollbar-track {
    background: transparent;
}
.tutor-messages::-webkit-scrollbar-thumb {
    background: var(--tutor-primary);
    border-radius: 4px;
}

.tutor-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tutor-bot {
    background: var(--tutor-card);
    color: var(--tutor-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--tutor-bot);
}

.tutor-user {
    background: var(--tutor-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Input */
.tutor-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    background: var(--tutor-card);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.tutor-input-area input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    background: var(--tutor-input);
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.tutor-input-area input:focus {
    border-color: var(--tutor-primary);
    box-shadow: 0 0 20px rgba(108, 99, 255, 0.2);
}

.tutor-input-area input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.tutor-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--tutor-primary);
    color: white;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tutor-send:hover {
    background: var(--tutor-secondary);
    transform: scale(1.05);
}

/* Status */
.tutor-status {
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00D4FF;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Responsive */
@media (max-width: 480px) {
    .tutor-panel {
        bottom: 80px;
        right: 10px;
        width: calc(100% - 20px);
        max-height: 450px;
    }

    .tutor-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 22px;
    }
}


/* ============================================
   ESTILOS PARA SVG EN EL CHAT
   ============================================ */
.tutor-messages svg {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    margin: 12px 0;
    border: 1px solid rgba(108, 99, 255, 0.08);
}

.tutor-messages svg text {
    font-family: 'Quicksand', -apple-system, sans-serif;
}

/* Contenedor de gráficos Chart.js */
.tutor-messages .chart-container {
    max-width: 100%;
    margin: 12px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(108, 99, 255, 0.08);
}

.tutor-messages .chart-container canvas {
    max-width: 100% !important;
    height: auto !important;
}

/* Estilos para fórmulas matemáticas en el chat */
.tutor-msg sup {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 1;
}

.tutor-msg sub {
    font-size: 0.75em;
    vertical-align: sub;
    line-height: 1;
}

.tutor-msg .math {
    font-family: 'Times New Roman', 'Cambria', 'Computer Modern', serif;
    font-size: 1.1em;
    background: #f8f9fa;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}
