:root {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #ececf1;
  --hover: #e4e4ec;
  --text: #17171c;
  --text-dim: #70707c;
  --accent: #5b5ef4;
  --accent-soft: rgba(91, 94, 244, 0.12);
  --on-accent: #ffffff;
  --danger: #d64545;
  --ok: #2fa36b;
  --border: #e2e2e9;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 4px 14px rgba(20, 20, 40, 0.05);
  --shadow-lift: 0 2px 4px rgba(20, 20, 40, 0.08), 0 8px 22px rgba(20, 20, 40, 0.09);
  --radius: 10px;
  --radius-s: 8px;
  font-size: 13.5px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161c;
    --surface: #201f27;
    --surface-2: #2a2933;
    --hover: #312f3b;
    --text: #ecebf1;
    --text-dim: #9d9ca8;
    --accent: #8f92ff;
    --accent-soft: rgba(143, 146, 255, 0.16);
    --on-accent: #17161c;
    --danger: #e0706a;
    --ok: #4cc088;
    --border: #302f3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 4px;
}

svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}

.spacer { flex: 1; }

/* ---- Icon buttons ---- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-s);
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.icon-btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow);
}

.icon-btn.primary:hover { filter: brightness(1.08); }

/* ---- Top bar ---- */

#topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px 5px;
}

/* ---- Dropdown menus ---- */

.menu {
  position: absolute;
  top: calc(100% - 2px);
  right: 8px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  max-width: 250px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}

.menu button {
  padding: 6px 10px;
  border-radius: 6px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu button:hover { background: var(--hover); }

/* Hamburger menu opens from the left of the top row. */
#main-menu { left: 8px; right: auto; }
#menu-toggle.active { color: var(--accent); background: var(--accent-soft); }

#search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#search-wrap svg {
  position: absolute;
  left: 9px;
  top: 50%;
  translate: 0 -50%;
  color: var(--text-dim);
  width: 14px;
  height: 14px;
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 5px 10px 5px 27px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search::placeholder { color: var(--text-dim); }

#search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- Note list ---- */

#list-view {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 8px;
}

#note-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#note-list li {
  position: relative;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

#note-list li:hover {
  box-shadow: var(--shadow-lift);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

/* Per-row actions. Kept quiet until the row is hovered or the button is
   focused, so the list stays calm; always shown where there is no hover. */
.row-more {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-s);
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.row-more svg { width: 13px; height: 13px; }
#note-list li:hover .row-more,
.row-more:focus-visible { opacity: 1; }
.row-more:hover { background: var(--hover); color: var(--text); }

@media (hover: none) {
  .row-more { opacity: 1; }
}

/* Anchored to the pointer or the ⋯ button, so it is placed from script. */
#row-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
}
#row-menu .row-menu-danger { color: var(--danger); }
#row-menu .row-menu-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.note-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  overflow: hidden;
}

/* Leave room for the ⋯ button in the corner. */
#note-list li:not(.group-label):not(.load-more) .note-title { padding-right: 22px; }

.note-title .t-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

.note-pin { color: var(--accent); display: inline-flex; }
.note-pin svg { width: 12px; height: 12px; }

.note-snippet {
  display: block;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 0.92em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.82em;
}

.time-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.95em;
  font-variant-numeric: tabular-nums;
}
.time-chip.tracked {
  color: var(--accent);
  background: var(--accent-soft);
}
.time-chip.tracked.running::before {
  content: "";
  width: 5px;
  height: 5px;
  margin-right: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: timer-pulse 1.4s ease-in-out infinite;
}
.time-chip.edited {
  color: var(--text-dim);
  background: color-mix(in srgb, var(--text-dim) 12%, transparent);
}

.tag-chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.95em;
  transition: background 0.15s;
}

.tag-chip:hover { background: var(--hover); }

.tag-chip.site-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.tag-chip.site-chip:hover { background: var(--hover); }

#note-list li.group-label,
#note-list li.group-label:hover {
  padding: 6px 4px 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  translate: none;
  cursor: default;
  color: var(--text-dim);
  font-size: 0.76em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#note-list li.load-more,
#note-list li.load-more:hover {
  padding: 9px 10px;
  background: none;
  border: 1px dashed var(--border);
  box-shadow: none;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85em;
}
#note-list li.load-more:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Folders ---- */

#folder-section { margin-bottom: 8px; }

