:root {
  color-scheme: light;
  --canvas: #f4f5f2;
  --surface: #ffffff;
  --surface-muted: #f0f1ee;
  --line: #dfe2dc;
  --line-strong: #c9cdc5;
  --ink: #1c211d;
  --ink-soft: #656c65;
  --accent: #1f6b4f;
  --accent-soft: #e3efe8;
  --accent-strong: #17543e;
  --warm: #b45b3f;
  --danger: #a43b32;
  --shadow: 0 10px 30px rgba(24, 31, 26, 0.08);
  --sidebar-width: 236px;
  --notes-width: 350px;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #171a18;
  --surface: #1e221f;
  --surface-muted: #272c28;
  --line: #343a35;
  --line-strong: #495049;
  --ink: #eef1ed;
  --ink-soft: #aeb6af;
  --accent: #72b992;
  --accent-soft: #233c30;
  --accent-strong: #95cfac;
  --warm: #db8c70;
  --danger: #ef8b83;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  border: 0;
}

.app-shell {
  display: flex;
  height: 100vh;
  min-height: 560px;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex: 0 0 var(--sidebar-width);
  flex-direction: column;
  width: var(--sidebar-width);
  min-width: 0;
  padding: 20px 14px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand-row {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 6px;
}

.brand-mark {
  flex: none;
  margin-right: 10px;
}

.brand-row div {
  min-width: 0;
}

.brand-row strong,
.brand-row span {
  display: block;
}

.brand-row strong {
  font-size: 16px;
  line-height: 20px;
}

.brand-row span {
  margin-top: 1px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 16px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 19px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--ink);
}

.sidebar-close,
.menu-button,
.back-button {
  display: none;
}

.new-note-sidebar,
.quick-new-button,
.list-empty button,
.editor-empty button,
.trash-actions button {
  min-height: 38px;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 650;
}

.new-note-sidebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  margin: 22px 0 14px;
}

.new-note-sidebar:hover,
.quick-new-button:hover,
.list-empty button:hover,
.editor-empty button:hover,
.trash-actions button:hover {
  background: var(--accent-strong);
}

.primary-nav {
  display: grid;
  gap: 3px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.nav-count {
  min-width: 20px;
  color: currentColor;
  font-size: 12px;
  text-align: right;
}

.sidebar-section {
  min-height: 0;
  margin-top: 24px;
  overflow-y: auto;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 10px 8px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.section-label-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tag-manage-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.tag-manage-button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.tag-list {
  display: grid;
  gap: 2px;
}

.tag-filter {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}

.tag-filter:hover,
.tag-filter.is-active {
  background: var(--surface-muted);
  color: var(--ink);
}

.tag-filter.is-active {
  box-shadow: inset 2px 0 0 var(--warm);
}

.tag-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warm);
}

.tag-filter span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-filter small {
  font-size: 11px;
}

/* 标签树（子文件夹） */
.tag-tree-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.tag-tree-row .tag-filter {
  flex: 1;
  min-width: 0;
}

.tag-toggle {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}

.tag-toggle:hover {
  background: var(--surface-muted);
  color: var(--accent);
}

.tag-toggle-spacer {
  width: 20px;
  flex: 0 0 auto;
}

.tag-add-child {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--accent-strong);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.tag-tree-row:hover .tag-add-child {
  opacity: 1;
}

.tag-add-child:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

/* 树状：父标签用文件夹图标，子标签用浅色圆点 */
.tag-filter.is-folder .tag-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--accent);
}

.tag-filter.is-child .tag-swatch {
  background: color-mix(in srgb, var(--warm) 55%, transparent);
}

/* 拖拽排序 */
.tag-tree-row {
  cursor: grab;
}

.tag-tree-row:active {
  cursor: grabbing;
}

.tag-tree-row.is-dragging {
  opacity: 0.4;
}

.tag-tree-row.is-drag-before {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.tag-tree-row.is-drag-after {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

.tag-tree-row.is-drag-child {
  background: var(--accent-soft);
  border-radius: 7px;
  box-shadow: inset 2px 0 0 0 var(--accent);
}

.tag-directory-add {
  margin-left: 2px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--accent-strong);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

.tag-directory-add:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 4px 0;
  border-top: 1px solid var(--line);
}

.account-button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 48px;
  margin: 0 0 9px;
  padding: 6px 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}

