:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --side: #1d2a25;
  --side-text: #d9e4df;
  --side-muted: #8fa39a;
  --side-hover: #2a3a33;
  --side-active: #31473e;
  --text: #1f2421;
  --muted: #6b736f;
  --line: #e4e6e3;
  --accent: #1f7a5a;
  --accent-soft: #e3f1ea;
  --danger: #b42318;
  --mark: #fff3a3;
  --code-bg: #f1f2f0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --panel: #191d1b;
    --side: #0f1311;
    --side-hover: #1d2421;
    --side-active: #24302b;
    --text: #e5e9e7;
    --muted: #94a09a;
    --line: #2b322f;
    --accent: #4cc293;
    --accent-soft: #1d332a;
    --danger: #f97066;
    --mark: #6b5d13;
    --code-bg: #222826;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
small, .muted { color: var(--muted); }

.primary, .ghost, .danger { padding: 8px 14px; border-radius: 6px; font-weight: 600; }
.primary { background: var(--accent); color: #fff; }
.ghost { border: 1px solid var(--line); }
.danger { background: var(--danger); color: #fff; }
.danger-text { color: var(--danger) !important; }
.small { padding: 4px 10px; font-size: .85rem; }
.icon-btn { width: 34px; height: 34px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 1.05rem; flex: none; }
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.on { background: var(--accent-soft); }
.only-mobile { display: none; }

/* ---------- Ingreso ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-card h1 { margin: 0 0 16px; color: var(--accent); }
.login-card label { display: block; font-weight: 600; margin: 12px 0; }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.login-card button { width: 100%; margin-top: 8px; padding: 10px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 600; }
.error { color: var(--danger); }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 250px 320px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--side); color: var(--side-text); overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; }
.list { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.editor { background: var(--panel); display: flex; flex-direction: column; min-width: 0; position: relative; }

/* ---------- Barra lateral ---------- */
.brand { font-weight: 800; font-size: 1.2rem; padding: 4px 10px 12px; color: #fff; }
.new-note { margin: 0 4px 12px; padding: 10px; border-radius: 20px; }
.nav { list-style: none; margin: 0 0 8px; padding: 0; }
.nav ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.nav.bottom { margin-top: auto; padding-top: 12px; }
.nav-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 4px; color: var(--side-muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.nav-head .more { font-size: 1.1rem; }
.nav-item { display: flex; align-items: center; border-radius: 6px; }
.nav-item:hover { background: var(--side-hover); }
.nav-item.active { background: var(--side-active); }
.nav-link { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 8px; text-align: left; min-width: 0; }
.nav-icon { width: 18px; text-align: center; flex: none; opacity: .85; }
.nav-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-name small { color: var(--side-muted); }
.count { color: var(--side-muted); font-size: .8rem; }
.more { color: var(--side-muted); width: 26px; height: 26px; border-radius: 4px; flex: none; opacity: 0; }
.nav-item:hover .more, .nav-item:focus-within .more, .nav-head .more { opacity: 1; }
.more:hover { color: #fff; background: var(--side-active); }
.stack-toggle { width: 100%; text-align: left; padding: 6px 8px; border-radius: 6px; color: var(--side-text); }
.stack-toggle:hover { background: var(--side-hover); }
.caret { display: inline-block; width: 12px; color: var(--side-muted); }
.empty-hint { color: var(--side-muted); font-size: .85rem; padding: 4px 10px; }

/* ---------- Lista ---------- */
.list-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; flex-wrap: wrap; }
.list-head h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-head .muted { font-size: .8rem; width: 100%; order: 3; }
.list-head select { border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 4px 6px; font-size: .85rem; }
.trash-hint { margin: 0; padding: 8px 14px; font-size: .8rem; color: var(--muted); background: var(--bg); }
.note-list { list-style: none; margin: 0; padding: 0; }
.note-item { display: block; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.note-item:hover { background: var(--bg); }
.note-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.note-title { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin { font-size: .8rem; margin-right: 4px; }
.note-snippet { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: .88rem; margin: 2px 0; min-height: 1.3em; }
.note-meta { font-size: .75rem; color: var(--muted); }
.empty { padding: 24px 14px; color: var(--muted); }

/* ---------- Editor ---------- */
.editor-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.editor-head select { max-width: 260px; min-width: 0; flex: 0 1 auto; border: 1px solid transparent; border-radius: 6px; background: transparent; padding: 4px 6px; }
.editor-head select:hover { border-color: var(--line); }
.save-status { flex: 1; text-align: right; font-size: .8rem; color: var(--muted); padding-right: 4px; }
.save-status.error { color: var(--danger); }
.banner { padding: 8px 16px; background: var(--accent-soft); font-size: .9rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner[hidden] { display: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.tb { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 5px; font-size: .9rem; }
.tb:hover:not(:disabled) { background: var(--bg); }
.tb.on { background: var(--accent-soft); color: var(--accent); }
.tb:disabled { opacity: .35; cursor: default; }
.tb-sep { width: 1px; background: var(--line); margin: 4px 4px; }
.editor-scroll { flex: 1; overflow-y: auto; padding: 20px clamp(16px, 5vw, 56px) 40px; }
.title-input { width: 100%; border: 0; background: transparent; font-size: 1.8rem; font-weight: 750; padding: 0; outline: none; }
.title-input::placeholder { color: var(--muted); opacity: .6; }
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 16px; }
.tag-chips { display: contents; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 2px 10px; font-size: .82rem; font-weight: 600; }
.chip button { color: inherit; font-size: 1rem; line-height: 1; }
.tag-input { border: 0; background: transparent; font-size: .85rem; min-width: 140px; outline: none; padding: 2px 0; }
.note-dates { font-size: .78rem; margin-top: 32px; }
.editor-empty { display: grid; place-items: center; position: absolute; inset: 0; color: var(--muted); background: var(--panel); }
.editor.has-note .editor-empty { display: none; }
.editor:not(.has-note) .editor-head, .editor:not(.has-note) .toolbar, .editor:not(.has-note) .editor-scroll { visibility: hidden; }

/* ---------- Contenido de la nota ---------- */
.prose { outline: none; min-height: 40vh; font-size: 1rem; line-height: 1.6; overflow-wrap: anywhere; }
.prose > * + * { margin-top: .6em; }
.prose p { margin: 0; }
.prose h1, .prose h2, .prose h3 { line-height: 1.25; margin: 1.1em 0 .3em; }
.prose h1 { font-size: 1.6rem; } .prose h2 { font-size: 1.3rem; } .prose h3 { font-size: 1.1rem; }
.prose a { color: var(--accent); }
.prose ul, .prose ol { padding-left: 1.5em; margin: .4em 0; }
.prose blockquote { border-left: 3px solid var(--line); margin: .6em 0; padding-left: 1em; color: var(--muted); }
.prose code { background: var(--code-bg); border-radius: 4px; padding: .1em .3em; font-size: .9em; }
.prose pre { background: var(--code-bg); border-radius: 6px; padding: 12px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose mark { background: var(--mark); color: inherit; border-radius: 2px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; }
.prose img.ProseMirror-selectednode { outline: 2px solid var(--accent); }
.prose ul[data-type='taskList'] { list-style: none; padding-left: .2em; }
.prose ul[data-type='taskList'] li { display: flex; gap: .5em; align-items: flex-start; }
.prose ul[data-type='taskList'] li > label { flex: none; margin-top: .2em; }
.prose ul[data-type='taskList'] li > div { flex: 1; }
.prose ul[data-type='taskList'] li[data-checked='true'] > div { text-decoration: line-through; color: var(--muted); }
.prose ul[data-type='taskList'] input { width: 16px; height: 16px; accent-color: var(--accent); }
.prose table { border-collapse: collapse; width: 100%; table-layout: fixed; margin: .8em 0; overflow: hidden; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; position: relative; }
.prose th { background: var(--bg); font-weight: 650; text-align: left; }
.prose .selectedCell::after { content: ''; position: absolute; inset: 0; background: var(--accent-soft); opacity: .5; pointer-events: none; }
.prose .tableWrapper { overflow-x: auto; }
.prose p.is-editor-empty:first-child::before { content: attr(data-placeholder); color: var(--muted); opacity: .6; float: left; height: 0; pointer-events: none; }

/* ---------- Diálogos, menús y avisos ---------- */
.dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; background: var(--panel); color: var(--text); width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / .35); }
.dialog h2 { margin: 0 0 12px; font-size: 1.1rem; }
.dialog label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0; }
.dialog input { display: block; width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog.history { width: min(900px, calc(100vw - 32px)); }
.history-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 16px; height: min(60vh, 560px); }
.history-list { overflow-y: auto; border-right: 1px solid var(--line); padding-right: 8px; }
.history-list ul { list-style: none; margin: 0; padding: 0; }
.history-list button { display: block; width: 100%; text-align: left; padding: 8px; border-radius: 6px; font-size: .88rem; }
.history-list button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list button:hover { background: var(--bg); }
.history-list button.active { background: var(--accent-soft); }
.history-preview { overflow-y: auto; }
.history-preview .prose { min-height: 0; }
.menu { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); padding: 4px; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 5px; color: var(--text); }
.menu button:hover, .menu button:focus { background: var(--bg); outline: none; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- Pantallas medianas y celular ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 220px 280px 1fr; }
}
@media (max-width: 899px) {
  .app { display: block; }
  .sidebar, .list, .editor { height: 100dvh; display: none; }
  .app[data-view='sidebar'] .sidebar { display: flex; }
  .app[data-view='list'] .list { display: flex; }
  .app[data-view='editor'] .editor { display: flex; }
  .only-mobile { display: inline-grid; }
  .more { opacity: 1; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; }
  .editor-head { padding: 6px 8px; gap: 2px; }
  .editor-head select { max-width: none; flex: 1 1 0; }
  .save-status { flex: 0 0 auto; font-size: .72rem; }
  .history-wrap { grid-template-columns: 1fr; grid-template-rows: 160px 1fr; }
  .history-list { border-right: 0; border-bottom: 1px solid var(--line); }
}