.folder-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 2px;
  color: var(--text-dim);
  font-size: 0.76em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.folder-head .spacer { flex: 1; }

.folder-add {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 1em;
  text-transform: none;
  letter-spacing: 0;
}
.folder-add:hover { background: var(--accent-soft); }

.folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: color-mix(in srgb, var(--fc, var(--accent)) 9%, var(--surface));
  border: 1px solid var(--border);
  border-left: 3px solid var(--fc, var(--accent));
  border-radius: var(--radius);
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.folder-row:hover {
  box-shadow: var(--shadow-lift);
  border-color: color-mix(in srgb, var(--fc, var(--accent)) 45%, var(--border));
}

.folder-emoji { font-size: 1.05rem; line-height: 1; flex: none; }
.folder-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-count { color: var(--text-dim); font-size: 0.82em; flex: none; }
.folder-chevron { color: var(--text-dim); display: inline-flex; flex: none; }

.folder-empty { text-align: center; padding: 18px 12px; }

/* Folder-view header (shown when inside a folder). Deliberately the same
   shape as a .folder-row: it is that row, opened. */
.folder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 7px;
  margin-bottom: 10px;
  background: color-mix(in srgb, var(--fc, var(--accent)) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--fc, var(--accent)) 25%, var(--border));
  border-left: 3px solid var(--fc, var(--accent));
  border-radius: var(--radius);
}
.folder-bar .folder-emoji { font-size: 1.2rem; }
.folder-bar .folder-title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 1.02rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-bar-time {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--fc, var(--accent));
  background: color-mix(in srgb, var(--fc, var(--accent)) 14%, transparent);
}
.folder-bar-time:empty { display: none; }

/* Colored folder tag on filed notes in the Home list */
.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px 1px 5px;
  border-radius: 999px;
  font-size: 0.82em;
  color: var(--fc, var(--accent));
  background: color-mix(in srgb, var(--fc, var(--accent)) 15%, transparent);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.82em;
  color: var(--sc, var(--accent));
  background: color-mix(in srgb, var(--sc, var(--accent)) 15%, transparent);
}
.status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sc, var(--accent));
}

.status-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 2px;
}
.status-option {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.95em;
  text-align: left;
  cursor: pointer;
}
.status-option:hover { background: var(--hover); }
.status-option.current {
  border-color: var(--sc, var(--accent));
  background: color-mix(in srgb, var(--sc, var(--accent)) 12%, transparent);
}
.status-option .status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sc, var(--accent));
  flex: none;
}

#empty-hint {
  margin-top: 38%;
  text-align: center;
  color: var(--text-dim);
  line-height: 1.7;
}

#empty-hint svg {
  width: 34px;
  height: 34px;
  stroke-width: 1.2;
  opacity: 0.65;
  margin-bottom: 8px;
}

/* ---- Editor ---- */

#editor-view, #settings-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Everything that belongs to the note being edited, so a reference note can
   sit beside (or above) the whole stack. */
#editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- Reference note (read-only second note) ---- */

#reference-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Stacked below the editor in the sidebar, where the note you are typing in
     keeps the top of the panel. --ref-h is whatever the divider was last
     dragged to; without it, a third of the height. */
  order: 2;
  flex: 0 0 var(--ref-h, 38%);
  min-height: 90px;
  max-height: 70%;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 55%, var(--bg));
}
#reference-pane[hidden] { display: none; }

/* The divider: a thin hit area that grows a visible line on hover. */
#ref-resizer {
  order: 1;
  flex: none;
  position: relative;
  height: 7px;
  margin: -3px 0;
  z-index: 5;
  cursor: row-resize;
  touch-action: none;
}
#ref-resizer[hidden] { display: none; }
#ref-resizer::after {
  content: "";
  position: absolute;
  inset: 3px 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}
#ref-resizer:hover::after,
#ref-resizer:focus-visible::after,
body.resizing #ref-resizer::after { opacity: 0.6; }
#ref-resizer:focus-visible { outline: none; }
/* While dragging, the pointer must not select text or flip the cursor. */
body.resizing { user-select: none; }
body.resizing * { cursor: inherit !important; }

#ref-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 10px;
  border-bottom: 1px solid var(--border);
}
#ref-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}
#ref-bar .icon-btn { width: 22px; height: 22px; }
#ref-link.on { background: var(--accent-soft); color: var(--accent); }

