/* ---------- design tokens (Holistics Docs system — design.md) ---------- */
:root {
  --bg: #FFFFFF;
  --surface: #F6F7F9;       /* slightly softer/darker than --bg for dialogs & popovers */
  --text: #212327;
  --text-soft: #727685;
  --text-faint: #505157;
  --border: #E3E7ED;
  --accent: #259B6C;
  --accent-hover: #196848;
  --accent-soft: #EAF8F2;
  --link: #1F815A;
  --info: #1B7CE4;
  --info-bg: #E8F2FD;
  --info-title: #05264C;
  --code-bg: #13151A;       /* pre background — stays dark in light mode */
  --code-fg: #E8EAE3;
  --code-inline: #F5F8FA;
  --danger: #E71F18;
  --radius: 6px;
  --sidebar-w: 300px;
  --font-ui: "InterVariable", "Inter", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191B1F;
    --surface: #222428;       /* slightly lighter/softer than --bg for dialogs & popovers */
    --text: #E8EAED;
    --text-soft: #989CA6;
    --text-faint: #D2D4D9;
    --border: #424347;
    --accent: #47CC97;
    --accent-hover: #8AE5C1;
    --accent-soft: #243830;
    --link: #77D9B2;
    --info: #6EB1F5;
    --info-bg: #252E47;
    --info-title: #B2D9FF;
    --code-bg: #292B2E;
    --code-fg: #E8EAE3;
    --code-inline: #2E3033;
    --danger: #F5837F;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ---------- inline icons ---------- */
.ico { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }

/* ---------- sidebar ---------- */
.sidebar {
  /* Flat — same background as the page, separated only by a hairline rule. */
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-ui);
  font-weight: 590;
  font-size: 18px;
  color: var(--text);
}
.brand-ico { width: 20px; height: 20px; color: var(--accent); }

.sidebar-header .icon-btn { color: var(--text-soft); }
.sidebar-header .icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- compact "+ New" + animated menu ---------- */
.new-wrap { position: relative; padding: 2px 12px 4px; }
.new-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.new-btn:hover, .new-btn.open { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.new-btn .ico { width: 16px; height: 16px; }
.new-btn .caret { width: 14px; height: 14px; opacity: 0.7; transition: transform 0.15s; }
.new-btn.open .caret { transform: rotate(180deg); }

.new-menu {
  position: absolute;
  top: calc(100% - 2px);
  left: 12px;
  min-width: 200px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}
.new-menu.open { opacity: 1; visibility: visible; transform: none; }
.new-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.new-menu-item:hover { background: var(--accent-soft); color: var(--accent); }
.new-menu-item .ico { width: 17px; height: 17px; color: var(--text-soft); }
.new-menu-item:hover .ico { color: var(--accent); }

/* ---------- organizer header ---------- */
.organizer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 2px;
}
.org-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.org-newfolder { color: var(--text-soft); padding: 5px; }
.org-newfolder:hover { background: var(--accent-soft); color: var(--accent); }
.org-newfolder .ico { width: 16px; height: 16px; }

/* ---------- import destination hint ---------- */
.import-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.import-hint-dest { color: var(--text-soft); font-weight: 600; }
.import-hint-clear {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font: inherit;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.import-hint-clear:hover { color: var(--text); }

/* ---------- search ---------- */
.sidebar-search { padding: 6px 12px 4px; position: relative; }
.search-ico {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}
.sidebar-search input {
  width: 100%;
  padding: 7px 12px 7px 36px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.sidebar-search input::placeholder { color: var(--text-faint); }
.sidebar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- note list ---------- */
.note-list { flex: 1; overflow-y: auto; padding: 6px 8px 8px; }

.note-list, .editor-scroll, .folder-list, .content-row, .tag-bar {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-faint) 35%, transparent) transparent;
}
.note-list::-webkit-scrollbar, .editor-scroll::-webkit-scrollbar, .folder-list::-webkit-scrollbar, .content-row::-webkit-scrollbar, .tag-bar::-webkit-scrollbar { width: 9px; }
.note-list::-webkit-scrollbar-track, .editor-scroll::-webkit-scrollbar-track, .folder-list::-webkit-scrollbar-track, .content-row::-webkit-scrollbar-track, .tag-bar::-webkit-scrollbar-track { background: transparent; }
.note-list::-webkit-scrollbar-thumb, .editor-scroll::-webkit-scrollbar-thumb, .folder-list::-webkit-scrollbar-thumb, .content-row::-webkit-scrollbar-thumb, .tag-bar::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-faint) 32%, transparent);
  border-radius: var(--radius);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.note-list::-webkit-scrollbar-thumb:hover, .editor-scroll::-webkit-scrollbar-thumb:hover, .folder-list::-webkit-scrollbar-thumb:hover, .content-row::-webkit-scrollbar-thumb:hover, .tag-bar::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-faint) 50%, transparent);
  background-clip: padding-box;
}