.account-button:hover {
  background: var(--surface-muted);
}

.account-button > span:last-child {
  margin-left: auto;
  font-size: 18px;
}

.account-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.account-copy strong,
.account-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy strong {
  color: var(--ink);
  font-size: 11px;
}

.account-copy small {
  font-size: 10px;
}

.account-button.is-cloud .status-dot {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.account-button.is-error .status-dot {
  background: var(--danger);
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
}

.footer-actions {
  display: flex;
  gap: 2px;
}

.usage-text {
  margin: 8px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-size: 11px;
}

.workspace {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.search-box {
  display: grid;
  grid-template-columns: 24px minmax(0, 520px) auto;
  align-items: center;
  width: min(100%, 600px);
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--ink-soft);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-box kbd {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 10px;
}

.search-clear {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.search-clear:hover {
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  color: var(--ink);
}

.quick-new-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 86px;
  margin-left: auto;
  padding: 0 14px;
}

.daily-note-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 76px;
  height: 38px;
  margin-left: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.daily-note-button:hover {
  border-color: var(--line-strong);
  color: var(--accent);
}

.knowledge-layout {
  display: grid;
  grid-template-columns: minmax(300px, var(--notes-width)) minmax(0, 1fr);
  min-height: 0;
  flex: 1;
}

.notes-pane {
  min-width: 0;
  padding: 24px 14px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--canvas);
}

.notes-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 6px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}

.notes-heading h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.25;
}

.notes-heading select {
  width: 108px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
}

.notes-heading select:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.sort-dir-btn {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.sort-dir-btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.sort-dir-btn:active {
  background: var(--surface-muted);
}

.notes-heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty-trash-button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  border-radius: 5px;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  white-space: nowrap;
}

.empty-trash-button:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.empty-trash-button:active {
  transform: translateY(1px);
}

.view-mode-button {
  height: 30px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.view-mode-button:hover {
  border-color: var(--line-strong);
  color: var(--accent);
}

.view-mode-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 650;
}

/* 排序下拉：文字 + 箭头 样式 */
.notes-heading select {
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  padding: 0 20px 0 4px;
  border: 0;
  background: transparent
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right 2px center;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.notes-heading select:hover {
  color: var(--accent);
}

/* 公告入口（不常驻） */
.announcement-entry {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.announcement-entry:hover {
  border-color: var(--line-strong);
  color: var(--accent);
}

.announcement-entry-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff7043;
  box-shadow: 0 0 5px rgba(255, 112, 67, 0.8);
}

.result-summary {
  margin: 7px 6px 18px;
  color: var(--ink-soft);
  font-size: 12px;
}

/* 标签快捷筛选栏 */
.tag-quick-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px 6px 2px;
}

.quick-tag {
  max-width: 150px;
  padding: 5px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.quick-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.quick-tag.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.notes-list {
  display: grid;
  gap: 10px;
}

.note-card {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  border: 1px solid rgba(31, 107, 79, 0.08);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(24, 31, 26, 0.04), 0 4px 14px rgba(24, 31, 26, 0.05);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.note-card:hover {
  border-color: rgba(31, 107, 79, 0.22);
  box-shadow: 0 8px 22px rgba(24, 31, 26, 0.12);
  transform: translateY(-2px);
}

.note-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(31, 107, 79, 0.14);
}

/* 星标笔记左侧橙色竖线标记 */
.note-card.note-favorited::before {
  content: "";
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 0;
  width: 3.5px;
  border-radius: 0 3px 3px 0;
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.55);
}

