:root {
    --fondo: #fff3de;
    --fondo-suave: #fff9ef;
    --panel: #ffffff;
    --sidebar: #ffe6b8;

    --principal: #ffd076;
    --principal-hover: #f4bd52;

    --borde: #efd29b;
    --texto: #2d2d2d;
    --texto-suave: #777067;

    --sombra: 0 12px 30px rgba(121, 78, 24, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    overflow: hidden;
    font-family: "Segoe UI", Arial, sans-serif;
    color: var(--texto);
    background: var(--fondo);
}

button,
input,
select {
    font: inherit;
}

/* ==============================
   Pantalla de bienvenida
============================== */

.welcome-screen {
    position: fixed;
    inset: 0;
    z-index: 100;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background:
        radial-gradient(
            circle at top left,
            rgba(255, 208, 118, 0.5),
            transparent 38%
        ),
        linear-gradient(135deg, #fff8eb, #ffe7ba);
}

.welcome-card {
    width: min(440px, 100%);

    display: flex;
    flex-direction: column;
    gap: 12px;

    padding: 34px;

    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 28px;
    box-shadow: var(--sombra);
}

.welcome-logo {
    width: 120px;
    margin: 0 auto 4px;
}

.welcome-card h1 {
    text-align: center;
    font-size: 29px;
}

.welcome-card p {
    margin-bottom: 6px;
    text-align: center;
    color: var(--texto-suave);
    line-height: 1.5;
}

.welcome-card label {
    margin-top: 4px;
    font-size: 14px;
    font-weight: 700;
}

.welcome-card input,
.welcome-card select {
    width: 100%;
    padding: 14px 15px;

    color: var(--texto);
    background: var(--fondo-suave);

    border: 1px solid var(--borde);
    border-radius: 14px;
    outline: none;
}

.welcome-card input:focus,
.welcome-card select:focus {
    border-color: var(--principal-hover);
    box-shadow: 0 0 0 3px rgba(255, 208, 118, 0.28);
}

.welcome-card button {
    margin-top: 10px;
    padding: 15px;

    color: var(--texto);
    background: var(--principal);

    border: none;
    border-radius: 15px;

    font-weight: 800;
    cursor: pointer;
}

.welcome-card button:hover {
    background: var(--principal-hover);
}

/* ==============================
   Aplicación
============================== */

.app {
    width: 100%;
    height: 100vh;

    display: flex;
    flex-direction: column;
}

/* Cabecera */

.app-header {
    height: 74px;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 28px;

    background: var(--panel);
    border-bottom: 1px solid var(--borde);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand img {
    width: 54px;
    height: 46px;
    object-fit: contain;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 21px;
}

.brand small {
    margin-top: 2px;
    color: var(--texto-suave);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
}

/* Distribución principal */

.app-layout {
    flex: 1;
    min-height: 0;

    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);

    background-color: #ffffff;
    background-image: url("../img/chat-background.png");
    background-position: center;
    background-size: cover;
}

/* Barra lateral */

.sidebar {
    min-height: 0;
    padding: 24px;

    overflow-y: auto;

    background: var(--sidebar);
    border-right: 1px solid var(--borde);
}

.sidebar h2 {
    margin-bottom: 16px;
    color: #795b2c;
    font-size: 16px;
}

.new-class-btn {
    width: 100%;
    padding: 14px;

    color: #765000;
    background: var(--panel);

    border: none;
    border-radius: 15px;

    font-weight: 800;
    cursor: pointer;

    transition: transform 0.2s, box-shadow 0.2s;
}

.new-class-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--sombra);
}

.class-list {
    margin-top: 18px;
}

/* Zona principal */

.classroom {
    min-width: 0;
    min-height: 0;

    display: flex;
    flex-direction: column;

    background: var(--fondo);
}

/* Profesor */

.teacher-header {
    flex-shrink: 0;

    display: flex;
    align-items: center;
    gap: 17px;

    margin: 24px 36px 16px;
    padding: 18px 22px;

    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 22px;
    box-shadow: var(--sombra);
}

.teacher-header img {
    width: 68px;
    height: 58px;
    object-fit: contain;
}

.teacher-header h1 {
    font-size: 26px;
}

.teacher-header p {
    margin-top: 3px;
    color: var(--texto-suave);
}

/* ==============================
   Conversación
============================== */

