/*  ==========================================================================   
    1. VARIABLES GLOBALES Y TEMAS (CLARO Y OSCURO)
    ========================================================================== */
/* Aquí guardamos los colores. Usar variables permite que la app cambie de aspecto instantáneamente solo cambiando de clase. */

/* SUBPARTE 1.1: Modo Claro (Por defecto) */
:root {
    --linea-alto: 30px; 
    --linea-ajuste: -4px;
    --color-primary: #2c3e50;     /* Azul oscuro para textos principales y header */
    --color-accent: #27ae60;      /* Verde principal para botones */
    --color-danger: #c0392b;      /* Rojo para alertas y eliminar */
    --color-bg: #f4f7f6;          /* Gris muy claro para el fondo de la app */
    --color-paper: #fafafa;       /* Blanco hueso para la hoja de papel */
    --color-lines: #a3c2e0;       /* Celeste para los renglones */
    --color-margin: #ff9999;      /* Rojo pálido para el margen de la hoja */
    --color-materia: #ffffff;     /* Blanco para tarjetas de materias */
    --color-text: #333333;        /* Color general del texto */
    --color-panel: #ffffff;       /* Fondo blanco de paneles y modales */
    --color-border: #eee;         /* Gris clarito para bordes divisorios */
    --color-header-bg: #2c3e50; /* Tu azul original para PC */
}

/* SUBPARTE 1.2: Modo Oscuro (Se activa desde JavaScript) */
.dark-mode {
    --color-primary: #ecf0f1;     /* Blanco grisáceo para textos en fondo oscuro */
    --color-accent: #2ecc71;      /* Verde un poco más brillante para destacar */
    --color-bg: #121212;          /* Negro carbón para el fondo de la app */
    --color-paper: #1e1e1e;       /* Gris oscuro para la hoja de papel */
    --color-lines: #333333;       /* Renglones sutiles oscuros */
    --color-margin: #8b0000;      /* Margen rojo oscuro */
    --color-materia: #1e1e1e;     /* Gris oscuro para tarjetas */
    --color-text: #e0e0e0;        /* Texto claro general */
    --color-panel: #1e1e1e;       /* Paneles grises casi negros */
    --color-border: #333333;      /* Bordes oscuros */
    --color-header-bg: #000000; /* Negro puro para la barra superior */
}

/*  ==========================================================================   
    2. CONFIGURACIÓN GLOBAL Y RESETEO
    ========================================================================== */
/* Aplica la caja de modelo estándar para que los "paddings" no agranden el tamaño de los elementos */
* { box-sizing: border-box; }

/* Le da a toda la página la tipografía por defecto y usa las variables de color de fondo y texto */
body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    margin: 0; padding: 0; 
    height: 100vh; height: 100dvh; 
    display: flex; flex-direction: column; 
    background-color: var(--color-bg); 
    color: var(--color-text); 
    transition: background-color 0.3s ease, color 0.3s ease; /* Hace que el cambio a oscuro sea suave */
}

/*  ==========================================================================   
    3. ESTRUCTURA Y LAYOUT PRINCIPAL
    ========================================================================== */

/* SUBPARTE 3.1: La Cabecera (Header) */
header { 
    background-color: var(--color-header-bg);
    color: white; /* El texto en el header siempre es blanco, en ambos modos */
    padding: 0 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 60px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
    z-index: 10; 
}

/* Clases para mostrar el logo y el texto dependiendo de si estás en PC o en Celular */
.brand { display: flex; align-items: center; gap: 10px; height: 100%; }
.logo-img { width: 60px; vertical-align: middle; }
.logo-desktop { margin: 0; font-size: 1.4rem; display: flex; align-items: center; gap: 10px; }
.logo-mobile, .text-mobile, .icono-perfil-svg { display: none; } 

/* [!--- MAGIA: Convierte el logo a blanco puro SOLO en modo oscuro ---] */
.dark-mode .logo-img {
    filter: brightness(0) invert(1);
}

