/* ============================================================
   AI TUTOR SYSTEM - Estilos del Tutor IA
   Sistema de Aprendizaje Profundo
   ============================================================ */

/* ---- Botones del Tutor en cada pregunta ---- */
.tutor-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.tutor-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: inherit;
}

.tutor-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tutor-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.tutor-btn-error {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.tutor-btn-chat {
    background: linear-gradient(135deg, #11998e, #38ef7d);
    color: white;
}

.tutor-btn-socratic {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    color: white;
}

.tutor-btn-save-review {
    background: linear-gradient(135deg, #fc5c7d, #6a82fb);
    color: white;
}

/* ---- Loading spinner ---- */
.tutor-btn .tutor-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: tutorSpin 0.8s linear infinite;
}

.tutor-btn.loading .tutor-spinner {
    display: inline-block;
}

.tutor-btn.loading .tutor-btn-text {
    opacity: 0.7;
}

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

/* ---- Panel de respuesta del Tutor ---- */
.tutor-response-panel {
    margin-top: 12px;
    padding: 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f8f9ff, #eef1ff);
    border: 1px solid #d4d9f7;
    animation: tutorFadeIn 0.4s ease;
    position: relative;
}

.tutor-response-panel .tutor-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #666;
    padding: 4px;
    line-height: 1;
}

.tutor-response-panel .tutor-close:hover {
    color: #333;
}

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

/* ---- Diagnóstico de error ---- */
.tutor-error-diagnosis {
    display: grid;
    gap: 12px;
}

.diagnosis-section {
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid;
}

.diagnosis-section h4 {
    margin: 0 0 6px;
    font-size: 0.95rem;
}

.diagnosis-section p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #333;
}

.diagnosis-error {
    background: #fef3f2;
    border-color: #ef4444;
}

.diagnosis-contrast {
    background: #eff6ff;
    border-color: #3b82f6;
}

.diagnosis-anchor {
    background: #f0fdf4;
    border-color: #22c55e;
}

.diagnosis-verify {
    background: #fefce8;
    border-color: #eab308;
}

/* ---- Chat del Tutor ---- */
.tutor-chat-container {
    margin-top: 12px;
    border-radius: 12px;
    border: 1px solid #d4d9f7;
    overflow: hidden;
    background: white;
    animation: tutorFadeIn 0.4s ease;
    max-width: 600px;
    display: flex;
    flex-direction: column;
}

.tutor-chat-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tutor-chat-header h4 {
    margin: 0;
    font-size: 0.95rem;
}

.tutor-chat-header .turns-badge {
    background: rgba(255,255,255,0.2);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
}

.tutor-chat-header .tutor-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    line-height: 1;
    margin-left: 8px;
}

.tutor-chat-header .tutor-close:hover {
    background: rgba(255,255,255,0.35);
}

.tutor-chat-messages {
    max-height: 300px;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tutor-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: tutorMsgIn 0.3s ease;
}

@keyframes tutorMsgIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.tutor-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-bottom-right-radius: 4px;
}

.tutor-msg-tutor {
    align-self: flex-start;
    background: #f3f4f6;
    color: #333;
    border-bottom-left-radius: 4px;
}

.tutor-msg-tutor p { margin: 4px 0; }
.tutor-msg-tutor h4, .tutor-msg-tutor h5 { margin: 6px 0 4px; font-size: 0.9rem; }

.tutor-chat-input {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
    flex-shrink: 0;
    align-items: center;
}

.tutor-chat-input input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    height: 40px;
}

.tutor-chat-input input:focus {
    border-color: #667eea;
}

.tutor-chat-input button {
    padding: 10px 18px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    transition: transform 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    height: 40px;
}

.tutor-chat-input button:hover {
    transform: scale(1.03);
}

.tutor-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Mensaje de límite de usos ---- */
.tutor-limit-msg {
    font-size: 0.85rem;
    color: #9ca3af;
    font-style: italic;
    padding: 4px 0;
}

.tutor-typing {
    display: flex;
    gap: 4px;
    padding: 8px 14px;
    align-self: flex-start;
}

.tutor-typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: tutorTyping 1.2s infinite;
}