.note-card-main {
  display: block;
  width: 100%;
  min-height: 118px;
  padding: 16px 44px 14px 16px;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.note-card h2 {
  margin: 0 0 8px;
  overflow: hidden;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 21px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card p {
  display: -webkit-box;
  min-height: 38px;
  margin: 0 0 12px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 19px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 10px;
}

.note-card-tag {
  max-width: 90px;
  padding: 2px 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card-tag.more {
  background: var(--surface-muted);
  color: var(--ink-soft);
}

/* 搜索关键词高亮 */
.note-card mark {
  background: rgba(245, 158, 11, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.note-card-favorite {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: transparent;
  color: rgba(120, 128, 124, 0.45);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  transition: transform 120ms ease, color 120ms ease, background 120ms ease;
}

.note-card-favorite:hover {
  background: var(--surface-muted);
  transform: scale(1.08);
}

.note-card-favorite.is-favorite {
  color: #f59e0b;
  text-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
}

.list-empty,
.editor-empty {
  text-align: center;
}

.list-empty {
  padding: 56px 24px;
  color: var(--ink-soft);
}

.empty-glyph {
  margin-bottom: 12px;
  font-size: 38px;
}

.list-empty h2,
.editor-empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 17px;
}

.list-empty p,
.editor-empty p {
  margin: 0 0 20px;
  font-size: 13px;
}

.list-empty button,
.editor-empty button {
  padding: 0 16px;
}

.editor-pane {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  background: var(--surface);
}

.editor-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(380px, calc(100% - 48px));
  color: var(--ink-soft);
  transform: translate(-50%, -54%);
}

.editor-empty img {
  margin-bottom: 22px;
  opacity: 0.82;
}

.editor {
  width: min(850px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: 22px 46px 36px;
}

#contentInput {
  width: 100%;
  min-height: 62vh;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  resize: none;
  box-sizing: border-box;
}

#contentInput:focus {
  outline: none;
  border-color: var(--accent);
}

.editor-topline {
  display: flex;
  align-items: center;
  min-height: 36px;
}

.save-state {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 11px;
}

.save-state.is-saving .status-dot {
  background: var(--warm);
}

.editor-actions {
  display: flex;
  gap: 3px;
  margin-left: auto;
}

.danger-button:hover {
  color: var(--danger);
}

.title-input {
  display: block;
  width: 100%;
  margin: 30px 0 11px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 32px;
  font-weight: 750;
  line-height: 1.25;
}

.title-input::placeholder,
#contentInput::placeholder {
  color: color-mix(in srgb, var(--ink-soft) 65%, transparent);
}

.note-meta-row {
  display: flex;
  align-items: center;
  min-height: 32px;
  color: var(--ink-soft);
  font-size: 11px;
}

.tag-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.tag-input-wrap input {
  width: min(320px, 34vw);
  min-width: 100px;
  padding: 4px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11px;
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-picker-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.tag-picker-chip:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.tag-picker-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.tag-picker-hint {
  width: 100%;
  font-size: 12px;
  color: var(--accent-strong);
  margin-bottom: 4px;
}

.editor-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 26px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.format-toolbar,
.mode-switch {
  display: flex;
  align-items: center;
  gap: 2px;
}

.format-toolbar button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 30px;
  padding: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.format-toolbar button:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.color-label {
  position: relative;
}

.color-label::after {
  content: "";
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: 2px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, #e5484d, #f5a524, #30a46c, #3e63dd, #8e4ec6);
}

.color-menu {
  position: fixed;
  z-index: 70;
  display: grid;
  grid-template-columns: repeat(4, 26px);
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

.color-menu button[data-color] {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
}

.color-menu button[data-color]:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.color-menu .color-clear {
  grid-column: 1 / -1;
  width: auto;
  height: 28px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  border-radius: 6px;
}

.color-menu .color-clear:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.announcement-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 14px;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.announcement-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.announcement-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}

.announcement-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 13px;
}

.announcement-link {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.announcement-link:hover {
  text-decoration: underline;
}

.announcement-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 16px;
}

.announcement-close:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.changelog-dialog .dialog-header {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.changelog-body {
  display: grid;
  gap: 16px;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  padding-right: 4px;
}

.changelog-entry:not(:first-child) {
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.changelog-entry-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.changelog-version {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-strong);
}

.changelog-date {
  font-size: 12px;
  color: var(--ink-soft);
}

.changelog-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.changelog-entry ul {
  display: grid;
  gap: 5px;
  margin: 6px 0 0;
  padding-left: 18px;
}

.changelog-entry li {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.mode-switch {
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.mode-switch button {
  height: 26px;
  padding: 0 10px;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11px;
}

.mode-switch button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ai-toolbar {
  position: relative;
  display: flex;
  align-items: center;
}

.ai-trigger {
  height: 30px;
  padding: 0 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, var(--warm)));
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.ai-trigger:hover {
  filter: brightness(1.06);
}

.ai-trigger.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.ai-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  display: grid;
  gap: 2px;
  min-width: 156px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

.ai-menu button {
  padding: 8px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.ai-menu button:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.ai-menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--line);
}

.ai-status {
  margin: 12px 0 0;
  color: var(--accent-strong);
  font-size: 12px;
}

#contentInput {
  display: block;
  width: 100%;
  min-height: 420px;
  padding: 28px 0;
  resize: none;
  overflow: hidden;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.9;
}

.wysiwyg-editor {
  width: 100%;
  min-height: 420px;
  padding: 28px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.85;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.wysiwyg-editor:focus {
  outline: 0;
}

.wysiwyg-editor.is-dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background: var(--accent-soft);
}

.wysiwyg-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-faint);
  pointer-events: none;
}

