/* Margen · Beta 1
   Estilo "digital typewriter": minimalista, serif legible, sin distracciones
   Paleta: blanco roto + azul pizarra + grises sutiles
   Tipografías: Source Serif 4 (contenido), Inter (UI), JetBrains Mono (código) */

:root {
    --bg: #fafaf9;
    --bg-sidebar: #f5f4f1;
    --bg-hover: #ecebe8;
    --bg-active: #e2e1dd;
    --texto: #2c2c2c;
    --texto-suave: #6b6b6b;
    --texto-tenue: #9a9a9a;
    --linea: #d8d7d3;
    --linea-suave: #e8e7e3;
    --acento: #3b5a7a;
    --acento-hover: #2c4660;
    --rojo: #c04545;

    --serif: 'Bitter', Georgia, serif;
    --sans: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    background: var(--bg);
    color: var(--texto);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.6;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--linea);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 18px 14px;
    border-bottom: 1px solid var(--linea);
}

.logo {
    font-family: var(--serif);
    font-weight: 700;
    font-size: 22px;
    color: var(--texto);
    letter-spacing: -0.3px;
}

.btn-nueva {
    background: var(--acento);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-family: var(--sans);
    font-weight: 400;
    line-height: 1;
    padding-bottom: 3px;
}

.btn-nueva:hover {
    background: var(--acento-hover);
}

.sidebar-search {
    padding: 12px 18px;
    border-bottom: 1px solid var(--linea);
}

.sidebar-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--linea);
    border-radius: 5px;
    font-family: var(--sans);
    font-size: 13px;
    background: white;
    color: var(--texto);
    outline: none;
    transition: border-color 0.15s;
}

.sidebar-search input:focus {
    border-color: var(--acento);
}

.sidebar-search input::placeholder {
    color: var(--texto-tenue);
}

.lista-notas {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.lista-notas li {
    padding: 10px 18px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.1s, border-color 0.1s;
}

.lista-notas li:hover {
    background: var(--bg-hover);
}

.lista-notas li.active {
    background: var(--bg-active);
    border-left-color: var(--acento);
}

.nota-titulo {
    font-family: var(--sans);
    font-weight: 500;
    font-size: 13px;
    color: var(--texto);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.nota-preview {
    font-family: var(--serif);
    font-size: 12px;
    color: var(--texto-tenue);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nota-fecha-lista {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--texto-tenue);
    margin-top: 4px;
}

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--linea);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--texto-tenue);
}

/* === EDITOR === */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 28px 14px;
    border-bottom: 1px solid var(--linea);
}

.input-titulo {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--serif);
    font-weight: 600;
    font-size: 22px;
    color: var(--texto);
    outline: none;
    letter-spacing: -0.3px;
}

.input-titulo::placeholder {
    color: var(--texto-tenue);
    font-style: italic;
}

.editor-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--texto-tenue);
}

.btn-borrar {
    background: none;
    border: 1px solid var(--linea);
    color: var(--texto-suave);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 11px;
    text-transform: lowercase;
    transition: all 0.15s;
}

.btn-borrar:hover {
    border-color: var(--rojo);
    color: var(--rojo);
}

.editor-split {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-pane {
    flex: 1;
    border-right: 1px solid var(--linea);
    overflow: hidden;
}

.preview-pane {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background: var(--bg);
}

.editor-textarea {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg);
    color: var(--texto);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.7;
    padding: 32px 40px;
    resize: none;
    outline: none;
}

.editor-textarea::placeholder {
    color: var(--texto-tenue);
    font-style: italic;
}

/* === PREVIEW (markdown renderizado) === */
.preview-content {
    font-family: var(--serif);
    font-size: 16px;
    line-height: 1.7;
    color: var(--texto);
}

.preview-content h1 {
    font-weight: 700;
    font-size: 28px;
    margin: 24px 0 12px;
    letter-spacing: -0.5px;
}

.preview-content h2 {
    font-weight: 600;
    font-size: 22px;
    margin: 22px 0 10px;
    letter-spacing: -0.3px;
}

.preview-content h3 {
    font-weight: 600;
    font-size: 18px;
    margin: 18px 0 8px;
}

.preview-content p {
    margin-bottom: 12px;
}

.preview-content ul,
.preview-content ol {
    margin: 8px 0 12px 24px;
}

.preview-content li {
    margin-bottom: 4px;
}

.preview-content code {
    font-family: var(--mono);
    font-size: 13px;
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--acento);
}

.preview-content pre {
    font-family: var(--mono);
    font-size: 13px;
    background: var(--bg-sidebar);
    padding: 14px 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--linea);
}

.preview-content pre code {
    background: none;
    padding: 0;
    color: var(--texto);
}

.preview-content blockquote {
    border-left: 3px solid var(--acento);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--texto-suave);
    font-style: italic;
}

.preview-content a {
    color: var(--acento);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.preview-content strong {
    font-weight: 700;
}

.preview-content em {
    font-style: italic;
}

.preview-content hr {
    border: none;
    border-top: 1px solid var(--linea);
    margin: 24px 0;
}

.preview-content img {
    max-width: 100%;
    border-radius: 4px;
}

/* === ESTADO VACIO === */
.estado-vacio {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: var(--texto-tenue);
}

.estado-vacio.activo {
    display: flex;
}

.vacio-icono {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.estado-vacio h2 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--texto-suave);
}

.estado-vacio p {
    font-family: var(--sans);
    font-size: 14px;
}

/* === SCROLLBAR === */
.lista-notas::-webkit-scrollbar,
.preview-pane::-webkit-scrollbar,
.editor-textarea::-webkit-scrollbar {
    width: 6px;
}

