:root {
  --burgundy: #3C101D;
  --burgundy-2: #4E1A2A;
  --burgundy-3: #66283B;
  --gold: #C09A24;
  --gold-soft: #E6D6A0;
  --cream: #F9F5EA;
  --cream-2: #F2ECDA;
  --cream-3: #E8E0C8;
  --ink: #2E2E2E;
  --muted: #7A6E66;
  --danger: #9B2C2C;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font: 400 15px/1.5 'Roboto', system-ui, -apple-system, sans-serif; color: var(--ink); background: var(--cream); overflow: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.btn-gold { background: var(--gold); color: var(--burgundy); border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-gold:hover { background: #CDA832; }
.btn-gold.wide { width: 100%; }
.icon-btn { background: none; border: 0; border-radius: 8px; padding: 6px; display: inline-grid; place-items: center; color: var(--burgundy); }
.icon-btn:hover { background: var(--cream-3); }
.icon-btn.txt { font-size: 13px; font-weight: 500; padding: 6px 10px; }
.icon-btn.on { color: var(--gold); background: var(--burgundy); }
.mobile-only { display: none; }

/* Login */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--burgundy); padding: 24px; }
#loginForm { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; color: var(--cream); }
.login-logo { width: 84px; height: 84px; margin: 0 auto; border-radius: 18px; }
#loginForm h1 { margin: 4px 0 0; font-weight: 700; font-size: 28px; }
#loginForm h1 span, .brand span { color: var(--gold); font-weight: 300; }
#loginForm p { margin: 0 0 12px; font-weight: 300; opacity: .8; }
#loginForm input { background: var(--cream); border: 2px solid transparent; border-radius: 8px; padding: 12px 14px; outline: none; color: var(--ink); }
#loginForm input:focus { border-color: var(--gold); }
.err { min-height: 20px; color: #F0B4B4; font-size: 14px; }

/* Layout */
#app { display: grid; grid-template-columns: 250px 330px 1fr; height: 100%; }
#sidebar { background: var(--burgundy); color: var(--cream); display: flex; flex-direction: column; padding: calc(16px + var(--sat)) 12px calc(12px + var(--sab)); gap: 14px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 6px; }
.brand img { border-radius: 8px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-title { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 0 10px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); font-weight: 500; min-height: 16px; }
.nav-title button { background: none; border: 0; color: var(--gold); font-size: 18px; line-height: 1; padding: 0 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; color: var(--cream); padding: 8px 10px; border-radius: 8px; font-weight: 300; }
.nav-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item em { font-style: normal; font-size: 12px; opacity: .6; }
.nav-item:hover { background: var(--burgundy-2); }
.nav-item.active { background: var(--burgundy-3); font-weight: 500; box-shadow: inset 3px 0 0 var(--gold); }
.nav-item .dots { opacity: 0; background: none; border: 0; color: var(--gold); padding: 0 4px; }
.nav-item:hover .dots { opacity: 1; }
.side-foot { display: flex; justify-content: space-between; font-size: 13px; padding: 0 6px; }
.side-foot a, .side-foot button { color: var(--gold-soft); background: none; border: 0; padding: 0; text-decoration: none; font-weight: 300; }

#list { background: var(--cream-2); border-right: 1px solid var(--cream-3); display: flex; flex-direction: column; min-height: 0; }
#list header { display: flex; align-items: center; gap: 6px; padding: calc(14px + var(--sat)) 16px 6px; }
#list h2 { margin: 0; flex: 1; font-size: 20px; font-weight: 700; color: var(--burgundy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { margin: 6px 14px; display: flex; align-items: center; gap: 8px; background: var(--cream); border: 1px solid var(--cream-3); border-radius: 8px; padding: 0 10px; color: var(--muted); }
.search:focus-within { border-color: var(--gold); }
.search input { flex: 1; border: 0; background: none; outline: none; padding: 9px 0; min-width: 0; }
.count { padding: 4px 18px; font-size: 12px; color: var(--muted); font-weight: 300; }
#notes { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#notes li { padding: 12px 18px; border-bottom: 1px solid var(--cream-3); cursor: pointer; }
#notes li:hover { background: var(--cream-3); }
#notes li.active { background: var(--cream); box-shadow: inset 4px 0 0 var(--gold); }
#notes .t { font-weight: 700; color: var(--burgundy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; }
#notes .t .pin { color: var(--gold); }
#notes .s { font-size: 13px; color: #5d544e; font-weight: 300; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; margin: 2px 0 4px; }
#notes .m { font-size: 11px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
#notes .tg { color: var(--gold); font-weight: 500; }
.link-danger { margin: 8px 18px calc(12px + var(--sab)); background: none; border: 0; color: var(--danger); text-align: left; font-size: 13px; }

/* Editor */
#editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--cream); }
.empty { margin: auto; text-align: center; color: var(--muted); font-weight: 300; }
.empty img { opacity: .25; border-radius: 16px; }
#pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ed-top { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--sat)) 14px 8px; border-bottom: 1px solid var(--cream-3); }
.spacer { flex: 1; }
#nbSel { background: var(--cream-2); border: 1px solid var(--cream-3); border-radius: 8px; padding: 5px 8px; color: var(--burgundy); font-weight: 500; max-width: 180px; }
.status { font-size: 12px; color: var(--muted); font-weight: 300; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px 14px; border-bottom: 1px solid var(--cream-3); background: var(--cream-2); }
.toolbar button { min-width: 32px; height: 32px; border: 0; background: none; border-radius: 6px; color: var(--burgundy); }
.toolbar button:hover { background: var(--cream-3); }
.toolbar button.active { background: var(--burgundy); color: var(--gold); }
.toolbar .hl { background: var(--gold-soft); font-weight: 700; }
.toolbar i { width: 1px; height: 20px; background: var(--cream-3); margin: 0 4px; }
.title { border: 0; background: none; outline: none; font: 700 28px/1.2 'Roboto', sans-serif; color: var(--burgundy); padding: 18px 28px 4px; width: 100%; }
.title::placeholder { color: #CFC5A6; }
.tags-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 28px 8px; align-items: center; }
.chip { background: var(--cream-3); color: var(--burgundy); border-radius: 99px; padding: 2px 6px 2px 10px; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.chip button { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: 14px; line-height: 1; }
.tags-bar input { border: 0; background: none; outline: none; font-size: 13px; min-width: 110px; padding: 3px 0; }
.body { flex: 1; overflow-y: auto; padding: 8px 28px calc(60px + var(--sab)); outline: none; font-size: 16px; line-height: 1.65; word-break: break-word; }
.body:empty::before { content: 'Empieza a escribir…'; color: #BDB293; }
.body h1 { font-size: 26px; color: var(--burgundy); margin: 1em 0 .3em; }
.body h2 { font-size: 20px; font-weight: 300; color: var(--burgundy); margin: 1em 0 .3em; }
.body p, .body div { margin: 0 0 .5em; }
.body blockquote { margin: .6em 0; padding: 2px 14px; border-left: 4px solid var(--gold); color: #5d544e; }
.body pre, .body code { background: var(--cream-3); border-radius: 4px; font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
.body code { padding: 1px 5px; }
.body pre { padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; }
.body img { max-width: 100%; height: auto; border-radius: 6px; }
.body a { color: var(--burgundy); text-decoration-color: var(--gold); text-underline-offset: 3px; }
.body mark { background: var(--gold-soft); color: inherit; padding: 0 2px; border-radius: 2px; }
.body hr { border: 0; border-top: 2px solid var(--cream-3); margin: 1.2em 0; }
.body ul.todo { list-style: none; padding-left: 4px; }
.body ul.todo li { position: relative; padding-left: 30px; }
.body ul.todo li::before { content: ''; position: absolute; left: 4px; top: .42em; width: 16px; height: 16px; border: 2px solid var(--burgundy); border-radius: 4px; cursor: pointer; }
.body ul.todo li.done { color: var(--muted); text-decoration: line-through; }
.body ul.todo li.done::before { background: var(--gold); border-color: var(--gold); }
.body ul.todo li.done::after { content: ''; position: absolute; left: 8px; top: .5em; width: 4px; height: 8px; border: solid var(--burgundy); border-width: 0 2px 2px 0; transform: rotate(40deg); }
.body[contenteditable=false] { opacity: .75; }

#toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translate(-50%, 20px); background: var(--burgundy); color: var(--cream); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; font-size: 14px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Tablet y móvil: un panel cada vez */
@media (max-width: 1000px) {
  #app { display: block; position: relative; }
  #sidebar, #list, #editor { position: absolute; inset: 0; width: 100%; transition: transform .22s ease; }
  #sidebar { z-index: 3; transform: translateX(-100%); }
  #editor { z-index: 2; transform: translateX(100%); }
  body[data-pane=sidebar] #sidebar { transform: none; }
  body[data-pane=editor] #editor { transform: none; }
  .mobile-only { display: inline-grid; }
  .title { font-size: 24px; padding: 14px 16px 4px; }
  .tags-bar { padding: 4px 16px 8px; }
  .body { padding: 8px 16px calc(60px + var(--sab)); }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; padding: 6px 10px; }
  .ed-top { padding-left: 6px; }
  .nav-item { padding: 12px 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* notas de voz */
[data-voice] { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; padding: 8px 12px; background: var(--cream-2); border: 1px solid var(--cream-3); border-left: 4px solid var(--gold); border-radius: 8px; user-select: none; }
[data-voice] audio { flex: 1; min-width: 200px; height: 36px; }
[data-voice] a { color: var(--burgundy); font-size: 13px; font-weight: 500; }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 8px 18px; background: var(--burgundy); color: var(--cream); }
.rec-bar[hidden] { display: none; }
.rec-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: #e0453a; animation: recpulse 1s infinite; }
.rec-bar .rec-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 300; color: var(--gold-soft); }
.rec-bar .icon-btn { color: var(--gold-soft); }
.rec-bar .btn-gold { padding: 6px 12px; }
@keyframes recpulse { 50% { opacity: .25; } }
.rec-bar.paused .dot { animation: none; background: var(--gold); }
.rec-bar { flex-wrap: wrap; }
[data-voice] span { font-size: 12px; font-weight: 500; color: var(--muted); }
