:root {
  --bg: #f6f5fb; --panel: #ffffff; --ink: #1c1b2e; --muted: #6b6a80; --line: #e4e2f0;
  --accent: #5b4fcf; --accent-ink: #ffffff; --warn-bg: #fff6d8; --warn-ink: #6a4b00; --danger: #c43d3d; --ok: #1f8a4c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #141320; --panel: #1e1d2c; --ink: #eceaf6; --muted: #a09fb5; --line: #2d2c3f; --warn-bg: #3a3012; --warn-ink: #ffd872; }
}
:root[data-theme="dark"] { --bg: #141320; --panel: #1e1d2c; --ink: #eceaf6; --muted: #a09fb5; --line: #2d2c3f; --warn-bg: #3a3012; --warn-ink: #ffd872; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.search { flex: 1; max-width: 420px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.status { margin-left: auto; color: var(--muted); font-size: 13px; }
#main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.gate { max-width: 560px; margin: 48px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.gate h1 { margin: 0 0 10px; font-size: 24px; }
.gate label { display: grid; gap: 6px; margin: 16px 0 8px; font-weight: 600; }
.gate input { padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.error { color: var(--danger); margin-top: 10px; min-height: 1em; }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button[type="submit"], #save { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
#app { display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.sidebar { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 64px; align-self: start; }
.sidebar button { text-align: left; border: none; background: transparent; padding: 8px 10px; }
.sidebar button.active { background: var(--accent); color: var(--accent-ink); }
.sidebar .subtle { color: var(--muted); font-size: 13px; }
.sidebar .spacer { flex: 1; min-height: 24px; }
.view { min-width: 0; }
.view h2 { margin: 4px 0 12px; }
.muted { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; max-height: 75vh; overflow-y: auto; }
.list li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: none; }
.list li.sel { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta, .entry .meta, .task .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.editor { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 60vh; display: flex; flex-direction: column; gap: 10px; }
.editor-bar { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.editor textarea { flex: 1; min-height: 50vh; border: none; resize: vertical; background: transparent; color: var(--ink); font: inherit; outline: none; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.tasks li { cursor: default; }
.task label { display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.task.done span { text-decoration: line-through; color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }
.entry { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.entry h3 { margin: 6px 0; }
.entry p { margin: 6px 0 0; white-space: pre-wrap; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.num.in { color: var(--ok); }
.capture { display: grid; gap: 10px; max-width: 640px; }
.capture input, .capture textarea { padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer { display: none; }
  .split { grid-template-columns: 1fr; }
  .list { max-height: 40vh; }
  .status { display: none; }
}
