:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f7f5;
  --text: #37352f;
  --text-soft: #787774;
  --text-faint: #9b9a97;
  --border: #ebeae8;
  --hover: rgba(55, 53, 47, 0.06);
  --active: rgba(55, 53, 47, 0.1);
  --accent: #2383e2;
  --callout-bg: #f1f1ef;
  --code-bg: #f6f5f4;
  --code-text: #c0392b;
  --danger: #eb5757;
  --shadow: 0 8px 30px rgba(15, 15, 15, 0.15), 0 0 0 1px rgba(15, 15, 15, 0.05);
  --overlay: rgba(15, 15, 15, 0.4);
  --toast-bg: #2f3437;
}

html[data-theme="dark"] {
  --bg: #191919;
  --sidebar-bg: #202020;
  --text: #d4d4d4;
  --text-soft: #9b9b9b;
  --text-faint: #6f6f6f;
  --border: #2f2f2f;
  --hover: rgba(255, 255, 255, 0.055);
  --active: rgba(255, 255, 255, 0.1);
  --accent: #529cca;
  --callout-bg: #262626;
  --code-bg: #232323;
  --code-text: #e06c5c;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
  --overlay: rgba(0, 0, 0, 0.6);
  --toast-bg: #3f4447;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; overflow: hidden; }

.hidden { display: none !important; }

kbd {
  font-family: inherit;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

button { color: inherit; }

/* ------------------------------------------------------------ sidebar */

#sidebar {
  width: 260px;
  min-width: 260px;
  height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px;
  overflow-y: auto;
}

.sidebar-spacer { flex: 1; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 10px; }

#trash-count { margin-left: auto; font-size: 12px; color: var(--text-faint); }

.ws-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 14px;
  font-weight: 600;
  font-size: 14px;
}

.ws-logo { font-size: 18px; }
.ws-name { flex: 1; }

#presence { display: flex; gap: 4px; }

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  cursor: default;
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text-soft);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.sidebar-action:hover { background: var(--hover); }
.sidebar-action .icon { width: 18px; text-align: center; }
.sidebar-action kbd { margin-left: auto; }
.sidebar-action.new-page { margin-top: 4px; }

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 14px 10px 4px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  position: relative;
}

.tree-item:hover { background: var(--hover); }
.tree-item.active { background: var(--active); color: var(--text); font-weight: 500; }

.tree-item.drop-above::before,
.tree-item.drop-below::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  background: var(--accent);
  opacity: 0.5;
  border-radius: 2px;
  pointer-events: none;
}

.tree-item.drop-above::before { top: -2px; }
.tree-item.drop-below::after { bottom: -2px; }
.tree-item.drop-into { box-shadow: inset 0 0 0 2px var(--accent); }

.tree-toggle {
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 10px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: transform 0.15s;
}

.tree-toggle:hover { background: var(--active); }
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }

.tree-icon { width: 18px; text-align: center; flex: none; font-size: 14px; }

.tree-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-title.untitled { color: var(--text-faint); }

.tree-actions { display: none; gap: 2px; }
.tree-item:hover .tree-actions { display: flex; }

.tree-actions button {
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-actions button:hover { background: var(--active); color: var(--text); }

.tree-children { margin-left: 14px; }

.tree-empty {
  font-size: 13px;
  color: var(--text-faint);
  padding: 4px 10px 4px 28px;
  font-style: italic;
}

/* ------------------------------------------------------------ main */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-size: 14px;
  gap: 12px;
}

#breadcrumbs { display: flex; align-items: center; gap: 6px; color: var(--text-soft); min-width: 0; }

.crumb {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crumb:hover { background: var(--hover); }
.crumb-sep { color: var(--text-faint); }

#topbar-right { display: flex; align-items: center; gap: 6px; flex: none; }

.topbar-btn {
  border: none;
  background: none;
  font: inherit;
  font-size: 15px;
  color: var(--text-soft);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.topbar-btn:hover { background: var(--hover); }
#comments-count { font-size: 12px; margin-left: 3px; }

#menu-wrap { position: relative; }

#topbar-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 60;
  width: 230px;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item .mi-icon { width: 20px; text-align: center; }

.menu-foot {
  font-size: 12px;
  color: var(--text-faint);
  padding: 8px 10px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

#save-status { font-size: 10px; color: #4caf50; transition: color 0.3s; }
#save-status.saving { color: #f5a623; }

#editor-scroll { flex: 1; overflow-y: auto; }

#editor {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 56px 30vh;
}

#editor.full-width { max-width: none; }

#empty-state {
  text-align: center;
  margin-top: 18vh;
  color: var(--text-faint);
}

.empty-emoji { font-size: 44px; margin-bottom: 8px; }

/* cover */

#page-cover {
  height: 210px;
  margin: -32px -56px 24px;
  background-size: cover;
  background-position: center;
  position: relative;
}

