/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f7f5;
  --bg-hover: rgba(55, 53, 47, 0.06);
  --bg-active: rgba(55, 53, 47, 0.1);
  --bg-inset: #f4f4f2;
  --text: #37352f;
  --text-muted: rgba(55, 53, 47, 0.5);
  --text-faint: rgba(55, 53, 47, 0.32);
  --border: rgba(55, 53, 47, 0.1);
  --border-strong: rgba(55, 53, 47, 0.18);
  --accent: #2f6fed;
  --danger: #d5462b;
  --shadow: 0 12px 32px rgba(15, 15, 15, 0.13), 0 3px 6px rgba(15, 15, 15, 0.08);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Malgun Gothic", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, "D2Coding", monospace;
}

html[data-theme="dark"] {
  --bg: #191919;
  --bg-sidebar: #202020;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-active: rgba(255, 255, 255, 0.1);
  --bg-inset: #252525;
  --text: #e9e9e7;
  --text-muted: rgba(255, 255, 255, 0.45);
  --text-faint: rgba(255, 255, 255, 0.28);
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.2);
  --accent: #5b8def;
  --danger: #ff7369;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4), 0 3px 6px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; }
a { color: inherit; }

::selection { background: rgba(47, 111, 237, 0.25); }

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

.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.18s ease;
  user-select: none;
}
.sidebar.collapsed { margin-left: -260px; }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 6px;
}
.workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: default;
}
.workspace:hover { background: var(--bg-hover); }
.workspace-avatar {
  width: 22px; height: 22px; border-radius: 5px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; flex: none;
}
.workspace-name {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
  border: none; background: none; cursor: pointer;
  width: 26px; height: 26px; border-radius: 5px;
  display: grid; place-items: center;
  color: var(--text-muted); flex: none;
  font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-section { padding: 2px 8px; }
.sidebar-nav { padding: 4px 8px 8px; }

.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 5px 8px; border: none; background: none;
  border-radius: 5px; cursor: pointer;
  font-size: 14px; color: var(--text-muted);
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item .ico { width: 18px; text-align: center; flex: none; opacity: 0.85; }
.nav-item kbd {
  margin-left: auto; font-size: 11px; font-family: var(--font);
  color: var(--text-faint); background: none;
}

.section-label {
  padding: 14px 14px 4px;
  font-size: 11.5px; font-weight: 600;
  color: var(--text-faint); letter-spacing: 0.03em;
  display: flex; align-items: center;
}
.section-label button { margin-left: auto; }

.tree { flex: 1; overflow-y: auto; padding: 0 8px 24px; }
.tree::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.tree-row {
  display: flex; align-items: center; gap: 2px;
  border-radius: 5px; cursor: pointer;
  color: var(--text-muted); font-size: 14px;
  padding-right: 4px;
  min-height: 27px;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); color: var(--text); font-weight: 500; }
.tree-row.drop-into { background: rgba(47, 111, 237, 0.16); box-shadow: inset 0 0 0 1.5px var(--accent); }
.tree-row.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.tree-row.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }

.twisty {
  width: 18px; height: 20px; flex: none;
  border: none; background: none; cursor: pointer;
  color: var(--text-faint); font-size: 10px;
  display: grid; place-items: center; border-radius: 4px;
  transition: transform 0.12s ease;
}
.twisty:hover { background: var(--bg-active); }
.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }

.tree-icon { width: 20px; flex: none; text-align: center; font-size: 14px; }
.tree-title {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 3px 0;
}
.tree-row .row-btn {
  opacity: 0; width: 22px; height: 22px; flex: none;
  border: none; background: none; border-radius: 4px;
  cursor: pointer; color: var(--text-muted); font-size: 14px;
  display: grid; place-items: center;
}
.tree-row:hover .row-btn { opacity: 1; }
.row-btn:hover { background: var(--bg-active); color: var(--text); }

.tree-empty { padding: 4px 12px 4px 30px; font-size: 13px; color: var(--text-faint); }

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

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.topbar {
  height: 45px; flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px;
  border-bottom: 1px solid transparent;
  font-size: 14px;
}
.topbar.scrolled { border-bottom-color: var(--border); }

