/* style.css — one stylesheet, no CDN fonts, no external anything.
   default-src 'none' in the CSP means a webfont request would simply be blocked, so
   this uses the system stack throughout. That is also what Apple Notes looks like. */

:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f7f5;
  --bg-raised: #ffffff;
  --fg: #1c1c1e;
  --fg-dim: #6b6b70;
  --fg-faint: #98989e;
  --line: #e3e3e0;
  --accent: #c8901e;
  --accent-soft: #fbf3e2;
  --danger: #c0392b;
  --sel: #ffe9b0;

  --hl-yellow: #fff2a8;
  --hl-green: #c8f0c8;
  --hl-blue: #c5def5;
  --hl-pink: #f8c8dc;
  --hl-purple: #dcc8f0;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 300px;
}

/* Dark values live in one place and are applied two ways: by the OS preference when
   the theme setting is "system" (no data-theme attribute), and explicitly when the
   user picks Dark. `:root[data-theme="light"]` must therefore win over the media
   query, which is why the query is scoped with :not(). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1e;
    --bg-sidebar: #161618;
    --bg-raised: #242427;
    --fg: #ececec;
    --fg-dim: #a0a0a6;
    --fg-faint: #74747a;
    --line: #333338;
    --accent: #e8b84b;
    --accent-soft: #2e2718;
    --danger: #e06c5b;
    --sel: #4a3f1c;

    --hl-yellow: #6b5b1a;
    --hl-green: #2f5233;
    --hl-blue: #26455f;
    --hl-pink: #5e2f42;
    --hl-purple: #45305e;
  }
}

:root[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-sidebar: #161618;
  --bg-raised: #242427;
  --fg: #ececec;
  --fg-dim: #a0a0a6;
  --fg-faint: #74747a;
  --line: #333338;
  --accent: #e8b84b;
  --accent-soft: #2e2718;
  --danger: #e06c5b;
  --sel: #4a3f1c;

  --hl-yellow: #6b5b1a;
  --hl-green: #2f5233;
  --hl-blue: #26455f;
  --hl-pink: #5e2f42;
  --hl-purple: #45305e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

::selection { background: var(--sel); }

a { color: var(--accent); }

button { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ setup */

.setup {
  display: flex;
  justify-content: center;
  padding: 3rem 1.25rem 5rem;
  overflow-y: auto;
  height: 100%;
}

.setup[hidden] { display: none; }

.setup-inner { width: 100%; max-width: 34rem; }

.setup h1 { font-size: 1.6rem; margin: 0 0 1.25rem; letter-spacing: -0.02em; }

.steps { padding-left: 1.2rem; color: var(--fg-dim); }
.steps li { margin: 0.4rem 0; }
.steps b { color: var(--fg); font-weight: 600; }

.reassure {
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  color: var(--fg-dim);
  font-size: 0.92rem;
  margin: 1.25rem 0 1.75rem;
}

.field { margin-bottom: 1rem; flex: 1; min-width: 0; }
.field-row { display: flex; gap: 0.75rem; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-dim);
  margin-bottom: 0.3rem;
}

.hint { font-weight: 400; color: var(--fg-faint); }

.field input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
}

.field input:focus,
#search:focus,
.title:focus,
.block-edit:focus,
.source:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.check {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.9rem;
  color: var(--fg-dim);
  margin: 0.5rem 0 1.5rem;
}

.check input { margin-top: 0.35rem; flex: none; }

.primary {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled { opacity: 0.5; cursor: default; }

.error {
  color: var(--danger);
  font-size: 0.9rem;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin: 0 0 1rem;
}

.error[hidden] { display: none; }

/* ------------------------------------------------------------------ layout */

.app { display: flex; height: 100%; }
.app[hidden] { display: none; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
}

#search {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
}

.icon-btn {
  flex: none;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raised);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.icon-btn:hover { border-color: var(--accent); }

.note-list { flex: 1; overflow-y: auto; padding: 0.4rem; }

.note-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
}

.note-item:hover { background: var(--bg-raised); }
.note-item.active { background: var(--accent-soft); }