.messages {
    flex: 1;
    min-height: 0;

    margin: 0 36px;
    padding: 22px;

    overflow-y: auto;
    overflow-x: hidden;

    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 24px;

    scroll-behavior: smooth;
}

/* Estilo compartido de mensajes */

.user,
.ia {
    width: fit-content;
    max-width: 78%;

    margin-bottom: 18px;
    padding: 15px 18px;

    border-radius: 18px;

    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Mensaje del usuario */

.user {
    max-width: min(520px, 75%);
    margin-left: auto;

    color: var(--texto);
    background: var(--principal);

    font-weight: 600;
}

/* Respuesta de la IA */

.ia {
    width: min(820px, 82%);

    margin-right: auto;

    /* La respuesta crece con su contenido.
       El único scroll queda en la conversación completa (.messages). */
    overflow: visible;

    color: var(--texto);
    background: var(--fondo-suave);

    border: 1px solid var(--borde);
}

/* ==============================
   Campo de escritura
============================== */

.composer {
    flex-shrink: 0;

    display: flex;
    gap: 12px;

    margin: 16px 36px 24px;
    padding: 11px;

    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 22px;
    box-shadow: var(--sombra);
}

.composer input {
    flex: 1;
    min-width: 0;

    padding: 13px;

    color: var(--texto);
    background: transparent;

    border: none;
    outline: none;

    font-size: 16px;
}

.composer input::placeholder {
    color: #9a9186;
}

.composer button {
    width: 50px;
    height: 50px;
    flex-shrink: 0;

    color: var(--texto);
    background: var(--principal);

    border: none;
    border-radius: 16px;

    font-size: 20px;
    font-weight: 900;

    cursor: pointer;
}

.composer button:hover {
    background: var(--principal-hover);
}

.composer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==============================
   Diseño adaptable
============================== */

@media (max-width: 800px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .app-header {
        padding: 0 18px;
    }

    .brand small {
        display: none;
    }

    .teacher-header {
        margin: 16px 18px 12px;
        padding: 14px 17px;
    }

    .teacher-header img {
        width: 55px;
        height: 48px;
    }

    .teacher-header h1 {
        font-size: 21px;
    }

    .messages {
        margin: 0 18px;
        padding: 16px;
    }

    .composer {
        margin: 13px 18px 17px;
    }

    .user,
    .ia {
        max-width: 92%;
    }

    .ia {
        width: 92%;
    }
}

@media (max-width: 480px) {
    .welcome-card {
        padding: 25px 20px;
    }

    .welcome-card h1 {
        font-size: 24px;
    }

    .user-area {
        font-size: 14px;
    }

    .teacher-header p {
        font-size: 14px;
    }

}
/* ==============================
   Sistema de comprensión y evaluación
============================== */

.message-author,
.message-content {
    display: block;
}

.message-author {
    margin-bottom: 5px;
    font-size: 13px;
}

.message-content {
    white-space: pre-wrap;
}

.learning-card {
    width: min(760px, 92%);
    margin: 0 auto 18px;
    padding: 20px;
    color: var(--texto);
    background: #fffdf7;
    border: 1px solid var(--borde);
    border-radius: 20px;
    box-shadow: 0 8px 22px rgba(121, 78, 24, 0.1);
}

.learning-card h2 {
    margin-bottom: 8px;
    font-size: 20px;
}

.learning-card > p {
    color: var(--texto-suave);
    line-height: 1.55;
}

.learning-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.learning-btn,
.quiz-option {
    min-height: 44px;
    padding: 11px 15px;
    border: 1px solid transparent;
    border-radius: 13px;
    font-weight: 750;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s, background 0.18s;
}

.learning-btn:hover:not(:disabled),
.quiz-option:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 7px 16px rgba(121, 78, 24, 0.12);
}

.learning-btn:disabled,
.quiz-option:disabled {
    cursor: not-allowed;
    opacity: 0.72;
}

.understood-btn {
    color: #176b39;
    background: #e3f7e9;
    border-color: #a7dfb8;
}

.partial-btn {
    color: #805b00;
    background: #fff4cf;
    border-color: #f0d981;
}

.not-understood-btn {
    color: #8a2d2d;
    background: #ffe6e6;
    border-color: #efb6b6;
}