#ref-find {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px 5px 8px;
  border-bottom: 1px solid var(--border);
}
#ref-find[hidden] { display: none; }
#ref-find input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85em;
}
#ref-find input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#ref-find-count {
  min-width: 2.6em;
  text-align: right;
  color: var(--text-dim);
  font-size: 0.78em;
  font-variant-numeric: tabular-nums;
}
#ref-find .icon-btn { width: 22px; height: 22px; font-size: 0.95rem; }
#ref-find-toggle.on { background: var(--accent-soft); color: var(--accent); }

/* Matches inside the rendered reference. */
mark.ref-hit {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: inherit;
  border-radius: 2px;
}
mark.ref-hit.current {
  background: var(--accent);
  color: var(--on-accent);
}

#ref-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 12px;
  font-size: var(--note-font, 14.5px);
  line-height: 1.6;
  unicode-bidi: plaintext;
}
/* Read-only: a checkbox that looked clickable would be lying. */
#ref-body input[type="checkbox"] { pointer-events: none; }

#editor-view[hidden], #settings-view[hidden], #preview[hidden] { display: none; }

#editor-bar, #settings-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px 3px;
}

.bar-title { padding-left: 4px; }

#mode-switch {
  display: flex;
  padding: 2px;
  margin-left: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-s);
}

.seg {
  padding: 2px 9px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.93em;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

#pin.pinned { color: var(--accent); }
#pin.pinned svg { fill: currentColor; }

.icon-btn.ok { color: var(--ok); }

#delete.armed {
  background: var(--danger);
  color: #fff;
}

#meta-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px 5px;
}

#meta-row input {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-size: 0.93em;
  min-width: 0;
}

#meta-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#tags { flex: 1; }

/* Spellcheck-language sheet input. */
#lang-input {
  width: 100%;
  margin-bottom: 4px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#lang-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.9em;
  flex: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pill svg { width: 13px; height: 13px; }

.pill:hover { background: var(--hover); }

.pill.on {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* ---- Formatting toolbar ---- */

#toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 8px 4px;
  overflow-x: auto;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 6px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.tool:hover { background: var(--hover); color: var(--text); }
.tool svg { width: 15px; height: 15px; }

.t-b { font-weight: 800; }
.t-i { font-style: italic; font-family: Georgia, serif; }
.t-s { text-decoration: line-through; }
.t-q { font-size: 1.15em; line-height: 1; }
.t-c { font-family: ui-monospace, Consolas, monospace; font-size: 0.78em; }

.tool-sep {
  width: 1px;
  height: 16px;
  margin: 0 4px;
  background: var(--border);
}

#glossary-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 8px 4px;
  padding: 3px 4px 3px 8px;
  border-radius: var(--radius-s);
  background: var(--accent-soft);
  color: var(--text-dim);
  font-size: 0.86em;
}

#glossary-hint span { flex: 1; }

#glossary-hint code {
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent);
}

#glossary-hint-close {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  color: var(--text-dim);
  font-size: 1.05em;
  line-height: 1;
}

#glossary-hint-close:hover {
  background: var(--hover);
  color: var(--text);
}

#editor-wrap {
  position: relative;
  flex: 1;
  display: flex;
  margin: 0 8px 8px;
  min-height: 0;
}

/* The textarea and the highlight backdrop must share text metrics exactly
   so the marks line up behind the characters. */
#editor,
#find-highlight {
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--note-font, 14.5px);
  line-height: 1.6;
  tab-size: 4;
  scrollbar-gutter: stable;
}

#editor {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  resize: none;
  border-color: var(--border);
  background: transparent;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  scroll-behavior: smooth;
}

#find-highlight {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--surface);
  color: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

#find-highlight mark {
  color: transparent;
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 26%, transparent);
}

#find-highlight mark.current {
  background: color-mix(in srgb, var(--accent) 60%, transparent);
}

body.mono #editor,
body.mono #find-highlight,
body.mono #preview {
  font-family: ui-monospace, Consolas, "Cascadia Mono", monospace;
}

#editor::placeholder { color: var(--text-dim); }

#editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- Scroll to top / bottom ---- */

#scroll-nav {
  position: absolute;
  right: 16px;
  bottom: 30px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

#scroll-nav button {
  width: 30px;
  height: 28px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