.lista-notas::-webkit-scrollbar-track,
.preview-pane::-webkit-scrollbar-track,
.editor-textarea::-webkit-scrollbar-track {
    background: transparent;
}

.lista-notas::-webkit-scrollbar-thumb,
.preview-pane::-webkit-scrollbar-thumb,
.editor-textarea::-webkit-scrollbar-thumb {
    background: var(--linea);
    border-radius: 3px;
}

.lista-notas::-webkit-scrollbar-thumb:hover,
.preview-pane::-webkit-scrollbar-thumb:hover,
.editor-textarea::-webkit-scrollbar-thumb:hover {
    background: var(--texto-tenue);
}

/* === RESPONSIVO === */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }

    .preview-pane {
        padding: 20px 24px;
    }

    .editor-textarea {
        padding: 20px 24px;
    }
}

@media (max-width: 560px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 180px;
        border-right: none;
        border-bottom: 1px solid var(--linea);
    }

    .editor-split {
        flex-direction: column;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--linea);
        height: 40%;
    }

    .preview-pane {
        height: 60%;
    }
}


/* === BETA 2: chuleta de markdown + boton === */

.btn-chuleta {
    background: none;
    border: 1px solid var(--linea);
    color: var(--texto-suave);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    font-family: var(--sans);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    margin-left: 4px;
}

.btn-chuleta:hover {
    border-color: var(--acento);
    color: var(--acento);
}

#panel-chuleta {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 1px solid var(--linea);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    max-width: 480px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.chuleta-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--linea);
}

.chuleta-header h3 {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 16px;
    color: var(--texto);
}

.chuleta-cerrar {
    background: none;
    border: none;
    color: var(--texto-tenue);
    cursor: pointer;
    font-size: 16px;
    font-family: var(--mono);
    padding: 4px 8px;
    border-radius: 4px;
}

.chuleta-cerrar:hover {
    background: var(--bg-hover);
    color: var(--texto);
}

.chuleta-tabla {
    width: 100%;
    border-collapse: collapse;
}

.chuleta-tabla tr {
    border-bottom: 1px solid var(--linea-suave);
}

.chuleta-tabla td {
    padding: 10px 20px;
    font-size: 13px;
    font-family: var(--sans);
    color: var(--texto);
}

.chuleta-sintaxis {
    font-family: var(--mono);
    color: var(--acento);
    white-space: nowrap;
    width: 45%;
}


/* === BETA 3: dark mode + ajustes + toolbar formulas === */

/* --- boton ajustes --- */
.btn-ajustes-margen {
    background: none;
    border: 1px solid var(--linea);
    color: var(--texto-suave);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: var(--sans);
    font-size: 11px;
    text-transform: lowercase;
    cursor: pointer;
    margin-left: 4px;
    transition: all 0.15s;
}

.btn-ajustes-margen:hover {
    border-color: var(--acento);
    color: var(--acento);
}

#panel-ajustes-margen {
    position: fixed;
    top: 60px;
    right: 20px;
    background: white;
    border: 1px solid var(--linea);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    min-width: 240px;
}

.ajustes-margen-fila {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
}

.ajustes-margen-fila:not(:last-child) {
    border-bottom: 1px solid var(--linea-suave);
}

.ajustes-margen-fila>span {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--texto-suave);
}

.ajustes-margen-toggle {
    display: flex;
    background: var(--bg-hover);
    border-radius: 5px;
    padding: 2px;
    gap: 2px;
}

.ajustes-margen-toggle button {
    background: none;
    border: none;
    color: var(--texto-tenue);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
}

.ajustes-margen-toggle button.active {
    background: var(--acento);
    color: white;
}


/* --- boton formulas --- */
.btn-formulas {
    background: none;
    border: 1px solid var(--linea);
    color: var(--texto-suave);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 12px;
    text-transform: lowercase;
    margin-left: 8px;
    transition: all 0.15s;
}

.btn-formulas:hover {
    border-color: var(--acento);
    color: var(--acento);
}

#toolbar-formulas {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--linea);
    background: var(--bg-sidebar);
}

.btn-formula {
    background: white;
    border: 1px solid var(--linea);
    color: var(--texto);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--mono);
    font-size: 14px;
    min-width: 32px;
    transition: all 0.1s;
}

.btn-formula:hover {
    border-color: var(--acento);
    color: var(--acento);
}

.btn-formula:active {
    background: var(--bg-hover);
}


/* --- DARK MODE --- */
body.tema-oscuro-margen {
    --bg: #1a1918;
    --bg-sidebar: #232220;
    --bg-hover: #2d2b29;
    --bg-active: #383533;
    --texto: #e8e4dc;
    --texto-suave: #a8a29e;
    --texto-tenue: #6b6760;
    --linea: #3a3733;
    --linea-suave: #2a2724;
    --acento: #6b8caa;
    --acento-hover: #8caac8;
}

body.tema-oscuro-margen .sidebar-search input,
body.tema-oscuro-margen .input-titulo,
body.tema-oscuro-margen .editor-textarea {
    background: var(--bg);
    color: var(--texto);
}

body.tema-oscuro-margen .sidebar-search input {
    background: var(--bg-sidebar);
}

body.tema-oscuro-margen #panel-ajustes-margen,
body.tema-oscuro-margen #panel-chuleta {
    background: var(--bg-sidebar);
}

body.tema-oscuro-margen .btn-formula {
    background: var(--bg-hover);
    color: var(--texto);
}

body.tema-oscuro-margen .preview-content code {
    background: var(--bg-hover);
    color: var(--acento);
}

body.tema-oscuro-margen .preview-content pre {
    background: var(--bg-sidebar);
}