.written-btn,
.multiple-btn,
.submit-answer-btn,
.next-question-btn,
.review-btn {
    color: #604000;
    background: var(--principal);
    border-color: #e9b750;
}

.secondary-btn,
.hint-btn {
    color: var(--texto);
    background: #f4f1eb;
    border-color: #dcd4c8;
}

.quiz-progress {
    height: 8px;
    margin: 14px 0 18px;
    overflow: hidden;
    background: #eee7dc;
    border-radius: 999px;
}

.quiz-progress span {
    display: block;
    height: 100%;
    background: var(--principal-hover);
    border-radius: inherit;
    transition: width 0.25s;
}

.quiz-options {
    display: grid;
    gap: 11px;
    margin-top: 18px;
}

.quiz-option {
    width: 100%;
    color: var(--texto);
    text-align: left;
    background: var(--panel);
    border-color: var(--borde);
}

.quiz-option.correct-option {
    color: #176b39;
    background: #def5e5;
    border-color: #80c997;
}

.quiz-option.wrong-option {
    color: #8a2d2d;
    background: #ffe3e3;
    border-color: #e8a1a1;
}

.written-answer-box {
    margin-top: 18px;
}

.written-answer-box textarea {
    width: 100%;
    min-height: 112px;
    resize: vertical;
    padding: 14px;
    color: var(--texto);
    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 14px;
    outline: none;
    font: inherit;
    line-height: 1.5;
}

.written-answer-box textarea:focus {
    border-color: var(--principal-hover);
    box-shadow: 0 0 0 3px rgba(255, 208, 118, 0.25);
}

.written-answer-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
}

.quiz-feedback {
    margin-top: 18px;
    padding: 15px;
    border-radius: 14px;
}

.quiz-feedback strong,
.quiz-feedback p {
    display: block;
}

.quiz-feedback p {
    margin: 6px 0 13px;
    line-height: 1.5;
}

.feedback-correct {
    color: #176b39;
    background: #e5f7ea;
    border: 1px solid #a9ddb7;
}

.feedback-wrong {
    color: #7d3030;
    background: #fff0e7;
    border: 1px solid #efc0a4;
}

.result-card {
    text-align: center;
}

.result-percentage {
    display: block;
    margin: 12px 0 5px;
    font-size: 38px;
    color: #7a5000;
}

.result-actions {
    justify-content: center;
}

.inline-alert {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
}

.inline-error,
.error-card {
    color: #8a2d2d;
    background: #ffe8e8;
    border-color: #eab0b0;
}

/* Oculta la explicación mientras el estudiante responde. */
.ia.contenido-censurado {
    position: relative;
    min-height: 150px;
    overflow: hidden;
    color: transparent;
    text-shadow: 0 0 10px rgba(45, 45, 45, 0.72);
    user-select: none;
    pointer-events: none;
}

.ia.contenido-censurado .message-author,
.ia.contenido-censurado .message-content {
    color: transparent;
}

.ia.contenido-censurado::after {
    content: "🔒 Explicación oculta durante la evaluación";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    color: #664713;
    background: rgba(255, 249, 239, 0.9);
    text-align: center;
    text-shadow: none;
    font-weight: 800;
    backdrop-filter: blur(5px);
}

@media (max-width: 600px) {
    .learning-card {
        width: 100%;
        padding: 16px;
    }

    .learning-actions,
    .written-answer-actions {
        flex-direction: column;
    }

    .learning-btn {
        width: 100%;
    }
}

/* Fórmulas generadas por MathJax */

.ia mjx-container,
.learning-card mjx-container {
    max-width: 100%;
    color: var(--texto);
}

.ia mjx-container[display="true"],
.learning-card mjx-container[display="true"] {
    display: block;
    max-width: 100%;
    margin: 14px 0 !important;
    padding: 10px 4px;

    overflow-x: auto;
    overflow-y: hidden;
}

.ia mjx-container[display="true"]::-webkit-scrollbar,
.learning-card mjx-container[display="true"]::-webkit-scrollbar {
    height: 7px;
}

.ia mjx-container[display="true"]::-webkit-scrollbar-thumb,
.learning-card mjx-container[display="true"]::-webkit-scrollbar-thumb {
    background: var(--principal);
    border-radius: 999px;
}

/* ==============================
   Registro e inicio de sesión
============================== */

[hidden] {
    display: none !important;
}