/* SUBPARTE 3.2: Botón de Usuario (Modo Estudiante / Perfil) */
.user-mode-btn {
    background: transparent; 
    border: 1px solid rgba(255,255,255,0.3); 
    color: white; 
    padding: 12px 16px; 
    border-radius: 10px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: all 0.2s ease; 
}
.text-desktop { font-weight: bold; letter-spacing: 0.2px; }
.user-mode-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.6); }
.user-mode-btn:active { transform: scale(0.93); background: rgba(255,255,255,0.25); }

/* SUBPARTE 3.3: Contenedor Principal (Donde va el contenido debajo del header) */
.contenedor-principal { 
    display: flex; flex: 1; overflow: hidden; 
    background-color: var(--color-bg); min-height: 0; 
}
.main-content { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* ========================================================================== 
    SUBPARTE 3.4.1: Elementos Internos del Editor (Listas y Formato)
========================================================================== 
*/
/* Corrección de alineación para que las listas respeten el interlineado */
#editorTexto ul,
#editorTexto ol {
    margin-top: 0;
    margin-bottom: 0;
    padding-left: 30px; /* Sangría de la viñeta/número */
}

#editorTexto li {
    margin: 0;
    line-height: inherit; /* Fuerza a heredar la altura del renglón normal */
}

/*  ==========================================================================   
    4. COMPONENTES VISUALES (PANELES, BOTONES, MODALES)
    ========================================================================== */

/* SUBPARTE 4.1: Paneles de Vistas */
.panel { flex: 1; width: 100%; display: flex; flex-direction: column; animation: aparecer 0.3s ease-in-out; min-height: 0; }

/* El panel secundario de la derecha (donde irá el Calendario) */
.panel-lateral {
    background: var(--color-panel); border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); border: 1px solid var(--color-border);
    display: flex; flex-direction: column; height: 100%; overflow-y: auto;
    animation: aparecer 0.3s ease-in-out; animation-delay: 0.1s; animation-fill-mode: forwards;
}

/* La barra superior dentro de cada panel (ej. donde dice "Mis Materias") */
.encabezado-panel { 
    padding: 15px 20px; background-color: var(--color-bg); border-bottom: 1px solid var(--color-border); 
    font-weight: bold; display: flex; justify-content: space-between; align-items: center; 
}