.note-item .n-title {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item .n-sub {
  display: block;
  font-size: 0.8rem;
  color: var(--fg-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item .n-folder { color: var(--accent); }
.note-item .n-dot { color: var(--accent); }

.group-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  padding: 0.75rem 0.6rem 0.25rem;
  font-weight: 700;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--fg-faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.account { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  font-size: 0.85rem;
  border-radius: 6px;
}

.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ------------------------------------------------------------------ editor */

.editor {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
}

.title {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.25rem;
  border-radius: 6px;
}

.status {
  flex: none;
  font-size: 0.8rem;
  color: var(--fg-faint);
  white-space: nowrap;
}

.status.warn { color: var(--accent); }
.status.bad { color: var(--danger); }

/* Sits beside the status. Tabular figures so the seconds ticking down do not make the
   topbar jitter as digit widths change. */
.countdown {
  flex: none;
  font-size: 0.75rem;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.countdown:not(:empty) {
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.banner[hidden] { display: none; }
.banner-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.doc {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem max(1rem, 50% - 22rem) 40vh;
}

.doc[hidden] { display: none; }

.source {
  flex: 1;
  width: 100%;
  border: 0;
  resize: none;
  padding: 1.5rem max(1rem, 50% - 22rem) 40vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.7;
  tab-size: 2;
}

.source[hidden] { display: none; }

.empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-faint);
}

.empty[hidden] { display: none; }

/* ---------------------------------------------------- rendered blocks */

.block {
  border-radius: 6px;
  padding: 1px 6px;
  margin: 0 -6px;
  cursor: text;
}

.block:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* The permanent click target below the last block. A new note is frontmatter and
   nothing else, so without this there is nowhere to start typing. */
.block-add { min-height: 2.5rem; }
.block-add p { margin: 0; height: 1.5rem; }
.block-add::after {
  content: "Click to write";
  color: var(--fg-faint);
  font-size: 0.85rem;
  opacity: 0;
}
.block-add:hover::after { opacity: 1; }

.block > :first-child { margin-top: 0; }
.block > :last-child { margin-bottom: 0; }

.block-edit {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: var(--bg-raised);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 0.5rem 0.6rem;
  resize: none;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
}

.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 {
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 1.4em 0 0.5em;
}

.doc h1 { font-size: 1.7rem; }
.doc h2 { font-size: 1.35rem; }
.doc h3 { font-size: 1.12rem; }
.doc h4, .doc h5, .doc h6 { font-size: 1rem; }

.doc p { margin: 0.7em 0; }

.doc ul, .doc ol { margin: 0.7em 0; padding-left: 1.5em; }
.doc li { margin: 0.2em 0; }

.doc li.task { list-style: none; margin-left: -1.3em; display: flex; gap: 0.5em; align-items: flex-start; }
.doc li.task input { margin-top: 0.45em; flex: none; accent-color: var(--accent); }
.doc li.task.done > span { color: var(--fg-faint); text-decoration: line-through; }

.doc blockquote {
  margin: 0.8em 0;
  padding-left: 0.9em;
  border-left: 3px solid var(--line);
  color: var(--fg-dim);
}

.doc pre {
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  overflow-x: auto;
  margin: 0.8em 0;
}

.doc pre code { background: none; padding: 0; font-size: 0.85rem; }

.doc code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05em 0.35em;
}

.doc hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }

.doc table { border-collapse: collapse; margin: 0.9em 0; font-size: 0.92rem; display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: 0.35em 0.7em; text-align: left; }
.doc th { background: var(--bg-sidebar); font-weight: 600; }

.doc img { max-width: 100%; border-radius: 8px; }

mark { border-radius: 3px; padding: 0.05em 0.15em; color: inherit; }
mark.hl-yellow { background: var(--hl-yellow); }
mark.hl-green  { background: var(--hl-green); }
mark.hl-blue   { background: var(--hl-blue); }
mark.hl-pink   { background: var(--hl-pink); }
mark.hl-purple { background: var(--hl-purple); }

.wikilink { text-decoration: none; border-bottom: 1px dashed var(--accent); }

.embed {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.88em;
  color: var(--fg-dim);
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.1em 0.45em;
}

.frontmatter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: center;
  padding-bottom: 0.6rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--fg-faint);
}

.tag {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.1em 0.6em;
  font-weight: 600;
}

.fm-key { color: var(--fg-faint); }
.fm-key::after { content: ":"; }
.fm-val { color: var(--fg-dim); margin-right: 0.5rem; }

/* ---------------------------------------------------- format toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.35rem 0;
}

.toolbar button {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1.5;
}

.toolbar button:hover { border-color: var(--accent); }
.toolbar .sw { width: 1.3rem; padding: 0.15rem 0; }

/* Deliberately NOT scoped to .toolbar. The format bar uses the same swatches, and
   scoping these to one parent is what left it showing five empty circles. */