#scroll-nav button:hover { background: var(--hover); color: var(--text); }
#scroll-nav button + button { border-top: 1px solid var(--border); }

#editor-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 5px;
  color: var(--text-dim);
  font-size: 0.82em;
}

#editor-status #save-state { margin-left: auto; text-align: right; }
#editor-status #save-state.save-error { color: var(--danger); }
#save-retry {
  padding: 1px 6px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: var(--radius-s);
  color: var(--danger);
  background: transparent;
  font: inherit;
}
#save-retry:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

#editor-view { position: relative; }

/* ---- Find in note ---- */

#find-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 6px;
}

#find-input {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9em;
}

#find-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#find-count {
  min-width: 2.4em;
  text-align: right;
  color: var(--text-dim);
  font-size: 0.8em;
}

#find-bar .icon-btn { width: 26px; height: 26px; font-size: 1rem; }

/* ---- Version history panel ---- */

#history-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#history-bar {
  display: flex;
  align-items: center;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
}

#history-hint { margin: 8px 12px 4px; }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 10px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}

.history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.history-when { font-size: 0.82em; color: var(--text-dim); }

.history-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

.history-row button {
  flex: none;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 0.88em;
}

.history-row button:hover { background: var(--hover); }

/* ---- Time tracker ---- */

/* Bar button lights up while this note is being tracked. */
#timer-btn.active { color: var(--accent); background: var(--accent-soft); }

/* Footer live chip — always visible while a timer is active. */
#timer-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px 1px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s, color 0.15s;
}
#timer-chip:hover { background: var(--hover); color: var(--text); }
#timer-chip.running { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
#timer-chip.other { font-style: italic; }
.timer-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  flex: none;
}
#timer-chip.running .timer-dot { opacity: 1; animation: timer-pulse 1.4s ease-in-out infinite; }
@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
@media (prefers-reduced-motion: reduce) {
  #timer-chip.running .timer-dot { animation: none; }
}

/* Full-height panel, mirroring the history panel. */
#timer-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#timer-bar {
  display: flex;
  align-items: center;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
}

#timer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timer-notice {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: var(--radius-s);
  background: var(--accent-soft);
  font-size: 0.88em;
}
.timer-notice-head { color: var(--text); font-weight: 500; }
.timer-other-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
}
.timer-other-row:hover { background: var(--hover); }
.to-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.5;
  flex: none;
}
.to-dot.running { background: var(--accent); opacity: 1; }
.to-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}
.to-time {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

#timer-display {
  text-align: center;
  font-size: 2.6rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  color: var(--text);
  padding: 6px 0 2px;
}
#timer-display.live { color: var(--accent); }

#timer-state { text-align: center; min-height: 1.2em; margin-top: -6px; }

#timer-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
#timer-controls button {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 0.92em;
  font-weight: 500;
  transition: background 0.15s, filter 0.15s;
}
#timer-controls button:hover { background: var(--hover); }
#timer-controls .primary-btn {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}
#timer-controls .primary-btn:hover { filter: brightness(1.08); background: var(--accent); }
#timer-controls .ghost-btn { color: var(--danger); }
#timer-controls .ghost-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

#timer-totals {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.timer-total { font-weight: 600; font-size: 1.02em; }

.link-btn {
  flex: none;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.92em;
  font-weight: 500;
}
.link-btn:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }

#timer-log-label { margin-top: 2px; }

.timer-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9em;
}
.te-when { flex: 1; min-width: 0; color: var(--text-dim); }
.te-dur { font-variant-numeric: tabular-nums; font-weight: 500; }
.te-del {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.85em;
}
.te-del:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* Stopwatch / Countdown tabs */
#timer-tabs {
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius-s);
  align-self: center;
}
#timer-tabs .seg { padding: 4px 16px; }

#timer-stopwatch, #timer-countdown {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Countdown / Pomodoro pane */
#cd-phase {
  align-self: center;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 0.82em;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
}
#cd-phase.break { background: var(--ok); }

#cd-display {
  text-align: center;
  font-size: 3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  padding: 4px 0 0;
}
#cd-display.live { color: var(--accent); }
#cd-state { text-align: center; min-height: 1.2em; margin-top: -8px; }