.note-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 8px 8px 8px 12px;
  margin-bottom: 2px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s;
}
.note-item:hover { background: var(--accent-soft); }
.note-item.active {
  background: var(--accent-soft);
}
.note-item.active .t { color: var(--accent); }
.note-main { flex: 1; min-width: 0; text-align: left; }
.note-item .t {
  display: block;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .p {
  display: block;
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-more {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 5px;
  border-radius: var(--radius);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s, background 0.12s, color 0.12s;
}
.note-item:hover .row-more, .row-more:focus-visible { opacity: 1; }
.row-more:hover { background: var(--accent-soft); color: var(--accent); }
.row-more .ico { width: 16px; height: 16px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

/* ---------- tag bar ---------- */
.tag-bar {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 7px;
  padding: 6px 12px 8px;
  max-height: 68px;   /* ~2 chip rows */
  overflow-y: auto;
}
.tag-bar.expanded { max-height: none; }
.tag-chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.tag-chip.tag-more {
  border-color: transparent;
  color: var(--text-faint);
  font-weight: 600;
}
.tag-chip.tag-more:hover { color: var(--accent); background: var(--accent-soft); }

/* ---------- folder tree (VS Code-style) ---------- */
.folder-head {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 6px 8px;
  margin-bottom: 1px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.folder-head:hover { background: var(--accent-soft); }
.folder-head .tri { flex: none; display: inline-flex; color: var(--text-faint); }
.folder-head .tri-ico { width: 14px; height: 14px; transition: transform 0.15s ease; }
.folder-head:not(.closed) .tri-ico { transform: rotate(90deg); }
.folder-head .fico { flex: none; display: inline-flex; color: var(--text-soft); }
.folder-head .fico .ico { width: 15px; height: 15px; }
.folder-head .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-head .fcount { color: var(--text-faint); font-weight: 500; font-size: 11.5px; }
.folder-head .row-target {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 3px;
  border-radius: var(--radius);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s, color 0.12s, background 0.12s;
}
.folder-head:hover .row-target { opacity: 0.8; }
.folder-head .row-target:hover { background: var(--accent-soft); color: var(--accent); }
.folder-head .row-target .ico { width: 15px; height: 15px; }
/* active import folder — doubled you-are-here signal */
.folder-head.active-folder { background: var(--accent-soft); color: var(--accent); }
.folder-head.active-folder .fico { color: var(--accent); }
.folder-head.active-folder .row-target { opacity: 1; color: var(--accent); }

.list-empty { padding: 16px 14px; font-size: 13px; color: var(--text-faint); }

/* ---------- buttons ---------- */
.new-note-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s;
}
.new-note-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.new-note-btn .ico { width: 16px; height: 16px; }

/* ---------- main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

/* Full-width bar, separated from the content below by a hairline rule.
   The hamburger is hidden on desktop (sidebar is always visible). */
.topbar {
  position: static;
  z-index: 15;
  display: none;              /* shown only when a note is open (.has-note) */
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.main.has-note .topbar { display: flex; }
/* actions/status only make sense with a note open */
.main:not(.has-note) .topbar-actions,
.main:not(.has-note) .save-status { display: none; }

.icon-btn.menu-btn { display: none; }

.save-status { font-size: 12px; color: var(--text-faint); font-weight: 500; padding: 0 4px; white-space: nowrap; }
.save-status:empty { display: none; }

.topbar-actions { display: flex; gap: 2px; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  line-height: 1;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-soft);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- content row (editor + TOC rail) ---------- */
.content-row { display: flex; flex: 1; min-height: 0; overflow-y: auto; }

/* ---------- editor ---------- */
.editor-scroll { flex: 1; min-width: 0; }

/* ---------- table of contents rail ---------- */
.toc-rail {
  flex: none;
  width: 320px;
  align-self: flex-start;
  position: sticky;
  top: 0;
  max-height: 100dvh;
  overflow-y: auto;
  padding: 34px 32px 20px 16px;
}
.toc-rail[hidden] { display: none; }
.toc-list { display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: block;
  padding: 4px 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-soft);
  text-decoration: none;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.toc-item:hover { color: var(--text); }
.toc-item.level-3 { padding-left: 16px; }
.toc-item.active { color: var(--link); font-weight: 600; }

.editor-page {
  max-width: 1010px;              /* 880px + 15% */
  margin: 0 auto;                /* centered writing column */
  padding: 16px 40px 40vh 48px;
}

.topbar-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.note-crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  padding: 0 6px;
}
.note-crumb .ico { width: 13px; height: 13px; }

.note-title {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 590;
  line-height: 1.3;
  padding: 2px 6px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  transition: background 0.12s;
}
.note-title:hover, .note-title:focus { background: var(--accent-soft); }
.note-title::placeholder { color: var(--text-faint); }

#editor {
  width: 100%;
  min-height: 55vh;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.75;
  padding: 12px 0;
  overflow: hidden;
}
#editor::placeholder { color: var(--text-faint); }

/* ---------- markdown preview ---------- */
.markdown-body { font-size: 17px; line-height: 1.75; padding: 12px 0; word-wrap: break-word; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-family: var(--font-ui);
  font-weight: 590;
  line-height: 1.2;
  margin: 1.5em 0 0.5em;
}
.markdown-body h1 { font-size: 30px; }
.markdown-body h2 { font-size: 22.5px; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 18.75px; }
.markdown-body p { margin: 0.6em 0; }
.markdown-body a { color: var(--link); text-decoration: none; font-weight: 500; }
.markdown-body a:hover { text-decoration: underline; color: var(--accent-hover); }
.markdown-body blockquote {
  margin: 1em 0;
  padding: 4px 0 4px 18px;
  border-left: 3px solid var(--accent);
  color: var(--text-soft);
}
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-inline);
  border-radius: var(--radius);
  padding: 2px 6px;
}
.markdown-body pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
}
.markdown-body pre code { background: none; padding: 0; font-size: 14px; color: inherit; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-body th { background: var(--code-inline); }
.markdown-body input[type="checkbox"] { accent-color: var(--accent); margin-right: 6px; }

/* ---------- empty state ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.empty-state[hidden] { display: none; }
.empty-inner { text-align: center; max-width: 400px; padding: 24px; }
.empty-ico { width: 52px; height: 52px; color: var(--accent); margin-bottom: 16px; }
.empty-inner h2 { font-family: var(--font-ui); font-weight: 590; margin: 0 0 8px; }
.empty-inner p { color: var(--text-soft); font-size: 14.5px; line-height: 1.6; margin: 0 0 20px; }
.empty-inner code { font-family: var(--font-mono); font-size: 0.85em; background: var(--code-inline); border-radius: var(--radius); padding: 2px 6px; }
.empty-inner .new-note-btn { width: auto; margin: 0 auto; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  opacity: 0;
  transform: scale(0.97) translateY(6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
dialog.dlg-in { opacity: 1; transform: none; }
dialog::backdrop {
  background: color-mix(in srgb, var(--text) 60%, transparent);
  opacity: 0;
  transition: opacity 0.16s ease;
}
dialog.dlg-in::backdrop { opacity: 1; }
.mini-dialog { padding: 22px; }
.mini-dialog h3 { font-family: var(--font-ui); font-weight: 590; font-size: 18px; margin: 0 0 6px; }
.mini-dialog .hint { margin: 0 0 4px; }
.mini-dialog input { margin-top: 10px; }
.mini-dialog .dialog-actions { margin-top: 18px; }
.settings-form { padding: 24px; }
.settings-form h3 { font-family: var(--font-ui); font-weight: 590; font-size: 22px; margin: 0 0 16px; }
.settings-form label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-soft); }
.settings-form label:first-of-type { margin-top: 0; }
.label-soft { font-weight: 400; color: var(--text-faint); }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; }

.settings-subhead {
  margin: 22px 0 4px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.settings-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.settings-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.settings-mono { font-family: var(--font-mono) !important; }

.settings-form input, .mini-dialog input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.settings-form input:focus, .mini-dialog input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: 12.5px; color: var(--text-faint); line-height: 1.5; margin: 8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- button variants (dialogs / picker) ---------- */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary:disabled:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 82%, black); border-color: color-mix(in srgb, var(--danger) 82%, black); }
.btn-primary .ico, .btn-secondary .ico, .btn-danger .ico { width: 15px; height: 15px; }