.auth-screen {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    background:
        radial-gradient(circle at top left, rgba(255, 208, 118, 0.5), transparent 38%),
        linear-gradient(135deg, #fff8eb, #ffe7ba);
}

.auth-card {
    width: min(440px, 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 30px 34px;
    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 28px;
    box-shadow: var(--sombra);
}

.auth-logo {
    width: 110px;
    margin: 0 auto;
}

.auth-card h1,
.auth-card > p {
    text-align: center;
}

.auth-card > p {
    color: var(--texto-suave);
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 5px;
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 15px;
}

.auth-tab {
    padding: 11px;
    color: var(--texto-suave);
    background: transparent;
    border: none;
    border-radius: 11px;
    font-weight: 750;
    cursor: pointer;
}

.auth-tab.active {
    color: var(--texto);
    background: var(--panel);
    box-shadow: 0 4px 12px rgba(121, 78, 24, 0.1);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-form label {
    margin-top: 3px;
    font-size: 14px;
    font-weight: 700;
}

.auth-form input {
    width: 100%;
    padding: 13px 15px;
    color: var(--texto);
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 14px;
    outline: none;
}

.auth-form input:focus {
    border-color: var(--principal-hover);
    box-shadow: 0 0 0 3px rgba(255, 208, 118, 0.28);
}

.auth-form button[type="submit"] {
    margin-top: 8px;
    padding: 14px;
    color: var(--texto);
    background: var(--principal);
    border: none;
    border-radius: 14px;
    font-weight: 800;
    cursor: pointer;
}

.auth-form button[type="submit"]:hover:not(:disabled) {
    background: var(--principal-hover);
}

.auth-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-message {
    min-height: 22px;
    margin-top: 2px;
    text-align: center;
    font-size: 14px;
}

.auth-message-error {
    color: #9b2e2e !important;
}

.logout-btn {
    margin-left: 8px;
    padding: 8px 11px;
    color: #765000;
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 11px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.logout-btn:hover:not(:disabled) {
    background: var(--principal);
}

@media (max-width: 480px) {
    .auth-card {
        padding: 24px 20px;
    }

    .logout-btn {
        padding: 7px 9px;
        font-size: 12px;
    }
}

/* ==============================
   Historial de clases en D1
============================== */

.class-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.class-empty {
    padding: 14px 10px;
    color: var(--texto-suave);
    font-size: 13px;
    line-height: 1.45;
    text-align: center;
}

.class-error {
    color: #a63b32;
}

.class-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid transparent;
    border-radius: 15px;
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.class-item:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.9);
}

.class-item.active {
    background: var(--panel);
    border-color: var(--principal-hover);
    box-shadow: 0 6px 18px rgba(121, 78, 24, 0.1);
}

.class-open-btn {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 8px;
    color: var(--texto);
    background: transparent;
    border: none;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
}

.class-open-btn:disabled,
.class-action-btn:disabled,
.new-class-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.class-title {
    width: 100%;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.class-meta {
    color: var(--texto-suave);
    font-size: 11px;
}

.class-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.class-action-btn {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    color: #75582f;
    background: transparent;
    border: none;
    border-radius: 9px;
    font-size: 17px;
    cursor: pointer;
}

.class-action-btn:hover {
    background: var(--fondo-suave);
}

.class-delete-btn:hover {
    color: #a62f2f;
    background: #fff0ed;
}

/* ==============================
   Imágenes adjuntas y visión
============================== */

.composer {
    flex-wrap: wrap;
}

.image-preview-box {
    flex: 0 0 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 16px;
}

.image-preview-box[hidden],
.image-error[hidden] {
    display: none;
}

.image-preview {
    width: 76px;
    height: 64px;
    display: block;
    object-fit: cover;
    background: #ffffff;
    border: 1px solid var(--borde);
    border-radius: 12px;
}

.image-preview-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.image-preview-info strong {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-info span {
    color: var(--texto-suave);
    font-size: 12px;
    line-height: 1.35;
}

.composer .remove-image-btn {
    width: 34px;
    height: 34px;
    color: #8f3333;
    background: #fff1ee;
    border: 1px solid #efc7c0;
    border-radius: 10px;
    font-size: 22px;
    line-height: 1;
}

.composer .remove-image-btn:hover:not(:disabled) {
    color: #742323;
    background: #ffe3de;
}

.image-error {
    flex: 0 0 100%;
    margin: 0;
    padding: 9px 12px;
    color: #8f2f2f;
    background: #fff0ed;
    border: 1px solid #efc7c0;
    border-radius: 12px;
    font-size: 13px;
}

.composer .attach-image-btn {
    color: #6f532a;
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    font-size: 21px;
}

.composer .attach-image-btn:hover:not(:disabled) {
    background: var(--principal);
}

.message-image {
    width: auto;
    max-width: min(100%, 430px);
    max-height: 360px;
    display: block;
    margin: 3px 0 10px;
    object-fit: contain;
    background: #ffffff;
    border: 1px solid rgba(91, 66, 31, 0.16);
    border-radius: 13px;
}

.user .message-image {
    margin-left: auto;
}

@media (max-width: 600px) {
    .image-preview-box {
        grid-template-columns: 62px minmax(0, 1fr) auto;
        gap: 9px;
    }

    .image-preview {
        width: 62px;
        height: 56px;
    }

    .image-preview-info span {
        font-size: 11px;
    }

    .composer .attach-image-btn,
    .composer .send-message-btn {
        width: 46px;
        height: 46px;
    }
}

/* ==============================
   Narrador de respuestas
============================== */

.narration-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(111, 83, 42, 0.16);
    white-space: normal;
}

.narration-btn {
    min-height: 34px;
    padding: 7px 11px;
    color: #68491d;
    background: #ffffff;
    border: 1px solid var(--borde);
    border-radius: 999px;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
}

.narration-btn:hover:not(:disabled) {
    background: var(--principal);
    border-color: var(--principal-hover);
    transform: translateY(-1px);
}

.narration-btn:focus-visible {
    outline: 3px solid rgba(244, 189, 82, 0.38);
    outline-offset: 2px;
}

.narration-btn-active {
    color: #5a3b0d;
    background: var(--principal);
    border-color: var(--principal-hover);
}

.narration-pause-btn[hidden] {
    display: none;
}

.ia.contenido-censurado .narration-controls {
    display: none;
}

@media (max-width: 600px) {
    .narration-btn {
        min-height: 32px;
        padding: 7px 10px;
        font-size: 11px;
    }
}

/* ==============================
   Generador de presentaciones
============================== */

.teacher-header {
    justify-content: space-between;
}

.presentation-open-btn {
    flex-shrink: 0;
    padding: 11px 16px;
    color: #68460e;
    background: var(--principal);
    border: 1px solid var(--principal-hover);
    border-radius: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.presentation-open-btn:hover {
    transform: translateY(-1px);
    background: var(--principal-hover);
    box-shadow: 0 7px 17px rgba(121, 78, 24, 0.14);
}

.presentation-open-btn:focus-visible,
.presentation-dialog button:focus-visible,
.presentation-dialog input:focus-visible,
.presentation-dialog select:focus-visible,
.presentation-dialog textarea:focus-visible {
    outline: 3px solid rgba(244, 189, 82, 0.38);
    outline-offset: 2px;
}

body.modal-open {
    overflow: hidden;
}

.presentation-modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: grid;
    place-items: center;
    padding: 22px;
    overflow-y: auto;
    background: rgba(44, 34, 20, 0.54);
    backdrop-filter: blur(5px);
}

.presentation-dialog {
    position: relative;
    width: min(620px, 100%);
    max-height: calc(100vh - 44px);
    overflow-y: auto;
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--borde);
    border-radius: 25px;
    box-shadow: 0 24px 70px rgba(61, 39, 10, 0.25);
}

.presentation-close-btn {
    position: absolute;
    top: 15px;
    right: 16px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    color: #74572e;
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 11px;
    font-size: 23px;
    line-height: 1;
    cursor: pointer;
}

.presentation-dialog-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-right: 42px;
    margin-bottom: 23px;
}

.presentation-icon {
    width: 58px;
    height: 58px;
    flex-shrink: 0;
    object-fit: contain;
    padding: 4px;
    background: #fff7e8;
    border-radius: 16px;
    box-shadow: 0 8px 18px rgba(167, 61, 43, 0.18);
}

.presentation-dialog-header h2 {
    font-size: 23px;
}

.presentation-dialog-header p {
    margin-top: 4px;
    color: var(--texto-suave);
    line-height: 1.45;
}

.presentation-form {
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.presentation-form label {
    margin-top: 2px;
    font-size: 14px;
    font-weight: 750;
}

.presentation-form input[type="text"],
.presentation-form select,
.presentation-form textarea {
    width: 100%;
    padding: 12px 14px;
    color: var(--texto);
    background: var(--fondo-suave);
    border: 1px solid var(--borde);
    border-radius: 13px;
    outline: none;
}

.presentation-form textarea {
    min-height: 88px;
    resize: vertical;
    line-height: 1.45;
}

.presentation-form input:focus,
.presentation-form select:focus,
.presentation-form textarea:focus {
    border-color: var(--principal-hover);
    box-shadow: 0 0 0 3px rgba(255, 208, 118, 0.24);
}

.presentation-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.presentation-form-grid > div {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.presentation-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    padding: 12px 13px;
    color: #62491f;
    background: #fff8e8;
    border: 1px solid var(--borde);
    border-radius: 13px;
    cursor: pointer;
}

.presentation-checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--principal-hover);
}