#cd-presets {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.cd-custom-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.85em;
}
#cd-custom {
  /* Room for three digits next to the number spinners, which overlay the
     right edge and squeezed "600" against them at the old width. */
  width: 6.5em;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9em;
  text-align: center;
}
#cd-custom:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#cd-custom:disabled { opacity: 0.5; }
#cd-presets button {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}
#cd-presets button:hover { background: var(--hover); }
#cd-presets button.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
#cd-presets.disabled { opacity: 0.45; pointer-events: none; }

#cd-pomodoro-row { justify-content: center; }

#cd-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
#cd-controls button {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 0.92em;
  font-weight: 500;
}
#cd-controls button:hover { background: var(--hover); }
#cd-controls .primary-btn {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}
#cd-controls .primary-btn:hover { filter: brightness(1.08); background: var(--accent); }
#cd-controls .ghost-btn { color: var(--danger); }
#cd-controls .ghost-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
#cd-cycles { text-align: center; min-height: 1.1em; }

/* Reminder due chip on list cards */
.reminder-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.82em;
  color: var(--accent);
  background: var(--accent-soft);
}
.reminder-chip.overdue { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* Reminder sheet */
#reminder-at {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  color-scheme: light dark;
}
#reminder-at:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.reminder-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.reminder-quick button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85em;
}
.reminder-quick button:hover { background: var(--hover); }

/* Existing reminders inside the sheet */
#reminder-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.reminder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  font-size: 0.9em;
}
.reminder-row.overdue { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.rr-when { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.reminder-row.overdue .rr-when { color: var(--danger); }
.rr-del {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.85em;
}
.rr-del:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ---- Agenda / Upcoming view ---- */

#agenda-view, #timers-view, #report-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#agenda-bar, #timers-bar, #report-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px 5px;
  border-bottom: 1px solid var(--border);
}
#agenda-body { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
#timers-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agenda-empty { margin-top: 30%; text-align: center; }

/* ---- Time report ---- */

#report-period {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 8px 4px;
}
#report-period button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85em;
}
#report-period button:hover { background: var(--hover); }
#report-period button.sel {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

#report-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 0;
  color: var(--text-dim);
  font-size: 0.85em;
}
#report-custom input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92em;
}

#report-csv {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82em;
}
#report-csv:hover { background: var(--hover); }
#report-csv:disabled { opacity: 0.4; pointer-events: none; }

