/* Northstar Notes. Built on the Altech UI kit: tokens first, change the look here. */

:root {
  --fs: 15px;
  --gap: 12px;
  --pad: 16px;
  --radius: 10px;
  --bar: 52px;
  --side: 260px;

  /* Dark (default) */
  --bg: #0a1213;
  --surface: #0f1819;
  --surface-2: #152122;
  --hover: rgba(233, 247, 233, 0.05);
  --text: #e8eee8;
  --muted: #93a39a;
  --line: rgba(233, 247, 233, 0.09);
  --accent: #b6f19b;
  --accent-2: #7fe0b4;
  --on-accent: #0a1212;
  --tint: rgba(182, 241, 155, 0.08);
  --danger: #ffb4ad;
  --danger-bg: rgba(255, 120, 110, 0.1);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  /* Code colours (keyword, control word, type, function, string, number, comment) */
  --hl-kw: #569cd6;
  --hl-ctl: #c586c0;
  --hl-type: #4ec9b0;
  --hl-fn: #dcdcaa;
  --hl-str: #ce9178;
  --hl-num: #b5cea8;
  --hl-com: #6a9955;
  color-scheme: dark;
}

:root[data-text="small"] { --fs: 14px; }
:root[data-text="large"] { --fs: 17px; }
:root[data-density="compact"] { --gap: 8px; --pad: 12px; --bar: 46px; }

:root[data-theme="light"] {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --hover: rgba(20, 40, 30, 0.05);
  --text: #18211c;
  --muted: #5d6b63;
  --line: #dde5df;
  --accent: #2f8a4a;
  --accent-2: #1f7a6a;
  --on-accent: #ffffff;
  --tint: rgba(47, 138, 74, 0.08);
  --danger: #b42318;
  --danger-bg: rgba(180, 35, 24, 0.07);
  --shadow: 0 12px 32px rgba(20, 30, 25, 0.12);
  --hl-kw: #0000ff;
  --hl-ctl: #af00db;
  --hl-type: #267f99;
  --hl-fn: #795e26;
  --hl-str: #a31515;
  --hl-num: #098658;
  --hl-com: #008000;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f5f7f5;
    --surface: #ffffff;
    --surface-2: #eef3ef;
    --hover: rgba(20, 40, 30, 0.05);
    --text: #18211c;
    --muted: #5d6b63;
    --line: #dde5df;
    --accent: #2f8a4a;
    --accent-2: #1f7a6a;
    --on-accent: #ffffff;
    --tint: rgba(47, 138, 74, 0.08);
    --danger: #b42318;
    --danger-bg: rgba(180, 35, 24, 0.07);
    --shadow: 0 12px 32px rgba(20, 30, 25, 0.12);
    --hl-kw: #0000ff;
    --hl-ctl: #af00db;
    --hl-type: #267f99;
    --hl-fn: #795e26;
    --hl-str: #a31515;
    --hl-num: #098658;
    --hl-com: #008000;
    color-scheme: light;
  }
}

/* ---- Base ---- */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs)/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: grid;
  grid-template-rows: var(--bar) minmax(0, 1fr);
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

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

.muted { color: var(--muted); }

/* ---- Buttons ---- */

.icon-btn,
.tool,
.button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.icon-btn { min-width: 34px; display: inline-grid; place-items: center; }
.icon-btn:hover, .tool:hover, .button:hover { background: var(--hover); }
.icon-btn.info { border-radius: 50%; padding: 0; font: italic 700 15px Georgia, serif; }

.button--primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.button--primary:hover { background: var(--accent-2); }
.button--danger { color: var(--danger); background: var(--danger-bg); border-color: transparent; }
.button--icon { min-width: 34px; display: inline-grid; place-items: center; padding: 0 8px; }
.button--icon.button--danger { margin-left: auto; }

/* ---- Top bar: menu | brand | contextual tools | save | settings | info ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 800;
}

.ctx-tools {
  flex: 1;
  display: flex;
  gap: 6px;
  justify-content: center;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.ctx-tools::-webkit-scrollbar { display: none; }

.tool { font-size: 0.9em; animation: fade 0.15s ease; }
.tool.is-on { border-color: var(--accent); color: var(--accent); background: var(--tint); }
.tool--danger { color: var(--danger); }
/* Icons in the tool bar and the line menu (drawn by icon() in app.js, colour from currentColor) */
.icon-svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool { display: inline-flex; align-items: center; gap: 6px; }
.tool-sep { width: 1px; align-self: stretch; margin: 6px 2px; background: var(--line); flex: none; }

@keyframes fade { from { opacity: 0; transform: translateY(-2px); } }