.presentation-checkbox:has(input:disabled) {
    opacity: 0.55;
    cursor: not-allowed;
}

.presentation-note {
    color: var(--texto-suave);
    font-size: 12px;
    line-height: 1.45;
}

.presentation-status {
    padding: 11px 13px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.45;
}

.presentation-status-loading {
    color: #71500d;
    background: #fff4d3;
    border: 1px solid #ecd184;
}

.presentation-status-success {
    color: #21653b;
    background: #e7f7ec;
    border: 1px solid #acd9ba;
}

.presentation-status-error {
    color: #8e2f2f;
    background: #fff0ed;
    border: 1px solid #efbdb5;
}

.presentation-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 7px;
}

.presentation-actions button {
    min-height: 44px;
    padding: 11px 16px;
    border-radius: 13px;
    font-weight: 800;
    cursor: pointer;
}

.presentation-actions button:disabled,
.presentation-close-btn:disabled {
    opacity: 0.58;
    cursor: wait;
}

.presentation-secondary-btn {
    color: var(--texto);
    background: #f4f1eb;
    border: 1px solid #dcd4c8;
}

.presentation-primary-btn {
    color: #614000;
    background: var(--principal);
    border: 1px solid var(--principal-hover);
}

.presentation-primary-btn:hover:not(:disabled) {
    background: var(--principal-hover);
}