#report-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rp-project {
  padding: 8px 10px;
  background: color-mix(in srgb, var(--fc, var(--text-dim)) 8%, var(--surface));
  border: 1px solid var(--border);
  border-left: 3px solid var(--fc, var(--border));
  border-radius: var(--radius);
}
.rp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
}
.rp-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-hours { color: var(--text-dim); font-size: 0.85em; font-variant-numeric: tabular-nums; }
.rp-amount {
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--fc, var(--accent)) 16%, transparent);
  color: var(--fc, var(--accent));
  font-size: 0.85em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rp-note {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 2px;
  border-top: 1px solid var(--border);
  text-align: left;
  font-size: 0.9em;
}
.rp-note:hover { color: var(--accent); }
.rp-note-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-note-time, .rp-note-amount {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.rp-chevron {
  display: inline-flex;
  flex: none;
  color: var(--text-dim);
  transition: transform 0.15s;
}
.rp-chevron svg { width: 12px; height: 12px; }
.rp-note[aria-expanded="true"] .rp-chevron { transform: rotate(90deg); }

.rp-sessions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 2px 4px 20px;
}
.rp-session {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
}
.rp-session-when { flex: 1; min-width: 0; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-session-hours {
  width: 4.2em;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rp-session-hours:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.rp-session-unit { color: var(--text-dim); }
.rp-session-amount {
  min-width: 4em;
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.rp-session-del {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-s);
  color: var(--text-dim);
}
.rp-session-del:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.rp-hint { padding-top: 6px; font-size: 0.8em; }

.rp-total {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
}
.rp-total-hours { flex: 1; color: var(--text-dim); font-size: 0.9em; font-variant-numeric: tabular-nums; }
.rp-total-amount {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Timer rows: a round pause/resume control + a click-to-open card. */
.timer-row { display: flex; align-items: center; gap: 8px; }
.tr-toggle {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tr-toggle svg { width: 13px; height: 13px; }
.tr-toggle:hover { background: var(--hover); color: var(--text); }
.tr-toggle.running { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.tr-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  text-align: left;
}
.tr-open:hover { background: var(--hover); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.tr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.tr-time { flex: none; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.timer-row.cd .tr-title { color: var(--accent); font-weight: 500; }
.timer-row.cd .tr-time { color: var(--accent); }
.agenda-head {
  padding: 12px 4px 4px;
  color: var(--text-dim);
  font-size: 0.76em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.agenda-head.overdue { color: var(--danger); }
.agenda-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 8px 8px;
  border-radius: var(--radius-s);
  text-align: left;
}
.agenda-row:hover { background: var(--hover); }
.ag-when {
  flex: none;
  min-width: 4.6em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 0.9em;
}
.ag-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

/* ---- Preview (rendered Markdown) ---- */

#preview {
  flex: 1;
  overflow-y: auto;
  margin: 0 8px 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--note-font, 14.5px);
  line-height: 1.65;
  unicode-bidi: plaintext;
  scroll-behavior: smooth;
}

.md li.task { list-style: none; margin-left: -1.15em; }
.md li.task label { display: flex; align-items: flex-start; gap: 7px; cursor: pointer; }
.md li.task input { margin-top: 4px; accent-color: var(--accent); flex: none; }
.md li.task input:checked + span { color: var(--text-dim); text-decoration: line-through; }

.md h1, .md h2, .md h3 { margin: 0.7em 0 0.35em; line-height: 1.3; }
.md :first-child { margin-top: 0; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.18em; }
.md h3 { font-size: 1.05em; }
.md p { margin: 0.45em 0; }
.md ul, .md ol { margin: 0.45em 0; padding-left: 1.4em; }
.md li { margin: 0.15em 0; }
.md a { color: var(--accent); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 0.9em 0; }

.md .wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  cursor: pointer;
}
.md .wikilink:hover { background: var(--accent-soft); }

.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.95em;
  overflow-x: auto;
  display: block;
}
.md th, .md td {
  border: 1px solid var(--border);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
  unicode-bidi: plaintext;
}
.md th { background: var(--surface-2); font-weight: 600; }

.backlinks {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.backlinks-title {
  color: var(--text-dim);
  font-size: 0.78em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.backlink {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 8px;
  margin: 2px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9em;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backlink:hover {
  background: var(--hover);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.md blockquote {
  margin: 0.6em 0;
  padding: 4px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  color: var(--text-dim);
}

.md code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.88em;
}

.md pre {
  margin: 0.6em 0;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  overflow-x: auto;
}

.md pre code { padding: 0; background: none; }

/* ---- Glossary table (inside preview) ---- */

.gloss-text {
  padding: 5px 2px;
  color: var(--text-dim);
}

.gloss-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 7px 10px;
  margin: 3px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  cursor: copy;
  unicode-bidi: plaintext;
  transition: background 0.15s, border-color 0.15s;
}

.gloss-row:hover {
  background: var(--hover);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.gloss-row.copied {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.gloss-row span { overflow-wrap: anywhere; }
.gloss-row span:last-child { color: var(--accent); font-weight: 500; }
.gloss-row.copied span:last-child { color: var(--on-accent); }

/* ---- Settings ---- */

#settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px;
}

.setting {
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  cursor: pointer;
}

.check-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.hint {
  margin-top: 7px;
  color: var(--text-dim);
  font-size: 0.88em;
  line-height: 1.55;
}

.hint.warn { color: var(--danger); }

#quota { margin-top: 10px; }

#quota-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

#quota-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s;
}

#quota-fill.full { background: var(--danger); }

.wide-btn {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-weight: 500;
  transition: background 0.15s;
}

.wide-btn:hover { background: var(--hover); }
.wide-btn + .wide-btn { margin-top: 8px; }
.wide-btn:disabled { opacity: 0.55; pointer-events: none; }

#sync-now-row { margin-top: 10px; }
#sync-now-state { margin-top: 4px; }

.setting > strong { display: block; margin-bottom: 2px; }

.setting .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 7px 0 5px;
}

.setting select {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.92em;
}

.check-row.slim { font-weight: 400; margin-top: 5px; }

.trash-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 0.9em;
}

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

.trash-row .when { color: var(--text-dim); font-size: 0.85em; flex: none; }

.trash-row button {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.9em;
  flex: none;
}

.trash-row button:hover { background: var(--hover); }
.trash-row button.danger:hover { color: var(--danger); }

#trash-list { margin-top: 4px; }
#empty-trash { margin-top: 6px; }

/* ---- Undo toast ---- */

#undo-toast {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 42px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  font-size: 0.9em;
}

#undo-btn {
  padding: 2px 10px;
  border-radius: 6px;
  color: var(--accent);
  font-weight: 600;
}

