/* ---------- theme tokens (dark by default, like Joplin's dark theme) ---------- */
:root {
  --side-bg: #1f2125;
  --side-text: #d6d8dc;
  --side-muted: #8b9098;
  --side-active: #26467e;
  --list-bg: #2b2e34;
  --list-border: #3a3e46;
  --list-active: #4a4e57;
  --bg: #1b1c1f;
  --surface: #22242a;
  --text: #e3e5e8;
  --muted: #9097a1;
  --border: #383c44;
  --accent: #7b8ef0;
  --accent-text: #0f1220;
  --link: #8ea2ff;
  --danger: #ef6b6b;
  --warn-bg: #3a2f12;
  --warn-text: #f2d48a;
  --code-bg: #2a2d34;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --side-bg: #2f343d;
    --side-text: #e8eaee;
    --side-muted: #a3a9b3;
    --side-active: #4a6fb5;
    --list-bg: #f2f3f5;
    --list-border: #dfe2e6;
    --list-active: #d8dce3;
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #6b7280;
    --border: #e1e4e8;
    --accent: #4a6fe0;
    --accent-text: #ffffff;
    --link: #2f5bd8;
    --danger: #c62828;
    --warn-bg: #fff6e0;
    --warn-text: #7a5300;
    --code-bg: #f3f4f6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: .45rem .6rem; border-radius: 6px; }

/* ---------- controls ---------- */
input, textarea, select, button { font: inherit; color: inherit; }
.btn {
  border: 1px solid transparent; border-radius: 4px; padding: .35rem .75rem;
  background: transparent; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.ghost { color: var(--side-muted); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  border: 1px solid transparent; background: transparent; border-radius: 4px;
  padding: .25rem .5rem; cursor: pointer; color: inherit; line-height: 1;
}
.icon-btn:hover, .btn.ghost:hover { background: rgba(127,127,127,.15); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 22rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem;
}
.login-card h1 { margin: 0 0 .25rem; font-size: 1.3rem; }
.login-card label { display: block; margin: .8rem 0; }
.login-card input {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 260px minmax(0, 1fr);
  height: 100vh; height: 100dvh;
}

/* sidebar */
.sidebar {
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar nav { flex: 1; overflow-y: auto; padding-bottom: .5rem; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem .9rem .4rem;
}
.tags-head { margin-top: 1rem; }
.side-title { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: .8rem; letter-spacing: .03em; }
.side-title svg { width: 16px; height: 16px; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-item {
  width: 100%; display: flex; align-items: center; gap: .5rem;
  border: 0; background: transparent; color: var(--side-text); cursor: pointer;
  padding: .4rem .9rem; text-align: left;
}
.side-item:hover { background: rgba(255,255,255,.06); }
.side-item.active { background: var(--side-active); }
.side-icon { width: 1.1rem; text-align: center; color: var(--side-muted); flex: none; }
.side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--side-muted); font-size: .8rem; }
.side-foot { padding: .75rem .9rem; display: grid; gap: .45rem; border-top: 1px solid rgba(255,255,255,.06); }
.side-foot .btn.outline { color: var(--side-text); border-color: var(--side-muted); }

/* note list */
.notelist {
  background: var(--list-bg); border-right: 1px solid var(--list-border);
  display: flex; flex-direction: column; min-height: 0;
}
.list-actions { display: flex; gap: .4rem; padding: .7rem .7rem .4rem; align-items: center; }
.list-actions .btn { flex: 1; padding: .35rem .4rem; }
.list-search { display: flex; gap: .3rem; padding: 0 .7rem .5rem; }
.list-search input {
  flex: 1; min-width: 0; padding: .35rem .5rem;
  background: var(--bg); border: 1px solid var(--list-border); border-radius: 4px;
}
.list-heading { padding: 0 .9rem .3rem; }
.notes { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.note-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .9rem; border-bottom: 1px solid var(--list-border);
  cursor: pointer; user-select: none;
}
.note-item:hover { background: rgba(127,127,127,.1); }
.note-item.active { background: var(--list-active); }
.note-item .n-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item.done .n-title { text-decoration: line-through; color: var(--muted); }
.note-item .todo-box { margin: 0; }
.empty { padding: 1rem; }

/* progress ring for notes containing checkboxes */
.ring { width: 18px; height: 18px; flex: none; }
.ring circle { fill: none; stroke-width: 2.2; }
.ring .track { stroke: var(--muted); opacity: .9; }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }

.todo-box {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 16px; height: 16px; border: 1.5px solid var(--muted); border-radius: 50%;
  display: inline-grid; place-content: center; cursor: pointer; margin: 0;
}
.todo-box:checked { background: var(--accent); border-color: var(--accent); }
.todo-box:checked::after { content: "✓"; font-size: 11px; color: var(--accent-text); line-height: 1; }

/* editor */
.editor { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.editor-empty { margin: auto; }
.editor-inner { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.editor-head { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem .3rem; }
.title-input {
  flex: 1; min-width: 0; font-size: 1.25rem; font-weight: 600;
  border: 0; background: transparent; outline: none; padding: .2rem 0;
}
.toolbar {
  display: flex; align-items: center; gap: .5rem;
  margin: 0 1rem; padding: .3rem .5rem; background: var(--surface); border-radius: 4px;
}
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: .2rem .55rem; cursor: pointer; font-size: .8rem; }
.seg button.active { background: var(--accent); color: var(--accent-text); }

.panes { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; padding: .6rem 1rem 0; gap: 1rem; }
.panes[data-layout="editor"] { grid-template-columns: 1fr; }
.panes[data-layout="editor"] .preview { display: none; }
.panes[data-layout="viewer"] { grid-template-columns: 1fr; }
.panes[data-layout="viewer"] textarea { display: none; }
#body-input {
  resize: none; border: 0; outline: none; background: transparent; min-height: 0;
  font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 0 .25rem;
  border-right: 1px solid var(--border);
}
.panes[data-layout="editor"] #body-input { border-right: 0; }
.preview { overflow-y: auto; min-height: 0; padding: 0 .25rem 2rem; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.editor-foot { padding: .5rem 1rem; border-top: 1px solid var(--border); }

/* rendered markdown */
.preview a { color: var(--link); }
.preview p { margin: 0 0 .6rem; }
.preview h1, .preview h2, .preview h3 { margin: 1rem 0 .5rem; line-height: 1.25; }
.preview h1 { font-size: 1.5rem; } .preview h2 { font-size: 1.25rem; } .preview h3 { font-size: 1.1rem; }
.preview img { max-width: 100%; height: auto; }
.preview code { background: var(--code-bg); padding: .1rem .3rem; border-radius: 3px; font-size: .9em; }
.preview pre { background: var(--code-bg); padding: .7rem; border-radius: 4px; overflow-x: auto; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin: 0 0 .6rem; padding-left: .8rem; border-left: 3px solid var(--border); color: var(--muted); }
.preview table { border-collapse: collapse; margin-bottom: .6rem; display: block; overflow-x: auto; }
.preview th, .preview td { border: 1px solid var(--border); padding: .3rem .5rem; }
.preview ul, .preview ol { padding-left: 1.4rem; margin: 0 0 .6rem; }
.preview li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.3rem; }
.preview li > input[type="checkbox"] { margin: 0 .45rem 0 0; vertical-align: -2px; accent-color: var(--accent); width: 15px; height: 15px; }
.preview li > input[type="checkbox"]:enabled { cursor: pointer; }
.preview li:has(> input[type="checkbox"]:checked) { color: var(--muted); text-decoration: line-through; }

/* ---------- responsive ---------- */
.only-mobile { display: none; }
@media (max-width: 1100px) {
  .app { grid-template-columns: 210px 230px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .only-mobile { display: inline-block; }
  .hide-narrow { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(80vw, 280px); z-index: 20;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .app.sidebar-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; display: none; }
  .app.sidebar-open .scrim { display: block; }
  .app[data-pane="list"] .editor { display: none; }
  .app[data-pane="note"] .notelist { display: none; }
  .notelist { border-right: 0; }
  .panes { grid-template-columns: 1fr; padding: .6rem 16px 0; }
  .editor-head { padding: .6rem 16px .3rem; }
  .toolbar { margin: 0 16px; }
  .editor-foot { padding: .5rem 16px; }
  #body-input { border-right: 0; }
}

.ico { width: 15px; height: 15px; vertical-align: -2px; }
.login-logo { width: 28px; height: 28px; vertical-align: -6px; margin-right: .3rem; }