.sw-yellow { background: var(--hl-yellow); }
.sw-green  { background: var(--hl-green); }
.sw-blue   { background: var(--hl-blue); }
.sw-pink   { background: var(--hl-pink); }
.sw-purple { background: var(--hl-purple); }

/* ------------------------------------------------------------------ narrow */

.only-narrow { display: none; }

@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .app.viewing .sidebar { display: none; }
  .app:not(.viewing) .editor { display: none; }
  .only-narrow { display: block; }
  .doc, .source { padding-left: 1rem; padding-right: 1rem; }
  .field-row { flex-direction: column; gap: 0; }
}

/* ------------------------------------------------------------------ views */

/* Compact drops the preview and tightens the rows; folders adds a tree. The row
   markup is identical in all three — only what is appended to it changes. */

.note-item .n-line {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.note-item .n-line .n-title { flex: 1; min-width: 0; }

.note-item .n-when {
  flex: none;
  font-size: 0.72rem;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.note-item .n-folder {
  display: block;
  font-size: 0.72rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Density is spacing ONLY — the same rows, closer together. Nothing is hidden or
   restructured at any level, so a setting change never loses information. Previews are
   an independent toggle and work at every density. */

.density-comfortable .note-item { padding: 0.5rem 0.6rem; }
.density-comfortable .folder-row { padding: 0.35rem 0.6rem; }

.density-compact .note-item { padding: 0.3rem 0.6rem; }
.density-compact .folder-row { padding: 0.25rem 0.6rem; }
.density-compact .note-item .n-title,
.density-compact .folder-row .folder-name { font-size: 0.88rem; }
.density-compact .note-item .n-sub { font-size: 0.76rem; }

.density-extra .note-item { padding: 0.12rem 0.6rem; }
.density-extra .folder-row { padding: 0.1rem 0.6rem; }
.density-extra .note-item .n-line,
.density-extra .folder-row { line-height: 1.35; }
.density-extra .note-item .n-title,
.density-extra .folder-row .folder-name { font-size: 0.84rem; font-weight: 500; }
.density-extra .note-item .n-sub { font-size: 0.74rem; }
.density-extra .note-item .n-folder { font-size: 0.68rem; }
.density-extra .note-list { padding: 0.2rem; }

.folder-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  color: var(--fg-dim);
}

.folder-row:hover { background: var(--bg-raised); }
.folder-row .caret { font-size: 0.7rem; color: var(--fg-faint); width: 0.8rem; flex: none; }
.folder-row .folder-name { font-weight: 600; font-size: 0.85rem; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-row .folder-count { font-size: 0.72rem; color: var(--fg-faint); flex: none; }

/* ------------------------------------------------------------------ settings */

.sheet {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #000 45%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}

.sheet[hidden] { display: none; }

.sheet-panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 26rem;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sheet-head h2 { font-size: 1.1rem; margin: 0; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.setting-label { font-size: 0.9rem; font-weight: 600; color: var(--fg-dim); flex: none; }

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-raised);
}

.segmented button {
  border: 0;
  background: none;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--fg-dim);
  border-left: 1px solid var(--line);
}

.segmented button:first-child { border-left: 0; }
.segmented button:hover { color: var(--fg); }
.segmented button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sheet .check { margin: 0.75rem 0; }
.sheet .check input:disabled + span { opacity: 0.5; }

.sheet-section { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: 0.75rem; }
.sheet-section h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-faint); margin: 0 0 0.4rem; }

.vault-info { font-size: 0.85rem; color: var(--fg-dim); margin: 0 0 0.3rem; word-break: break-word; }
#cache-info { font-size: 0.78rem; margin: 0; }

.sheet-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.icon-btn.small { width: 1.75rem; height: 1.75rem; font-size: 0.9rem; }

/* ------------------------------------------------------------------ mobile */

/* iOS zooms the page when a focused input's font-size is under 16px. The block editor
   and the search box are the two places that would otherwise trigger it on every tap. */
@media (max-width: 720px) {
  .block-edit, #search, .source { font-size: 16px; }
  .sheet-panel { max-height: 85vh; }
}

/* ------------------------------------------------------------------ move + drag */

.move-list {
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.25rem;
  margin-bottom: 1rem;
  background: var(--bg-sidebar);
}