.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 1; overflow: hidden; }
.crumb {
  border: none; background: none; cursor: pointer;
  padding: 3px 6px; border-radius: 4px;
  font-size: 14px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.crumb:hover { background: var(--bg-hover); }
.crumb-sep { color: var(--text-faint); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.text-btn {
  border: none; background: none; cursor: pointer;
  padding: 5px 9px; border-radius: 5px;
  font-size: 14px; color: var(--text-muted);
}
.text-btn:hover { background: var(--bg-hover); color: var(--text); }

.presence { display: flex; align-items: center; margin-right: 4px; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 600;
  border: 2px solid var(--bg); margin-left: -6px;
}
.avatar.here { box-shadow: 0 0 0 2px #3fa66a; }

.scroller { flex: 1; overflow-y: auto; }
.scroller::-webkit-scrollbar { width: 12px; }
.scroller::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 4px solid var(--bg); }

.page { max-width: 740px; margin: 0 auto; padding: 40px 60px 45vh; }
.page.wide { max-width: 1100px; }

.cover { height: 200px; background-size: cover; background-position: center; position: relative; }
.cover-actions { position: absolute; right: 16px; bottom: 12px; display: none; gap: 6px; }
.cover:hover .cover-actions { display: flex; }
.cover-actions button {
  border: none; background: rgba(255, 255, 255, 0.9); color: #37352f;
  font-size: 12px; padding: 4px 8px; border-radius: 4px; cursor: pointer;
}

.page-icon {
  font-size: 72px; line-height: 1; cursor: pointer;
  display: inline-block; border-radius: 8px; padding: 2px 6px; margin-left: -8px;
}
.page-icon:hover { background: var(--bg-hover); }

.page-title {
  font-size: 40px; font-weight: 700; line-height: 1.2;
  outline: none; margin: 4px 0 6px; word-break: break-word;
}
.page-title:empty::before {
  content: "제목 없음"; color: var(--text-faint);
}

.page-meta {
  display: flex; gap: 10px; align-items: center;
  font-size: 12.5px; color: var(--text-faint);
  margin-bottom: 18px;
}
.add-controls { display: flex; gap: 8px; margin: 6px 0 14px; }
.add-controls button {
  border: none; background: none; cursor: pointer;
  font-size: 13.5px; color: var(--text-faint);
  padding: 4px 6px; border-radius: 4px;
}
.add-controls button:hover { background: var(--bg-hover); color: var(--text-muted); }

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

.blocks { min-height: 40px; }

.block {
  position: relative;
  display: flex;
  align-items: flex-start;
  padding: 1px 0;
}
.block-gutter {
  position: absolute; left: -46px; top: 0;
  display: flex; gap: 1px; opacity: 0;
  transition: opacity 0.1s;
  padding-top: 3px;
}
.block:hover .block-gutter, .block.menu-open .block-gutter { opacity: 1; }
.gutter-btn {
  width: 20px; height: 22px; border: none; background: none;
  border-radius: 4px; cursor: grab; color: var(--text-faint);
  display: grid; place-items: center; font-size: 13px; line-height: 1;
}
.gutter-btn:hover { background: var(--bg-hover); color: var(--text-muted); }

.block-body { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 6px; }

.editable {
  outline: none; flex: 1; min-width: 0;
  padding: 3px 2px; word-break: break-word; white-space: pre-wrap;
}
.editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint); pointer-events: none;
}
.block:not(.focused) .editable:empty::before { content: ""; }
.block[data-type="text"]:first-child .editable:empty::before { content: attr(data-placeholder); }

.block[data-type="h1"] .editable { font-size: 30px; font-weight: 700; margin-top: 22px; line-height: 1.3; }
.block[data-type="h2"] .editable { font-size: 24px; font-weight: 700; margin-top: 18px; line-height: 1.3; }
.block[data-type="h3"] .editable { font-size: 19px; font-weight: 600; margin-top: 14px; line-height: 1.3; }

.marker {
  flex: none; user-select: none;
  display: flex; align-items: flex-start; justify-content: center;
  min-width: 22px; padding-top: 4px; color: var(--text);
}
.block[data-type="numbered"] .marker { font-size: 15.5px; color: var(--text); }