.save { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85em; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.save[data-state="saving"] .save-dot, .save[data-state="loading"] .save-dot { background: #e7c66b; }
.save[data-state="error"] { color: var(--danger); }
.save[data-state="error"] .save-dot { background: var(--danger); }

/* ---- Layout: sidebar + document, full screen ---- */

.layout { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; }

.sidebar {
  width: var(--side);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}

:root[data-side="closed"] .sidebar { display: none; }
/* With no sidebar in the grid, the page must take the full row, not its content width. */
:root[data-side="closed"] .layout { grid-template-columns: minmax(0, 1fr); }

.side-head { display: flex; gap: 6px; }

.side-head input {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.nav-list { display: grid; gap: 2px; align-content: start; overflow-y: auto; min-height: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.nav-item:hover { background: var(--hover); }

/* Page tree: each level indents a little. */
.nav-row { display: flex; align-items: center; gap: 2px; padding-left: calc(var(--depth, 0) * 14px); min-width: 0; }
.nav-row .nav-item { flex: 1; min-width: 0; padding-left: 4px; }

.nav-toggle {
  flex: none;
  width: 20px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8em;
}

button.nav-toggle:hover { background: var(--hover); color: var(--text); }

.nav-add {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
}

.nav-row:hover .nav-add,
.nav-row.is-active .nav-add,
.nav-add:focus-visible { opacity: 1; }
.nav-add:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--tint); color: var(--accent); font-weight: 600; }
.nav-icon { width: 20px; flex: none; text-align: center; }
.nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-empty { padding: 8px; color: var(--muted); font-size: 0.9em; }

/* The ⋯ button on each page row: same look as +, and always there on a touch screen. */
.nav-more {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1em;
  line-height: 1;
  opacity: 0;
}
.nav-row:hover .nav-more,
.nav-row.is-active .nav-more,
.nav-more:focus-visible,
.nav-more[aria-expanded="true"] { opacity: 1; }
.nav-more:hover { background: var(--hover); color: var(--text); }
@media (hover: none) { .nav-more { opacity: 1; } }

/* Favourites: a header and a short list above the page tree. */
.fav-section { display: grid; gap: 4px; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.fav-head {
  margin: 0;
  padding: 4px 8px 0;
  color: var(--muted);
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.fav-list { display: grid; gap: 2px; max-height: 30vh; overflow-y: auto; align-content: start; }
.fav-list .nav-empty { padding: 4px 8px; }

/* Side peek: the page's lines, read only. */
.peek-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.peek-body { align-content: start; }
.peek-block { padding-left: calc(var(--depth, 0) * 16px); min-width: 0; overflow-wrap: anywhere; }
.peek-block p, .peek-block h3, .peek-block blockquote, .peek-block details { margin: 0; }
.peek-block h3 { font-size: 1.05em; }
.peek-block blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.peek-block .peek-pre { white-space: pre-wrap; }
.peek-block pre { margin: 0; padding: 8px; border-radius: 8px; background: var(--bg); overflow-x: auto; }
.peek-block img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.peek-block hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.peek-todo { display: flex; gap: 8px; align-items: flex-start; }
.peek-todo.is-done span { color: var(--muted); text-decoration: line-through; }
.peek-page {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: var(--hover);
  text-align: left;
}
.peek-foot { padding: 8px; border-top: 1px solid var(--line); border-bottom: 0; }
.peek-foot .nav-item { width: 100%; }

.scrim { position: fixed; inset: var(--bar) 0 0 0; background: rgba(0, 0, 0, 0.45); z-index: 5; }

/* ---- Document ---- */

.doc {
  overflow-y: auto;
  padding: calc(var(--pad) * 1.5) clamp(16px, 5vw, 72px) 96px;
  min-width: 0;
}

.page-head { display: flex; align-items: flex-start; gap: 10px; }

.page-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 1.7em;
  line-height: 1;
}

.page-icon:hover { background: var(--hover); }

.page-title {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 4px 0;
  background: transparent;
  font-size: 1.75em;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  resize: none;
  overflow: hidden;
}

.page-title:focus, .block-text:focus { outline: none; }

.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 4px 0 18px 54px;
  color: var(--muted);
  font-size: 0.85em;
}

.tag { padding: 1px 8px; border-radius: 999px; background: var(--tint); color: var(--accent); }

.blocks { display: grid; gap: 2px; }

/* Path to the current page */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin-bottom: 8px; font-size: 0.85em; color: var(--muted); }
.crumb { border: 0; border-radius: 6px; padding: 2px 6px; background: transparent; color: inherit; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb:hover { background: var(--hover); color: var(--text); }

/* A link to a sub-page, shown as a line on the parent page */
.page-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.page-link:focus { outline: none; }
.page-link-icon { width: 20px; text-align: center; }
.page-link-title { font-weight: 600; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.page-link:hover .page-link-title { text-decoration-color: var(--accent); }

.block {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 8px;
  border-radius: 8px;
}

.block { position: relative; margin-left: calc(var(--indent, 0) * 24px); }
.block:hover { background: var(--hover); }

/* Drag handle, shown on hover to the left of a line (mouse only). */
.block-drag {
  position: absolute;
  top: 6px;
  left: -24px;
  width: 20px;
  color: var(--muted);
  font-size: 0.85em;
  letter-spacing: -2px;
  text-align: center;
  cursor: grab;
  user-select: none;
  opacity: 0;
}

.block:hover .block-drag { opacity: 1; }
.block.is-dragging { opacity: 0.4; }
.block.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.block.drop-after { box-shadow: 0 2px 0 var(--accent); }

@media (hover: none) { .block-drag { display: none; } }

/* Hover controls to the left of the grab handle: ⋯ (line options) then + (add a line below). */
.line-tools {
  position: absolute;
  top: 4px;
  left: -64px;
  z-index: 2;
  display: flex;
  opacity: 0;
  transition: opacity 0.12s;
}
.block:hover .line-tools, .block:focus-within .line-tools, .line-tools:focus-within { opacity: 1; }
.line-tool {
  display: grid;
  place-items: center;
  width: 18px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.line-tool:hover, .line-tool:focus-visible { background: var(--hover); color: var(--text); outline: none; }
.line-add { font-weight: 700; }
@media (hover: none) { .line-tools { display: none; } }

/* The menu opened by ⋯ */
.line-menu {
  position: fixed;
  z-index: 31;
  min-width: 190px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.line-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.line-menu-item:hover, .line-menu-item:focus-visible { background: var(--hover); outline: none; }
.line-menu-item.is-danger { color: var(--danger); }
.line-menu-item.is-open { background: var(--hover); }
/* On a phone the second menu takes the first one's place; the first waits behind it. */
.line-menu.is-behind { visibility: hidden; }
.line-menu-item .icon-svg { flex: none; }
.line-menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-menu-hint { flex: none; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.85em; }
.line-menu-tick { flex: none; color: var(--accent); }
.line-menu-more { flex: none; color: var(--muted); font-size: 1.1em; line-height: 1; }
.line-menu-sep { height: 1px; margin: 6px 4px; border: 0; background: var(--line); }

/* The rename row at the top of a column heading menu */
.menu-head { display: flex; align-items: center; gap: 6px; padding: 2px 2px 4px; }
.menu-head-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu-head-icon:hover, .menu-head-icon:focus-visible { background: var(--hover); outline: none; }
.menu-name {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.menu-name:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* The "Type / for options" hint only shows on the line being typed in. */
.block--text .block-text:not(:focus)::placeholder { color: transparent; }

/* Photos and files */
.media { flex: 1; min-width: 0; display: grid; gap: 4px; padding: 4px 0; }
.image-link { justify-self: start; display: block; max-width: 100%; border-radius: 8px; }
.block-image { display: block; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; }

.block-caption {
  width: 100%;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.9em;
  resize: none;
  overflow: hidden;
}

.block-caption:focus { outline: none; color: var(--text); }
.block--image:not(:focus-within) .block-caption:placeholder-shown { opacity: 0; }

.file-card {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.file-card:hover { background: var(--hover); }
.file-card.is-missing { color: var(--muted); font-size: 0.9em; }
.file-icon { font-size: 1.3em; }
.file-meta { display: grid; min-width: 0; }
.file-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta small { color: var(--muted); }

.upload-progress { display: grid; gap: 6px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); }
.upload-progress progress { width: 100%; accent-color: var(--accent); }
.doc.is-drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* Formatted view of a line (shown when it isn't being edited) */
.block-view {
  display: none;
  flex: 1;
  min-width: 0;
  padding: 4px 0;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}

.block.has-view:not(.is-editing) .block-view { display: block; }
.block.has-view:not(.is-editing) .block-text:not(.toggle-body) { display: none; }
.block--heading .block-view { font-size: 1.3em; font-weight: 700; line-height: 1.3; }
.block--quote .block-view { font-size: 1.08em; }
.block--todo.is-done .block-view { color: var(--muted); text-decoration: line-through; }
.block-view a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.block-view code { padding: 1px 5px; border-radius: 4px; background: var(--surface-2); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88em; }
.block-view .mention { padding: 0 4px; border-radius: 4px; background: var(--tint); font-weight: 600; text-decoration: none; }
.block-view .mention:hover { text-decoration: underline; }
.mention.is-missing { color: var(--muted); text-decoration: line-through; }

.backlinks { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); }
.backlinks-head { width: 100%; margin: 0 0 4px; color: var(--muted); font-size: 0.85em; }

.block-mark { flex: none; min-width: 18px; padding-top: 4px; color: var(--muted); text-align: center; line-height: 1.55; }
.block-mark--num { min-width: 22px; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

.toggle-btn {
  flex: none;
  width: 22px;
  height: 26px;
  margin-top: 3px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.toggle-btn:hover { background: var(--hover); color: var(--text); }
.toggle-stack { flex: 1; min-width: 0; display: grid; }
.toggle-body { font-size: 0.95em; }

.block--quote { border-left: 3px solid var(--text); border-radius: 0 8px 8px 0; padding-left: 12px; }
.block--quote .block-text { font-size: 1.08em; }

.block--code { padding: 8px 12px; background: var(--surface-2); }
.block--code:hover, .block--code:focus-within { background: var(--surface-2); }
/* The text box and its coloured copy (.code-hl) must match exactly, so the colours sit under the letters. */
.block--code .block-text, .block--code .code-hl {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 2;
}

.block--divider { padding-top: 6px; padding-bottom: 6px; }
.divider { flex: 1; padding: 6px 0; border-radius: 4px; cursor: pointer; }
.divider hr { margin: 0; border: 0; border-top: 1px solid var(--line); }
.divider:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The / menu */
.slash-menu {
  position: fixed;
  z-index: 30;
  width: min(300px, calc(100vw - 16px));
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.slash-head { margin: 4px 8px 6px; color: var(--muted); font-size: 0.75em; letter-spacing: 0.05em; text-transform: uppercase; }

.slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.slash-item:hover { background: var(--hover); }
.slash-item.is-on { background: var(--tint); }

.slash-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.85em;
}

.slash-text { display: grid; min-width: 0; }
.slash-text small { color: var(--muted); font-size: 0.8em; }
.block:focus-within { background: var(--surface-2); }

.block-text {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 4px 0;
  background: transparent;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
}

.block-text::placeholder, .page-title::placeholder { color: var(--muted); opacity: 0.7; }

.block--heading { margin-top: 12px; }
.block--heading .block-text { font-size: 1.3em; font-weight: 700; line-height: 1.3; }

.block--callout { padding: 6px 12px; background: var(--tint); border-left: 3px solid var(--accent); }
.block--callout:hover, .block--callout:focus-within { background: var(--tint); }

.block-check { flex: none; width: 18px; height: 18px; margin: 6px 0 0; accent-color: var(--accent); cursor: pointer; }
.block--todo.is-done .block-text { color: var(--muted); text-decoration: line-through; }

.add-block {
  margin-top: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.add-block:hover { background: var(--hover); color: var(--text); }

.empty { display: grid; gap: 12px; justify-items: start; color: var(--muted); }

/* ---- Database tables ---- */

.db { display: grid; gap: 6px; justify-items: start; }
.db-scroll { justify-self: stretch; }

.db-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

/* Fixed layout: each column's width comes from its <col>, so dragging a heading's edge sets it exactly.
   The last column (the + one) takes whatever room is left. The table's min-width is set in code. */
.db-table { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; }

.db-table th,
.db-table td {
  min-width: 0;
  padding: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--grid-line);
  text-align: left;
  vertical-align: middle;
}
.db-table th { position: relative; }
.db-table td { overflow: hidden; }

/* Lines between columns: clearer than the row lines, and the same on a phone. */
:root { --grid-line: color-mix(in srgb, var(--text) 28%, transparent); }
.db-table.no-vlines th,
.db-table.no-vlines td { border-right-color: transparent; }

/* Left, centred or right content, set per column in its settings. */
.db-table [data-align="center"] { text-align: center; }
.db-table [data-align="right"] { text-align: right; }
.db-table [data-align="center"] .th-btn,
.db-table [data-align="center"] .cell-pills,
.db-table [data-align="center"] .cell-links,
.db-table [data-align="center"] .name-cell { justify-content: center; }
.db-table [data-align="right"] .th-btn,
.db-table [data-align="right"] .cell-pills,
.db-table [data-align="right"] .cell-links,
.db-table [data-align="right"] .name-cell { justify-content: flex-end; }
.db-table [data-align="center"] .th-btn,
.db-table [data-align="center"] .cell-pills { text-align: center; }
.db-table [data-align="right"] .th-btn,
.db-table [data-align="right"] .cell-pills { text-align: right; }

.db-table .col-end { border-right: 0; }
.db-table tbody tr:last-child td { border-bottom: 0; }
.db-table thead th { background: var(--surface); color: var(--muted); font-size: 0.9em; }
.db-table tbody tr:hover td { background: var(--hover); }

/* The first column stays put when the table scrolls sideways. */
.db-table .col-sticky { position: sticky; left: 0; z-index: 1; background: var(--bg); }
.db-table thead .col-sticky { z-index: 2; background: var(--surface); }
.db-table tbody tr:hover .col-sticky { background: var(--surface-2); }
/* The last frozen column gets a firmer edge, so it is clear what stays put. */
.db-table .col-sticky-last { border-right: 2px solid var(--line); }
.db-table tfoot .col-sticky { background: var(--surface); }

/* The totals row under the table */
.db-table .db-totals td { border-top: 1px solid var(--line); border-bottom: 0; background: var(--surface); }
.cell-total {
  display: flex;
  align-items: baseline;
  justify-content: inherit;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 4px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9em;
  text-align: inherit;
  cursor: pointer;
}
.cell-total:hover, .cell-total:focus-visible { background: var(--hover); outline: none; }
.total-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.total-value { color: var(--text); font-weight: 600; }
/* With no total set, the word "Calculate" only shows when the pointer is over the row. */
.db-totals .cell-total:not(:hover):not(:focus-visible) .total-value:only-child { color: transparent; }
.db-table .col-open { text-align: center; }
.db-table .col-open .open-btn { margin: 0; }

/* The handle on a heading's right edge, over the line between columns. Drag it to resize the column. */
.col-resize {
  position: absolute;
  top: 0;
  right: -6px;
  bottom: 0;
  width: 12px;
  z-index: 3;
  cursor: col-resize;
  touch-action: none;
}
.col-resize::after {
  content: "";
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 4px;
  width: 4px;
  border-radius: 2px;
  background: transparent;
  transition: background 0.12s;
}
.col-resize:hover::after, .col-resize:focus-visible::after, .col-resize.is-on::after { background: var(--accent); }
.col-resize:focus-visible { outline: none; }
.db-table.is-resizing { user-select: none; cursor: col-resize; }
@media (pointer: coarse) {
  .col-resize { right: -12px; width: 24px; }
  .col-resize::after { left: 10px; background: color-mix(in srgb, var(--accent) 40%, transparent); }
}

.th-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.th-btn .th-name { overflow: hidden; text-overflow: ellipsis; }

button.th-btn:hover { background: var(--hover); color: var(--text); }
.th-type { width: 18px; flex: none; text-align: center; color: var(--muted); font-size: 0.85em; }
.th-emoji { color: inherit; font-size: 1em; }

/* Chrome draws a date's text inside its own box, so give that box the column's alignment too. */
.db-table [data-align="center"] input[type="date"]::-webkit-datetime-edit,
.db-table [data-align="right"] input[type="date"]::-webkit-datetime-edit { text-align: inherit; }
.cell-input {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  text-align: inherit;
}

.cell-input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface-2); }
/* Wrapped columns: the text box grows down instead of scrolling sideways. */
.db-table td.is-wrap { overflow: visible; white-space: normal; }
.cell-wrap { display: block; overflow: hidden; resize: none; line-height: 1.45; }
.cell-name { font-weight: 600; }
.cell-check { width: 18px; height: 18px; margin: 10px; accent-color: var(--accent); cursor: pointer; }

.cell-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  text-align: left;
}

.cell-empty { color: var(--muted); }
.name-cell { display: flex; align-items: center; }

.open-btn {
  flex: none;
  margin-right: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8em;
  opacity: 0;
}

.db-table tr:hover .open-btn,
.db-table tr:focus-within .open-btn,
.open-btn:focus-visible { opacity: 1; }

@media (hover: none) { .open-btn { opacity: 1; } }
.open-btn.is-always { opacity: 1; }

/* Option pills. Soft colours that read on light and dark. */
.pill { padding: 1px 8px; border-radius: 999px; background: var(--pill, rgba(140, 150, 145, 0.28)); font-size: 0.85em; white-space: nowrap; }
.pill[data-color="gray"] { --pill: rgba(140, 150, 145, 0.28); }
.pill[data-color="brown"] { --pill: rgba(160, 110, 70, 0.32); }
.pill[data-color="orange"] { --pill: rgba(230, 140, 50, 0.32); }
.pill[data-color="yellow"] { --pill: rgba(220, 185, 50, 0.34); }
.pill[data-color="green"] { --pill: rgba(80, 185, 105, 0.32); }
.pill[data-color="blue"] { --pill: rgba(70, 140, 230, 0.32); }
.pill[data-color="purple"] { --pill: rgba(150, 110, 220, 0.34); }
.pill[data-color="pink"] { --pill: rgba(225, 100, 170, 0.32); }
.pill[data-color="red"] { --pill: rgba(230, 80, 70, 0.32); }

/* Properties at the top of a row's own page: a dropdown, like the Settings cards */
.row-props-group { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.row-props-group > summary { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 8px; border-radius: 6px; cursor: pointer; list-style: none; color: var(--muted); }
.row-props-group > summary::-webkit-details-marker { display: none; }
.row-props-group > summary:hover { background: var(--hover); color: var(--text); }
.row-props-group > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-props-title { font-weight: 600; }
.row-props-count { color: var(--muted); font-size: 0.85em; }
.row-props-group > summary .set-chev { margin-left: auto; }
.row-props-group[open] > summary .set-chev { transform: rotate(-135deg); }
.row-props { display: grid; grid-template-columns: minmax(110px, 180px) minmax(0, 1fr); gap: 2px 8px; margin-top: 6px; }

.row-prop-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.row-prop-name:hover { background: var(--hover); color: var(--text); }
.row-prop-value { min-width: 0; border-radius: 6px; }
.row-prop-value:hover { background: var(--hover); }

/* Views: tabs, board */
.db-body { display: grid; gap: 6px; justify-items: start; width: 100%; min-width: 0; }

.view-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  justify-self: stretch;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.view-tab {
  min-height: 30px;
  padding: 2px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.view-tab[role=tab] { touch-action: none; user-select: none; -webkit-user-select: none; position: relative; cursor: grab; }
.view-tab.is-dragging { z-index: 5; cursor: grabbing; background: var(--surface-2); color: var(--text); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); opacity: 0.95; }
.view-bar.is-sorting { cursor: grabbing; }
.view-tab.drop-before::before,
.view-tab.drop-after::after { content: ""; position: absolute; top: 2px; bottom: 2px; width: 3px; border-radius: 2px; background: var(--accent); }
.view-tab.drop-before::before { left: -3px; }
.view-tab.drop-after::after { right: -3px; }
.view-tab:hover { background: var(--hover); color: var(--text); }
.view-tab.is-on { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* Icon buttons above a table, with New and its menu on the right */
.view-tools { display: flex; align-items: center; gap: 2px; margin-left: auto; }

.view-tool {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.view-tool:hover, .view-tool:focus-visible { background: var(--hover); color: var(--text); }
.view-tool.is-on { color: var(--accent); }

.view-tool-count {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}

.new-split { display: inline-flex; margin-left: 6px; }
.new-main, .new-more {
  min-height: 32px;
  border: 0;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.new-main { padding: 0 12px; border-radius: 6px 0 0 6px; }
.new-more { display: inline-grid; place-items: center; width: 30px; padding: 0; border-left: 1px solid color-mix(in srgb, var(--bg) 35%, transparent); border-radius: 0 6px 6px 0; }
.new-main:hover, .new-more:hover { filter: brightness(1.1); }

.view-search { display: flex; align-items: center; gap: 6px; justify-self: stretch; padding: 2px 6px 2px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--muted); }
.view-search-input { flex: 1; min-width: 0; min-height: 34px; border: 0; background: transparent; color: var(--text); }
.view-search-input:focus { outline: none; }
.view-search:focus-within { border-color: var(--accent); }

.db-holder { display: grid; gap: 6px; justify-self: stretch; width: 100%; min-width: 0; }
.full-title { margin-right: 10px; }
/* Full screen: covers the page under the top bar. Drawers (z-index 10) still open above it. */
.db.is-full {
  position: fixed;
  inset: var(--bar) 0 0 0;
  z-index: 9;
  align-content: start;
  padding: 10px 14px 20px;
  overflow: auto;
  background: var(--bg);
}

.choice--align { grid-auto-flow: column; justify-content: center; justify-items: center; align-items: center; gap: 6px; padding: 8px 10px; }
.drawer-actions[hidden] { display: none; }

.board { display: flex; align-items: flex-start; gap: var(--gap); width: 100%; overflow-x: auto; padding-bottom: 8px; }

.lane {
  flex: 0 0 270px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
}

.lane.is-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.lane-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; }
.lane-count { color: var(--muted); font-size: 0.85em; }
.lane-add { justify-self: start; margin-top: 0; }

.card {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.card.is-dragging { opacity: 0.5; }
.card:focus-within { border-color: var(--accent); }
.card-top { display: flex; align-items: center; gap: 4px; }
.card-drag { padding: 0 2px; color: var(--muted); cursor: grab; user-select: none; letter-spacing: -2px; }
.card-title { flex: 1; min-width: 0; padding: 2px 0; border: 0; background: transparent; font-weight: 600; }
.card-title:focus { outline: none; }
.card-props { display: flex; flex-wrap: wrap; gap: 4px; }
.card-meta { color: var(--muted); font-size: 0.8em; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-status { width: auto; min-height: 28px; padding: 2px 4px; border-radius: 6px; }
.card .open-btn { opacity: 1; margin: 0; }

@media (hover: none) { .card-drag { display: none; } }

.filter-row { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.field .filter-row .opt-row select { flex: 1; min-width: 0; width: auto; }
.field .opt-row #v-sort, .field .opt-row #v-dir { flex: 1; min-width: 0; width: auto; }

/* Calendar view */
.cal { gap: 10px; }
.cal-head { display: flex; align-items: center; gap: 6px; }
.cal-month { min-width: 9em; margin: 0 4px; font-size: 1.1em; text-align: center; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  justify-self: stretch;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.cal-wd {
  padding: 6px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8em;
  font-weight: 600;
}

.cal-day {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  min-height: 96px;
  padding: 4px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.cal-day.is-out { background: var(--surface); }
.cal-day.is-out .cal-num { color: var(--muted); opacity: 0.6; }
.cal-day.is-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.cal-day.is-picked { background: var(--tint); }

.cal-num {
  align-self: flex-start;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 0.85em;
}

.cal-num:hover { background: var(--hover); }
.cal-day.is-today .cal-num { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.cal-items { display: grid; gap: 3px; min-width: 0; }
.cal-dots { display: none; color: var(--accent); font-size: 0.8em; letter-spacing: 1px; text-align: center; }

.cal-chip {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 2px 6px;
  border: 0;
  border-left: 3px solid var(--pill, rgba(140, 150, 145, 0.6));
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 0.8em;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-chip:hover { background: var(--hover); }
.cal-chip.is-dragging { opacity: 0.4; }
.cal-chip[data-color="gray"] { --pill: rgba(140, 150, 145, 0.7); }
.cal-chip[data-color="brown"] { --pill: rgba(160, 110, 70, 0.8); }
.cal-chip[data-color="orange"] { --pill: rgba(230, 140, 50, 0.85); }
.cal-chip[data-color="yellow"] { --pill: rgba(220, 185, 50, 0.85); }
.cal-chip[data-color="green"] { --pill: rgba(80, 185, 105, 0.85); }
.cal-chip[data-color="blue"] { --pill: rgba(70, 140, 230, 0.85); }
.cal-chip[data-color="purple"] { --pill: rgba(150, 110, 220, 0.85); }
.cal-chip[data-color="pink"] { --pill: rgba(225, 100, 170, 0.85); }
.cal-chip[data-color="red"] { --pill: rgba(230, 80, 70, 0.85); }

.cal-agenda, .cal-undated { display: grid; gap: 6px; justify-self: stretch; }
.cal-agenda h3 { margin: 6px 0 0; font-size: 1em; }
.cal-list { display: grid; gap: 4px; max-width: 520px; }
.cal-list .cal-chip { padding: 8px 10px; font-size: 0.95em; }
.cal-undated summary { color: var(--muted); cursor: pointer; }
.cal-undated[open] summary { margin-bottom: 6px; }

/* Option picker and property drawer */
.choose-list { display: grid; gap: 2px; }
.choose-item { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.choose-item:hover { background: var(--hover); }
.choose-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.opt-list { display: grid; gap: 6px; }
.opt-row { display: flex; align-items: center; gap: 6px; }
.field .opt-row input { flex: 1; min-width: 0; }
.field .opt-row select { width: auto; flex: none; }

/* ---- Drawers (info, settings, page details) ---- */

.drawer {
  position: fixed;
  top: var(--bar);
  right: 0;
  bottom: 0;
  z-index: 10;
  width: min(360px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--pad);
  border-bottom: 1px solid var(--line);
}

.drawer-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; padding: var(--pad); overflow-y: auto; }
.drawer-body p, .drawer-body ul { margin: 0; }
.drawer-body ul { padding-left: 18px; display: grid; gap: 8px; }
.drawer-body kbd { padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font-size: 0.9em; }

.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; font-weight: 600; font-size: 0.9em; }
.field select, .field input { max-width: 100%; }

.field input, .field textarea, .field select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-weight: 400;
  font-size: var(--fs);
}

/* Tick boxes inside a field are not text boxes: keep them small and square. */
.field input[type="checkbox"] {
  flex: none;
  width: 18px;
  height: 18px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  accent-color: var(--accent);
}

.field textarea { resize: vertical; }
.field small { color: var(--muted); font-weight: 400; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Buttons that are links (Change password, People) look like the other buttons. */
a.button { display: inline-flex; align-items: center; justify-content: center; color: inherit; text-decoration: none; }
a.button:visited { color: inherit; }

/* Settings covers the whole screen. Its body fills the width too (the old 720px cap
   hugged the left edge, because justify-self does nothing inside a flex column). */
#settings { top: 0; left: 0; right: 0; width: auto; max-width: none; border-left: 0; }
#settings .drawer-body { width: 100%; }

/* Surface styles: Slate is the default (the blue-grey already in :root).
   Graphite, Midnight and Warm Stone each override --bg, --surface, --surface-2,
   --hover, --text, --muted, --line and --shadow for dark and light. */

/* Graphite – neutral and near black */
:root[data-surface="graphite"] {
  --bg: #0e0e0e;
  --surface: #161616;
  --surface-2: #1e1e1e;
  --hover: rgba(255, 255, 255, 0.05);
  --text: #e4e4e4;
  --muted: #999;
  --line: rgba(255, 255, 255, 0.09);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
:root[data-surface="graphite"][data-theme="light"] {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #eaeaea;
  --hover: rgba(0, 0, 0, 0.05);
  --text: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
}
@media (prefers-color-scheme: light) {
  :root[data-surface="graphite"][data-theme="auto"] {
    --bg: #f4f4f4;
    --surface: #ffffff;
    --surface-2: #eaeaea;
    --hover: rgba(0, 0, 0, 0.05);
    --text: #1a1a1a;
    --muted: #666;
    --line: #ddd;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
  }
}

/* Midnight – deep navy */
:root[data-surface="midnight"] {
  --bg: #060e1e;
  --surface: #0b1528;
  --surface-2: #111d34;
  --hover: rgba(180, 210, 255, 0.06);
  --text: #dde4f0;
  --muted: #7e90ab;
  --line: rgba(180, 210, 255, 0.1);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
:root[data-surface="midnight"][data-theme="light"] {
  --bg: #f0f3f9;
  --surface: #ffffff;
  --surface-2: #e4e9f3;
  --hover: rgba(20, 35, 70, 0.05);
  --text: #161c2e;
  --muted: #5a6580;
  --line: #d3dae8;
  --shadow: 0 12px 32px rgba(15, 25, 50, 0.12);
}
@media (prefers-color-scheme: light) {
  :root[data-surface="midnight"][data-theme="auto"] {
    --bg: #f0f3f9;
    --surface: #ffffff;
    --surface-2: #e4e9f3;
    --hover: rgba(20, 35, 70, 0.05);
    --text: #161c2e;
    --muted: #5a6580;
    --line: #d3dae8;
    --shadow: 0 12px 32px rgba(15, 25, 50, 0.12);
  }
}

/* Warm stone – soft and warm */
:root[data-surface="warmstone"] {
  --bg: #12100e;
  --surface: #1a1714;
  --surface-2: #231f1b;
  --hover: rgba(240, 220, 190, 0.06);
  --text: #e8e0d6;
  --muted: #a09484;
  --line: rgba(240, 220, 190, 0.1);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
:root[data-surface="warmstone"][data-theme="light"] {
  --bg: #f7f3ef;
  --surface: #fffdf9;
  --surface-2: #ede8e1;
  --hover: rgba(60, 40, 20, 0.05);
  --text: #2a2218;
  --muted: #786a5a;
  --line: #ddd5ca;
  --shadow: 0 12px 32px rgba(50, 30, 10, 0.1);
}
@media (prefers-color-scheme: light) {
  :root[data-surface="warmstone"][data-theme="auto"] {
    --bg: #f7f3ef;
    --surface: #fffdf9;
    --surface-2: #ede8e1;
    --hover: rgba(60, 40, 20, 0.05);
    --text: #2a2218;
    --muted: #786a5a;
    --line: #ddd5ca;
    --shadow: 0 12px 32px rgba(50, 30, 10, 0.1);
  }
}

/* ---- Settings: one tab per group (Notes, Appearance, App, Backup, Account); the panel under the tabs shows the chosen one ---- */
/* The tabs wrap rather than scroll: inside the drawer's grid a scrolling bar can shrink to nothing. */
.icon-tabs.set-tabs { margin-bottom: 14px; flex-wrap: wrap; overflow: visible; }
.set-panel { min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.set-panel[hidden] { display: none; }
.set-heading { display: grid; gap: 2px; }
.set-heading strong { font-weight: 600; }
.set-heading small { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.set-sub { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.set-body { display: grid; gap: 10px; padding: 16px; }
.set-body .set-note { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.set-label { font-weight: 600; font-size: 0.9em; }

/* Appearance Mode: big choice buttons, a tick box and colour swatches. */
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choice { display: grid; gap: 6px; align-content: start; justify-items: start; min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 0.9em; font-weight: 600; text-align: left; cursor: pointer; }
.choice small { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--tint); color: var(--accent); }
/* Logo and icons, at the bottom of Appearance Mode. */
.brand-section { display: grid; gap: 10px; margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.brand-icons { display: grid; gap: 10px; }
.prev { display: flex; gap: 4px; }
.prev i { font-style: normal; width: 22px; height: 22px; display: inline-grid; place-items: center; font-size: 1.1em; line-height: 1; }
.prev-plain i { color: var(--muted); }
.prev i.tile { border-radius: 7px; background: color-mix(in srgb, currentColor 20%, transparent); }
.ct-blue { color: var(--c-blue); }
.ct-green { color: var(--c-green); }
.ct-amber { color: var(--c-amber); }
.ct-violet { color: var(--c-violet); }
.ct-rose { color: var(--c-rose); }
.ct-teal { color: var(--c-teal); }

/* Surface style cards: 4 columns on desktop, 2 on phone, each with a colour preview slab. */
/* Appearance Mode: text size, spacing, surface style and theme are dropdown pickers. */
.picker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
@media (max-width: 600px) { .picker-grid { grid-template-columns: minmax(0, 1fr); } }
.picker select { cursor: pointer; }
/* Where the browser allows it (Chrome 135+), the pickers open a themed list, and Surface style
   shows a colour swatch left of each name. Elsewhere they stay plain dropdowns without swatches. */
@supports (appearance: base-select) {
  .picker select, .picker select::picker(select) { appearance: base-select; }
  .picker select { display: flex; align-items: center; }
  .picker select > button { display: flex; align-items: center; flex: 1; min-width: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; }
  .picker selectedcontent { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .picker select::picker-icon { color: var(--muted); }
  .picker select::picker(select) { margin-top: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
  .picker option { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 8px 10px; border-radius: 7px; font-weight: 400; cursor: pointer; }
  .picker option::checkmark { display: none; }
  .picker option:hover, .picker option:focus-visible { background: var(--hover); outline: none; }
  .picker option:checked { background: var(--tint); color: var(--accent); }
}
.opt-swatch { position: relative; flex: none; width: 20px; height: 20px; border-radius: 5px; border: 1px solid color-mix(in srgb, var(--text) 25%, transparent); background: var(--ss-bg); overflow: hidden; }
.opt-swatch::after { content: ""; position: absolute; top: 4px; left: 4px; right: 4px; bottom: 4px; border-radius: 3px; background: var(--ss-surface); }
.sw-slate     { --ss-bg: #0a1213; --ss-surface: #1c2b2d; }
.sw-graphite  { --ss-bg: #0e0e0e; --ss-surface: #262626; }
.sw-midnight  { --ss-bg: #060e1e; --ss-surface: #13244a; }
.sw-warmstone { --ss-bg: #12100e; --ss-surface: #2e2822; }

.check-row[hidden] { display: none; }
.check-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 600; cursor: pointer; }
.check-row input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.check-row span { display: grid; gap: 2px; min-width: 0; }
.check-row small { color: var(--muted); font-weight: 400; font-size: 0.85em; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { display: grid; justify-items: center; gap: 6px; padding: 4px 6px; border: 0; border-radius: 10px; background: none; color: var(--muted); font: inherit; font-size: 0.8em; cursor: pointer; }
.swatch::before { content: ""; width: 32px; height: 32px; border-radius: 50%; background: var(--sw); }
.swatch[aria-pressed="true"] { color: var(--text); font-weight: 600; }
.swatch[aria-pressed="true"]::before { box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--sw); }
.swatch-green { --sw: #3fae6a; }
.swatch-blue { --sw: #2563eb; }
.swatch-indigo { --sw: #4f46e5; }
.swatch-violet { --sw: #7c3aed; }
.swatch-rose { --sw: #e11d48; }
.swatch-orange { --sw: #ea580c; }
.swatch-cyan { --sw: #0891b2; }

/* Menu icons: Tiles is the look the app has always had, so it sets nothing. */
:root[data-icons="plain"] .icon-tile { background: none; color: var(--muted); }
:root[data-icons="coloured"] .icon-tile { background: none; }
:root[data-icons="coloured"] .icon-tile.tint-blue { color: var(--c-blue); }
:root[data-icons="coloured"] .icon-tile.tint-green { color: var(--c-green); }
:root[data-icons="coloured"] .icon-tile.tint-amber { color: var(--c-amber); }
:root[data-icons="coloured"] .icon-tile.tint-violet { color: var(--c-violet); }
:root[data-icons="coloured"] .icon-tile.tint-rose { color: var(--c-rose); }
:root[data-icons="coloured"] .icon-tile.tint-teal { color: var(--c-teal); }

/* Box shadows (off by default). */
:root[data-shadows="on"] { --soft: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.12); }
:root[data-shadows="on"] :is(.button, .card, .choice, .check-row, .set-panel, .field input, .field select, .field textarea) { box-shadow: var(--soft); }

/* A row's links back to other tables: one pill per linked row. */
.cell-links { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 0; }
.cell-links .cell-pills { min-height: 0; padding: 2px 0; }

/* ---- Bin, backup, undo ---- */

.side-foot { padding-top: 6px; border-top: 1px solid var(--line); }
.side-foot .nav-item { color: var(--muted); }

.bin-list { display: grid; gap: 10px; }
.reminder-list { display: grid; gap: 8px; }
.reminder-group { font-size: 0.9em; margin: 12px 0 2px; color: var(--muted, inherit); }
.reminder-item { display: grid; gap: 4px; width: 100%; text-align: left; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: none; color: inherit; cursor: pointer; font: inherit; }
.bin-item { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.bin-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bin-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-button { display: inline-flex; align-items: center; cursor: pointer; }

/* Logo and icons (admin, Settings) */
.brand-logo { height: 28px; width: auto; max-width: 140px; object-fit: contain; }
.brand-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.brand-text { flex: 1 1 160px; min-width: 0; display: grid; gap: 2px; }
.brand-text small { color: var(--muted); font-weight: 400; }
.brand-preview {
  width: 44px;
  height: 44px;
  flex: none;
  object-fit: contain;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.brand-preview--empty { border-style: dashed; }

.notice {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 24px;
  width: fit-content;
  margin: 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

.notice .button { color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .notice { bottom: 76px; }
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 72px;
  width: fit-content;
  margin: 0 auto;
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  /* Solid, so the page text behind it can't show through. */
  background: linear-gradient(var(--danger-bg), var(--danger-bg)), var(--surface);
  border: 1px solid var(--danger);
  color: var(--danger);
  box-shadow: var(--shadow);
}

.toast.ok {
  background: linear-gradient(var(--tint), var(--tint)), var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Phone ---- */

@media (max-width: 720px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .brand-name, .save-label { display: none; }
  .topbar { padding: 0 10px; }
  .save { margin-left: auto; padding: 0 6px; }

  .sidebar,
  :root[data-side="closed"] .sidebar {
    display: flex;
    position: fixed;
    top: var(--bar);
    bottom: 0;
    left: 0;
    z-index: 6;
    width: min(300px, 85vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  body.side-open .sidebar { transform: none; }

  /* Tools sit at the bottom, above the keyboard, where thumbs reach. */
  .ctx-tools {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    justify-content: flex-start;
    padding: 8px 28px calc(8px + env(safe-area-inset-bottom)) 10px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    /* Fade the right edge so a cut-off button hints that the row scrolls. */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }

  .ctx-tools:empty { display: none; }
  .ctx-tools { gap: 4px; }
  .tool { min-height: 40px; padding: 0 9px; }

  .doc { padding: 16px 12px 96px; }
  .page-title { font-size: 1.5em; }
  .page-cover-img { max-height: 170px; border-radius: 10px; }
  .page-name-row { gap: 10px; }
  .page-icon { width: 38px; height: 38px; font-size: 1.5em; }
  .page-meta { margin-left: 0; }
  .row-props { grid-template-columns: minmax(96px, 120px) minmax(0, 1fr); }
  .lane { flex-basis: 78vw; }
  .cal-day { min-height: 52px; align-items: center; padding: 3px 2px; }
  .cal-num { align-self: center; }
  .cal-items { display: none; }
  .cal-dots { display: block; }
  .cal-wd { padding: 4px 2px; text-align: center; }
  .cal-month { min-width: 0; flex: 1; }
  .view-tools { width: 100%; margin-left: 0; justify-content: space-between; }
  .new-split { margin-left: 0; }
  .block { padding: 2px 6px; }
}

/* Mouse users keep at least 64px on the left, so the hover controls fit beside each line. */
@media (hover: hover) {
  .doc { padding-left: max(clamp(16px, 5vw, 72px), 64px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- Login page ---- */

.login-shell { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
body.login { display: block; overflow: auto; }

.login-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.login-card .brand { font-size: 1.15em; }
.login-card label { display: grid; gap: 6px; font-weight: 600; }

.login-card input {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1rem;
}

.login-card .button { min-height: 44px; }

.login-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
}

.sidebar .nav-list { flex: 1; }

/* People and password pages (admin and account screens). */
.account-shell { align-items: start; }
.account-card { width: min(560px, 100%); max-width: 560px; }
.account-title { font-size: 1.3em; margin: 8px 0 4px; }
.account-subtitle { font-size: 1.05em; margin: 22px 0 4px; }
.account-note, .account-muted { color: var(--muted, inherit); font-size: 0.95em; }
.account-links { font-size: 0.95em; }
.account-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.account-row {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: 10px; padding: 12px; border: 1px solid var(--line, #2a3b3d); border-radius: 10px;
}
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-actions form { margin: 0; }
.account-form { display: grid; gap: 12px; margin-top: 12px; }
.account-form label { display: grid; gap: 6px; font-weight: 600; }
.account-form input {
  min-height: 44px; font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line, #2a3b3d); background: transparent; color: inherit;
}
.account-notice {
  padding: 12px; border-radius: 10px; border: 1px solid var(--line, #2a3b3d); margin: 12px 0;
}
.temp-password code { font-size: 1.2em; word-break: break-all; }

/* ---- Coloured icons and tech-info tiles ---- */

/* One colour per page (picked from its id in app.js). Light and dark both use these. */
:root {
  --c-blue: #7fb8ff;
  --c-green: #7fe0b4;
  --c-amber: #ffc66b;
  --c-violet: #c4a6ff;
  --c-rose: #ff9fb8;
  --c-teal: #6fd8d8;
  --c-red: #ff8a80;
}
:root[data-theme="light"] {
  --c-blue: #2366c4;
  --c-green: #1f8a5b;
  --c-amber: #b7700a;
  --c-violet: #6d45c9;
  --c-rose: #c2366a;
  --c-teal: #137d80;
  --c-red: #b42318;
}

.icon-tile { border-radius: 8px; }
.nav-icon.icon-tile { width: 24px; height: 24px; display: inline-grid; place-items: center; font-size: 0.95em; }
.icon-tile.tint-blue { background: color-mix(in srgb, var(--c-blue) 20%, transparent); }
.icon-tile.tint-green { background: color-mix(in srgb, var(--c-green) 20%, transparent); }
.icon-tile.tint-amber { background: color-mix(in srgb, var(--c-amber) 20%, transparent); }
.icon-tile.tint-violet { background: color-mix(in srgb, var(--c-violet) 20%, transparent); }
.icon-tile.tint-rose { background: color-mix(in srgb, var(--c-rose) 20%, transparent); }
.icon-tile.tint-teal { background: color-mix(in srgb, var(--c-teal) 20%, transparent); }

.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.stat-tile {
  display: grid; gap: 2px; padding: 10px; border-radius: 8px;
  border: 1px solid var(--line); border-top: 3px solid var(--tone, var(--muted));
  background: var(--surface-2);
}
.stat-tile.tone-red { --tone: var(--c-red); }
.stat-tile.tone-amber { --tone: var(--c-amber); }
.stat-tile.tone-green { --tone: var(--c-green); }
.stat-value { font-size: 1.5em; font-weight: 700; line-height: 1.1; color: var(--tone, var(--text)); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.8em; color: var(--muted); }

/* ---- Drag a line into a toggle ---- */

.block.drop-into { background: var(--tint); box-shadow: inset 0 0 0 2px var(--accent); }

/* ---- Page icon: a box that opens a menu ---- */

.icon-field { display: grid; gap: 6px; font-weight: 600; font-size: 0.9em; }
.icon-box {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  font-size: 28px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.icon-box:hover, .icon-box[aria-expanded="true"] { border-color: var(--accent); background: var(--tint); }

/* The icon box and the page name side by side, lined up at the bottom. */
.page-name-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: end; }
.page-name-row .field { min-width: 0; }

/* Page details: the header image, and the same picture across the top of the page. */
.cover-field { display: grid; gap: 6px; font-weight: 600; font-size: 0.9em; }
.cover-preview { overflow: hidden; aspect-ratio: 16 / 6; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.cover-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.page-cover { margin: 0 0 16px; }
.page-cover-img { display: block; width: 100%; max-height: 240px; object-fit: cover; border: 1px solid var(--line); border-radius: 12px; }
.icon-menu {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}
.icon-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.icon-tab {
  flex: none;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.icon-tab:hover, .icon-tab:focus-visible { background: var(--tint); outline: none; }
.icon-tab[aria-selected="true"] { border-color: var(--accent); background: var(--tint); color: var(--text); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; }
.icon-choice {
  height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 19px;
  cursor: pointer;
}
.icon-choice:hover, .icon-choice:focus-visible { border-color: var(--accent); background: var(--tint); outline: none; }
.icon-clear { justify-self: start; }
.icon-own { gap: 4px; }
.icon-own input { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: var(--fs); }

/* ---- Code lines: language and Run ---- */

.code-stack { display: grid; grid-template-columns: minmax(0, 1fr); flex: 1 1 auto; gap: 6px; min-width: 0; }
.code-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-lang {
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.85em;
}
.code-run { min-height: 32px; padding: 0 12px; font-size: 0.85em; }

/* The terminal under a code line. Output stays inside its box; the page never scrolls sideways. */
.term {
  display: grid;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.term-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.term.is-shut { gap: 0; padding-top: 4px; padding-bottom: 4px; }

/* Six coloured dots. Left: teal formats the code, red shows or hides the output, blue shows or hides the code.
   Right: amber clears the output, green is full screen, purple wraps long lines or not.
   Each button is 24px to tap; the dot inside is 12px. */
.term-dots { display: flex; align-items: center; gap: 2px; }
.term-dots--left { margin-right: 4px; }
.term-dots--right { margin-left: 4px; }
/* On a mouse screen the dots stay hidden until the pointer is over the code line, or a dot has keyboard focus.
   Touch screens have no hover, so their dots always show. */
@media (hover: hover) {
  .term-dots { opacity: 0; transition: opacity 0.15s ease; }
  .code-stack:hover .term-dots, .term-dots:focus-within { opacity: 1; }
}
.term-dot {
  --dot: #ff5f57;
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.term-dot:hover, .term-dot:active, .term-dot:focus { background: transparent; }
.term-dot::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: inset 0 0 0 2px var(--dot);
  transition: transform 0.12s ease;
}
.term-dot:hover::before, .term-dot:focus-visible::before { transform: scale(1.25); }
.term-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.term-dot.is-off::before { background: transparent; }
.term-dot--format { --dot: #5ee0c0; }
.term-dot--clear { --dot: #febc2e; }
.term-dot--full { --dot: #28c840; }
.term-dot--code { --dot: #3b9eff; }
.term-dot--wrap { --dot: #c792ea; }

.code-stack.code-hidden > .code-edit { display: none; }

/* The text box sits over its coloured copy in one grid cell. The copy never takes clicks. */
.code-edit { display: grid; min-width: 0; }
.code-edit > * { grid-area: 1 / 1; min-width: 0; }
.code-edit .block-text { position: relative; z-index: 1; color: transparent; caret-color: var(--text); }
.block--code .code-hl { margin: 0; padding: 4px 0; color: var(--text); overflow: hidden; pointer-events: none; }
.code-hl .hl-kw { color: var(--hl-kw); }
.code-hl .hl-ctl { color: var(--hl-ctl); }
.code-hl .hl-type { color: var(--hl-type); }
.code-hl .hl-fn { color: var(--hl-fn); }
.code-hl .hl-str { color: var(--hl-str); }
.code-hl .hl-num { color: var(--hl-num); }
.code-hl .hl-com { color: var(--hl-com); }

/* Wrap off: long lines stay on one row and the text box scrolls sideways (the copy follows).
   The extra bottom padding keeps the last line clear of the scrollbar. */
.code-stack.code-nowrap .block-text { white-space: pre; overflow-x: auto; overflow-y: hidden; }
.code-stack.code-nowrap .block-text, .code-stack.code-nowrap .code-hl { padding-bottom: 14px; }
.code-stack.code-nowrap .code-hl { white-space: pre; }

/* Full screen: the code line covers the page under the top bar. Esc or the green dot leaves. */
.code-stack.is-full {
  position: fixed;
  inset: var(--bar) 0 0 0;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 16px;
  overflow: auto;
  background: var(--bg);
}
.code-stack.is-full > * { flex: 0 0 auto; }
.code-stack.is-full > .term { flex: 1 1 auto; grid-template-rows: auto minmax(0, 1fr); min-height: 160px; }
.code-stack.is-full .term-out { max-height: none; }
.term-title { margin-right: auto; font-size: 0.8em; font-weight: 600; color: var(--muted); }
.term-status { font-size: 0.8em; color: var(--muted); }
.term-btn { min-height: 28px; padding: 0 10px; font-size: 0.8em; }
.term-out {
  margin: 0;
  max-height: 240px;
  min-width: 0;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}
.term-out:empty::before { content: "No output yet."; color: var(--muted); }
.term-line.term-error { color: var(--danger); }
.term-line.term-warn { color: var(--c-amber); }
.term-line.term-info { color: var(--muted); font-style: italic; }
.term-line.term-note { color: var(--text); }

/* ---- Templates drawer ---- */
.template-list { display: grid; gap: 8px; }
.template-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.template-card:hover, .template-card:focus-visible { border-color: var(--accent); background: var(--tint); outline: none; }
.template-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); font-size: 24px; }
.template-text { display: grid; gap: 2px; min-width: 0; }
.template-text small { color: var(--muted); font-size: 0.85em; line-height: 1.35; }

/* In a table, the name box shrinks with its column. */
.name-cell .cell-input { flex: 1; min-width: 0; }

/* Column types added with Created time, Files & media, Formula, Button and the rest. */
.cell-calc { color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-button { min-height: 32px; padding: 4px 10px; font-size: 0.9em; }
.cell-files { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.file-chip { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; padding: 2px 4px 2px 8px; border-radius: 999px; background: var(--tint); }
.file-chip a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14em; color: inherit; }
.file-chip .icon-btn { width: 22px; height: 22px; min-height: 0; padding: 0; font-size: 12px; flex: none; }

/* ---- Link cards ---- */

.block--bookmark { align-items: flex-start; }
.bookmark-stack { display: grid; gap: 8px; flex: 1; min-width: 0; padding: 4px 0; }
.bookmark-holder { position: relative; min-width: 0; }
.bookmark-card {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: inherit;
  text-decoration: none;
}
.bookmark-card:hover { border-color: var(--accent); }
.bookmark-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bookmark-info {
  display: grid;
  align-content: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
}
.bookmark-title {
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
}
.bookmark-desc {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.bookmark-foot { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 2px; }
.bookmark-fav { width: 16px; height: 16px; flex: none; border-radius: 3px; object-fit: contain; }
.bookmark-fav--none { font-size: 12px; line-height: 16px; text-align: center; }
.bookmark-url {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
/* A card with a picture is a fixed height, so the picture has a height to fill
   and a tall or tiny picture can't stretch the card. */
.bookmark-card { height: 116px; }
.bookmark-card--plain { height: auto; min-height: 72px; }
.bookmark-shot { flex: 0 0 34%; max-width: 230px; background: var(--surface); }
.bookmark-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bookmark-card--plain .bookmark-info { padding: 10px 14px; }
.bookmark-change {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  opacity: 0;
}
.bookmark-holder:hover .bookmark-change,
.bookmark-change:focus-visible { opacity: 1; }
.bookmark-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bookmark-input {
  flex: 1 1 220px;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.bookmark-status { color: var(--muted); }

/* Touch screens have no hover, so the pencil always shows. */
@media (hover: none) {
  .bookmark-change { opacity: 1; }
}

@media (max-width: 640px) {
  .bookmark-card { height: 104px; }
  .bookmark-shot { flex-basis: 38%; }
  .bookmark-info { padding: 10px 11px; }
  .bookmark-desc { -webkit-line-clamp: 2; line-clamp: 2; }
}

/* ---- Property visibility drawer ---- */

.pv-search input {
  width: 100%;
  padding: 9px 11px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.pv-group { margin-top: 18px; }
.pv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}
.pv-all {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.pv-all:hover { text-decoration: underline; }
.pv-all[disabled] { color: var(--muted); cursor: default; text-decoration: none; opacity: 0.6; }
.pv-list { display: grid; gap: 1px; }
.pv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 8px;
  min-width: 0;
}
.pv-item:hover { background: var(--surface-2); }
.pv-grip { color: var(--muted); cursor: grab; touch-action: none; padding: 0 2px; line-height: 1; }
.pv-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.pv-grip--fixed { visibility: hidden; }
.pv-mark { color: var(--muted); width: 18px; text-align: center; flex: none; }
.pv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-eye { flex: none; color: var(--text); }
.pv-eye--off { color: var(--muted); }
.pv-item.pv-dragging { opacity: 0.5; }
.pv-item.pv-drop-before { box-shadow: 0 -2px 0 0 var(--accent); }
.pv-item.pv-drop-after { box-shadow: 0 2px 0 0 var(--accent); }
.pv-none { margin-top: 14px; }

/* ---- Layout drawer ---- */

.lay-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lay-tile {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 12px 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.lay-tile:hover:not([disabled]) { background: var(--surface-2); }
.lay-tile.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.lay-tile[disabled] { opacity: 0.4; cursor: default; }
.lay-tile svg { width: 22px; height: 22px; }
.lay-name { line-height: 1; }
.lay-options { margin-top: 18px; display: grid; gap: 2px; }
.lay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 4px;
  min-height: 40px;
}
.lay-row select {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-align: right;
  max-width: 55%;
  cursor: pointer;
}
.lay-split { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }

/* The on/off switches in the Layout drawer. */
.switch { position: relative; flex: none; width: 38px; height: 22px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch-track {
  display: block;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s;
  pointer-events: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- List and gallery views ---- */

.db-list { display: grid; gap: 1px; }
.db-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.db-list-open {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 2px 0;
  border-radius: 6px;
}
.db-list-open:hover .db-list-name { text-decoration: underline; }
.db-list-icon { flex: none; }
.db-list-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-list-meta { display: flex; align-items: center; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; max-width: 50%; }

.db-gallery { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.db-gallery--medium { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.db-gallery--large { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.gal-card {
  display: grid;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
}
.gal-card:hover { border-color: var(--accent); }
.gal-shot { display: block; height: 120px; background: var(--surface-2); overflow: hidden; }
.db-gallery--medium .gal-shot { height: 150px; }
.db-gallery--large .gal-shot { height: 190px; }
.gal-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.db-gallery--fit .gal-shot img { object-fit: contain; }
.gal-shot--empty { display: grid; place-items: center; color: var(--muted); font-size: 1.6rem; }
.gal-shot--text { display: grid; align-content: start; gap: 4px; padding: 10px 12px; color: var(--muted); font-size: 0.8rem; }
.gal-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gal-body { display: grid; gap: 6px; padding: 10px 12px; min-width: 0; }
.gal-title { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.gal-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gal-meta { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .db-gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .db-list-meta { max-width: 40%; }
}

/* "Wrap all content" in the Layout drawer: cells show every line instead of
   cutting the text off at one line. */
.db-table.db-wrap td, .db-table.db-wrap td .cell-text {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.db-table.db-wrap td { vertical-align: top; }