/* SUBPARTE 4.2: Botones Genéricos */
.btn { background-color: var(--color-accent); color: white; border: none; padding: 8px 15px; cursor: pointer; border-radius: 5px; font-size: 0.95rem; transition: background 0.2s; }
.btn:hover { background-color: #2ecc71; }
.btn-volver { background-color: #7f8c8d; }
.btn-eliminar {
    background-color: transparent; color: var(--color-danger); border: none; cursor: pointer;
    font-weight: bold; font-size: 1.3rem; padding: 5px; border-radius: 5px;
    width: 60px; height: 40px; display: flex; align-items: center; justify-content: center;
}
.btn-eliminar:hover { background-color: rgba(231, 76, 60, 0.1); } /* Fondo rojo tenue al hacer hover */

/* SUBPARTE 4.3: Selectores Personalizados (Listas Desplegables) */
.custom-select { position: relative; display: inline-block; min-width: 105px; }
.select-selected {
    background-color: var(--color-panel); border: 1px solid var(--color-border); border-radius: 6px;
    color: var(--color-text); font-size: 0.9rem; height: 38px; padding: 0 10px;
    cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    transition: all 0.2s ease; user-select: none;
}
.select-selected:hover { border-color: var(--color-primary); }
.select-arrow { font-size: 0.6rem; margin-left: 8px; }

.icono-mobile-select { display: none; font-weight: bold; font-size: 1.1rem; }
.texto-desktop-select { display: inline-block; }

/* La lista desplegable (Escondida por defecto) */
.select-items {
    /* [!--- POSICIÓN Y NIVEL ---] */
    position: fixed !important;      /* [!--- Saca el menú de la "cárcel" del contenedor ---] */
    z-index: 99999 !important;      /* [!--- Fuerza a que esté arriba de TODO ---] */
    
    /* [!--- TAMAÑO Y FORMA ---] */
    display: none;                  /* [!--- Por defecto oculto ---] */
    width: auto !important;         /* [!--- [ARREGLO] Evita que se estire al 100% ---] */
    min-width: 120px;               /* [!--- Un tamaño mínimo lógico ---] */
    max-width: 200px;               /* [!--- Un límite para que no sea gigante ---] */
    max-height: 300px;              /* [!--- Si la lista es larga, que se pueda hacer scroll dentro ---] */
    overflow-y: auto;               /* [!--- Scroll interno para listas largas ---] */
    
    background-color: var(--color-panel);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.select-items li {
    padding: 10px; font-size: 0.9rem; cursor: pointer; color: var(--color-text);
    transition: background 0.2s ease;
}
.select-items li:hover { background-color: var(--color-bg); color: var(--color-accent); font-weight: bold; }

/* SUBPARTE 4.4: Listas e Ítems */
.lista-items { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }

/* Diseño de cada fila (cada Materia u Hoja en modo PC) */
.item { padding: 20px; border-bottom: 1px solid var(--color-border); cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; background-color: var(--color-panel); color: var(--color-text); transition: background-color 0.2s; }
.item:hover { background-color: var(--color-bg); color: var(--color-accent); }

.tarjeta-materia { transition: background 0.3s ease; }
.input-texto { padding: 10px; border: 1px solid var(--color-border); border-radius: 5px; font-size: 1rem; width: 100%; outline: none; background: var(--color-panel); color: var(--color-text); }
.input-texto:focus { border-color: var(--color-accent); }

/* SUBPARTE 4.5: El Editor de Texto */
#panelEditor { position: relative; }
.encabezado-app {
    position: relative; width: 100%; height: 60px;
    background-color: var(--color-bg); border-bottom: 1px solid var(--color-border);
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 10px; z-index: 100; transition: margin-top 0.3s;
}
.encabezado-oculto { margin-top: -60px; } 

.btn-icono { flex: 0 0 45px; height: 45px; background: none; border: none; font-size: 1.5rem; color: var(--color-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 1001; }
.titulo-app { flex: 1; min-width: 0; max-width: calc(100% - 90px); font-weight: bold; font-size: 1.1rem; color: var(--color-primary); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 5px; }

.menu-flotante { position: absolute; top: 65px; right: 10px; background-color: var(--color-panel); border: 1px solid var(--color-border); border-radius: 5px; padding: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.15); z-index: 1000; display: flex; flex-direction: column; gap: 10px; }

/* Magia de CSS: Este fondo dibuja la hoja rayada con el margen */
.hoja-papel {
    display: block; flex: 1; width: 100%; border: none;
    padding: calc(var(--linea-alto) * 2) 30px calc(var(--linea-alto) * 2) 80px; 
    line-height: var(--linea-alto); font-size: 16px; color: var(--color-primary); 
    resize: none; background-color: var(--color-paper);
    background-image:
        linear-gradient(90deg, transparent 70px, var(--color-margin) 70px, var(--color-margin) 72px, transparent 72px),
        linear-gradient(var(--color-paper) calc(var(--linea-alto) * 2), transparent calc(var(--linea-alto) * 2)),
        linear-gradient(to top, var(--color-paper) calc(var(--linea-alto) * 2), transparent calc(var(--linea-alto) * 2)),
        linear-gradient(transparent calc(var(--linea-alto) - 1px), var(--color-lines) calc(var(--linea-alto) - 1px), var(--color-lines) var(--linea-alto), transparent var(--linea-alto));
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% var(--linea-alto);
    background-position: left top, left top, left bottom, left var(--linea-ajuste);
    background-repeat: no-repeat, no-repeat, no-repeat, repeat;
    background-attachment: local;
    outline: none; white-space: pre-wrap; word-wrap: break-word;
    overflow-y: auto;
    transition: background-color 0.3s ease;
}

/* SUBPARTE 4.6: Modales y Botón Flotante (FAB) */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.modal-box {
    background: var(--color-panel); padding: 20px; border-radius: 15px; width: 90%; max-width: 300px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    color: var(--color-text); border: 1px solid var(--color-border);
}
.modal-box-user { margin-bottom: 5px; padding-bottom: 15px; border-bottom: 1px solid var(--color-border); }
.modal-box-user-btn {
    background-color: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); padding: 12px 16px; border-radius: 10px; cursor: default; display: flex; margin: auto; align-items: center; justify-content: center;
}
.modal-botones { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }
.btn-eliminar-confirmar { background-color: var(--color-danger); color: white; }
.btn-cancelar { background-color: #95a5a6; color: white; }

.fab {
    position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; border-radius: 50%;
    background-color: var(--color-accent); color: white; font-size: 30px; border: none; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); cursor: pointer; z-index: 1000;
    transition: transform 0.2s, background-color 0.2s; display: flex; align-items: center; justify-content: center;
    visibility: hidden; animation: aparecer-fab 0.5s ease-out forwards; 
}
.fab:hover { background-color: #2ecc71; transform: scale(1.05); }
.fab:active { transform: scale(0.9); }

/* SUBPARTE 4.7: Ajustes y Preferencias (Toggle Switch) */
/* El diseño del interruptor deslizable para encender/apagar el modo oscuro */
.grupo-ajuste { border-color: var(--color-border) !important; background: var(--color-bg) !important; }
.ajuste-info span { color: var(--color-text) !important; }

.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider-switch {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}
.slider-switch:before {
    position: absolute; content: "";
    height: 20px; width: 20px;
    left: 4px; bottom: 4px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0.0, 0.2, 1); /* Curva suave al deslizar */
    border-radius: 50%;
}
/* Cuando el checkbox está activo (Modo Oscuro ON), se pinta de verde */
.theme-switch input:checked + .slider-switch {
    background-color: var(--color-accent);
}
/* Cuando está activo, la bolita se mueve a la derecha */
.theme-switch input:checked + .slider-switch:before {
    transform: translateX(22px);
}

/* SUBPARTE 4.8: Barra de Herramientas del Editor */
.editor-toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 15px;
    background-color: var(--color-bg); border-bottom: 1px solid var(--color-border);
    align-items: center; position: relative; z-index: 50;
    justify-content: center !important;
}
.editor-toolbar::-webkit-scrollbar { display: none; }

.btn-toolbar {
    background: var(--color-panel); border: 1px solid var(--color-border); border-radius: 6px; cursor: pointer;
    font-size: 1.1rem; color: var(--color-text); transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center;
    min-width: 38px; height: 38px; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.btn-toolbar:hover { background: var(--color-bg); border-color: var(--color-primary); transform: translateY(-1px); }
.btn-toolbar:active { transform: translateY(1px); box-shadow: none; }
.btn-toolbar.active { background-color: var(--color-accent); color: white; border-color: var(--color-accent); }
.separador-toolbar { color: var(--color-border); margin: 0 5px; user-select: none; }
.content-editable-area:empty:before { content: attr(data-placeholder); color: #95a5a6; pointer-events: none; display: block; }
.grupo-opcion { display: flex; flex-direction: column; gap: 5px; }
.grupo-opcion small { color: #7f8c8d; font-weight: bold; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }

/* SUBPARTE 4.9: Estados Vacíos (Mensajes cuando no hay datos) */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #95a5a6;
    font-size: 1rem;
    font-style: italic;
    background-color: var(--color-panel);
    border: 1px dashed var(--color-border);
    margin: 20px;
    border-radius: 10px;
}

/* [!--- SUBPARTE 4.10: Estilo del Checkbox en el Editor ---]*/
/* [!--- El contenedor checklist-item garantiza que el checkbox siempre esté centrado con el texto ---] */
.checklist-wrapper {
    display: flex;
    align-items: center;
    height: var(--linea-alto); /* [!--- Hereda la altura de tus renglones ---]*/
    margin: 2px 0;
}

.editor-checkbox {
    cursor: pointer;
    width: 16px;
    height: 16px;
    margin-right: 10px;
    flex-shrink: 0; /*[!--- Evita que el checkbox se achique ---]*/
    height: 16px;
}

/* [!--- SUBPARTE 4.11: Limpieza y Separación de Selectores ---] */

/* 1. Eliminamos los puntos de la lista y el padding por defecto */
.select-items {
    list-style: none !important; /* [!--- ¡Adiós puntos feos! ---] */
    padding: 0 !important;
    margin: 0 !important;
}

/* 2. Damos formato a cada ítem y agregamos la línea divisoria */
.select-items li {
    list-style: none !important; /* [!--- Garantizamos que no haya puntos ---] */
    padding: 12px 15px !important;
    border-bottom: 1px solid var(--color-border); /* [!--- Línea divisoria entre ítems ---] */
    cursor: pointer;
    transition: background 0.2s;
}

/* 3. Eliminamos la línea del último ítem para que no quede un borde al final del menú */
.select-items li:last-child {
    border-bottom: none;
}

/* 4. Efecto hover para que se note qué seleccionas */
.select-items li:hover {
    background-color: var(--color-bg);
}

.contenedor-opciones { position: relative; display: flex; align-items: center; }
.btn-opciones { 
    background-color: transparent; border: none; border-radius: 50%; cursor: pointer; 
    width: 38px; height: 38px; color: #a4b0be; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s ease;
}
.btn-opciones:hover { color: var(--color-primary); background-color: rgba(127, 140, 141, 0.2); }

.menu-desplegable { 
    position: absolute; right: 55px; top: 0px; background: var(--color-panel); border: 1px solid var(--color-border); 
    border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); display: flex; flex-direction: column; 
    z-index: 100; overflow: hidden; min-width: 140px; 
}
.menu-desplegable button { 
    background: none; border: none; padding: 12px 15px; text-align: left; cursor: pointer; 
    font-size: 0.95rem; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--color-border); white-space: nowrap; color: var(--color-text);
}
.menu-desplegable button:hover { background: var(--color-bg); color: var(--color-accent); }
.btn-menu-eliminar { color: var(--color-danger) !important; }

.item-info { display: flex; flex-direction: column; justify-content: center; }
.item-fecha { font-size: 0.75rem; color: #95a5a6; margin-top: 3px; font-weight: 500; }
#fechaModificacionHoja { display: block; font-size: 0.8rem; color: #7f8c8d; margin-top: 4px; }

/*  ==========================================================================   
    5. ANIMACIONES (EFECTOS DE TRANSICIÓN)
    ========================================================================== */
@keyframes aparecer {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}
@keyframes aparecer-fab {
    0% { opacity: 0; transform: scale(0.5) translateY(20px); visibility: hidden; }
    100% { opacity: 1; transform: scale(1) translateY(0); visibility: visible; }
}
.anim-fade-in { animation: aparecer 0.3s ease-out forwards; }

/* [!--- SUBPARTE 5.3: Estilos de Componentes Especiales (Checklist) ---] */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
    min-height: 24px;
}

.checklist-item input {
    margin: 0;
    flex-shrink: 0;
}

.checklist-item span {
    flex-grow: 1;
    outline: none;
    min-height: 1.2em;
}

/*  ==========================================================================    
    6. RESPONSIVE Y MEDIA QUERIES (ADAPTACIÓN A PANTALLAS)
    ========================================================================== */

/* SUBPARTE 6.1: Diseño de Escritorio (Pantallas Grandes / PC) */
@media (min-width: 900px) {
    .contenedor-principal {
        display: grid !important; grid-template-columns: 1fr auto; gap: 20px;
        padding: 20px; height: 100vh;
    }
    #panelCalendario[style*="display: none"] { display: none; }
    .contenedor-principal:has(#panelCalendario[style*="display: none"]) .main-content { grid-column: span 2; }
    
    .tarjeta-materia {
        border-left: 8px solid var(--color-materia) !important;
        background-color: var(--color-panel) !important; color: var(--color-text) !important;
        border-top: 1px solid var(--color-border); border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
    }
    .tarjeta-materia .btn-opciones { color: #a4b0be; }
}

/* SUBPARTE 6.2: Diseño Móvil (Celulares) */
@media (max-width: 899px) {

    /* 6.2.1: Header, Logo y Navegación Móvil */
    .logo-desktop, .text-desktop { display: none !important; }
    .logo-mobile, .text-mobile, .icono-perfil-svg { display: block !important; }
    header { padding: 0 10px; height: 50px; }
    .logo-mobile { margin: 0; font-size: 1rem; }
    .logo-mobile .logo-img { width: 42px; }
    .icono-perfil-svg { width: 24px; height: 24px; fill: #ffffffd3; }
    .user-mode-btn { background-color: transparent; padding: 5px 5px; border: 1px solid rgba(255,255,255,0.3); border-radius: 50%; }
    .panel-lateral, .texto-ocultable { display: none; }
    body.modo-editor header { display: none; }

    /* 6.2.2: Listas, Tarjetas y Navegación Carrusel */
    .lista-items {
        display: flex; overflow-x: auto; scroll-snap-type: x mandatory; 
        padding: 20px 7.5%; gap: 5vw; align-items: center; height: 100%; scrollbar-width: none;
    }
    .lista-items::-webkit-scrollbar { display: none; }

    .tarjeta-materia {
        flex: 0 0 85vw; height: 65vh; scroll-snap-align: center;
        border-radius: 30px; box-shadow: 0 15px 35px rgba(0,0,0,0.12); 
        transition: transform 0.4s ease; 
        background-color: var(--color-materia) !important; 
        color: white !important; /* Mantiene texto blanco sobre color base en móvil */
        display: flex; flex-direction: column; justify-content: space-between;
        padding: 40px; text-align: center; position: relative;
    }
    .tarjeta-materia .item-info { width: 100%; margin-bottom: 20px; }
    .tarjeta-materia .item-info span { font-size: 1.4rem; font-weight: 700; }

    .tarjeta-hoja {
        flex: 0 0 90vw; height: 70vh; background-color: var(--color-panel) !important; 
        color: var(--color-text) !important; border-radius: 25px; box-shadow: 0 10px 20px rgba(0,0,0,0.08);
        display: flex; flex-direction: column; justify-content: center; align-items: center;
        padding: 30px; text-align: center; scroll-snap-align: center; border: 1px solid var(--color-border);
    }
    .fab { width: 85px; height: 85px; font-size: 35px; bottom: 25px; right: 25px; }

    /* 6.2.3: Barra de Herramientas (Editor) - Corrección de Menú */
    .editor-toolbar {
        display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 8px;
        overflow: visible !important; position: relative; z-index: 100;
    }
    .btn-toolbar, .select-selected {
        flex: 0 0 40px !important; width: 40px !important; height: 40px !important; min-width: 40px !important;
        padding: 0 !important; margin: 0 !important; display: flex !important; align-items: center !important;
        justify-content: center !important; border-radius: 8px !important; box-sizing: border-box !important;
    }
    .select-items {
        min-width: 100px !important; width: auto !important; left: 50% !important; transform: translateX(-50%);
    }
    #textoFuenteActual, #textoTamanoActual { display: none !important; }
    .icono-mobile-select { display: flex !important; align-items: center; justify-content: center; font-weight: bold; font-size: 1.1rem; width: 100%; height: 100%; }
    .select-arrow { display: none !important; }
    .custom-select { min-width: 40px !important; width: 40px !important; }

    /* 6.2.4: Encabezados Fijos (Sticky) en Móvil */
    .encabezado-panel, 
    .encabezado-app {
        position: sticky;
        top: 0;
        z-index: 100;
        /* Ya tienen var(--color-bg) por defecto, pero nos aseguramos que el texto pase por debajo sin verse */
        background-color: var(--color-bg); 
    }

/* SUBPARTE 6.3: Menús de Opciones (Los Tres Puntos) */
.contenedor-opciones { position: relative; display: flex; align-items: center; }
.btn-opciones { 
    background-color: transparent; border: none; border-radius: 50%; cursor: pointer; 
    width: 38px; height: 38px; color: #a4b0be; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s ease;
}
.btn-opciones:hover { color: var(--color-primary); background-color: rgba(127, 140, 141, 0.2); }

.menu-desplegable { 
    position: absolute; right: 55px; top: 0px; background: var(--color-panel); border: 1px solid var(--color-border); 
    border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); display: flex; flex-direction: column; 
    z-index: 100; overflow: hidden; min-width: 140px; 
}
.menu-desplegable button { 
    background: none; border: none; padding: 12px 15px; text-align: left; cursor: pointer; 
    font-size: 0.95rem; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--color-border); white-space: nowrap; color: var(--color-text);
}
.menu-desplegable button:hover { background: var(--color-bg); color: var(--color-accent); }
.btn-menu-eliminar { color: var(--color-danger) !important; }

.item-info { display: flex; flex-direction: column; justify-content: center; }
.item-fecha { font-size: 0.75rem; color: #95a5a6; margin-top: 3px; font-weight: 500; }
#fechaModificacionHoja { display: block; font-size: 0.8rem; color: #7f8c8d; margin-top: 4px; }

/* Magia de accesibilidad: Cambia el color del botón según fondo */
.item[style*="background-color"] .btn-opciones { color: rgba(255, 255, 255, 0.85); }
.item[style*="background-color"] .btn-opciones:hover { color: white; background-color: rgba(255, 255, 255, 0.2); }
.item:not([style*="background-color"]) .btn-opciones { color: #7f8c8d; }
.item:not([style*="background-color"]) .btn-opciones:hover { color: var(--color-primary); background-color: rgba(127, 140, 141, 0.2); }

/* [!--- SUBPARTE 6.4: Barra de herramientas móvil (Scroll Horizontal) ---] */
    .editor-toolbar {
        display: flex !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        overflow-x: auto !important;
        
        /* [!--- ESTO ES LO QUE LO ARREGLA ---] */
        width: 100vw !important;           /* [!--- Forzamos el ancho a ser exacto al de la ventana ---] */
        max-width: 100vw !important;       /* [!--- Impide que se pase de ese tamaño ---] */
        box-sizing: border-box !important; /* [!--- Obliga a incluir padding en el ancho ---] */
        
        padding: 5px 10px !important;      /* [!--- Padding uniforme ---] */
        gap: 6px !important;
        
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    /* [!--- Asegura que los botones sean un poco más compactos para que quepan más en pantalla ---] */
    .btn-toolbar {
        flex: 0 0 36px !important;         /* [!--- Reducimos de 40px a 36px ---] */
        height: 36px !important;           /* [!--- Reducimos el alto también ---] */
        font-size: 0.9rem !important;      /* [!--- Texto/Icono un poco más chico ---] */
    }

    .editor-toolbar::-webkit-scrollbar {
        display: none;
    }
}

/*  ==========================================================================   
    7. PAPELERA Y EXCEPCIONES VISUALES
    ========================================================================== */
.btn-papelera { background-color: var(--color-border); color: var(--color-text); font-weight: bold; }
.btn-papelera:hover { background-color: #7f8c8d; color: white; }
.acciones-papelera { display: flex; align-items: center; gap: 8px; }
.btn-restaurar { background-color: #3498db; }
.btn-restaurar:hover { background-color: #2980b9; }

.btn-borrar-def { background: transparent; border: none; cursor: pointer; font-size: 1.2rem; padding: 6px 8px; border-radius: 6px; color: var(--color-text); }
.btn-borrar-def:hover { background-color: rgba(231, 76, 60, 0.2); }

.papelera-vacia { list-style: none; text-align: center; color: #95a5a6; padding: 40px 20px; font-size: 1rem; }

/* Excepción de contraste para móvil */
@media (max-width: 899px) {
    .tarjeta-materia.materia-blanca { color: #2c3e50 !important; border: 1px solid #ecf0f1; }
    .tarjeta-materia.materia-blanca .btn-opciones { color: #a4b0be !important; }
}