.tutor-typing span:nth-child(2) { animation-delay: 0.2s; }
.tutor-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes tutorTyping {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

.tutor-limit {
    text-align: center;
    color: #6b7280;
    font-style: italic;
    padding: 8px;
}

/* ---- Método Socrático ---- */
.tutor-socratic-panel {
    margin-top: 12px;
    border-radius: 12px;
    border: 1px solid #f0d4f7;
    overflow: hidden;
    background: white;
    animation: tutorFadeIn 0.4s ease;
}

.socratic-input-area {
    padding: 16px;
    background: linear-gradient(135deg, #fdf2f8, #fce7f3);
}

.socratic-input-area h4 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    color: #831843;
}

.socratic-input-area p {
    margin: 0 0 10px;
    font-size: 0.85rem;
    color: #9d174d;
}

.socratic-input-area textarea {
    width: 100%;
    min-height: 60px;
    padding: 10px 14px;
    border: 1px solid #f9a8d4;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.socratic-input-area textarea:focus {
    border-color: #ec4899;
}

.socratic-submit-btn {
    margin-top: 8px;
    padding: 8px 20px;
    background: linear-gradient(135deg, #f093fb, #f5576c);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}

.tutor-socratic-eval {
    padding: 16px;
}

.socratic-verdict {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.socratic-correct-reasoning {
    background: #f0fdf4;
    border-left: 4px solid #22c55e;
}

.socratic-flawed-reasoning {
    background: #fef3f2;
    border-left: 4px solid #ef4444;
}

.socratic-insight {
    padding: 10px 16px;
    background: #eff6ff;
    border-radius: 8px;
    border-left: 4px solid #3b82f6;
    margin-bottom: 10px;
}

.socratic-growth {
    padding: 10px 16px;
    background: #fefce8;
    border-radius: 8px;
    border-left: 4px solid #eab308;
}

.socratic-verdict h4,
.socratic-insight h4,
.socratic-growth h4 {
    margin: 0 0 6px;
    font-size: 0.9rem;
}

.socratic-verdict p,
.socratic-insight p,
.socratic-growth p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.5;
}

/* ---- Revisión Post-Simulacro ---- */
.tutor-review-session {
    padding: 4px 0;
}

.tutor-review-session h3 {
    margin: 16px 0 8px;
    font-size: 1.05rem;
    color: #1e293b;
}

.review-overview {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    padding: 16px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.review-overview h3 { margin-top: 0; }
.review-overview p { margin: 0; line-height: 1.6; }

.error-group {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
}

.error-group h4 {
    margin: 0 0 4px;
    font-size: 0.95rem;
    color: #1e293b;
}

.error-group .error-count {
    font-size: 0.8rem;
    color: #ef4444;
    margin-bottom: 8px;
}

.micro-lesson {
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 8px;
    border-left: 3px solid #667eea;
}

.micro-lesson h5 {
    margin: 0 0 4px;
    font-size: 0.85rem;
}

.micro-lesson p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.5;
}

.competency-map {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.competency-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
}

.competency-item[data-level="alto"] {
    background: #f0fdf4;
    border-left: 3px solid #22c55e;
}

.competency-item[data-level="medio"] {
    background: #fefce8;
    border-left: 3px solid #eab308;
}

.competency-item[data-level="bajo"] {
    background: #fef3f2;
    border-left: 3px solid #ef4444;
}

.review-action-plan ol {
    padding-left: 20px;
    margin: 8px 0 0;
}

.review-action-plan li {
    margin-bottom: 6px;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* ---- Banner de Repaso Espaciado ---- */
.spaced-review-banner {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 14px 20px;
    border-radius: 12px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: tutorFadeIn 0.5s ease;
    cursor: pointer;
    transition: transform 0.2s;
}

.spaced-review-banner:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.spaced-review-banner .review-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.spaced-review-banner .review-icon {
    font-size: 1.5rem;
}

.spaced-review-banner .review-text h4 {
    margin: 0;
    font-size: 0.95rem;
}

.spaced-review-banner .review-text p {
    margin: 2px 0 0;
    font-size: 0.8rem;
    opacity: 0.85;
}

.spaced-review-banner .review-count {
    background: rgba(255,255,255,0.2);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.1rem;
}

/* ---- Ajuste de dificultad mid-session ---- */
.difficulty-adjust-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 14px 20px;
    border-radius: 12px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 10000;
    animation: toastSlide 0.5s ease, toastFade 0.5s ease 4s forwards;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    max-width: 320px;
}

.difficulty-toast-up {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.difficulty-toast-down {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

@keyframes toastSlide {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastFade {
    to { opacity: 0; transform: translateY(20px); }
}

/* ---- Modo Socrático Toggle ---- */
.socratic-mode-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #fdf2f8, #fce7f3);
    border-radius: 8px;
    font-size: 0.85rem;
    color: #831843;
}

.socratic-mode-toggle small {
    opacity: 0.7;
    margin-left: 48px;
}

.socratic-toggle-label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.socratic-mode-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.socratic-slider {
    position: relative;
    display: inline-block;
    width: 38px;
    min-width: 38px;
    height: 20px;
    background: #d1d5db;
    border-radius: 10px;
    transition: background 0.3s;
}

.socratic-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: left 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="checkbox"]:checked + .socratic-slider {
    background: linear-gradient(135deg, #f093fb, #f5576c);
}

input[type="checkbox"]:checked + .socratic-slider::before {
    left: 18px;
}

.socratic-text {
    font-weight: 600;
}

/* ---- Revisión modal ---- */
.tutor-review-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: tutorFadeIn 0.3s ease;
}

.tutor-review-modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.tutor-review-modal-content .modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .tutor-actions {
        flex-direction: column;
    }
    
    .tutor-btn {
        width: 100%;
        justify-content: center;
    }
    
    .tutor-chat-messages {
        max-height: 200px;
    }
    
    .tutor-msg {
        max-width: 95%;
    }
    
    .spaced-review-banner {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .difficulty-adjust-toast {
        left: 10px;
        right: 10px;
        bottom: 10px;
        max-width: none;
    }
}

/* ---- Dark mode support ---- */
@media (prefers-color-scheme: dark) {
    .tutor-response-panel {
        background: linear-gradient(135deg, #1e1e2e, #252540);
        border-color: #383860;
    }
    
    .diagnosis-section p,
    .tutor-msg-tutor,
    .socratic-verdict p,
    .socratic-insight p,
    .socratic-growth p {
        color: #e0e0e0;
    }
    
    .diagnosis-error { background: #2d1b1b; }
    .diagnosis-contrast { background: #1b2335; }
    .diagnosis-anchor { background: #1b2d1b; }
    .diagnosis-verify { background: #2d2b1b; }
    
    .tutor-chat-container {
        background: #1e1e2e;
        border-color: #383860;
    }
    
    .tutor-msg-tutor {
        background: #2a2a40;
    }
    
    .tutor-chat-input {
        background: #252540;
        border-color: #383860;
    }
    
    .tutor-chat-input input {
        background: #1e1e2e;
        border-color: #383860;
        color: #e0e0e0;
    }
}

/* ---- Tema claro override (para la clase .tema-claro) ---- */
body.tema-claro .tutor-response-panel {
    background: linear-gradient(135deg, #f8f9ff, #eef1ff);
    border-color: #d4d9f7;
}
