/* Todo Notes - app components on top of styles.css (CI). Tokens only, no raw colors.
   The workspace uses the full window width: folders and notes (one tree) | the open note. Phones show one pane at a time. */

[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.grow { flex: 1; }
.small { font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.btn.sm { padding: 4px 10px; font-size: 13.5px; }
.btn.danger, .btn.primary.danger { background: var(--danger); border-color: var(--danger); color: var(--panel); }
.danger-text { color: var(--danger); }
.btn.disabled { opacity: .45; pointer-events: none; }
a.btn { display: inline-block; text-decoration: none; text-align: center; }
input[type="search"] {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%;
}
.btn.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 7px 9px; align-self: stretch; }
.btn.icon-btn.ghost { align-self: auto; background: transparent; border-color: transparent; padding: 4px 6px; color: var(--muted); }
.btn.icon-btn.ghost:hover { color: var(--text); border-color: var(--border); background: var(--panel-2); }
.ico { display: block; flex: none; }

/* ---------- Header ---------- */
.app-top { padding-bottom: 10px; }
.app-top.wide { max-width: none; width: 100%; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 8px; display: block; }
.userbox { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.user-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ---------- Pages (users) ---------- */
.page { max-width: 1040px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 4px; }
.page-head h1 { font-size: clamp(26px, 4vw, 34px); }
.page.narrow { max-width: 900px; }
.table-wrap { overflow-x: auto; }
.add-user { align-items: flex-end; }
.add-user .field { flex: 1 1 260px; }
.add-user .check { padding-bottom: 8px; }
table.users { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.users td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.u-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.u-email { overflow-wrap: anywhere; }

/* ---------- Login ---------- */
.login-main { display: grid; place-items: center; min-height: calc(100vh - 140px); }
.login-card { max-width: 440px; width: 100%; text-align: center; display: grid; gap: 12px; justify-items: center; padding: 30px 26px; }
.login-mark { border-radius: 16px; }
.login-btn { width: 100%; padding: 10px 14px; }
.setup { text-align: left; width: 100%; }
.setup-list { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }

/* ---------- Workspace ---------- */
body.workspace-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.workspace {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 12px;
  padding: 0 16px 16px;
}
.pane { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 8px 16px; }
.pane-head h2 { font-size: 17px; overflow-wrap: anywhere; }
.pane-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn.with-icon { display: inline-flex; align-items: center; gap: 5px; }
.btn.icon-only { display: inline-flex; align-items: center; padding: 4px 8px; }
.pane-note { padding: 8px 16px; }
.pane-tabs { display: none; margin: 0 16px 10px; }
.pane-tabs button { flex: 1; }

/* the tree of folders and notes */
.tree-tools { display: flex; align-items: center; gap: 12px; padding: 0 12px 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tree-tools input[type="search"] { flex: 1 1 140px; }
.tree-scroll { flex: 1; min-height: 0; overflow-y: auto; }
#tree { list-style: none; margin: 0; padding: 6px 6px 14px; min-height: 40px; }
#tree.drop-end { box-shadow: inset 0 -3px 0 var(--tone); }
.node {
  display: flex; align-items: center; gap: 6px; min-height: 36px; border: 1px solid transparent; border-radius: 9px; cursor: pointer;
  padding: 3px 4px 3px calc(4px + var(--depth, 0) * 20px);
}
.node:hover { background: var(--panel-2); }
.node.sel { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.node.open:not(.sel) { background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.node.open .title { font-weight: 600; }
.node.item-folder .title { font-weight: 600; }
.folder-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 17px; color: var(--fc); }
.folder-icon svg { fill: currentColor; }   /* folders are solid, not just an outline */
.note-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 17px; color: var(--muted); }
.fc-red { --fc: var(--fc-red); }
.fc-orange { --fc: var(--fc-orange); }
.fc-yellow { --fc: var(--fc-yellow); }
.fc-green { --fc: var(--fc-green); }
.fc-teal { --fc: var(--fc-teal); }
.fc-blue { --fc: var(--fc-blue); }
.fc-purple { --fc: var(--fc-purple); }
.fc-pink { --fc: var(--fc-pink); }
.fc-gray { --fc: var(--fc-gray); }

/* the color picker of a folder */
.skipped { margin: 0; padding-left: 20px; max-height: 40vh; overflow: auto; font-size: 14px; overflow-wrap: anywhere; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 2px; }
.swatch { position: relative; display: inline-flex; cursor: pointer; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch .dot { width: 30px; height: 30px; border-radius: 50%; background: var(--fc); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--border); }
.swatch.none .dot { background: var(--panel-2); border-color: var(--border); box-shadow: none; display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.swatch input:checked + .dot { box-shadow: 0 0 0 3px var(--text); }
.swatch input:focus-visible + .dot { outline: 2px solid var(--focus); outline-offset: 3px; }

.node .count { font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: right; }
.node .path { max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.node .title { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
.node.item-task { cursor: pointer; }
.node.item-task .title { font-size: .95em; }
.node.done .title { color: var(--muted); text-decoration: line-through; }
.node .meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; flex: none; }
.node .has-notes { display: inline-flex; }
.progress { font-variant-numeric: tabular-nums; font-weight: 600; }
.progress.all { color: var(--tone-text); }
.twisty, .twisty-gap { flex: none; width: 22px; height: 22px; }
.twisty { display: inline-flex; align-items: center; justify-content: center; background: none; border: 0; border-radius: 6px; color: var(--muted); cursor: pointer; padding: 0; }
.twisty:hover { background: var(--border); color: var(--text); }
.chk { flex: none; width: 17px; height: 17px; margin: 0; accent-color: var(--tone); cursor: pointer; }
.node .row-add, .node .row-more { opacity: 0; flex: none; }
.node:hover .row-add, .node:hover .row-more, .node:focus-within .row-add, .node:focus-within .row-more,
.node.sel .row-add, .node.sel .row-more { opacity: 1; }
@media (hover: none) { .node .row-add, .node .row-more { opacity: 1; } }
input.rename {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--tone);
  border-radius: 7px; padding: 4px 8px;
}
.node.adder { cursor: default; }
.node.adder:hover { background: none; }
.node.result .title { cursor: pointer; }
.empty-state { text-align: center; padding: 36px 20px; display: grid; gap: 12px; justify-items: center; }

/* drag and drop markers */
.dragging { opacity: .45; }
.node.drop-before { box-shadow: inset 0 3px 0 var(--tone); }
.node.drop-after { box-shadow: inset 0 -3px 0 var(--tone); }
.node.drop-inside { background: color-mix(in srgb, var(--tone) 18%, var(--panel)); border-color: var(--tone); }

/* ---------- Notes ---------- */
.notes-pane { position: relative; }
.note { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 12px; container: note / inline-size; }
.note-head { display: flex; align-items: center; gap: 10px; }
input.note-title {
  flex: 1; min-width: 0; font: inherit; font-size: 21px; font-weight: 700; letter-spacing: -.01em; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 3px 8px;
}
input.note-title:hover { border-color: var(--border); }
input.note-title:focus { background: var(--panel-2); border-color: var(--border); }
.crumbs { margin-top: -6px; padding-left: 8px; overflow-wrap: anywhere; }
.crumbs:empty { display: none; }
.banner {
  padding: 8px 12px; border-radius: 10px; display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  font-weight: 600; font-size: 14px;
}
.banner span { flex: 1 1 220px; }
.note-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.btn.tb { min-width: 32px; height: 30px; padding: 0 7px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.tb-bold { font-weight: 800; }
.tb-italic { font-style: italic; font-weight: 700; }
.tb-strike { text-decoration: line-through; font-weight: 700; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.note-body { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 10px; border-radius: 12px; }
.note-body.drop { outline: 2px dashed var(--tone); outline-offset: 3px; }
.note-body[data-mode="edit"] .note-preview, .note-body[data-mode="preview"] .note-text { display: none; }
.note-body[data-mode="split"] { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
@container note (min-width: 700px) {
  .note-body[data-mode="split"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
}
.note-text {
  width: 100%; height: 100%; resize: none; font: 14px/1.6 ui-monospace, "Cascadia Code", Consolas, "SF Mono", monospace; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; tab-size: 2;
  font-variant-ligatures: none;   /* -- and -> must look like what is typed */
}
.note-preview { overflow: auto; border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; background: var(--panel); min-width: 0; }
.note-foot { display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
#save-state.error { color: var(--danger); font-weight: 600; }

/* rendered Markdown (markdown.js) */
.md { overflow-wrap: anywhere; line-height: 1.6; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.1em 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
.md h1 { font-size: 1.55em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md .table-wrap { margin: 0 0 .75em; }
.md ul, .md ol { padding-left: 1.5em; }
.md li > ul, .md li > ol { margin: .15em 0 .15em; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md li.task > input { margin: 0 .5em 0 0; accent-color: var(--tone); vertical-align: -1px; }
.md code { font: .9em ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: .05em .35em; }
.md pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; font-size: 13px; }
.md blockquote { border-left: 4px solid var(--accent); background: var(--panel-2); border-radius: 0 8px 8px 0; padding: .4em 1em; color: var(--muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md table { border-collapse: collapse; font-size: .95em; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md th { background: var(--panel-2); text-align: left; }
.md .al-center { text-align: center; } .md .al-right { text-align: right; }
.md img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); display: block; }
.md a.md-image { display: inline-block; vertical-align: bottom; }
.md a.md-external { text-decoration-style: dotted; }
.md del { color: var(--muted); }
.md pre.md-frontmatter { color: var(--muted); font-size: .85em; }
.md a.wikilink { text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); font-weight: 600; }
.md a.wikilink:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.md .wikilink.missing { color: var(--muted); border-bottom: 1px dashed var(--muted); cursor: pointer; }
.md .wikilink.missing:hover, .md .wikilink.missing:focus-visible { color: var(--text); }

.md button.secret {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; vertical-align: bottom; text-align: left; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 0 9px;
}
.md button.secret:hover { border-color: var(--accent); }

/* the list that opens while typing [[ */
.suggest { position: absolute; z-index: 20; width: min(340px, calc(100% - 8px)); max-height: 260px; overflow-y: auto; padding: 4px; box-shadow: var(--shadow); }
.suggest-item { display: flex; flex-direction: column; padding: 6px 9px; border-radius: 7px; cursor: pointer; overflow-wrap: anywhere; }
.suggest-item.on, .suggest-item:hover { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.suggest-title { font-weight: 600; }

/* ---------- Dialogs, menu, toast ---------- */
dialog.dlg { width: min(480px, calc(100vw - 32px)); color: var(--text); padding: 20px 22px; max-height: calc(100vh - 32px); }
dialog.dlg::backdrop { background: rgb(0 0 0 / .4); }
.dlg-form { display: grid; gap: 12px; }
.dlg .field input, .dlg .field select, .dlg .field textarea { width: 100%; }
.dlg-fields { display: grid; gap: 12px; }
.dlg .field input[type="password"], .dlg .field textarea {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.dlg .field textarea { font: 14px/1.5 ui-monospace, "Cascadia Code", Consolas, "SF Mono", monospace; resize: vertical; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: var(--panel); }
.ctx-menu { position: fixed; z-index: 60; min-width: 200px; padding: 5px; display: grid; gap: 1px; border-radius: 10px; box-shadow: var(--shadow); }
.ctx-item {
  font: inherit; font-size: 14px; text-align: left; padding: 7px 10px; border: 0; border-radius: 7px;
  background: none; color: var(--text); cursor: pointer; white-space: nowrap;
}
.ctx-item:disabled { opacity: .4; cursor: default; }
.ctx-item.danger-text { color: var(--danger); }
.ctx-item:not(:disabled):hover, .ctx-item:focus-visible { background: var(--panel-2); outline: none; }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* ---------- Narrower screens ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .pane-tabs { display: flex; }
  .workspace > .pane { display: none; }
  .workspace[data-pane="folders"] > .folders-pane,
  .workspace[data-pane="notes"] > .notes-pane { display: flex; }
}
@media (max-width: 600px) {
  .user-name { display: none; }
  .workspace { padding: 0 8px 8px; }
  .pane-tabs { margin: 0 8px 8px; }
  .note { padding: 12px 10px 10px; }
  .crumbs { padding-left: 0; }
}

/* ---------- Settings and the sync bar ---------- */
.stack { display: grid; gap: 12px; }
.panel.stack { margin-top: 14px; }
.actions.left { justify-content: flex-start; }
.grow { flex: 1 1 220px; }
.crumb-line { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; color: var(--muted); }
.folder-list { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--border); border-radius: 10px; max-height: 280px; overflow: auto; display: grid; gap: 2px; }
.folder-list li { display: block; }
.btn.folder-item { width: 100%; justify-content: flex-start; text-align: left; }
.sync-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border-top: 1px solid var(--border); }
.sync-bar.busy { opacity: .6; pointer-events: none; }
.sync-bar .branch { max-width: 60%; }
.sync-bar .branch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--border); }