.check {
  width: 16px; height: 16px; margin-top: 6px;
  border: 1.6px solid var(--border-strong); border-radius: 3px;
  cursor: pointer; flex: none; display: grid; place-items: center;
  color: transparent; font-size: 11px;
}
.check.checked { background: var(--accent); border-color: var(--accent); color: #fff; }
.block.done .editable { color: var(--text-faint); text-decoration: line-through; }

.block[data-type="quote"] .block-body {
  border-left: 3px solid var(--text); padding-left: 12px; margin: 4px 0;
}

.block[data-type="callout"] .block-body {
  background: var(--bg-inset); border-radius: 6px;
  padding: 12px 14px; margin: 4px 0; gap: 10px;
}
.callout-emoji { font-size: 18px; line-height: 1.4; cursor: pointer; flex: none; }

.block[data-type="divider"] .block-body { padding: 10px 0; }
.block[data-type="divider"] hr {
  border: none; border-top: 1px solid var(--border); width: 100%; margin: 0;
}

.block[data-type="code"] .block-body { position: relative; margin: 5px 0; }
.code-wrap {
  background: var(--bg-inset); border-radius: 6px;
  padding: 26px 16px 14px; width: 100%; position: relative;
}
.code-wrap .editable {
  font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  white-space: pre-wrap; tab-size: 2;
}
.code-lang {
  position: absolute; top: 4px; left: 10px;
  font-size: 11px; color: var(--text-faint);
  background: none; border: none; cursor: pointer; font-family: var(--mono);
}
.code-copy {
  position: absolute; top: 4px; right: 8px;
  font-size: 11px; color: var(--text-faint);
  background: none; border: none; cursor: pointer;
}
.code-copy:hover, .code-lang:hover { color: var(--text); }

.block[data-type="image"] .block-body { flex-direction: column; margin: 6px 0; }
.block-image { max-width: 100%; border-radius: 4px; display: block; cursor: zoom-in; }
.image-caption { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; outline: none; }
.image-drop {
  width: 100%; padding: 22px; text-align: center;
  background: var(--bg-inset); border-radius: 6px;
  color: var(--text-muted); font-size: 14px; cursor: pointer;
}
.image-drop:hover { background: var(--bg-hover); }

.block[data-type="pagelink"] .block-body { padding: 3px 0; }
.pagelink {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; border-radius: 4px; padding: 3px 4px;
  text-decoration: none; font-weight: 500;
  border-bottom: 1px solid var(--border); width: 100%;
}
.pagelink:hover { background: var(--bg-hover); }

.editable a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.editable code {
  background: rgba(135, 131, 120, 0.2); color: #c7254e;
  font-family: var(--mono); font-size: 0.87em;
  padding: 2px 5px; border-radius: 4px;
}
html[data-theme="dark"] .editable code { color: #ff8080; }

.indent-1 { margin-left: 26px; }
.indent-2 { margin-left: 52px; }
.indent-3 { margin-left: 78px; }
.indent-4 { margin-left: 104px; }

.block-selected { background: rgba(47, 111, 237, 0.16); border-radius: 3px; }
.block-selected .editable::selection { background: transparent; }

.block.dragging { opacity: 0.35; }
.block.drop-target-above::before,
.block.drop-target-below::after {
  content: ""; position: absolute; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.block.drop-target-above::before { top: -1px; }
.block.drop-target-below::after { bottom: -1px; }

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

.menu {
  position: fixed; z-index: 200;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; min-width: 220px; max-height: 340px; overflow-y: auto;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; border: none; background: none;
  padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 14px;
}
.menu-item:hover, .menu-item.sel { background: var(--bg-hover); }
.menu-item .mi-ico {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 14px; background: var(--bg);
}
.menu-item .mi-sub { font-size: 12px; color: var(--text-faint); }
.menu-item.danger { color: var(--danger); }
.menu-label {
  padding: 8px 8px 4px; font-size: 11.5px;
  color: var(--text-faint); font-weight: 600;
}
.menu-sep { height: 1px; background: var(--border); margin: 5px 0; }

.overlay {
  position: fixed; inset: 0; z-index: 190;
  background: rgba(15, 15, 15, 0.35);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.overlay.plain { background: transparent; }

.modal {
  width: min(620px, 92vw);
  background: var(--bg); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; max-height: 70vh;
}
.modal-search {
  border: none; outline: none; background: none;
  padding: 16px 18px; font-size: 17px; color: var(--text);
  border-bottom: 1px solid var(--border); font-family: inherit;
}
.modal-body { overflow-y: auto; padding: 8px; }
.modal-head {
  padding: 14px 18px; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; border-bottom: 1px solid var(--border);
}
.modal-head .icon-btn { margin-left: auto; }
.modal-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

.result {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.result:hover, .result.sel { background: var(--bg-hover); }
.result-main { min-width: 0; flex: 1; }
.result-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-snippet {
  font-size: 12px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.btn {
  border: 1px solid var(--border-strong); background: var(--bg);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }

.share-panel { padding: 16px 18px; width: 340px; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.share-row .label { font-size: 14px; }
.share-row .sub { font-size: 12px; color: var(--text-faint); }
.link-box {
  display: flex; gap: 6px; margin-top: 10px;
}
.link-box input {
  flex: 1; min-width: 0; font-size: 12.5px; font-family: var(--mono);
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-inset); color: var(--text); outline: none;
}

.switch {
  width: 34px; height: 20px; border-radius: 10px; flex: none;
  background: var(--border-strong); position: relative;
  cursor: pointer; border: none; transition: background 0.15s; margin-left: auto;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(14px); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 7px; font-size: 13.5px;
  z-index: 400; box-shadow: var(--shadow); opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.emoji-grid {
  display: grid; grid-template-columns: repeat(10, 1fr);
  gap: 2px; padding: 6px; max-height: 260px; overflow-y: auto;
}
.emoji-grid button {
  border: none; background: none; cursor: pointer;
  font-size: 20px; padding: 4px; border-radius: 5px; line-height: 1;
}
.emoji-grid button:hover { background: var(--bg-hover); }

.lightbox {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0, 0, 0, 0.85);
  display: grid; place-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; }

/* ----------------------------------------------------------------- auth */

.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--bg-sidebar);
}
.auth-card {
  width: min(400px, 100%); background: var(--bg);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-card p.sub { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 9px 11px; font-size: 14.5px; font-family: inherit;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }
.auth-error {
  color: var(--danger); font-size: 13px; margin: 4px 0 10px; min-height: 18px;
}
.auth-switch { text-align: center; margin-top: 16px; font-size: 13.5px; color: var(--text-muted); }
.auth-switch button {
  border: none; background: none; color: var(--accent);
  cursor: pointer; font-size: 13.5px; padding: 0;
}

/* --------------------------------------------------------------- shared */

.share-topbar {
  height: 48px; display: flex; align-items: center; gap: 10px;
  padding: 0 20px; border-bottom: 1px solid var(--border);
  font-size: 14px; color: var(--text-muted);
}
.share-badge {
  margin-left: auto; font-size: 12px; color: var(--text-faint);
  border: 1px solid var(--border); padding: 3px 9px; border-radius: 20px;
}
.readonly .block-gutter, .readonly .add-controls { display: none !important; }
.readonly .check { cursor: default; }

/* -------------------------------------------------------- page templates */

.tpl { margin-top: 18px; }
.tpl-label {
  font-size: 12px; color: var(--text-faint);
  font-weight: 600; margin-bottom: 8px;
}
.tpl-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px;
}
.tpl-card {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: pointer; padding: 12px 13px;
}
.tpl-card:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.tpl-card:disabled { opacity: 0.5; cursor: default; }
.tpl-ico { font-size: 20px; line-height: 1.3; }
.tpl-name { font-size: 14px; font-weight: 500; }
.tpl-desc { font-size: 12px; color: var(--text-faint); }

/* ------------------------------------------------------------ file block */

.file-card {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; margin: 4px 0;
  border: 1px solid var(--border); border-radius: 6px;
  text-decoration: none; color: inherit; background: var(--bg);
}
.file-card:hover { background: var(--bg-hover); }
.file-ico { font-size: 22px; flex: none; line-height: 1; }
.file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file-name {
  font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-size { font-size: 12px; color: var(--text-faint); }
.file-dl { font-size: 12.5px; color: var(--text-faint); flex: none; }
.file-card:hover .file-dl { color: var(--accent); }

/* --------------------------------------------------------- database view */

.db-host { width: 100%; }

.dbv { width: 100%; margin: 10px 0 18px; }

.dbv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.dbv-title {
  font-size: 17px; font-weight: 600; outline: none;
  padding: 2px 4px; border-radius: 4px; min-width: 40px;
}
.dbv-title:hover { background: var(--bg-hover); }
.dbv-title:empty::before { content: attr(data-placeholder); color: var(--text-faint); }

.dbv-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.dbv-tool, .dbv-new {
  border: none; background: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
  padding: 4px 8px; border-radius: 5px;
}
.dbv-tool:hover { background: var(--bg-hover); color: var(--text); }
.dbv-new { background: var(--accent); color: #fff; font-weight: 500; padding: 5px 11px; }
.dbv-new:hover { filter: brightness(1.08); }

.dbv-search input {
  border: 1px solid transparent; background: var(--bg-inset);
  border-radius: 5px; padding: 4px 9px; font-size: 13px;
  color: var(--text); outline: none; width: 130px; font-family: inherit;
}
.dbv-search input:focus { border-color: var(--border-strong); width: 180px; }

.dbv-filterbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.dbv-chip {
  border: 1px solid var(--border-strong); background: var(--bg);
  border-radius: 20px; padding: 3px 11px; font-size: 12.5px;
  cursor: pointer; color: var(--text-muted);
}
.dbv-chip:hover { background: var(--bg-hover); }
.dbv-chip.ghost { border-style: dashed; color: var(--text-faint); }

.dbv-scroll { overflow-x: auto; border-top: 1px solid var(--border); }
.dbv-scroll::-webkit-scrollbar { height: 9px; }
.dbv-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }

.dbv-table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 14px; }
.dbv-table th, .dbv-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0; vertical-align: top; position: relative;
}
.dbv-table th:last-child, .dbv-table td:last-child { border-right: none; }

.dbv-th {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 9px; cursor: pointer; color: var(--text-muted);
  font-weight: 500; font-size: 13px; white-space: nowrap;
  overflow: hidden;
}
.dbv-th:hover { background: var(--bg-hover); }
.dbv-th-ico { color: var(--text-faint); font-size: 12px; flex: none; }
.dbv-th-name { overflow: hidden; text-overflow: ellipsis; }
.dbv-th-sort { margin-left: auto; color: var(--accent); font-size: 12px; }

.dbv-resize {
  position: absolute; top: 0; right: -2px; width: 5px; height: 100%;
  cursor: col-resize; z-index: 2;
}
.dbv-resize:hover { background: var(--accent); opacity: 0.5; }

.dbv-addcol { width: 40px; }
.dbv-addcol button {
  width: 100%; border: none; background: none; cursor: pointer;
  color: var(--text-faint); font-size: 15px; padding: 7px 0;
}
.dbv-addcol button:hover { background: var(--bg-hover); color: var(--text); }

.dbv-table tbody tr:hover { background: var(--bg-hover); }

.dbv-cell {
  padding: 7px 9px; outline: none; min-height: 33px;
  word-break: break-word; white-space: pre-wrap;
}
.dbv-cell:focus { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 3px; }
.dbv-titlecell { font-weight: 500; padding-right: 60px; }
.dbv-date { cursor: pointer; color: var(--text); }
.dbv-url { color: var(--accent); text-decoration: underline; }
.dbv-urledit {
  position: absolute; right: 4px; top: 5px; border: none; background: none;
  cursor: pointer; color: var(--text-faint); font-size: 12px; opacity: 0;
}
td:hover .dbv-urledit { opacity: 1; }

.dbv-check {
  width: 16px; height: 16px; margin: 9px;
  border: 1.6px solid var(--border-strong); border-radius: 3px;
  cursor: pointer; display: grid; place-items: center;
  color: transparent; font-size: 11px;
}
.dbv-check.checked { background: var(--accent); border-color: var(--accent); color: #fff; }

.dbv-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px 9px; min-height: 33px; align-items: center;
}
.dbv-tags.clickable { cursor: pointer; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12.5px; line-height: 1.5; white-space: nowrap;
}
.tag.gray   { background: #e3e2e0; color: #37352f; }
.tag.brown  { background: #eedfd9; color: #5c3b28; }
.tag.orange { background: #fadec9; color: #8a4d1c; }
.tag.yellow { background: #fdecc8; color: #7a5a17; }
.tag.green  { background: #dbeddb; color: #1d5b31; }
.tag.blue   { background: #d3e5ef; color: #1a4f6d; }
.tag.purple { background: #e8deee; color: #4c2b6b; }
.tag.pink   { background: #f5e0e9; color: #7a2647; }
.tag.red    { background: #ffe2dd; color: #9b2417; }

html[data-theme="dark"] .tag.gray   { background: #454b4e; color: #d5d5d3; }
html[data-theme="dark"] .tag.brown  { background: #5c3b28; color: #f0d9cd; }
html[data-theme="dark"] .tag.orange { background: #8a4d1c; color: #fbe0c8; }
html[data-theme="dark"] .tag.yellow { background: #7a5a17; color: #fbeeca; }
html[data-theme="dark"] .tag.green  { background: #1d5b31; color: #d6ecd9; }
html[data-theme="dark"] .tag.blue   { background: #1a4f6d; color: #d3e7f2; }
html[data-theme="dark"] .tag.purple { background: #4c2b6b; color: #e5d8ef; }
html[data-theme="dark"] .tag.pink   { background: #7a2647; color: #f6dde7; }
html[data-theme="dark"] .tag.red    { background: #9b2417; color: #ffdfd9; }

.dbv-rowtools {
  position: absolute; right: 4px; top: 4px;
  display: none; gap: 2px;
}
td:hover .dbv-rowtools { display: flex; }
.dbv-open, .dbv-rowmenu {
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 4px; cursor: pointer; font-size: 11.5px;
  padding: 2px 7px; color: var(--text-muted);
}
.dbv-open:hover, .dbv-rowmenu:hover { background: var(--bg-hover); color: var(--text); }

.dbv-newrow {
  padding: 8px 10px; cursor: pointer;
  color: var(--text-faint); font-size: 13.5px;
}
.dbv-newrow:hover { background: var(--bg-hover); color: var(--text-muted); }
.dbv-empty { padding: 14px 10px; color: var(--text-faint); font-size: 13.5px; }
.dbv-count { padding: 6px 2px; font-size: 12.5px; color: var(--text-faint); }

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

.dbv-views { display: flex; gap: 2px; margin-right: 4px; }
.dbv-viewtab {
  border: none; background: none; cursor: pointer;
  font-size: 13px; color: var(--text-faint);
  padding: 4px 9px; border-radius: 5px;
}
.dbv-viewtab:hover { background: var(--bg-hover); color: var(--text); }
.dbv-viewtab.on { background: var(--bg-active); color: var(--text); font-weight: 500; }

.cal-nav { display: flex; align-items: center; gap: 4px; padding: 4px 0 8px; }
.cal-month { font-size: 15px; font-weight: 600; min-width: 110px; text-align: center; }

.cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--border); border-left: 1px solid var(--border);
}
.cal-dow {
  padding: 6px 8px; font-size: 12px; color: var(--text-faint);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  text-align: right; background: var(--bg-inset);
}
.cal-dow.sun { color: #d5462b; }
.cal-dow.sat { color: #2f6fed; }

.cal-cell {
  min-height: 104px; padding: 4px 5px 6px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.cal-cell.outside { background: var(--bg-inset); }
.cal-cell.outside .cal-daynum { color: var(--text-faint); opacity: 0.6; }
.cal-cell.today .cal-daynum {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 22px; height: 22px; display: grid; place-items: center;
}
.cal-daynum { font-size: 12.5px; color: var(--text-muted); padding: 1px 3px; }

.cal-add {
  position: absolute; top: 3px; right: 3px;
  border: none; background: none; cursor: pointer;
  color: var(--text-faint); font-size: 14px;
  width: 20px; height: 20px; border-radius: 4px; opacity: 0;
}
.cal-cell:hover .cal-add { opacity: 1; }
.cal-add:hover { background: var(--bg-active); color: var(--text); }

.cal-entries { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.cal-entry {
  font-size: 12px; padding: 2px 6px; border-radius: 4px;
  background: var(--bg-active); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-entry:hover { filter: brightness(0.95); }
html[data-theme="dark"] .cal-entry:hover { filter: brightness(1.25); }

.cal-undated { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; max-width: 320px; }

.dbv-popinput {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 5px;
  padding: 6px 8px; font-size: 13.5px; font-family: inherit;
  background: var(--bg); color: var(--text); outline: none; margin-bottom: 5px;
}
.dbv-popinput:focus { border-color: var(--accent); }
.dbv-tick { margin-left: auto; color: var(--accent); }
.dbv-pop .menu-item { gap: 6px; }

.readonly.dbv .dbv-new, .readonly.dbv .dbv-addcol button, .readonly.dbv .dbv-newrow { display: none; }

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 100; height: 100%; box-shadow: var(--shadow); }
  .page { padding: 28px 22px 40vh; }
  .block-gutter { display: none; }
}