@media (max-width: 800px) {
    .teacher-header {
        align-items: flex-start;
    }

    .presentation-open-btn {
        padding: 9px 12px;
        font-size: 13px;
    }
}

@media (max-width: 520px) {
    .presentation-modal {
        align-items: end;
        padding: 0;
    }

    .presentation-dialog {
        width: 100%;
        max-height: 92vh;
        padding: 24px 18px;
        border-radius: 24px 24px 0 0;
    }

    .presentation-dialog-header {
        align-items: flex-start;
    }

    .presentation-dialog-header h2 {
        font-size: 20px;
    }

    .presentation-icon {
        width: 46px;
        height: 46px;
    }

    .presentation-form-grid {
        grid-template-columns: 1fr;
    }

    .presentation-actions {
        flex-direction: column-reverse;
    }

    .presentation-actions button {
        width: 100%;
    }

    .teacher-header {
        gap: 10px;
    }

    .presentation-open-btn {
        max-width: 115px;
        padding: 8px 10px;
        font-size: 12px;
        line-height: 1.2;
    }
}


/* ==============================
   Imágenes generadas por KARPI
============================== */

.generated-image {
    display: block;
    width: min(100%, 520px);
    max-height: 620px;
    margin: 10px 0 12px;
    object-fit: contain;
    background: #fffaf1;
    border: 1px solid var(--borde);
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(75, 54, 24, 0.12);
}

.generated-image-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 2px 0 10px;
}

.generated-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 13px;
    color: #654200;
    background: var(--principal);
    border: 1px solid var(--principal-hover);
    border-radius: 12px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.generated-download-btn:hover {
    background: var(--principal-hover);
}

.generated-image-warning {
    display: block;
    margin-top: 8px;
    color: #8b5f2c;
    font-size: 12px;
}

/* ==============================
   Escenario visual del chat
============================== */

.classroom {
    position: relative;
    background: transparent;
}

.teacher-header,
.messages,
.composer {
    position: relative;
    z-index: 1;
}

