/* ==============================================
   STYLES.CSS - Gestor de Conocimiento (Layout Editor)
   Estilo para el layout de 2 columnas (index.html)
   
   SOLUCIÓN: Usa un <textarea> simple (para scroll) 
   y un Modal de Vista Previa (para parsear Markdown).
   ============================================== */

/* --- VARIABLES --- */
:root {
    --leti-primary: #b38f54;
    --leti-accent: #c9a56d;
    --leti-bg: #fdfbf8;
    --leti-surface: #ffffff;
    --leti-border: #e8e5e0;
    --leti-text: #333333;
    --leti-text-muted: #6c757d;
}

/* --- LAYOUT DEL EDITOR --- */
body.editor-layout {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--leti-text);
    background-color: var(--leti-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Fija la altura y evita el scroll del body */
    height: 100vh;
    overflow: hidden; 
}

.editor-container {
    height: 100vh;
    max-height: 100vh;
}

.editor-header {
    background-color: var(--leti-surface);
    flex-shrink: 0; /* No se encoge */
}

/* Contenedor principal de las 2 columnas */
.editor-main {
    height: 100%;
    min-height: 0; /* CRÍTICO: Evita que crezca más de 100vh */
}

/* --- Columna Izquierda (Sidebar) --- */
.editor-sidebar {
    width: 300px;
    flex-shrink: 0;
    background-color: var(--leti-surface);
    overflow-y: hidden; /* El scroll va en la lista */
    height: 100%;
}

.editor-sidebar .list-group {
    overflow-y: auto; /* Scroll solo en la lista */
    flex-grow: 1; /* Ocupa el espacio restante */
    min-height: 0; /* CRÍTICO: Permite el scroll en la lista */
}

.editor-sidebar .list-group-item {
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.65rem 1.25rem;
    border: none;
    border-bottom: 1px solid var(--leti-border);
}

.editor-sidebar .list-group-item:last-child {
    border-bottom: none;
}

.editor-sidebar .list-group-item.active {
    background-color: var(--leti-primary);
    color: white;
    font-weight: 600;
}

/* --- Columna Derecha (Contenido) --- */
.editor-content {
    background-color: var(--leti-bg);
    overflow-y: hidden; /* El scroll lo maneja el editor */
    height: 100%;
    min-height: 0; /* CRÍTICO: Evita que la columna crezca */
}

.editor-content-header {
    background-color: var(--leti-surface);
    flex-shrink: 0;
}

/*
 * ===========================================
 * EDITOR ASISTIDO (Toolbar + Textarea)
 * ===========================================
 */

/* 1. Contenedor del editor (del index.html) */
.editor-area-wrapper {
    display: flex;
    flex-direction: column; /* Apila toolbar y textarea */
    flex-grow: 1;
    min-height: 0; /* CRÍTICO: Evita que este wrapper crezca */
    padding: 1rem;
    padding-top: 0.5rem;
    background-color: var(--leti-surface); /* Fondo blanco para el editor */
    border-top: 1px solid var(--leti-border);
}

/* 2. BARRA DE HERRAMIENTAS */
.markdown-toolbar {
    flex-shrink: 0; /* No se encoge */
    padding: 0.5rem;
    border: 1px solid var(--leti-border);
    border-bottom: none; /* Se une con el textarea */
    background-color: #fcfcfc;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.markdown-toolbar .btn {
    margin-right: 0.25rem;
    line-height: 1; /* Ajusta altura de iconos */
}

.markdown-toolbar .toolbar-divider {
    display: inline-block;
    width: 1px;
    background-color: var(--leti-border);
    height: 1.5rem;
    vertical-align: middle;
    margin: 0 0.5rem 0 0.25rem;
}

/* 3. El <textarea> estándar */
textarea#contenido.editor-textarea {
    flex-grow: 1; /* Ocupa todo el espacio restante */
    height: 100%;
    min-height: 0; /* CRÍTICO: Activa el scroll interno */
    
    /* Estilos de textarea */
    resize: none; /* Deshabilita el resize manual */
    border: 1px solid var(--leti-border);
    border-top: none; /* Se une a la toolbar */
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    padding: 1rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    background-color: var(--leti-surface);
}

textarea#contenido.editor-textarea:focus {
    border-color: var(--leti-accent);
    border-top: 1px solid var(--leti-accent); /* Asegura que el borde superior aparezca al enfocar */
    box-shadow: 0 0 0 0.2rem rgba(201, 165, 109, 0.3);
    outline: none;
    position: relative; /* Ayuda al z-index del focus */
    z-index: 2;
}


/* --- ESTILOS DEL MODAL DE VISTA PREVIA --- */
#previewContent { color: var(--leti-text); }
#previewContent h1, 
#previewContent h2, 
#previewContent h3 {
    font-weight: 600;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    border-bottom: 1px solid var(--leti-border);
    padding-bottom: 0.3em;
}
#previewContent h1 { font-size: 2rem; }
#previewContent h2 { font-size: 1.75rem; }
#previewContent h3 { font-size: 1.5rem; }
#previewContent p { margin-bottom: 1.25em; }
#previewContent ul, 
#previewContent ol { margin-bottom: 1.25em; padding-left: 2em; }
#previewContent code {
    background-color: #f0f0f0;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
#previewContent pre {
    background-color: #f0f0f0;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
}
#previewContent pre code { background-color: transparent; padding: 0; }
#previewContent blockquote {
    border-left: 4px solid var(--leti-border);
    padding-left: 1.5em;
    margin: 0 0 1.25em 0;
    font-style: italic;
    color: var(--leti-text-muted);
}


/* --- ESTILOS DE COMPONENTES (Bootstrap Overrides) --- */
.btn-primary {
    background-color: var(--leti-primary);
    border-color: var(--leti-primary);
}
.btn-primary:hover {
    background-color: #a07d4a;
    border-color: #a07d4a;
}
.btn-check:checked + .btn-outline-primary,
.btn-outline-primary:hover {
    background-color: var(--leti-primary);
    border-color: var(--leti-primary);
    color: white;
}
.btn-outline-primary {
    color: var(--leti-primary);
    border-color: var(--leti-primary);
}
.form-control:focus,
.form-select:focus {
    border-color: var(--leti-accent);
    box-shadow: 0 0 0 0.25rem rgba(201, 165, 109, 0.3);
}
.modal-content {
    border-radius: 12px;
    border: 1px solid var(--leti-border);
}
.modal-header, .modal-footer {
    border-color: var(--leti-border);
}

/* --- Layout Móvil --- */
@media (max-width: 767.98px) {
    .editor-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
    }
    .editor-sidebar.show {
        transform: translateX(0);
    }
    .editor-content {
        width: 100%;
    }
    #backBtn {
        display: block !important;
    }
}
