/* Visual style carried over from the work app: restrained, dense, system
   fonts, color only where it carries meaning (selection, tags, flags, save
   state). Dark mode follows the device unless Light or Dark is chosen in the
   menu (data-theme on <html>). */

:root {
  color-scheme: light;
  --ink: #1b1f24;
  --ink-soft: #55606b;
  --line: #d3d9df;
  --line-soft: #e6eaee;
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --accent: #1b4d8f;
  --accent-fill: #1b4d8f;
  --accent-fill-hover: #163f74;
  --accent-soft: #e7eefb;
  --ok: #1b6e3c;
  --ok-soft: #e6f4ea;
  --warn: #8a5a00;
  --warn-soft: #fdf1dc;
  --err: #a32026;
  --err-soft: #fbe9e9;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  /* The frame: a light blue-grey backdrop, a slightly lighter category
     panel, and the white content panel (--bg). */
  --app-bg: #e8edf2;
  --side-bg: #f3f6f9;
  --hover: #e6ebf0;
  --selected: #dde5ee;
  --neutral: #4a6485;       /* line and buttons when there's no category color */
  --group-title: #3d5a80;   /* "This Month", "Last Month"… in the notes list */
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e6e9ec;
    --ink-soft: #9aa5b1;
    --line: #3a424b;
    --line-soft: #2b323a;
    --bg: #20262d;
    --bg-soft: #171b20;
    --accent: #6fa4e8;
    --accent-fill: #2f6fc2;
    --accent-fill-hover: #4a86d3;
    --accent-soft: #223350;
    --ok: #5cbf7f;
    --ok-soft: #1c3324;
    --warn: #e0ab4c;
    --warn-soft: #3a2e14;
    --err: #e57478;
    --err-soft: #3a2022;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    --app-bg: #13171c;
    --side-bg: #1a1f26;
    --hover: #262d36;
    --selected: #2c3642;
    --neutral: #5b7aa0;
    --group-title: #8fb0d8;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6e9ec;
  --ink-soft: #9aa5b1;
  --line: #3a424b;
  --line-soft: #2b323a;
  --bg: #20262d;
  --bg-soft: #171b20;
  --accent: #6fa4e8;
  --accent-fill: #2f6fc2;
  --accent-fill-hover: #4a86d3;
  --accent-soft: #223350;
  --ok: #5cbf7f;
  --ok-soft: #1c3324;
  --warn: #e0ab4c;
  --warn-soft: #3a2e14;
  --err: #e57478;
  --err-soft: #3a2022;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  --app-bg: #13171c;
  --side-bg: #1a1f26;
  --hover: #262d36;
  --selected: #2c3642;
  --neutral: #5b7aa0;
  --group-title: #8fb0d8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--sans);
  color: var(--ink);
  background: var(--app-bg);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.muted { color: var(--ink-soft); font-size: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer;
}
button:hover { background: var(--bg-soft); }
button:active { background: var(--line-soft); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
button.primary:hover { background: var(--accent-fill-hover); }
button.danger { color: var(--err); }
.link-btn { border: none; background: none; color: var(--accent); padding: 2px 0; font-size: 12px; }
.link-btn:hover { background: none; text-decoration: underline; }
button.wide { width: 100%; padding: 10px; }

input[type="text"], input[type="search"], input[type="password"], input[type="date"], select, textarea {
  font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); min-width: 0;
}
label { font-size: 12px; color: var(--ink-soft); display: block; margin-bottom: 2px; }

/* ---------- Sign-in ---------- */
#login-view { min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 24px; }
.login-card h1 { font-size: 20px; font-weight: 400; margin-bottom: 18px; }
.login-card .or { text-align: center; color: var(--ink-soft); margin: 14px 0; }
.login-card label { margin-top: 10px; }
.login-card input { width: 100%; font-size: 16px; }
.login-card button[type="submit"] { margin-top: 16px; }
.login-error { background: var(--err-soft); color: var(--err); padding: 8px 10px; border-radius: 4px; font-size: 13px; margin: 14px 0 0; }

/* ---------- App frame ---------- */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#topbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 2px;
  padding: 8px 14px 8px 20px; padding-top: max(8px, env(safe-area-inset-top));
}
.brand { font-size: 18px; font-weight: 400; color: var(--ink); letter-spacing: -0.01em; }
.brand b { font-weight: 700; }
.spacer { flex: 1 1 auto; }
.top-icon {
  position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: none; border-radius: 8px; background: transparent; color: var(--ink-soft);
}
.top-icon:hover { background: var(--hover); color: var(--ink); }
.top-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.top-icon.save-saved { color: var(--ok); cursor: default; }
.top-icon.save-saved:hover { background: transparent; color: var(--ok); }
.top-icon.save-error { color: var(--err); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }
.backup-dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 2px var(--app-bg); }
.backup-dot-inline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: 8px; vertical-align: 1px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: none;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-ok .badge-dot { background: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-warn .badge-dot { background: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-err .badge-dot { background: var(--err); }

#message-banner { flex: 0 0 auto; display: none; align-items: center; gap: 12px; padding: 8px 16px; margin: 0 12px 10px; border-radius: 8px; font-size: 13px; }
#message-banner.show { display: flex; }
#message-banner.ok { background: var(--ok-soft); color: var(--ok); }
#message-banner.warn { background: var(--warn-soft); color: var(--warn); }
#message-banner.err { background: var(--err-soft); color: var(--err); }
#message-text { flex: 1 1 auto; }
#message-banner .dismiss { font-size: 12px; padding: 2px 8px; background: transparent; color: inherit; border-color: currentColor; }

/* Two rounded panels on the backdrop, with the resize handle as the gap between them. */
#app-body { flex: 1 1 auto; display: flex; overflow: hidden; min-height: 0; padding: 0 12px 12px; }

/* ---------- Left pane ---------- */
#left-pane { width: 260px; flex: 0 0 auto; background: var(--side-bg); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
#left-pane-resizer { flex: 0 0 12px; cursor: col-resize; touch-action: none; position: relative; }
#left-pane-resizer::after { content: ''; position: absolute; top: 12px; bottom: 12px; left: 5px; width: 2px; border-radius: 1px; background: transparent; }
#left-pane-resizer:hover::after, #left-pane-resizer.resizing::after { background: var(--neutral); }
#cat-list { flex: 1 1 auto; overflow-y: auto; padding: 10px 8px 6px; min-height: 0; }
#cat-foot { flex: 0 0 auto; padding: 0 8px 8px; }
#cat-foot .ml-trash { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 2px; padding-top: 8px; }

.ml-item { position: relative; min-height: 32px; padding: 5px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.ml-item:hover { background: var(--hover); }
.ml-item.selected { background: var(--selected); font-weight: 600; }
.ml-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-count { color: var(--ink-soft); font-size: 12px; white-space: nowrap; font-weight: 400; font-variant-numeric: tabular-nums; }
.ml-glyph { display: inline-flex; color: var(--ink-soft); }
.ml-glyph svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ml-top { margin-top: 2px; }
.ml-child { padding-left: 28px; }
.ml-review.has-items .ml-count { color: var(--warn); font-weight: 600; }
.ml-heading {
  display: flex; align-items: center; gap: 4px; min-height: 28px; margin: 14px 0 4px; padding: 0 8px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft);
}
.ml-empty { font-size: 12px; color: var(--ink-soft); padding: 8px 10px; margin: 0; }
.ml-archived-toggle { display: block; width: 100%; text-align: left; border: none; background: none; padding: 6px 8px; border-radius: 8px; font-size: 12px; color: var(--ink-soft); }
.ml-archived-toggle:hover { background: var(--hover); color: var(--ink); }
.ml-archived .ml-item { color: var(--ink-soft); }

/* Hover tools (filter, +, ⋯). They replace the count while showing. */
.ml-tools { display: none; align-items: center; gap: 2px; margin-left: auto; }
.ml-item:hover .ml-tools, .ml-item:focus-within .ml-tools, .ml-item.tools-open .ml-tools,
.ml-heading:hover .ml-tools, .ml-heading:focus-within .ml-tools, .ml-heading.tools-open .ml-tools { display: inline-flex; }
.ml-item:hover:has(.ml-tools) .ml-count, .ml-item:focus-within:has(.ml-tools) .ml-count, .ml-item.tools-open .ml-count { display: none; }
.ml-tool {
  display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: none; border-radius: 6px; background: transparent; color: var(--ink-soft);
}
.ml-tool:hover { background: var(--bg); color: var(--ink); }
.ml-tool.on { background: var(--bg); color: var(--neutral); }
.ml-tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
/* Touch screens can't hover: keep the tools on the heading and the selected row. */
@media (hover: none) {
  .ml-heading .ml-tools, .ml-item.selected .ml-tools { display: inline-flex; }
  .ml-item.selected:has(.ml-tools) .ml-count { display: none; }
  .ml-tool { width: 32px; height: 32px; }
}

/* The field a filter or + icon opens under its row. */
.ml-field { margin: 2px 8px 6px; }
.ml-field.ml-child { margin-left: 28px; padding-left: 0; }
.ml-field-input { width: 100%; height: 30px; border-radius: 6px; }
.ml-field-hint { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.ml-field-error { font-size: 12px; color: var(--err); background: var(--err-soft); border-radius: 4px; padding: 4px 6px; margin-top: 4px; }

/* ---------- Right pane ---------- */
#right-pane { flex: 1 1 auto; display: flex; flex-direction: column; overflow: hidden; min-width: 0; background: var(--bg); border-radius: var(--radius); }
#grid-view, #editor-view, #security-view { flex: 1 1 auto; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.mobile-only { display: none; }
.back-btn { font-size: 12px; padding: 4px 10px; }

/* The notes list's header: big title, a line in the category's color, then
   the two "new" buttons (also in that color) and the plain Search / Sort. */
#right-pane { --cat-solid: var(--neutral); }   /* the default; a .cat-<color> on #grid-view overrides it */
#grid-head { flex: 0 0 auto; padding: 20px 24px 4px; }
.view-title { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin: 0; overflow-wrap: anywhere; }
.title-crumb { color: var(--ink-soft); font-weight: 600; }
.title-rule { height: 3px; border-radius: 2px; background: var(--cat-solid); margin: 10px 0 14px; }
.grid-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-toolbar svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.cat-btn, .plain-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px; font-size: 13px; white-space: nowrap; }
.cat-btn { background: var(--cat-solid); border: 1px solid var(--cat-solid); color: #fff; font-weight: 600; }
.cat-btn:hover { background: var(--cat-solid); filter: brightness(1.08); }
.cat-btn:active { background: var(--cat-solid); filter: brightness(0.95); }
.plain-btn { background: transparent; border: 1px solid transparent; color: #4a525b; font-weight: 500; }
.plain-btn:hover, .plain-btn.active { background: var(--hover); }
.plain-btn .val { color: var(--ink); font-weight: 600; }
.lbl-phone { display: none; }
.plain-btn { position: relative; }
.filter-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--neutral); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.tagbar-empty { font-size: 12px; color: var(--ink-soft); }
.grid-toolbar .tb-sep { height: 22px; align-self: center; }
.search-box { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; width: 280px; max-width: 100%; color: var(--ink-soft); margin: 0; }
.search-box:focus-within { border-color: var(--neutral); }
.search-box input { flex: 1 1 auto; min-width: 0; border: none; outline: none; padding: 0; background: transparent; }
.grid-summary { display: block; font-size: 12px; color: var(--ink-soft); margin: 12px 0 2px; }

#tag-bar-row { flex: 0 0 auto; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg-soft); }
#tag-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tagbar-chip {
  display: inline-flex; align-items: center; gap: 5px; background: var(--bg); border: 1px solid var(--line);
  color: var(--ink); border-radius: 999px; padding: 3px 10px; font-size: 12px;
}
.tagbar-chip:hover { border-color: var(--accent); background: var(--bg); }
.tagbar-chip.active { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.tagbar-count { color: var(--ink-soft); font-size: 11px; }
.tagbar-chip.active .tagbar-count { color: rgba(255, 255, 255, 0.8); }
.tagbar-mode {
  font-size: 11px; font-weight: 600; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 999px; padding: 3px 10px; background: var(--accent-soft);
}
.tagbar-clear { font-size: 12px; color: var(--ink-soft); background: none; border: none; text-decoration: underline; padding: 3px 4px; }
.tagbar-clear:hover { background: none; color: var(--ink); }
#tag-bar { flex-direction: column; align-items: stretch; gap: 8px; }
.tagbar-group { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tagbar-label { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); min-width: 52px; }
.tagbar-chip.person-filter:not(.active) { background: var(--bg); }

#notes-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; background: var(--bg); padding: 0 12px 12px; }
#tag-bar-row { margin: 8px 24px 0; border-radius: 8px; border-bottom: none !important; }
table.notes-grid { width: 100%; min-width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
table.notes-grid:not([style*="width"]) { min-width: 860px; }
table.notes-grid th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.notes-grid th.sortable { cursor: pointer; user-select: none; }
table.notes-grid th.sortable:hover { color: var(--ink); }
.sort-arrow { display: inline-block; width: 12px; margin-left: 2px; }
.col-resize-handle { position: absolute; top: 6px; right: 0; bottom: 6px; width: 7px; cursor: col-resize; touch-action: none; border-right: 2px solid transparent; }
.col-resize-handle:hover, .col-resize-handle.resizing { border-right-color: var(--neutral); }
table.notes-grid td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; overflow-wrap: break-word; }
table.notes-grid tr.row-editing td { vertical-align: top; }
table.notes-grid tr:hover td { background: var(--bg-soft); }
table.notes-grid tr.row-review td:first-child { box-shadow: inset 3px 0 var(--warn); }
table.notes-grid tr.row-editing td { background: var(--accent-soft); }
table.notes-grid.hide-category .col-category { display: none; }

/* Group titles ("This Month", "Church", …); the caret folds the group. */
table.notes-grid tr.group-row td { padding: 16px 4px 6px; border-bottom: 1px solid var(--line); background: var(--bg) !important; }
table.notes-grid tr.group-row:first-child td { padding-top: 10px; }
.group-toggle { display: inline-flex; align-items: center; gap: 6px; border: none; background: none; padding: 2px 6px; border-radius: 6px; color: var(--group-title); font-size: 14px; font-weight: 700; }
.group-toggle:hover { background: var(--hover); }
.group-caret { display: inline-block; width: 12px; font-size: 10px; transition: transform 0.15s; }
tr.group-row.folded .group-caret { transform: rotate(-90deg); }
.group-count { color: var(--ink-soft); font-size: 12px; font-weight: 500; }
.title-wrap { display: flex; align-items: center; min-width: 0; }
.grid-title-link { color: var(--accent); text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grid-title-link:hover { text-decoration: underline; }
.grid-title { font-weight: 600; }
.grid-kind {
  display: inline-block; flex: 0 0 auto; font-size: 10px; font-weight: 700; letter-spacing: 0.03em; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 1px;
}
.grid-kind.kind-pdf { color: #b0413e; border-color: rgba(176, 65, 62, 0.35); }
.grid-kind.kind-md { color: #2f6bc0; border-color: rgba(47, 107, 192, 0.35); }
.grid-none { color: var(--ink-soft); }
.grid-date { font-variant-numeric: tabular-nums; }
table.notes-grid .col-type, table.notes-grid .col-category { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.notes-grid tr.row-editing .col-type, table.notes-grid tr.row-editing .col-category { overflow: visible; white-space: normal; }
.cat-cell { display: inline-flex; align-items: center; max-width: 100%; }
.cat-cell span:last-child { overflow: hidden; text-overflow: ellipsis; }
/* People: plain grey pills; click one to show only their notes. */
.person-chip { display: inline-block; margin: 1px 4px 1px 0; padding: 1px 8px; border-radius: 999px; border: none; background: var(--line-soft); color: var(--ink); font-size: 12px; line-height: 1.5; }
button.person-chip:hover { background: var(--selected); }
button.person-chip.active { background: var(--neutral); color: #fff; }
.tag-chip.person-chip { display: inline-flex; padding: 2px 4px 2px 8px; margin: 0; }
.tag-count { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 12px; }
.tag-count:hover { background: var(--hover); color: var(--ink); }
.tag-count svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tags-pop { width: auto; min-width: 180px; max-width: min(320px, calc(100vw - 20px)); }
.tag-pop-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 2px 2px; }
.tag-pop-chip { border: none; margin: 0; font-size: 12px; padding: 3px 10px; cursor: pointer; }
.tag-pop-chip:hover { filter: brightness(0.95); }
.tag-pop-chip.active { box-shadow: inset 0 0 0 1.5px currentColor; }
table.notes-grid .col-meta { display: none; }
.meta-sep { margin: 0 5px; color: var(--line); }
/* Content type: a dropdown, or the "new type" field in its place. */
.type-select { width: 100%; }
.type-new { display: flex; gap: 4px; }
.type-new input { flex: 1 1 auto; min-width: 0; }
.type-new button { padding: 4px 8px; font-size: 12px; }
.grid-desc { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.grid-flag { font-size: 11px; color: var(--warn); font-weight: 600; }
.tag-chip-static { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; font-size: 11px; margin: 0 4px 4px 0; }
.col-actions { text-align: right; white-space: nowrap; }
.grid-edit-btn, .grid-delete-btn { font-size: 12px; padding: 4px 10px; border-radius: 6px; }
.grid-edit-btn.done { background: var(--neutral); border-color: var(--neutral); color: #fff; }
/* Editing: Done above Delete, so the column stays narrow. */
tr.row-editing .col-actions { display: table-cell; }
tr.row-editing .col-actions button { display: block; width: 100%; margin: 0 0 6px; }
.grid-delete-btn { color: var(--err); }
.grid-empty { text-align: center; color: var(--ink-soft); padding: 40px 0; }
.grid-date-input { width: 100%; }
.grid-title-input, .grid-desc-input { display: block; width: 100%; }
.grid-title-input { font-weight: 600; }
.grid-desc-input { font-size: 12px; margin-top: 4px; }

/* ---------- Pickers ---------- */
.cat-picker { position: relative; }
.cat-picker input { width: 100%; }
.cat-picker.flagged input { border-color: var(--err); background: var(--err-soft); }
.picker-dropdown {
  position: fixed; max-width: min(440px, calc(100vw - 16px)); max-height: 300px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); z-index: 700;
}
.picker-item { padding: 7px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-item:hover, .picker-item.active { background: var(--accent-soft); }
.picker-parent { color: var(--ink-soft); }
.picker-create { color: var(--accent); font-weight: 600; }
.picker-empty { padding: 7px 10px; font-size: 12px; color: var(--ink-soft); }
.picker-create-form { padding: 10px; font-size: 13px; width: 320px; max-width: 100%; }
.picker-create-form label { margin-top: 8px; }
.picker-create-form input, .picker-create-form select { width: 100%; }
.pcf-title { font-weight: 600; }
.pcf-error { background: var(--err-soft); color: var(--err); padding: 6px 8px; border-radius: 4px; margin-top: 8px; font-size: 12px; white-space: normal; }
.pcf-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.tag-picker { position: relative; }
.tp-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tp-chips:not(:empty) { margin-bottom: 4px; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 4px 2px 8px; font-size: 12px; }
.tag-chip-remove { border: none; background: transparent; color: inherit; font-size: 14px; padding: 0 3px; line-height: 1; }
.tag-chip-remove:hover { background: transparent; color: var(--err); }
.tp-input { width: 100%; }

/* ---------- Popovers and menu ---------- */
.action-popover {
  position: fixed; background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); z-index: 600; padding: 12px; width: 300px; max-width: calc(100vw - 20px); font-size: 13px;
}
.action-popover h3 { font-size: 13px; margin: 0 0 8px; overflow-wrap: anywhere; }
.action-popover .ap-section { padding: 10px 0; border-top: 1px solid var(--line-soft); }
.action-popover .ap-section:first-of-type { border-top: none; padding-top: 0; }
.action-popover label { margin-top: 6px; }
.action-popover input[type="text"], .action-popover select { width: 100%; }
.ap-row { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.ap-row input, .ap-row select { flex: 1 1 auto; }
.ap-end { justify-content: flex-end; margin-top: 12px; }
.ap-error { background: var(--err-soft); color: var(--err); padding: 6px 8px; border-radius: 4px; font-size: 12px; margin-top: 8px; }
.ap-danger { color: var(--err); }
.ap-note { font-size: 12px; color: var(--ink-soft); margin: 6px 0 0; }
.menu-popover { width: 260px; }
.ap-menu-list { display: flex; flex-direction: column; gap: 2px; }
.ap-menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); padding: 2px 6px 4px; }
.ap-menu-item { text-align: left; border: none; background: none; padding: 8px 6px; border-radius: 4px; font-size: 13px; width: 100%; }
.ap-menu-item:hover { background: var(--bg-soft); }
.ap-menu-item.ap-danger:hover { background: var(--err-soft); }
.ap-check { display: flex; justify-content: space-between; }
.ap-tick { display: inline-block; width: 18px; color: var(--neutral); font-weight: 700; }
.ap-hint { display: block; margin-left: 18px; font-size: 11px; color: var(--ink-soft); }
.sort-popover { width: 200px; }

/* ---------- Typed-note editor ---------- */
#editor-view { background: var(--bg); }
.editor-header { flex: 0 0 auto; padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.editor-topline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editor-status { font-size: 12px; color: var(--ink-soft); }
.editor-status.ok { color: var(--ok); font-weight: 600; }
.editor-status.err { color: var(--err); font-weight: 600; }
.editor-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.form-field { display: flex; flex-direction: column; min-width: 200px; }
.form-field.wide { flex: 2 1 260px; }
.form-field.narrow { min-width: 160px; }
.form-field.wide input { width: 100%; }
#editor-title { font-size: 15px; font-weight: 600; }
.editor-toolbar { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 6px 16px; border-bottom: 1px solid var(--line-soft); background: var(--bg-soft); flex-wrap: wrap; }
.editor-toolbar button { font-size: 12px; padding: 3px 8px; min-width: 30px; }
.tb-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.editor-mode-toggle { margin-left: auto; display: inline-flex; }
.editor-mode-toggle button { border-radius: 0; margin-left: -1px; }
.editor-mode-toggle button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.editor-mode-toggle button:last-child { border-radius: 0 4px 4px 0; }
.editor-mode-toggle button.active { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.editor-panes { flex: 1 1 auto; display: flex; min-height: 0; }
#editor-body {
  flex: 1 1 50%; min-width: 0; resize: none; border: none; border-radius: 0; outline: none; padding: 16px 20px;
  font-family: var(--mono); font-size: 13px; line-height: 1.6; background: var(--bg); color: var(--ink);
}
.editor-preview { flex: 1 1 50%; min-width: 0; overflow-y: auto; padding: 16px 24px; border-left: 1px solid var(--line); }
.editor-panes.mode-write .editor-preview { display: none; }
.editor-panes.mode-preview #editor-body { display: none; }
.editor-panes.mode-preview .editor-preview { border-left: none; }
.editor-print-header { display: none; }
.meta-toggle { display: none; }   /* phones only, see below */

/* Existing notes: details shown read-only until "Edit details". */
.editor-details { display: none; align-items: flex-start; gap: 12px; }
#editor-view.details-locked .editor-details { display: flex; }
#editor-view.details-locked .editor-fields,
#editor-view.details-locked .meta-toggle { display: none !important; }
.ed-text { flex: 1 1 auto; min-width: 0; }
.ed-title { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.ed-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.ed-meta .tag-chip-static { margin: 0; }
.ed-sep { color: var(--line); }
#btn-edit-details { flex: 0 0 auto; font-size: 12px; padding: 4px 10px; }
.fields-done { min-width: 0; align-self: flex-end; align-items: flex-end; }
.md-empty { color: var(--ink-soft); font-style: italic; }

/* Rendered Markdown, scoped so the app's own compact heading styles don't leak in. */
.md-body { max-width: 780px; font-size: 14px; line-height: 1.6; color: var(--ink); overflow-wrap: break-word; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 {
  text-transform: none; letter-spacing: normal; color: var(--ink); margin: 1.1em 0 0.4em; line-height: 1.3;
}
.md-body > :first-child { margin-top: 0; }
.md-body h1 { font-size: 22px; }
.md-body h2 { font-size: 18px; border-bottom: 1px solid var(--line-soft); padding-bottom: 3px; }
.md-body h3 { font-size: 16px; }
.md-body h4, .md-body h5, .md-body h6 { font-size: 14px; }
.md-body p { margin: 0 0 0.8em; }
.md-body ul, .md-body ol { margin: 0 0 0.8em; padding-left: 1.6em; }
.md-body li > ul, .md-body li > ol { margin-bottom: 0; }
.md-body li.task { list-style: none; margin-left: -1.3em; }
.md-body li.task input { margin: 0 6px 0 0; vertical-align: middle; }
.md-body blockquote { margin: 0 0 0.8em; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--ink-soft); }
.md-body code { font-family: var(--mono); font-size: 12px; background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 3px; padding: 0 4px; }
.md-body pre { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 4px; padding: 10px 12px; overflow-x: auto; margin: 0 0 0.8em; }
.md-body pre code { background: none; border: none; padding: 0; }
.md-body hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md-body a { color: var(--accent); }
.md-body table { border-collapse: collapse; margin: 0 0 0.8em; font-size: 13px; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.md-body th { background: var(--bg-soft); }
.md-body .al-center { text-align: center; }
.md-body .al-right { text-align: right; }

/* ---------- Security page ---------- */
.page-scroll { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.page-title { font-size: 18px; margin: 0; }
#security-content { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 720px; }
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; }
.panel p { margin: 0 0 8px; }
.panel-note { font-size: 12px; color: var(--ink-soft); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.plain-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.plain-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.plain-table td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); }
.sec-actions { text-align: right; white-space: nowrap; }
.sec-actions button { font-size: 12px; padding: 3px 8px; margin-left: 4px; }

/* ---------- Phones: one pane at a time ---------- */
@media (max-width: 700px) {
  #topbar { padding-left: 16px; padding-right: 8px; }
  #app-body { padding: 0 8px 8px; }
  #message-banner { margin: 0 8px 8px; }
  #left-pane { width: 100% !important; }
  #left-pane-resizer { display: none; }
  #right-pane { display: none; }
  body.mobile-notes #left-pane { display: none; }
  body.mobile-notes #right-pane { display: flex; }
  .mobile-only { display: inline-block; }
  #grid-head { padding: 12px 14px 2px; }
  #btn-show-categories { margin: 0 0 8px -4px; }
  .view-title { font-size: 22px; }
  .grid-toolbar { gap: 4px; }
  .cat-btn, .plain-btn { padding: 0 8px; gap: 5px; }
  .plain-btn { width: 34px; justify-content: center; padding: 0; }
  .cat-btn svg, .lbl-wide { display: none; }   /* room for every button on one row */
  .lbl-phone { display: inline; }
  .plain-btn .lbl, .grid-toolbar .tb-sep { display: none; }   /* Search and Sort become icons */
  .search-box { order: 10; width: 100%; }
  .filter-count { position: absolute; top: -4px; right: -4px; }
  #notes-scroll { padding: 0 2px 8px; }
  #tag-bar-row { padding: 8px 12px; margin: 8px 14px 0; }
  /* An open note fills the screen edge to edge. */
  body.in-editor #app-body { padding: 0; }
  body.in-editor #right-pane { border-radius: 0; }
  .ml-item { padding-top: 10px; padding-bottom: 10px; }
  /* iPhone Safari zooms the whole page in when a field under 16px is focused,
     and doesn't zoom back out. Every field is 16px or more on phones. */
  input[type="text"], input[type="search"], input[type="date"], select, textarea,
  #editor-title, #editor-body { font-size: 16px; }
  #editor-body { line-height: 1.5; }
  /* iPhone date fields otherwise keep a minimum width wider than their box. */
  input[type="date"] { min-width: 0; max-width: 100%; }

  /* The grid becomes a list of cards: the title (and Edit) on top, then one
     line with content type · date · category · people · tag count. */
  table.notes-grid, table.notes-grid tbody { display: block; min-width: 0 !important; width: auto !important; }
  table.notes-grid colgroup, table.notes-grid thead { display: none; }
  table.notes-grid tr { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 3px 10px; padding: 10px 8px; border-bottom: 1px solid var(--line-soft); }
  table.notes-grid td { display: block; padding: 0; border: none; background: none !important; }
  table.notes-grid tr.row-review { box-shadow: inset 3px 0 var(--warn); }
  table.notes-grid tr.row-review td:first-child { box-shadow: none; }
  table.notes-grid tr.row-editing { background: var(--accent-soft); }
  table.notes-grid .col-check { grid-column: 1; grid-row: 1 / span 2; padding-top: 2px; text-align: left; }
  table.notes-grid .col-title { grid-column: 2; grid-row: 1; }
  table.notes-grid .col-actions { grid-column: 3; grid-row: 1; }
  table.notes-grid .col-meta { display: block; grid-column: 2 / -1; grid-row: 2; font-size: 12px; color: var(--ink-soft); }
  table.notes-grid tr:not(.row-editing) :is(.col-type, .col-date, .col-category, .col-people, .col-tags) { display: none; }
  .grid-title-link { white-space: normal; }
  /* Editing on a phone: every field on its own line, labelled. */
  table.notes-grid tr.row-editing td:not(.col-check):not(.col-actions):not(.col-title) { grid-column: 2 / -1; grid-row: auto; margin-top: 6px; }
  table.notes-grid tr.row-editing td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--ink-soft); margin-bottom: 2px; }
  table.notes-grid tr.row-editing .col-category { display: block !important; }
  table.notes-grid .grid-empty { grid-column: 1 / -1; }
  table.notes-grid tr.group-row { display: block; padding: 0; }
  table.notes-grid tr.group-row td { display: block; padding: 14px 4px 6px; }

  .editor-header { padding: 8px 12px; }
  .form-field, .form-field.wide { min-width: 0; flex: 1 1 100%; }
  .editor-toolbar { padding: 6px 12px; }
  .editor-panes.mode-split .editor-preview { display: none; }   /* too narrow for side by side */

  /* While the text box is showing, the fields fold into one tappable line. */
  #editor-view:not([data-mode="preview"]) .meta-toggle {
    display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
    padding: 6px 8px; font-size: 13px; background: var(--bg-soft); border-color: var(--line-soft);
  }
  .meta-chevron { color: var(--ink-soft); transition: transform 0.15s; flex: 0 0 auto; }
  .meta-toggle[aria-expanded="true"] .meta-chevron { transform: rotate(90deg); }
  .meta-label { font-weight: 600; flex: 0 0 auto; }
  .meta-summary { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  #editor-view.meta-collapsed:not([data-mode="preview"]) .editor-fields { display: none; }
  #editor-body { padding: 12px; }
  .page-scroll { padding: 12px; }
}

/* ---------- Adding scans (staging) ---------- */
#upload-view { background: var(--bg); }
.upload-header { flex: 0 0 auto; padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.upload-header .page-title { margin: 0; }
.upload-header .panel-note { margin: 0; }
.upload-summary { font-size: 13px; color: var(--ink-soft); }
.bulk-toolbar { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 8px 10px; background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 6px; }
.bulk-toolbar.has-selection { border-color: var(--accent); }
.bt-label { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.bulk-count { min-width: 6.5em; }  /* fixed width, so selecting rows never shifts the toolbar */
.bt-group { display: flex; align-items: center; gap: 6px; }
.bulk-category { width: 220px; }
.bulk-tag { width: 170px; }
.bulk-toolbar button { font-size: 12px; padding: 4px 10px; }
.staging-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; }
table.staging-table { width: 100%; min-width: 820px; border-collapse: collapse; font-size: 13px; }
table.staging-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); padding: 8px; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 2; white-space: nowrap; }
table.staging-table td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.staging-table tr.row-review td:first-child { box-shadow: inset 3px 0 var(--warn); }
table.staging-table input[type="text"], table.staging-table input[type="date"] { width: 100%; }
table.staging-table .col-check { width: 32px; }
table.staging-table .col-date { width: 150px; }
table.staging-table .col-category, table.staging-table .col-tags { width: 210px; }
.staging-filename { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); max-width: 220px; overflow-wrap: anywhere; }
.staging-filename a { color: var(--accent); }
.staging-status { font-size: 12px; }
.same-as-above { display: block; margin-top: 4px; text-align: left; white-space: normal; }
.progress { display: block; height: 6px; max-width: 320px; margin-top: 6px; background: var(--line-soft); border-radius: 3px; overflow: hidden; }
.progress-fill { display: block; height: 100%; width: 0; background: var(--accent-fill); transition: width 0.15s; }
.upload-failed { color: var(--err); }
.upload-dup { color: var(--ink-soft); }
.upload-dup a { color: var(--accent); }

#drop-overlay { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; background: rgba(27, 77, 143, 0.12); border: 3px dashed var(--accent); pointer-events: none; }
#drop-overlay div { background: var(--bg); color: var(--accent); font-size: 18px; font-weight: 600; padding: 16px 24px; border-radius: 8px; box-shadow: var(--shadow); }

@media (max-width: 700px) {
  .lbl-long { display: none; }
  .upload-header { padding: 8px 12px; }
  .upload-header .panel-note { display: none; }
  /* Bulk tools stay folded away until a row is ticked. */
  .bulk-toolbar:not(.has-selection) .bt-group { display: none; }
  .bulk-toolbar:not(.has-selection) .bulk-count::after { content: ' — tick rows to change several at once'; }
  .bulk-category, .bulk-tag { width: 100%; }
  .bt-group { flex: 1 1 100%; }
  table.staging-table, table.staging-table tbody { display: block; min-width: 0; }
  table.staging-table thead { display: none; }
  table.staging-table tr { display: grid; grid-template-columns: 28px 1fr; gap: 6px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
  table.staging-table tr.row-review { box-shadow: inset 3px 0 var(--warn); }
  table.staging-table tr.row-review td:first-child { box-shadow: none; }
  table.staging-table td { display: block; padding: 0; border: none; width: auto !important; }
  table.staging-table td:not(.col-check) { grid-column: 2; }
  table.staging-table .col-check { grid-row: 1; }
  .staging-filename { max-width: none; }
}


@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .plain-btn { color: var(--ink-soft); } }
:root[data-theme="dark"] .plain-btn { color: var(--ink-soft); }

/* ---------- Tag and category colors ----------
   Names match shared/colors.js. Chips use --chip-bg/--chip-fg; category
   dots and swatches use --dot. Anything without a color keeps the accent. */
.color-gray { --chip-bg: #eceff2; --chip-fg: #4a5561; --dot: #8a96a3; }
.color-red { --chip-bg: #fde8e8; --chip-fg: #a32026; --dot: #e0484f; }
.color-orange { --chip-bg: #feeede; --chip-fg: #9a4a0b; --dot: #ee7d24; }
.color-amber { --chip-bg: #fdf3d7; --chip-fg: #7d5a00; --dot: #d9a21b; }
.color-green { --chip-bg: #e4f4e8; --chip-fg: #1b6e3c; --dot: #2e9d57; }
.color-teal { --chip-bg: #dff4f2; --chip-fg: #0f6b66; --dot: #1fa39a; }
.color-blue { --chip-bg: #e7eefb; --chip-fg: #1b4d8f; --dot: #3a78d0; }
.color-indigo { --chip-bg: #ecebfb; --chip-fg: #3d3a9e; --dot: #5b57d6; }
.color-purple { --chip-bg: #f3e8fb; --chip-fg: #6d2c91; --dot: #9b51cf; }
.color-pink { --chip-bg: #fde7f1; --chip-fg: #9c1f5c; --dot: #df4f94; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .color-gray { --chip-bg: #2d343c; --chip-fg: #c3ccd5; }
  :root:not([data-theme="light"]) .color-red { --chip-bg: #3d2224; --chip-fg: #f08a8d; }
  :root:not([data-theme="light"]) .color-orange { --chip-bg: #3d2b1b; --chip-fg: #f5a86a; }
  :root:not([data-theme="light"]) .color-amber { --chip-bg: #3a3119; --chip-fg: #e8c46a; }
  :root:not([data-theme="light"]) .color-green { --chip-bg: #1e3627; --chip-fg: #6fcf8f; }
  :root:not([data-theme="light"]) .color-teal { --chip-bg: #183634; --chip-fg: #5fcdc4; }
  :root:not([data-theme="light"]) .color-blue { --chip-bg: #223350; --chip-fg: #8cb6ee; }
  :root:not([data-theme="light"]) .color-indigo { --chip-bg: #2a2a4d; --chip-fg: #a7a4f0; }
  :root:not([data-theme="light"]) .color-purple { --chip-bg: #37264a; --chip-fg: #cf9bf0; }
  :root:not([data-theme="light"]) .color-pink { --chip-bg: #40233a; --chip-fg: #f39ac5; }
}
:root[data-theme="dark"] .color-gray { --chip-bg: #2d343c; --chip-fg: #c3ccd5; }
:root[data-theme="dark"] .color-red { --chip-bg: #3d2224; --chip-fg: #f08a8d; }
:root[data-theme="dark"] .color-orange { --chip-bg: #3d2b1b; --chip-fg: #f5a86a; }
:root[data-theme="dark"] .color-amber { --chip-bg: #3a3119; --chip-fg: #e8c46a; }
:root[data-theme="dark"] .color-green { --chip-bg: #1e3627; --chip-fg: #6fcf8f; }
:root[data-theme="dark"] .color-teal { --chip-bg: #183634; --chip-fg: #5fcdc4; }
:root[data-theme="dark"] .color-blue { --chip-bg: #223350; --chip-fg: #8cb6ee; }
:root[data-theme="dark"] .color-indigo { --chip-bg: #2a2a4d; --chip-fg: #a7a4f0; }
:root[data-theme="dark"] .color-purple { --chip-bg: #37264a; --chip-fg: #cf9bf0; }
:root[data-theme="dark"] .color-pink { --chip-bg: #40233a; --chip-fg: #f39ac5; }

.tag-chip-static, .tag-chip { background: var(--chip-bg, var(--accent-soft)); color: var(--chip-fg, var(--accent)); }
.tagbar-chip:not(.active) { background: var(--chip-bg, var(--bg)); color: var(--chip-fg, var(--ink)); }
.tagbar-chip:not(.active) .tagbar-count { color: inherit; opacity: 0.7; }
.cat-dot { display: inline-block; flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--dot, transparent); margin-right: 6px; vertical-align: 0; }
.ml-item .cat-dot { margin-right: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 2px solid transparent; background: var(--dot, var(--bg)); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.swatch:hover { background: var(--dot, var(--bg-soft)); transform: scale(1.1); }
.swatch.none { background: var(--bg); position: relative; }
.swatch.none::after { content: ''; position: absolute; inset: 4px; border-top: 2px solid var(--err); transform: rotate(-45deg) translate(-3px, 4px); }
.swatch.current { border-color: var(--ink); }
.swatch-btn { width: 22px; height: 22px; padding: 0; border-radius: 50%; background: var(--dot, var(--bg)); border: 1px solid var(--line); }
.swatch-btn:hover { background: var(--dot, var(--bg-soft)); }
.swatch-btn:not([class*="color-"]) { border: 1px dashed var(--ink-soft); }   /* "no color" still visible in dark mode */

/* ---------- Grid selection and bulk bar ---------- */
@media (min-width: 701px) {
  table.notes-grid .col-check { text-align: center; padding-left: 8px; padding-right: 4px; }
  table.notes-grid tr.row-editing td.col-check { padding-top: 12px; }
}
#grid-bulk { flex: 0 0 auto; margin: 8px 16px; }
.small-btn { font-size: 12px; padding: 5px 10px; white-space: nowrap; }
.bulk-remove { max-width: 160px; }

/* ---------- Manage tags / categories ---------- */
.manage-tabs { display: inline-flex; max-width: 100%; overflow-x: auto; }
.manage-tabs button { flex: 0 0 auto; }
.manage-tabs button { border-radius: 0; margin-left: -1px; padding: 6px 16px; }
.manage-tabs button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.manage-tabs button:last-child { border-radius: 0 4px 4px 0; }
.manage-tabs button.active { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.manage-content { width: 100%; max-width: 980px; }
.manage-content .form-row { margin: 0 0 12px; }
.manage-table td { vertical-align: middle; }
.manage-table .m-color { width: 34px; }
.manage-table.no-color .m-color { display: none; }
.manage-table .m-name input { width: 100%; min-width: 140px; }
.manage-table .m-count { color: var(--ink-soft); font-size: 12px; white-space: nowrap; }
.manage-table .m-actions { white-space: nowrap; text-align: right; }
.manage-table .m-actions button { font-size: 12px; padding: 4px 8px; margin-left: 4px; }
.manage-table select { max-width: 190px; }
.manage-table tr.m-child .m-name { padding-left: 28px; }
.manage-table tr.m-top .m-name input { font-weight: 600; }
.manage-table tr.m-archived .m-name input { color: var(--ink-soft); }

/* ---------- Trash ---------- */
.trash-head { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 900px; }
.trash-table { max-width: 900px; }
.trash-table td { vertical-align: top; }
.trash-when { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.trash-actions { white-space: nowrap; text-align: right; }
.trash-actions button { font-size: 12px; padding: 4px 8px; margin-left: 4px; }

@media (max-width: 700px) {
  #grid-bulk { margin: 8px 12px; }
  .manage-table, .manage-table tbody { display: block; }
  .manage-table tr { display: grid; grid-template-columns: 34px 1fr; gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
  .manage-table td { display: block; padding: 0; border: none; }
  .manage-table td:not(.m-color) { grid-column: 2; }
  .manage-table.no-color tr { grid-template-columns: 1fr; }
  .manage-table.no-color td:not(.m-color) { grid-column: 1; }
  .manage-table .m-actions { text-align: left; }
  .manage-table .m-actions button:first-child { margin-left: 0; }
  .manage-table select { max-width: 100%; width: 100%; }
  .manage-table tr.m-child { padding-left: 20px; }
  .manage-table tr.m-child .m-name { padding-left: 0; }
  .trash-table, .trash-table tbody { display: block; }
  .trash-table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
  .trash-table td { display: block; padding: 0; border: none; }
  .trash-table .trash-actions { grid-column: 1 / -1; text-align: left; }
  .trash-table .trash-actions button:first-child { margin-left: 0; }
}

/* ---------- Phone editor (full-screen note) ---------- */
.phone-only { display: none !important; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 34px; padding: 0; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.active { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.icon-badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--accent-fill); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center; }
.tags-popover { width: 320px; }

/* Write / Preview pill (phones): in the category's color, gray without one.
   The active mode shows its word; the other just its icon. */
.mode-pill { flex: 0 0 auto; align-self: center; margin-left: auto; padding: 3px; gap: 2px; border-radius: 999px; background: var(--cat, var(--ink-soft)); }
.mode-pill button { display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 999px; background: transparent; color: #fff; font-weight: 600; font-size: 14px; padding: 5px 10px; }
.mode-pill button:hover { background: rgba(255, 255, 255, 0.15); }
.mode-pill button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mode-pill button span { display: none; }
.mode-pill button.active { background: var(--bg); color: var(--cat, var(--ink)); padding: 5px 14px; }
.mode-pill button.active svg { display: none; }
.mode-pill button.active span { display: inline; }

@media (max-width: 700px) {
  .phone-only { display: inline-flex !important; }
  /* The title row always shows (it holds the Write/Preview pill); while the
     fields are open, only the pill remains in it. The line under it takes
     the category's color. */
  #editor-view .editor-details { display: flex; align-items: center; }
  #editor-view:not(.details-locked) .ed-text { display: none; }
  .ed-meta { flex-direction: column; align-items: flex-start; gap: 1px; }   /* date above category, no separator */
  .ed-sep { display: none; }
  .editor-header { border-bottom: 2px solid var(--cat, var(--line)); }

  /* The app fills exactly the visible area, even with the keyboard open
     (--vvh / --vvtop are kept up to date by main.js). */
  #app { position: fixed; left: 0; right: 0; top: var(--vvtop, 0px); height: var(--vvh, 100dvh); }
  body.in-editor { background: var(--bg); }
  body.in-editor #topbar { display: none; }

  /* The note's own top bar: Back · status · tags · pen · trash. */
  .editor-header { padding-top: max(8px, env(safe-area-inset-top)); }
  .editor-topline { flex-wrap: nowrap; gap: 6px; }
  .editor-topline .back-btn { font-size: 14px; padding: 6px 12px; }
  #btn-editor-delete, #btn-edit-details, .fields-done, .meta-toggle { display: none !important; }
  .editor-status { font-size: 11px; white-space: nowrap; }
  .editor-status:not(.ok):not(.err) { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

  /* Tags live behind the tag icon only. */
  .ed-meta .tag-chip-static, .editor-fields .tags-field { display: none !important; }

  /* Split isn't offered on a phone; Write/Preview sit on the band instead. */
  .editor-toolbar .editor-mode-toggle { display: none; }
  #editor-view[data-mode="preview"] .editor-toolbar { display: none; }

  /* Formatting buttons: one row that scrolls sideways. */
  .editor-toolbar { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .editor-toolbar::-webkit-scrollbar { display: none; }
  .editor-toolbar button { flex: 0 0 auto; font-size: 13px; padding: 6px 10px; }
  .editor-toolbar .tb-sep { flex: 0 0 1px; }

  /* Room below the last line, so typing happens above the keyboard, not at its edge. */
  #editor-body { padding-bottom: calc(var(--vvh, 100dvh) * 0.35); }
  .editor-preview { padding-bottom: 40px; }
}

/* A category's color: --cat for the open note (set on #editor-view by
   editor.js), --cat-solid, a deeper shade that white text reads well on,
   for the notes list's line and buttons (set on #grid-view by grid.js). */
.cat-gray { --cat: #8a96a3; --cat-solid: #5f6b78; }
.cat-red { --cat: #e0484f; --cat-solid: #c23a41; }
.cat-orange { --cat: #ee7d24; --cat-solid: #c2621a; }
.cat-amber { --cat: #d9a21b; --cat-solid: #a57705; }
.cat-green { --cat: #2e9d57; --cat-solid: #23804a; }
.cat-teal { --cat: #1fa39a; --cat-solid: #16877f; }
.cat-blue { --cat: #3a78d0; --cat-solid: #2f6bc0; }
.cat-indigo { --cat: #5b57d6; --cat-solid: #4d49c8; }
.cat-purple { --cat: #9b51cf; --cat-solid: #8545b8; }
.cat-pink { --cat: #df4f94; --cat-solid: #c23c7e; }