#editor.full-width #page-cover { margin-left: -56px; margin-right: -56px; }

.cover-g1 { background-image: linear-gradient(135deg, #667eea, #764ba2); }
.cover-g2 { background-image: linear-gradient(135deg, #f093fb, #f5576c); }
.cover-g3 { background-image: linear-gradient(135deg, #4facfe, #00f2fe); }
.cover-g4 { background-image: linear-gradient(135deg, #43e97b, #38f9d7); }
.cover-g5 { background-image: linear-gradient(135deg, #fa709a, #fee140); }
.cover-g6 { background-image: linear-gradient(135deg, #a18cd1, #fbc2eb); }
.cover-g7 { background-image: linear-gradient(135deg, #ff9a9e, #fecfef); }
.cover-g8 { background-image: linear-gradient(135deg, #30cfd0, #330867); }

.cover-actions {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

#page-cover:hover .cover-actions { opacity: 1; }

.cover-actions button {
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: #37352f;
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.cover-actions button:hover { background: #fff; }

.cover-swatches {
  display: grid;
  grid-template-columns: repeat(4, 52px);
  gap: 6px;
  padding: 4px;
}

.cover-swatches button {
  height: 36px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.cover-swatches button:hover { outline: 2px solid var(--accent); }

#add-cover-btn {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-faint);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

#editor:hover #add-cover-btn { opacity: 1; }
#add-cover-btn:hover { background: var(--hover); }
#add-cover-btn.hidden-btn { display: none; }

/* icon + title */

#icon-row { position: relative; min-height: 8px; display: flex; align-items: center; gap: 4px; }

#page-icon {
  border: none;
  background: none;
  font-size: 64px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
}

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

#page-icon.empty {
  font-size: 13px;
  color: var(--text-faint);
  padding: 4px 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

#editor:hover #page-icon.empty { opacity: 1; }

#emoji-picker {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 32px);
  gap: 2px;
}

#emoji-picker button {
  border: none;
  background: none;
  font-size: 20px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  border-radius: 6px;
}

#emoji-picker button:hover { background: var(--hover); }

#emoji-picker .remove-icon {
  grid-column: 1 / -1;
  width: 100%;
  font-size: 12px;
  color: var(--text-soft);
  height: 26px;
}

#page-title {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
  margin: 10px 0 4px;
  outline: none;
  word-break: break-word;
}

[contenteditable][data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}

/* plain text blocks only hint when focused, so empty lines stay clean */
.block[data-type="text"] .content:empty::before { opacity: 0; }
.block[data-type="text"] .content:focus:empty::before { opacity: 1; }

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

#blocks { padding-top: 8px; }

.block {
  display: flex;
  align-items: flex-start;
  position: relative;
  padding: 1px 0;
  margin-left: -24px;
}

.block.collapsed-away { display: none; }

.block.drop-above::before,
.block.drop-below::after {
  content: '';
  position: absolute;
  left: 24px;
  right: 0;
  height: 3px;
  background: rgba(35, 131, 226, 0.4);
  border-radius: 2px;
}

.block.drop-above::before { top: -2px; }
.block.drop-below::after { bottom: -2px; }

.handle {
  width: 24px;
  flex: none;
  color: var(--text-faint);
  font-size: 14px;
  letter-spacing: -2px;
  text-align: center;
  cursor: grab;
  opacity: 0;
  padding-top: 5px;
  user-select: none;
}

.block:hover .handle { opacity: 1; }
.handle:active { cursor: grabbing; }

.block .prefix {
  flex: none;
  user-select: none;
  padding-top: 3px;
}

.content {
  flex: 1;
  min-width: 0;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  font-size: 16px;
  padding: 3px 2px;
}

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

a.page-chip {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--text-faint);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

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

.content code {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 85%;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* type-specific */

.block[data-type="h1"] .content { font-size: 30px; font-weight: 700; padding-top: 18px; }
.block[data-type="h2"] .content { font-size: 24px; font-weight: 650; padding-top: 14px; }
.block[data-type="h3"] .content { font-size: 20px; font-weight: 600; padding-top: 10px; }

.block[data-type="bullet"] .prefix,
.block[data-type="number"] .prefix {
  width: 24px;
  text-align: center;
  line-height: 1.6;
  padding-top: 3px;
}

.block[data-type="bullet"] .prefix { font-size: 18px; }
.block[data-type="number"] .prefix { font-size: 15px; color: var(--text); }

.block[data-type="todo"] .prefix { width: 24px; display: flex; justify-content: center; padding-top: 7px; }

.block[data-type="todo"] input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.block[data-type="todo"].checked .content {
  color: var(--text-faint);
  text-decoration: line-through;
}

.block[data-type="toggle"] .prefix {
  width: 24px;
  display: flex;
  justify-content: center;
  padding-top: 5px;
}

.toggle-arrow {
  border: none;
  background: none;
  font-size: 11px;
  color: var(--text-soft);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  transition: transform 0.15s;
  transform: rotate(90deg);
}

.toggle-arrow:hover { background: var(--hover); }
.block[data-type="toggle"].collapsed .toggle-arrow { transform: rotate(0deg); }

.block[data-type="quote"] .content {
  border-left: 3px solid var(--text);
  padding-left: 14px;
  font-size: 16px;
}

.block[data-type="callout"] {
  background: var(--callout-bg);
  border-radius: 6px;
  padding: 12px 12px 12px 0;
  margin-top: 4px;
  margin-bottom: 4px;
}

.block[data-type="callout"] .prefix {
  width: 40px;
  text-align: center;
  font-size: 18px;
  padding-top: 2px;
}

.block[data-type="code"] .content {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 14px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  tab-size: 2;
}

.block[data-type="divider"] { align-items: center; }

.block[data-type="divider"] .content {
  padding: 0;
  height: 18px;
  display: flex;
  align-items: center;
  caret-color: transparent;
}

.block[data-type="divider"] .content::after {
  content: '';
  width: 100%;
  height: 1px;
  background: var(--border);
}

.block[data-type="image"] .content { padding: 4px 0; }

.block[data-type="image"] img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  cursor: pointer;
}

.block[data-type="image"] img.img-selected {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* bookmark + embed blocks */

.block.block-selected > .content { outline: 3px solid var(--accent); outline-offset: 1px; border-radius: 6px; }

.bookmark-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 4px 0;
  cursor: pointer;
}

.bookmark-card:hover { background: var(--hover); }
.bookmark-card .bm-title { font-size: 14px; font-weight: 500; }
.bookmark-card .bm-title a { color: var(--text); text-decoration: none; }
.bookmark-card .bm-title a:hover { text-decoration: underline; }
.bookmark-card .bm-desc {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bookmark-card .bm-host { font-size: 12px; color: var(--text-faint); margin-top: 6px; }

.dbembed-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 6px 0;
  overflow: hidden;
}

.dbembed-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.dbembed-head .open-db {
  margin-left: auto;
  border: none;
  background: none;
  font: inherit;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 5px;
}

.dbembed-head .open-db:hover { background: var(--hover); color: var(--text); }

.dbembed-box table { border-collapse: collapse; width: 100%; font-size: 13px; }
.dbembed-box th, .dbembed-box td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.dbembed-box th { color: var(--text-soft); font-weight: 500; background: var(--sidebar-bg); }
.dbembed-box tr:last-child td { border-bottom: none; }
.dbembed-box th:last-child, .dbembed-box td:last-child { border-right: none; }
.dbembed-empty { padding: 14px; font-size: 13px; color: var(--text-faint); }

/* ------------------------------------------------------------ database table */

#dbview { padding-top: 16px; padding-left: 68px; margin-left: -68px; }

.db-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  /* Wrap. There are enough tools now that a single row runs off the right
     of a laptop, never mind a phone — and the ones that fall off the end
     are the newest, which are exactly the ones nobody has found yet. */
  flex-wrap: wrap;
  row-gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  padding-bottom: 2px;
}
/* The view tabs stay together as a group on the first line. */
.db-toolbar .spacer { flex: 1 1 auto; min-width: 0; }

.view-tab {
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text-faint);
  padding: 5px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -3px;
}

.view-tab.active { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }
.view-tab:hover { color: var(--text-soft); }

.db-toolbar .db-tool-btn {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.db-toolbar .db-tool-btn:hover { background: var(--hover); }
.db-toolbar .db-tool-btn.filters-on { color: var(--accent); }
.db-toolbar .spacer { flex: 1; }

.filter-row {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
}

.filter-row select, .filter-row input {
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  max-width: 110px;
}

.filter-row button {
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
  border-radius: 4px;
}

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

/* board view */

.board {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 20px;
}

.board-col {
  min-width: 230px;
  width: 230px;
  flex: none;
}

.board-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 10px;
  font-size: 13px;
}

.board-col-head .count { color: var(--text-faint); }

.board-col.drag-over .board-cards {
  background: var(--hover);
  border-radius: 8px;
}

.board-cards { min-height: 30px; display: flex; flex-direction: column; gap: 8px; padding: 2px; }

.board-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(15, 15, 15, 0.06);
}

html[data-theme="dark"] .board-card { background: #232323; }

.board-card:hover { background: var(--hover); }
.board-card.dragging { opacity: 0.4; }
.board-card .bc-title { font-size: 14px; font-weight: 500; word-break: break-word; }
.board-card .bc-title.untitled { color: var(--text-faint); }
.board-card .bc-fields { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.board-card .bc-field { font-size: 12px; color: var(--text-soft); }

.board-add {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-faint);
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  width: 100%;
  margin-top: 4px;
}

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

.board-hint { color: var(--text-faint); font-size: 14px; padding: 20px 0; }

/* row editor modal */

.row-modal { width: 480px; padding: 22px 26px; max-height: 70vh; overflow-y: auto; }

.row-field { margin-bottom: 14px; }
.row-field label {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.row-field input[type="text"], .row-field input[type="number"], .row-field input[type="date"] {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.row-field input:focus { border-color: var(--accent); }

.row-modal-foot { display: flex; justify-content: space-between; margin-top: 18px; }

.row-modal-foot button {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-soft);
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
}

.row-modal-foot button:hover { background: var(--hover); }
.row-modal-foot .danger:hover { color: var(--danger); border-color: var(--danger); }

.db-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

.db-table th, .db-table td {
  border: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
  min-width: 110px;
  position: relative;
}

.db-table th {
  background: var(--sidebar-bg);
  font-weight: 500;
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
  user-select: none;
}

.db-table th:hover { background: var(--hover); }

.db-th-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
}

.db-th-inner .col-type-icon { font-size: 12px; opacity: 0.7; }
.db-th-inner .sort-ind { margin-left: auto; font-size: 11px; color: var(--accent); }

.db-cell {
  padding: 7px 10px;
  outline: none;
  min-height: 34px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

td.first-col .db-cell { font-weight: 500; }
td .db-cell:focus { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 2px; }
.db-cell-num { text-align: right; }

.db-cell-center {
  display: flex;
  justify-content: center;
  padding: 9px;
}

.db-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.db-table input[type="date"] {
  border: none;
  background: none;
  font: inherit;
  color: var(--text);
  padding: 7px 10px;
  width: 100%;
  color-scheme: light dark;
}

.select-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.select-empty {
  color: var(--text-faint);
  cursor: pointer;
  padding: 7px 10px;
  display: block;
  font-size: 13px;
}

.url-cell { display: flex; align-items: flex-start; }
.url-cell .db-cell { flex: 1; color: var(--accent); }
.url-go {
  flex: none;
  padding: 7px 8px;
  font-size: 12px;
  color: var(--text-faint);
  text-decoration: none;
}
.url-go:hover { color: var(--accent); }

.row-del {
  position: absolute;
  left: -26px;
  top: 5px;
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
}

tr:hover .row-del { opacity: 1; }
.row-del:hover { background: var(--hover); color: var(--danger); }

/* Row grip + row menu, in the gutter left of the first cell. */
.row-grip, .row-menu {
  position: absolute; top: 5px; width: 20px; height: 24px;
  border: none; background: none; color: var(--text-faint);
  font-size: 12px; line-height: 1; cursor: pointer; border-radius: 4px;
  opacity: 0; transition: opacity .1s; padding: 0;
}
.row-grip { left: -44px; cursor: grab; touch-action: none; letter-spacing: -2px; }
.row-menu { left: -23px; font-size: 14px; }
tr:hover .row-grip, tr:hover .row-menu { opacity: 1; }
.row-grip:hover, .row-menu:hover { background: var(--hover); color: var(--text); }
.row-grip.disabled { cursor: help; }
.row-grip:active { cursor: grabbing; }
tr.row-dragging { opacity: .55; background: var(--hover); }
body.row-drag-active { user-select: none; cursor: grabbing; }

/* On a phone there is no hover and no gutter — put them inline and always on. */
@media (max-width: 720px) {
  .row-grip, .row-menu { opacity: 1; position: static; display: inline-block; vertical-align: middle; }
  .row-grip { width: 26px; height: 34px; }
  .row-menu { width: 26px; height: 34px; }
  td.first-col { white-space: nowrap; }
}

.db-add-row, .db-add-col {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-faint);
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 6px;
  text-align: left;
}

.db-add-row { display: block; width: 100%; }
.db-add-row:hover, .db-add-col:hover { background: var(--hover); color: var(--text-soft); }

.db-footer { font-size: 12px; color: var(--text-faint); padding: 8px 2px; }

/* ------------------------------------------------------------ float menu (slash + mentions) */

#float-menu {
  position: fixed;
  z-index: 50;
  width: 290px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

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

.slash-item .slash-icon {
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg);
}

.slash-item .slash-name { font-size: 14px; font-weight: 500; }
.slash-item .slash-desc { font-size: 12px; color: var(--text-faint); }

.slash-empty { padding: 10px; font-size: 13px; color: var(--text-faint); }

/* ------------------------------------------------------------ popover (db menus, page menus) */

#popover {
  position: fixed;
  z-index: 70;
  min-width: 200px;
  max-width: 280px;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  max-height: 60vh;
  overflow-y: auto;
}

#popover .pop-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 6px;
}

#popover .pop-input:focus { border-color: var(--accent); }
#popover .pop-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; padding: 6px 8px 2px; }

/* ------------------------------------------------------------ overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
}

.modal {
  background: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 460px;
  max-width: calc(100vw - 40px);
}

.list-modal { width: 560px; }

.list-modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.list-modal-head span { flex: 1; }

.list-modal-head button {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
}

.list-modal-head button:hover { background: var(--hover); }
#empty-trash:hover { color: var(--danger); }

.list-modal-body { max-height: 50vh; overflow-y: auto; padding: 8px; }

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
}

.list-row:hover { background: var(--hover); }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: 14px; font-weight: 500; }
.list-row .lr-sub { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-row button {
  border: 1px solid var(--border);
  background: none;
  font: inherit;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  flex: none;
}

.list-row button:hover { background: var(--hover); color: var(--text); }
.list-row button.danger:hover { color: var(--danger); border-color: var(--danger); }

.list-empty { text-align: center; color: var(--text-faint); padding: 30px; font-size: 14px; }

.name-modal { padding: 32px; text-align: center; }
.modal-emoji { font-size: 40px; }
.name-modal h2 { margin: 12px 0 4px; }
.name-modal p { color: var(--text-soft); margin: 0 0 20px; }

.name-modal input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
}

.name-modal input:focus { border-color: var(--accent); }

.name-modal button {
  width: 100%;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
}

.search-modal { overflow: hidden; }

#search-input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 16px 18px;
  border: none;
  border-bottom: 1px solid var(--border);
  outline: none;
  background: var(--bg);
  color: var(--text);
}

#search-results { max-height: 320px; overflow-y: auto; padding: 6px; }

.search-result {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.search-result.selected { background: var(--hover); }
.search-result .sr-title { font-size: 14px; font-weight: 500; }
.search-result .sr-snippet {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-hint {
  font-size: 11px;
  color: var(--text-faint);
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------ comments */

#comments-panel {
  width: 300px;
  min-width: 300px;
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.cp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

#cp-close {
  border: none;
  background: none;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
}

#cp-close:hover { background: var(--hover); }

#comments-list { flex: 1; overflow-y: auto; padding: 10px 14px; }

.comment { margin-bottom: 14px; position: relative; }
.comment .c-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.comment .c-name { font-size: 13px; font-weight: 600; }
.comment .c-time { font-size: 11px; color: var(--text-faint); }
.comment .c-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.comment .c-del {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
}

.comment:hover .c-del { opacity: 1; }
.comment .c-del:hover { color: var(--danger); background: var(--hover); }

.cp-empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 0; }

.cp-input { padding: 12px 14px; border-top: 1px solid var(--border); }

.cp-input textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  resize: none;
  background: var(--bg);
  color: var(--text);
}

.cp-input textarea:focus { border-color: var(--accent); }

.cp-input button {
  margin-top: 6px;
  width: 100%;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 7px;
  cursor: pointer;
}

/* ------------------------------------------------------------ selection toolbar */

#fmt-toolbar {
  position: fixed;
  z-index: 80;
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
}

#fmt-toolbar button {
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  min-width: 28px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text);
}

#fmt-toolbar button:hover { background: var(--hover); }
#fmt-toolbar button.fmt-b { font-weight: 700; }
#fmt-toolbar button.fmt-i { font-style: italic; }
#fmt-toolbar button.fmt-u { text-decoration: underline; }
#fmt-toolbar button.fmt-s { text-decoration: line-through; }
#fmt-toolbar button.fmt-h { background: #fff3a3; color: #37352f; }
#fmt-toolbar button.fmt-h:hover { background: #ffe87a; }

mark { background: #ffe28a; color: #37352f; border-radius: 2px; padding: 0 1px; }
html[data-theme="dark"] mark { background: #6b5a1e; color: #f0e6c8; }

/* ------------------------------------------------------------ TOC + block extras */

.block[data-type="toc"] .content { padding: 8px 0; }

.toc-box {
  border-left: 2px solid var(--border);
  padding-left: 12px;
}

.toc-item {
  display: block;
  font-size: 14px;
  color: var(--text-soft);
  padding: 3px 6px;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
}

.toc-item:hover { background: var(--hover); color: var(--text); }
.toc-item.toc-h2 { padding-left: 20px; }
.toc-item.toc-h3 { padding-left: 34px; }
.toc-empty { font-size: 13px; color: var(--text-faint); font-style: italic; }

.block.flash { animation: blockflash 1.2s ease-out; }

@keyframes blockflash {
  0% { background: rgba(35, 131, 226, 0.18); }
  100% { background: transparent; }
}

.cmt-badge {
  position: absolute;
  right: -36px;
  top: 4px;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 5px;
  white-space: nowrap;
}

.cmt-badge:hover { background: var(--hover); }

#cp-context {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-soft);
  background: var(--callout-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 6px;
}

#cp-context span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#cp-context button { border: none; background: none; color: var(--text-faint); cursor: pointer; }

.comment .c-quote {
  font-size: 12px;
  color: var(--text-faint);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin: 2px 0 4px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment .c-quote:hover { color: var(--text-soft); }

/* ------------------------------------------------------------ templates + sidebar chrome */

#template-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--callout-bg);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}

#use-template-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}

#sidebar-toggle {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 15px;
  cursor: pointer;
  border-radius: 5px;
  padding: 1px 7px;
}

#sidebar-toggle:hover { background: var(--hover); color: var(--text); }

body.no-sidebar #sidebar { display: none; }

#sidebar-reopen {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 40;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-soft);
  font-size: 15px;
  padding: 4px 9px;
  border-radius: 7px;
  cursor: pointer;
}

#sidebar-reopen:hover { background: var(--hover); }
body.no-sidebar #breadcrumbs { margin-left: 38px; }

/* ------------------------------------------------------------ relation + formula cells */

.rel-chip {
  display: inline-block;
  font-size: 13px;
  background: var(--hover);
  border-radius: 5px;
  padding: 2px 8px;
  margin: 2px 3px 2px 0;
  cursor: pointer;
  white-space: nowrap;
}

.rel-chip:hover { background: var(--active); }
.rel-cell { padding: 5px 8px; cursor: pointer; min-height: 34px; }
.rel-empty { color: var(--text-faint); font-size: 13px; }

.formula-cell {
  padding: 7px 10px;
  color: var(--text-soft);
  font-size: 14px;
  min-height: 34px;
}

.formula-err { color: var(--danger); font-size: 12px; }

#popover .pop-check {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

#popover .pop-check:hover { background: var(--hover); }

#popover textarea.pop-input { resize: vertical; min-height: 60px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.pop-hint { font-size: 11px; color: var(--text-faint); padding: 2px 8px 6px; line-height: 1.5; }

/* ------------------------------------------------------------ calendar view */

.cal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 12px;
}

.cal-head .cal-title { font-size: 15px; font-weight: 600; min-width: 150px; text-align: center; }

.cal-head button {
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

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

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.cal-dow {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.cal-cell {
  min-height: 96px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px 6px;
  position: relative;
}

.cal-cell.other-month { background: var(--sidebar-bg); }
.cal-cell .cal-day { font-size: 12px; color: var(--text-faint); }
.cal-cell.today .cal-day {
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
}

.cal-add {
  position: absolute;
  top: 3px;
  right: 4px;
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  border-radius: 4px;
  padding: 0 5px;
  opacity: 0;
}

.cal-cell:hover .cal-add { opacity: 1; }
.cal-add:hover { background: var(--hover); }

.cal-event {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  font: inherit;
  font-size: 12px;
  background: var(--callout-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  margin-top: 3px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-event:hover { background: var(--hover); }

/* ------------------------------------------------------------ gallery view */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.gallery .board-card { width: auto; }

.gallery-add {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  min-height: 64px;
}

.gallery-add:hover { background: var(--hover); }

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

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
}

#toast button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #7cc4ff;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* ------------------------------------------------------------ small screens */

@media (max-width: 900px) {
  #comments-panel { position: fixed; right: 0; top: 0; z-index: 90; box-shadow: var(--shadow); }
}

@media (max-width: 720px) {
  #sidebar { width: 200px; min-width: 200px; }
  #editor { padding: 24px 20px 30vh; }
}

/* ---- Tasks batch: people, due dates, totals, My tasks ---- */
.person-chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.person-chip .avatar { width: 20px; height: 20px; font-size: 9px; flex: 0 0 auto; }
.date-overdue { color: var(--danger) !important; font-weight: 600; }
.db-table tfoot td { border-top: 2px solid var(--border); padding: 6px 10px; font-size: 12px; color: var(--text-soft); }
.db-table tfoot td.db-total-num { font-weight: 600; }
.mt-section { padding: 12px 6px 4px; font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-faint); }
.mt-section.overdue { color: var(--danger); }
.mt-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; font: inherit; color: var(--text); }
.mt-item:hover { background: var(--hover); }
.mt-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-meta { font-size: 12px; color: var(--text-soft); white-space: nowrap; }

/* ---- Boards batch: option colours, lane totals, timeline ---- */
.swatches { display: flex; gap: 5px; padding: 2px 12px 8px; }
.swatch { width: 15px; height: 15px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--text); }
.lane-total { padding: 2px 10px 8px; font-size: 12px; color: var(--text-soft); font-weight: 600; }

.timeline { overflow-x: auto; padding-bottom: 8px; }
.tl-grid { position: relative; min-width: calc(var(--tl-cell) * var(--tl-days)); }
.tl-head { display: flex; height: 26px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.tl-tick { width: var(--tl-cell); flex: 0 0 var(--tl-cell); position: relative; font-size: 10px; color: var(--text-faint); }
.tl-tick.weekend { background: var(--hover); }
.tl-tick.month-start { border-left: 1px solid var(--border); }
.tl-month { position: absolute; left: 3px; top: 5px; white-space: nowrap; font-weight: 700; color: var(--text-soft); }
.tl-day { position: absolute; left: 0; right: 0; top: 7px; text-align: center; }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: .7; pointer-events: none; }
.tl-row { position: relative; height: 32px; }
.tl-bar { position: absolute; top: 3px; height: 26px; border: 0; border-radius: 6px; background: var(--accent); color: #fff;
  font: inherit; font-size: 12px; font-weight: 600; text-align: left; padding: 0 8px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-bar:hover { filter: brightness(1.08); }

/* ---- Automations + inbox ---- */
.rule-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.rule-word { font-size: 12px; color: var(--text-soft); }
.rule-row select { font: inherit; font-size: 12px; max-width: 110px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 4px; }
.rule-input { font: inherit; font-size: 12px; width: 82px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 6px; }
.rule-del { background: none; border: 0; color: var(--text-faint); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.rule-del:hover { color: var(--danger); }
.inbox-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 6px; margin-left: 4px; }
.mt-item.unread .mt-title { font-weight: 700; }
.mt-item.unread::before { content: "●"; color: var(--accent); font-size: 10px; margin-right: 2px; }

/* ---- Progress, recurring, row templates ---- */
.prog-cell { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.prog-track { flex: 1; min-width: 60px; height: 8px; border-radius: 999px; background: var(--hover); cursor: pointer; overflow: hidden; }
.prog-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .12s; }
.prog-fill.full { background: #2ea043; }
.prog-label { font-size: 11px; color: var(--text-soft); font-weight: 700; min-width: 32px; text-align: right; }
.repeat-chip { display: inline-block; font-size: 12px; padding: 3px 9px; margin: 5px 8px; border-radius: 999px;
  background: var(--hover); color: var(--text-soft); cursor: pointer; font-weight: 600; }
.db-add-wrap { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------------------------------------------------- phones
   The team uses this standing up, on a phone, at a door. Below 720px the
   sidebar stops being a column that eats half the screen and becomes a
   drawer that slides over the content. */
.nav-only { display: none; }
#nav-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 110; }

@media (max-width: 720px) {
  .nav-only { display: inline-flex; align-items: center; justify-content: center; }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 120;
    width: 82vw; max-width: 310px; min-width: 0;
    transform: translateX(-100%); transition: transform .18s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.nav-open #sidebar { transform: none; box-shadow: var(--shadow); }
  /* the desktop "collapsed" preference must not make the drawer unreachable */
  body.no-sidebar #sidebar { display: flex; }
  #sidebar-toggle, #sidebar-reopen { display: none !important; }

  #editor { padding: 18px 16px 30vh; }
  #page-title { font-size: 30px; overflow-wrap: normal; word-break: normal; hyphens: none; }
  #topbar { padding-left: 6px; gap: 4px; }
  #breadcrumbs { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Wide things scroll inside themselves rather than pushing the page sideways. */
  #dbview { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .db-table { min-width: 560px; }
  .board { overflow-x: auto; }
  .modal { width: calc(100vw - 24px); max-width: none; }
  .row-modal { max-height: 82vh; overflow-y: auto; }
  #comments-panel { width: 100vw; }
  /* Touch targets: 44px is the floor, and steppers were 36. */
  .stepper button, .fbtn, .view-tab { min-height: 40px; }
}

/* ================= tables: columns, selection, groups, steps =========== */

/* Columns drag by their header and resize by their right edge. The bar is
   4px of visible line inside a 12px grab area — a 4px target is a target
   nobody hits, and a 12px line looks like a mistake. */
.db-table th { position: relative; }
.db-table th .db-th-inner { cursor: grab; }
body.row-drag-active .db-table th .db-th-inner { cursor: grabbing; }
.db-table th.col-dragging { background: var(--hover); opacity: 0.75; }
.col-resize {
  position: absolute; top: 0; right: -6px; width: 12px; height: 100%;
  cursor: col-resize; z-index: 2;
}
.col-resize::after {
  content: ''; position: absolute; top: 20%; left: 4px;
  width: 2px; height: 60%; border-radius: 2px; background: transparent;
}
.col-resize:hover::after { background: var(--accent); }
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing * { cursor: col-resize !important; }

/* Selecting rows. The box only appears on hover or once anything is
   picked — otherwise every table grows a column of empty checkboxes and
   looks like a form. */
/* Three things now live in the 66px gutter: pick, grip, menu. They are
   positioned from the same left edge as the existing two rather than each
   guessing, so adding a fourth later moves one number. */
.row-pick {
  position: absolute; top: 5px; left: -65px; width: 20px; height: 24px;
  border: 0; background: none; cursor: pointer; padding: 0;
  font-size: 13px; line-height: 24px; color: var(--text-faint);
  border-radius: 4px; opacity: 0; transition: opacity .1s;
}
.db-table tr:hover .row-pick,
.row-pick.on { opacity: 1; }
.row-pick:hover { background: var(--hover); color: var(--text); }
.row-pick.on { color: var(--accent); }
td.first-col { padding-left: 4px; }
.db-table tr.row-picked > td { background: var(--accent-soft, rgba(120,140,255,0.09)); }

.sel-bar {
  position: sticky; bottom: 12px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 12px 0 4px; padding: 10px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.sel-count { font-weight: 700; font-size: 13.5px; }
.sel-act {
  border: 1px solid var(--border); background: var(--bg-1); color: var(--text-1);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.sel-act:hover { background: var(--hover); }
.sel-act.danger { color: #d9534f; }

/* Group headers inside the table. A band, not a row — it must not read as
   something you could type into. */
.db-table tr.group-head td {
  background: var(--bg-2); font-weight: 700; font-size: 12.5px;
  letter-spacing: 0.02em; padding: 9px 12px; color: var(--text-2);
  border-top: 1px solid var(--border);
}

/* A step under a job. Indent plus a corner mark, so it reads as belonging
   to the line above rather than as a row that happens to be indented. */
.db-table td.first-col.is-child { padding-left: 30px; position: relative; }
.db-table td.first-col.is-child::before {
  content: '↳'; position: absolute; left: 12px; top: 12px;
  color: var(--text-3); font-size: 12px;
}
.db-table tr.row-child > td { background: var(--bg-1); }

.row-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.row-file {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-2); text-decoration: none; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-file:hover { background: var(--hover); color: var(--text-1); }

.view-tab.saved { font-style: normal; }
.view-tab.add-view { opacity: 0.6; }
.view-tab.add-view:hover { opacity: 1; }

.person-chip {
  background: var(--accent-soft, rgba(120,140,255,0.14));
  border-radius: 5px; padding: 1px 5px; font-weight: 600; white-space: nowrap;
}

/* Two taps from a phone. Above the thumb, out of the way of the text. */
.quick-add {
  position: fixed; right: 18px; bottom: 22px; z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 27px; line-height: 1;
  cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  display: none;
}
.quick-add:active { transform: scale(0.94); }
@media (max-width: 720px) {
  .quick-add { display: block; }
  /* The selection bar and the button would sit on top of each other. */
  .sel-bar { bottom: 88px; }
  /* No gutter on a phone — the pick box goes inline with the grip and the
     menu, and is always visible because there is no hover to reveal it. */
  .row-pick {
    opacity: 1; position: static; display: inline-block; vertical-align: middle;
    width: 26px; height: 34px; line-height: 34px;
  }
}

/* The way back out of a parent page. Hidden until a drag starts, because
   a permanent grey strip under the tree is clutter 99% of the time. */
.tree-root-drop {
  display: none;
  margin: 6px 10px 10px; padding: 12px 10px; border-radius: 10px;
  border: 1.5px dashed var(--border); color: var(--text-3);
  font-size: 12px; text-align: center; line-height: 1.35;
}
body.tree-dragging .tree-root-drop { display: block; }
.tree-root-drop.over { border-color: var(--accent); color: var(--accent); background: var(--hover); }

/* ---- find, pin, keyboard help ---- */

.db-find {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-1); color: var(--text-1);
  min-width: 150px; max-width: 220px;
}
.db-find:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Pinning the first column. sticky, not a duplicated table: one source of
   truth for the row heights, which a two-table approach never keeps. */
.db-table.frozen td.first-col,
.db-table.frozen th:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--bg-0);
  box-shadow: 1px 0 0 var(--border);
}
.db-table.frozen tr:hover td.first-col { background: var(--hover); }

.shortcut-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0, 0, 0, 0.5);
}
.shortcut-card {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px 24px; max-width: 460px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.shortcut-card h3 { margin: 0 0 14px; font-size: 17px; }
.shortcut-row {
  display: flex; gap: 14px; align-items: baseline;
  padding: 7px 0; border-top: 1px solid var(--border); font-size: 13.5px;
}
.shortcut-row:first-of-type { border-top: 0; }
.shortcut-row kbd {
  flex: 0 0 128px; font-family: inherit; font-size: 12px; font-weight: 700;
  color: var(--text-2); white-space: nowrap;
}
.shortcut-row span { color: var(--text-1); }
.shortcut-close {
  margin-top: 16px; width: 100%; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-1);
  font: inherit; font-weight: 600; cursor: pointer;
}
.shortcut-close:hover { background: var(--hover); }