.wysiwyg-editor h1,
.wysiwyg-editor h2,
.wysiwyg-editor h3 {
  margin: 1.4em 0 0.55em;
  line-height: 1.35;
}

.wysiwyg-editor h1:first-child,
.wysiwyg-editor h2:first-child,
.wysiwyg-editor h3:first-child,
.wysiwyg-editor p:first-child {
  margin-top: 0;
}

.wysiwyg-editor p {
  margin: 0 0 0.5em;
  min-height: 1em;
}

.wysiwyg-editor ul {
  margin: 0.4em 0 0.8em;
  padding-left: 1.5em;
}

.wysiwyg-editor li {
  margin: 0.2em 0;
}

.wysiwyg-editor blockquote {
  margin: 0.6em 0;
  padding: 0.2em 0 0.2em 0.9em;
  border-left: 3px solid var(--line-strong);
  color: var(--ink-soft);
}

.wysiwyg-editor code {
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background: var(--surface-muted);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.wysiwyg-editor pre {
  margin: 0.8em 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-muted);
  overflow-x: auto;
}

.wysiwyg-editor pre code {
  padding: 0;
  background: transparent;
}

.wysiwyg-editor a {
  color: var(--accent-strong);
  text-decoration: underline;
  cursor: pointer;
}

.wysiwyg-editor .note-link {
  color: var(--accent-strong);
  border-bottom: 1px dashed var(--accent-soft);
  cursor: pointer;
}

.markdown-preview {
  min-height: 420px;
  padding: 28px 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.85;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  margin: 1.4em 0 0.55em;
  line-height: 1.35;
}

.markdown-preview h1:first-child,
.markdown-preview h2:first-child,
.markdown-preview h3:first-child,
.markdown-preview p:first-child {
  margin-top: 0;
}

.markdown-preview p {
  margin: 0 0 1em;
}

.markdown-preview blockquote {
  margin: 1em 0;
  padding: 2px 0 2px 15px;
  border-left: 3px solid var(--warm);
  color: var(--ink-soft);
}

.markdown-preview code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--accent-strong);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
}

.markdown-preview pre {
  padding: 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.markdown-preview pre code {
  padding: 0;
  background: transparent;
  color: var(--ink);
}

.markdown-preview a {
  color: var(--accent);
}

.markdown-preview .note-link {
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  cursor: pointer;
}

.markdown-preview .note-link:hover {
  color: var(--accent-strong);
  border-bottom-style: solid;
}

.backlinks {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.backlinks h3 {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
}

.backlinks-list {
  display: grid;
  gap: 6px;
}

.backlink-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--ink);
  text-align: left;
}

.backlink-item:hover {
  border-color: var(--line-strong);
}

.backlink-item strong {
  display: block;
  font-size: 13px;
}

.backlink-item small {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backlinks-empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.trash-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 28px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-muted);
}

.trash-actions p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.trash-actions div {
  display: flex;
  gap: 8px;
}

.trash-actions button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.trash-actions .danger-text-button {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  background: transparent;
  color: var(--danger);
}

.toast-region {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--ink);
  box-shadow: var(--shadow);
  color: var(--surface);
  font-size: 12px;
  animation: toast-in 160ms ease-out;
}

.account-dialog {
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  padding: 22px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.account-dialog::backdrop {
  background: rgba(17, 21, 18, 0.52);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tag-dialog {
  width: min(480px, calc(100vw - 28px));
}

.tag-add-form {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  margin-bottom: 18px;
}

.tag-dialog .tag-add-form input {
  margin: 0;
}

.tag-add-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 20px;
}

.tag-directory-list {
  display: grid;
  gap: 7px;
  max-height: min(420px, 52vh);
  overflow-y: auto;
}

.tag-directory-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 34px;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 4px 5px 4px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--canvas);
}