/* ---------- folder picker ---------- */
.folder-picker { padding: 24px; }
.folder-picker h3 { font-family: var(--font-ui); font-weight: 590; font-size: 22px; margin: 0 0 14px; }
.folder-current {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  margin-bottom: 10px;
}
.folder-current .ico { width: 15px; height: 15px; color: var(--accent); flex: none; }
.folder-current .fc-path { word-break: break-all; }
.folder-list {
  height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 4px;
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.folder-row:hover { background: var(--accent-soft); }
.folder-row.up { color: var(--text-soft); }
.folder-row .ic { flex-shrink: 0; display: inline-flex; color: var(--accent); }
.folder-row.up .ic { color: var(--text-soft); }
.folder-row .ic .ico { width: 16px; height: 16px; }
.folder-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-empty { padding: 14px 12px; font-size: 13px; color: var(--text-faint); }
.folder-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.folder-actions .spacer { flex: 1; }

.scrim { display: none; }

/* ---------- per-note context menu ---------- */
.ctx-menu {
  position: fixed;
  z-index: 200;
  min-width: 190px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
}
.ctx-menu[hidden] { display: none; }
.ctx-header {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 6px 10px 4px;
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.ctx-item:hover { background: var(--accent-soft); color: var(--accent); }
.ctx-item .ico { width: 16px; height: 16px; flex: none; color: var(--text-soft); }
.ctx-item:hover .ico { color: var(--accent); }
.ctx-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-item.ctx-danger { color: var(--danger); }
.ctx-item.ctx-danger .ico { color: var(--danger); }
.ctx-item.ctx-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 5px 6px; }
.ctx-empty { padding: 6px 10px 8px; font-size: 12.5px; color: var(--text-faint); }

/* ---------- wiki links ---------- */
.wiki-link {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
.wiki-link:hover { text-decoration: underline; color: var(--accent-hover); }

/* ---------- AI import ---------- */
.ai-import-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.ai-import-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ai-import-btn .ico { width: 16px; height: 16px; }

.ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--text) 50%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-overlay[hidden] { display: none; }
.ai-overlay-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  max-width: 320px;
}
.ai-overlay-card h3 { font-family: var(--font-ui); font-weight: 590; margin: 14px 0 6px; }
.ai-overlay-card p { margin: 0; font-size: 13.5px; color: var(--text-soft); }
.ai-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: vb-spin 0.9s linear infinite;
}
@keyframes vb-spin { to { transform: rotate(360deg); } }