.teacher-header {
    background: rgba(255, 255, 255, 0.86);
    border-color: rgba(216, 216, 216, 0.88);
    box-shadow: 0 10px 28px rgba(67, 67, 67, 0.08);
    backdrop-filter: blur(8px);
}

.chat-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
}

.chat-empty-state,
.conversation-stage {
    flex: 1;
    min-width: 0;
    min-height: 0;
}

.chat-empty-state {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px 36px 4px;
}

.chat-empty-mascot {
    width: clamp(280px, 23vw, 360px);
    max-height: 88%;
    display: block;
    object-fit: contain;
    filter: drop-shadow(12px 10px 0 rgba(255, 191, 79, 0.14));
}

.conversation-stage {
    position: relative;
    width: min(1280px, calc(100% - 72px));
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
}

.messages {
    width: 100%;
    margin: 0;
    padding: clamp(22px, 3vw, 42px);
    background: rgba(222, 222, 222, 0.78);
    border: 0;
    border-radius: clamp(38px, 5vw, 82px);
    box-shadow: none;
    backdrop-filter: blur(2px);
}

.composer {
    width: min(1188px, calc(100% - 72px));
    align-self: center;
    margin: 16px auto 24px;
    padding: 7px 10px;
    gap: 8px;
    background: rgba(222, 222, 222, 0.84);
    border: 0;
    border-radius: 999px;
    box-shadow: none;
    backdrop-filter: blur(3px);
}

.composer input {
    padding: 11px 13px;
    color: #454545;
}

.composer input::placeholder {
    color: #858585;
}

.composer .attach-image-btn {
    color: #858585;
    background: transparent;
    border: 0;
    border-radius: 999px;
    font-size: 24px;
}

.composer .attach-image-btn:hover:not(:disabled) {
    color: #555555;
    background: rgba(255, 255, 255, 0.72);
}

.composer .send-message-btn {
    width: 46px;
    height: 46px;
    color: #604000;
    border-radius: 999px;
}

.classroom.chat-is-empty .chat-empty-state {
    display: flex;
}

.classroom.chat-is-empty .conversation-stage {
    display: none;
}

.classroom.chat-is-empty .composer {
    width: min(904px, calc(100% - 72px));
}

.classroom.chat-is-active .chat-empty-state {
    display: none;
}

.image-preview-box,
.image-error {
    border-radius: 20px;
}

.composer:has(.image-preview-box:not([hidden])),
.composer:has(.image-error:not([hidden])) {
    border-radius: 24px;
}

@media (max-width: 800px) {
    .chat-empty-state {
        padding-inline: 18px;
    }

    .chat-empty-mascot {
        width: clamp(270px, 64vw, 380px);
    }

    .conversation-stage {
        width: calc(100% - 36px);
    }

    .messages {
        padding: 22px 18px;
        border-radius: 34px;
    }

    .composer,
    .classroom.chat-is-empty .composer {
        width: calc(100% - 36px);
        margin: 13px auto 17px;
    }
}

@media (max-width: 480px) {
    .teacher-header {
        margin-inline: 14px;
    }

    .chat-empty-mascot {
        width: min(300px, 82vw);
    }

    .conversation-stage {
        width: calc(100% - 28px);
    }

    .composer,
    .classroom.chat-is-empty .composer {
        width: calc(100% - 28px);
    }
}

/* ==============================
   Identidad de los mensajes
============================== */

.messages {
    background: rgba(232, 232, 232, 0.82);
}

.user,
.ia {
    position: relative;
    border: 1px solid transparent;
    box-shadow: 0 8px 20px rgba(70, 70, 70, 0.09);
}