.tag-directory-row input {
  height: 36px;
  min-width: 0;
  margin: 0;
  padding: 0 7px;
  border-color: transparent;
  background: transparent;
  font-weight: 600;
}

.tag-directory-row input:hover,
.tag-directory-row input:focus {
  border-color: var(--line-strong);
  background: var(--surface);
}

.tag-directory-row small {
  color: var(--ink-soft);
  font-size: 11px;
  white-space: nowrap;
}

.tag-directory-delete {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 17px;
}

.tag-directory-delete:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}

.tag-directory-empty {
  margin: 24px 0 6px;
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 21px;
}

.dialog-copy {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.65;
}

.invite-notice {
  margin: 0 0 14px;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  line-height: 1.5;
}

.account-dialog form {
  display: grid;
}

.field-label {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.account-dialog input {
  width: 100%;
  height: 40px;
  margin-bottom: 15px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--canvas);
  color: var(--ink);
}

.field-help {
  margin: -5px 0 17px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.5;
}

.dialog-primary,
.dialog-secondary,
.text-button {
  min-height: 40px;
  border-radius: 6px;
  font-weight: 650;
}

.dialog-primary {
  padding: 0 15px;
  background: var(--accent);
  color: #ffffff;
}

.dialog-primary:hover {
  background: var(--accent-strong);
}

.dialog-primary:disabled,
.dialog-secondary:disabled {
  cursor: wait;
  opacity: 0.58;
}

.dialog-secondary {
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.dialog-secondary:hover {
  background: var(--surface-muted);
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 8px;
  margin-top: 2px;
}

.text-button {
  margin-top: 12px;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  font-weight: 550;
}

.resend-button {
  margin-right: 18px;
}

.dialog-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line));
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  color: var(--danger);
  font-size: 11px;
  line-height: 1.5;
}

.signed-in-account {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--canvas);
}

.account-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 750;
  text-transform: uppercase;
}

.signed-in-account strong,
.signed-in-account span {
  display: block;
}

.signed-in-account strong {
  max-width: 300px;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signed-in-account span {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 11px;
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (max-width: 960px) {
  :root {
    --notes-width: 320px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86vw);
    transform: translateX(-101%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-close,
  .menu-button {
    display: inline-grid;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 10px;
    cursor: pointer;
  }

  .sidebar-close {
    margin-left: auto;
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 15;
    inset: 0;
    background: rgba(17, 21, 18, 0.38);
  }

  .topbar {
    gap: 10px;
    padding: 0 14px;
  }

  .search-box {
    flex: 1;
  }

  .search-box kbd {
    display: none;
  }

  .quick-new-button {
    display: flex;
  }

  .editor-controls {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .format-toolbar {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .ai-toolbar,
  .mode-switch {
    flex-shrink: 0;
  }

  .mode-switch button {
    white-space: nowrap;
  }
}

@media (max-width: 720px) {
  .app-shell {
    min-height: 480px;
  }

  .topbar {
    min-height: 58px;
  }

  .quick-new-button {
    min-width: 40px;
    width: 40px;
    padding: 0;
  }

  .quick-new-button span:last-child {
    display: none;
  }

  .knowledge-layout {
    display: block;
  }

  .notes-pane {
    height: calc(100vh - 58px);
    padding-top: 20px;
    border-right: 0;
  }

  .editor-pane {
    position: fixed;
    z-index: 10;
    inset: 58px 0 0;
    display: none;
  }

  .editor-pane.is-open {
    display: block;
  }

  .editor {
    padding: 12px 20px 32px;
  }

  .back-button {
    display: inline-grid;
    margin-right: 8px;
  }

  .title-input {
    margin-top: 22px;
    font-size: 27px;
  }

  .note-meta-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .tag-input-wrap {
    width: 100%;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .tag-input-wrap input {
    width: 100%;
  }

  .editor-controls {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 6px;
  }

  .format-toolbar {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
  }

  .ai-toolbar {
    flex-shrink: 0;
  }

  #contentInput,
  .markdown-preview {
    min-height: 320px;
  }

  .trash-actions {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .notes-heading h1 {
    font-size: 21px;
  }

  .notes-heading select {
    width: 88px;
  }

  .editor {
    padding-right: 16px;
    padding-left: 16px;
  }

  .title-input {
    font-size: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