.drop-hint {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--accent-soft);
  border: 3px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-hint[hidden] { display: none; }
.drop-hint-inner {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  font-weight: 600;
}
.drop-hint-inner .ico { color: var(--accent); }

/* ---------- mobile ---------- */
@media (max-width: 768px) {
  /* Pre-calculate the fixed topbar height so the content below can
     offset itself. Line height (~30 px) + vertical padding (16 px)
     + safe-area-inset-top = 46 px + inset. */
  :root {
    --topbar-h: calc(46px + env(safe-area-inset-top, 0px));
  }

  /* Let the document body scroll naturally. iOS Safari only collapses its
     address bar / bottom toolbar when the root scrolls — an internal
     overflow-y:auto container will never trigger that behaviour. */
  html, body {
    height: auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Drop the fixed-viewport flex container; let the page flow. */
  .app {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .toc-rail { display: none; }

  /* ---- sidebar drawer (fixed overlay) ---- */
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: min(84vw, 320px);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); border-right: 1px solid var(--border); }
  .sidebar-header { padding-top: 8px; }
  .sidebar-footer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

  /* Scrim — extend past all safe-area edges so nothing peeks through. */
  .scrim {
    display: block;
    position: fixed;
    z-index: 25;
    top: calc(-1 * env(safe-area-inset-top, 0px));
    right: calc(-1 * env(safe-area-inset-right, 0px));
    bottom: calc(-1 * env(safe-area-inset-bottom, 0px));
    left: calc(-1 * env(safe-area-inset-left, 0px));
    background: color-mix(in srgb, var(--text) 40%, transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }

  /* Freeze the body scroll when the sidebar drawer is open so the browser
     chrome doesn't flicker / show gray behind the scrim. */
  body:has(.scrim.show) {
    overflow: hidden;
  }

  .icon-btn.menu-btn { display: inline-flex; }

  /* Main is no longer a flex child — let it be a natural block. */
  .main {
    display: block;
    flex: none;
    position: relative;
    min-height: 100dvh;
  }

  /* Topbar — fixed to the viewport so it never scrolls away.
     Only the note content below it scrolls with the document body. */
  .topbar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 12;
    gap: 8px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .topbar .save-status { flex: 1; }

  /* Push content below the fixed topbar. */
  .content-row {
    display: block;
    flex: none;
    min-height: 0;
    overflow: visible;
    padding-top: var(--topbar-h, 46px);
  }

  .editor-scroll { overflow: visible; }

  /* Bottom padding: home indicator clearance + generous reading cushion. */
  .editor-page {
    padding: 8px 20px calc(30vh + env(safe-area-inset-bottom, 0px));
    max-width: 100%;
  }

  #editor, .markdown-body { font-size: 16.5px; }

  /* Empty state pushes below the fixed topbar so the message is centered
     in the visible area rather than behind the bar. */
  .empty-state {
    padding-top: var(--topbar-h, 46px);
  }
  .empty-inner {
    padding: calc(24px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px));
  }
}