.move-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.move-option:hover { background: var(--bg-raised); }
.move-option.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.move-icon { flex: none; font-size: 0.85rem; }
.move-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.primary.compact { width: auto; padding: 0.45rem 1.1rem; font-size: 0.9rem; }

/* Drag feedback. The drop target outline is inset so it does not shift the row. */
.note-item.dragging,
.folder-row.dragging { opacity: 0.4; }

.note-item.drop-target,
.folder-row.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.note-list.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.note-item, .folder-row { -webkit-user-drag: element; }

/* ------------------------------------------------------------------ pending */

/* The countdown pie. A conic-gradient driven by --p, which JS updates once a second
   through element.style — CSP blocks style attributes in markup but not the CSSOM. */
.pie {
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: conic-gradient(var(--accent) calc(var(--p, 100) * 1%), transparent 0);
}

.pie-delete { border-color: var(--danger); background: conic-gradient(var(--danger) calc(var(--p, 100) * 1%), transparent 0); }

.note-item.pending .n-title { font-style: italic; }
.note-item.pending-delete .n-title { text-decoration: line-through; color: var(--fg-faint); }
.note-item.pending-create .n-title,
.note-item.pending-move .n-title { color: var(--accent); }

.n-undo {
  flex: none;
  font-size: 0.72rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

/* A small icon beside the gear, not a banner. It only appears when there is something
   to send, so its presence is the message and it needs no label. */
.save-now {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.save-now { display: inline-flex; align-items: center; justify-content: center; }
.save-now svg { display: block; }
.save-now:disabled { opacity: 0.5; cursor: default; }
.save-now[hidden] { display: none; }

/* Folder row actions: present but quiet until the row is touched. */
.folder-actions {
  display: flex;
  gap: 0.25rem;
  flex: none;
  opacity: 0;
}

.folder-row:hover .folder-actions,
.folder-row:focus-within .folder-actions { opacity: 1; }

.folder-action {
  font-size: 0.72rem;
  padding: 0 0.15rem;
  border-radius: 4px;
  cursor: pointer;
  color: var(--fg-faint);
}

.folder-action:hover { color: var(--accent); background: var(--bg); }

/* Touch has no hover, so the actions would be unreachable if they stayed hidden. */
@media (hover: none) {
  .folder-actions { opacity: 1; }
}

/* ------------------------------------------------------------------ visual editor */

/* The editable surface. Blocks look identical to the read-only rendering — the whole
   point is that there is no "edit mode" to enter. */
.doc[contenteditable="true"] { outline: none; caret-color: var(--accent); }
.doc[data-visual] .block { cursor: text; }
.doc[data-visual] .block:hover { background: none; }

/* Blocks the visual editor cannot represent. Shown, never silently mangled. */
.doc[data-visual] .block.locked {
  position: relative;
  background: color-mix(in srgb, var(--fg-faint) 6%, transparent);
  border-radius: 6px;
  cursor: default;
  user-select: text;
}

.doc[data-visual] .block.locked::after {
  content: "Source only";
  position: absolute;
  top: 0.15rem;
  right: 0.35rem;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-faint);
  opacity: 0;
}

.doc[data-visual] .block.locked:hover::after { opacity: 1; }

/* A file drop target while dragging attachments in. */
.doc.drop-files { outline: 2px dashed var(--accent); outline-offset: -6px; }

.format-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  /* The same horizontal inset as .doc, so the controls line up with the text they act
     on instead of hugging the window edge. */
  padding: 0.35rem max(1rem, 50% - 22rem);
  border-bottom: 1px solid var(--line);
  background: var(--bg-sidebar);
}

.format-bar[hidden] { display: none; }

.fmt-style {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-raised);
  color: var(--fg);
}

.fmt-group { display: flex; gap: 0.2rem; align-items: center; }

.format-bar button {
  min-width: 1.7rem;
  height: 1.7rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--fg-dim);
}

.format-bar button:hover { background: var(--bg-raised); border-color: var(--line); color: var(--fg); }

.format-bar .sw {
  min-width: 1.1rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 1px solid var(--line);
}

/* ------------------------------------------------------------------ files panel */

.files-list {
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-sidebar);
  margin-bottom: 0.6rem;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
}

.file-row:last-child { border-bottom: 0; }

.file-thumb {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 5px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  overflow: hidden;
}

.file-thumb img { width: 100%; height: 100%; object-fit: cover; }

.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.file-name {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub { font-size: 0.72rem; color: var(--fg-faint); }
.file-sub.orphan { color: var(--accent); }