.user {
    color: #303030;
    background: linear-gradient(135deg, #d8d8d8 0%, #c9c9c9 100%);
    border-color: rgba(172, 172, 172, 0.8);
    border-bottom-right-radius: 7px;
}

.user .message-author {
    color: #555555;
}

.ia {
    width: min(820px, calc(100% - 66px));
    max-width: calc(100% - 66px);
    margin-left: 62px;
    color: #353535;
    background: rgba(247, 247, 247, 0.95);
    border-color: rgba(190, 190, 190, 0.88);
    border-left: 4px solid #b6b6b6;
    border-bottom-left-radius: 7px;
}

.ia::before {
    content: "";
    position: absolute;
    top: 9px;
    left: -61px;
    width: 48px;
    height: 42px;
    background-image: url("../img/karpi-mascot.svg");
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    filter: drop-shadow(3px 4px 0 rgba(255, 185, 58, 0.16));
    transform: rotate(-7deg);
    pointer-events: none;
}

.ia .message-author {
    color: #555555;
}

.ia[data-tipo="estado"] {
    color: #666666;
    background: rgba(238, 238, 238, 0.96);
}

.ia[data-tipo="error"] {
    background: rgba(235, 235, 235, 0.96);
    border-color: #bdbdbd;
    border-left-color: #8f8f8f;
}

@media (max-width: 800px) {
    .ia {
        width: calc(100% - 50px);
        max-width: calc(100% - 50px);
        margin-left: 48px;
    }

    .ia::before {
        top: 8px;
        left: -48px;
        width: 38px;
        height: 35px;
    }
}

/* ==============================
   Historial integrado al fondo
============================== */

.sidebar {
    background: transparent;
    border-right-color: transparent;
    scrollbar-color: #bdbdbd transparent;
}

.sidebar h2 {
    color: #555555;
}

.new-class-btn {
    color: #404040;
    background: #ffffff;
    border: 1px solid #d1d1d1;
    box-shadow: 0 6px 16px rgba(65, 65, 65, 0.06);
}

.new-class-btn:hover:not(:disabled) {
    background: #e5e5e5;
    border-color: #bdbdbd;
    box-shadow: 0 8px 18px rgba(65, 65, 65, 0.1);
}

.class-item {
    background: rgba(255, 255, 255, 0.82);
    border-color: #dddddd;
}

.class-item:hover {
    background: #f8f8f8;
    border-color: #c9c9c9;
}

.class-item.active {
    background: #dedede;
    border-color: #a9a9a9;
    box-shadow: 0 6px 16px rgba(65, 65, 65, 0.09);
}

.class-open-btn,
.class-action-btn {
    color: #4d4d4d;
}

.class-meta,
.class-empty {
    color: #777777;
}

.class-action-btn:hover {
    color: #333333;
    background: #e2e2e2;
}

/* ==============================
   Menú desplegable de clases
============================== */

.sidebar {
    overflow: visible;
}

.classes-menu {
    position: relative;
    z-index: 20;
}

.classes-menu::after {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    height: 12px;
    content: "";
}

.sidebar .classes-menu-heading {
    margin: 0;
}

.classes-menu-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    color: #4c4c4c;
    background: transparent;
    border: 0;
    border-radius: 12px;
    font: inherit;
    font-size: 16px;
    font-weight: 800;
    text-align: left;
    cursor: default;
    transition: color 0.2s ease, background 0.2s ease;
}

.classes-menu-trigger:hover,
.classes-menu-trigger:focus-visible,
.classes-menu.is-open .classes-menu-trigger {
    color: #222222;
    background: rgba(255, 255, 255, 0.72);
    outline: none;
}

.classes-menu-trigger:focus-visible {
    box-shadow: 0 0 0 3px rgba(95, 95, 95, 0.18);
}

.classes-menu-chevron {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.25s ease;
}

.classes-menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    left: 0;
    max-height: calc(100vh - 160px);
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid #d6d6d6;
    border-radius: 18px;
    box-shadow: 0 18px 45px rgba(30, 30, 30, 0.16);
    pointer-events: none;
    transform: translateY(-8px) scale(0.98);
    transform-origin: top center;
    transition:
        opacity 0.2s ease,
        transform 0.24s ease,
        visibility 0s linear 0.24s;
}

.classes-menu.is-open .classes-menu-panel {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
}

.classes-menu.is-open .classes-menu-chevron {
    transform: translateY(2px) rotate(225deg);
}

.classes-menu-panel .class-list {
    margin-top: 12px;
}

@media (hover: hover) and (pointer: fine) {
    .classes-menu:hover .classes-menu-panel {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
        transition-delay: 0s;
    }

    .classes-menu:hover .classes-menu-chevron {
        transform: translateY(2px) rotate(225deg);
    }
}

.class-delete-btn:hover {
    color: #555555;
    background: #d7d7d7;
}

.app-header {
    background: rgba(255, 255, 255, 0.97);
    border-bottom-color: #d5d5d5;
}