#undo-btn:hover { background: var(--accent-soft); }

/* ---- Modal sheets (folder create/edit, folder picker) ---- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 10, 20, 0.35);
}

.sheet-card {
  width: 100%;
  /* The sheet is fixed to the viewport, so on a wide window (the web app)
     it would stretch past the app column without a cap of its own. */
  max-width: 460px;
  max-height: 88%;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: var(--shadow-lift);
}

/* Past the sidebar's width a bottom sheet reads as a stray strip; centre it
   as a dialog instead. */
@media (min-width: 560px) and (min-height: 520px) {
  .sheet { align-items: center; }
  .sheet-card {
    max-height: 82%;
    border-radius: 16px;
  }
}

.sheet-title { display: block; margin-bottom: 10px; font-size: 1.02rem; }

#folder-name {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#folder-name:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-label {
  margin: 12px 0 6px;
  color: var(--text-dim);
  font-size: 0.82em;
  font-weight: 600;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  /* Roughly five rows; the rest scrolls so the sheet keeps its height. */
  max-height: 210px;
  overflow-y: auto;
  padding-right: 2px;
}
.emoji-grid button {
  aspect-ratio: 1;
  width: 100%;
  max-width: 40px;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-s);
  font-size: 1.1rem;
  background: var(--bg);
}
.emoji-grid button:hover { background: var(--hover); }
.emoji-grid button.sel {
  background: var(--accent-soft);
  /* Drawn inside the button: the grid scrolls, and an outward outline is
     clipped by the scroll container on the top and bottom rows. */
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rate-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.rate-row input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92em;
}
#folder-rate { width: 7em; }
#folder-currency { width: 5.5em; text-transform: uppercase; }
.rate-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.rate-row .hint { flex-basis: 100%; }

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-row button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--sw);
  border: 2px solid transparent;
}
.color-row button.sel {
  border-color: var(--text);
  outline: 2px solid var(--sw);
  outline-offset: 1px;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}
.sheet-actions button {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  font-size: 0.92em;
}
.sheet-actions button:hover { background: var(--hover); }
.sheet-actions .primary-btn {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}
.sheet-actions .primary-btn:hover { filter: brightness(1.08); }
.sheet-actions .danger-btn { color: var(--danger); }
.sheet-actions .danger-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

#ref-search {
  width: 100%;
  margin-bottom: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#ref-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#ref-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 46vh;
  overflow-y: auto;
}
#ref-picker-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  text-align: left;
}
#ref-picker-list button:hover { background: var(--hover); }

#folder-picker-list { display: flex; flex-direction: column; gap: 4px; }
#folder-picker-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
  text-align: left;
}
#folder-picker-list button:hover { background: var(--hover); }
#folder-picker-list button.sel {
  border-color: var(--accent);
  background: var(--accent-soft);
}
#folder-picker-list .pk-emoji { font-size: 1.05rem; flex: none; }
#folder-picker-list .pk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Bottom bar ---- */

#bottombar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#bottombar > button:not(.icon-btn) {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.9em;
  transition: background 0.15s;
}

#bottombar > button:not(.icon-btn):hover { background: var(--hover); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-dim);
  font-size: 0.82em;
  cursor: default;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.badge.synced { color: var(--ok); }
.badge.synced::before { background: var(--ok); }

/* ---- Bulk selection ---- */

#select-toggle.active { color: var(--accent); background: var(--accent-soft); }
body.selecting #new-note { display: none; } /* only bulk actions during select */

#note-list li.selectable {
  position: relative;
  padding-left: 36px;
}
.sel-box {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sel-box svg { width: 12px; height: 12px; stroke-width: 2.2; color: var(--on-accent); opacity: 0; }
#note-list li.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
#note-list li.selected .sel-box { background: var(--accent); border-color: var(--accent); }
#note-list li.selected .sel-box svg { opacity: 1; }

#selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
#sel-count { font-size: 0.88em; font-weight: 500; }
#selection-bar > button:not(.icon-btn) {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.9em;
  transition: background 0.15s, filter 0.15s;
}
#selection-bar > button:not(.icon-btn):hover { background: var(--hover); }
#selection-bar > button:disabled { opacity: 0.45; pointer-events: none; }
#selection-bar .danger-btn {
  border-color: transparent;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  font-weight: 600;
}
#selection-bar .danger-btn:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }

/* ---- Wide layout: the list and the open note side by side ----
 *
 * Driven by width, not by platform: the web app gets it on any roomy window,
 * and so does a Firefox sidebar the user has dragged wide. Below 900px none
 * of this applies and the panel is exactly the single-column sidebar it has
 * always been. panel.js keeps the list visible in this mode (see showView).
 */
@media (min-width: 900px) {
  body {
    --workspace-gutter: clamp(24px, 3vw, 48px);
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  /* Left column: search, the list, and whichever footer is showing. */
  #topbar { grid-area: 1 / 1; }
  #list-view { grid-area: 2 / 1; }
  #selection-bar, #bottombar { grid-area: 3 / 1; }
  #topbar, #list-view, #selection-bar, #bottombar {
    border-right: 1px solid var(--border);
  }

  /* Right column: exactly one of these is visible at a time. */
  #editor-view,
  #settings-view,
  #agenda-view,
  #timers-view,
  #report-view,
  #pane-empty {
    grid-area: 1 / 2 / -1 / 2;
    min-height: 0;
  }

  /* Anchor the working column near the note list. A stable left edge is
     quicker to scan between than a document that drifts toward the centre as
     the window grows; the 84ch cap still protects reading measure. */
  #editor-bar,
  #meta-row,
  #toolbar,
  #find-bar,
  #glossary-hint,
  #editor-wrap,
  #preview,
  #editor-status {
    width: min(84ch, calc(100% - var(--workspace-gutter) - 24px));
    margin-left: var(--workspace-gutter);
    margin-right: auto;
  }
  #editor-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  #preview { box-shadow: var(--shadow); }
  /* The textarea sits on that surface, so it must not paint its own — the
     find-highlight backdrop shows through from behind it. */
  #editor-wrap #editor { background: transparent; }

  #editor-main { min-width: 0; }

  /* The history and timer overlays cover the pane, so they get the column as
     padding instead. Keep their controls aligned with the note. */
  #history-panel, #timer-panel {
    padding-left: var(--workspace-gutter);
    padding-right: 24px;
  }

  #settings-body, #agenda-body, #timers-body, #report-body {
    width: min(90ch, calc(100% - var(--workspace-gutter) - 24px));
    margin-left: var(--workspace-gutter);
    margin-right: auto;
  }

  /* The list stays on screen while a note is open, so it has to show which
     note that is. */
  #note-list li.current {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  #pane-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    color: var(--text-dim);
    text-align: center;
  }
  #pane-empty[hidden] { display: none; }
  #pane-empty svg { width: 34px; height: 34px; opacity: 0.5; }
}

/* A reference becomes a right-hand reading rail only when both panes have a
   useful width. Between 900px and 1279px it keeps the stacked layout, so
   opening it never crushes the editor into a narrow strip. Because the main
   column is left-anchored, docking the reference does not move the note. */
@media (min-width: 1280px) {
  #editor-view { flex-direction: row; }
  #reference-pane {
    flex: 0 0 var(--ref-w, clamp(320px, 30%, 480px));
    min-height: 0;
    min-width: 240px;
    max-height: none;
    max-width: 520px;
    border-top: none;
    border-left: 1px solid var(--border);
  }
  #ref-resizer {
    width: 7px;
    height: auto;
    margin: 0 -3px;
    cursor: col-resize;
  }
  #ref-resizer::after { inset: 0 3px; }
}

/* A wider window buys a wider list, not a wider line of text — the note
   column stays at its measure either way. */
@media (min-width: 1400px) {
  body { grid-template-columns: 400px minmax(0, 1fr); }
}

/* Past this the app stops growing and centres as a frame, so the eye never
   has to travel the full width of a large monitor. The surround is darkened
   in both themes; html needs its own background or body's would propagate
   to the canvas and the frame would be invisible. */
@media (min-width: 1921px) {
  html { background: color-mix(in srgb, var(--bg) 88%, #000); }
  body {
    width: 100%;
    max-width: 1920px;
    margin-inline: auto;
    border-inline: 1px solid var(--border);
    box-shadow: var(--shadow-lift);
  }
}
