:root {
  color-scheme: light;
  --page-bg: #f6f8fb;
  --ink: #0f172a;
  --ink-soft: #475467;
  --ink-faint: #667085;
  --accent: #0071e3;
  --accent-strong: #0058b0;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(0, 113, 227, 0.32);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-soft: rgba(255, 255, 255, 0.78);
  --surface-muted: rgba(248, 250, 252, 0.92);
  --danger: #dc2626;
  --danger-soft: #fff1f2;
  --shadow-panel: 0 28px 80px rgba(15, 23, 42, 0.14);
  --shadow-soft: 0 12px 32px rgba(15, 23, 42, 0.1);
  --shadow-hover: 0 16px 36px rgba(15, 23, 42, 0.13);
  --radius-panel: 28px;
  --radius-card: 22px;
  --radius-control: 15px;
  --sans: "SF Pro Display", "SF Pro Text", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --serif: "Noto Serif SC", "Songti SC", Georgia, serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(145deg, #fbfdff 0%, #eef3f8 48%, #f8fafc 100%);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.14;
  background-image: radial-gradient(rgba(148, 163, 184, 0.22) 0.5px, transparent 0.5px);
  background-size: 4px 4px;
}

.notes-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

.app-shell,
.dialog,
.select-menu,
.toast {
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: linear-gradient(165deg, var(--surface), var(--surface-soft));
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(22px) saturate(145%);
  -webkit-backdrop-filter: blur(22px) saturate(145%);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  color: #0b1220;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.06;
  font-weight: 760;
}

h2 {
  margin-bottom: 5px;
  font-size: 21px;
  line-height: 1.22;
  font-weight: 740;
}

h3 {
  margin-bottom: 0;
  font-size: 21px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-width: 0;
  border-radius: 0;
  box-shadow: none;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 54px minmax(0, 1fr);
}

.sidebar {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(248, 250, 252, 0.62);
}

.app-shell.sidebar-collapsed .sidebar {
  overflow: visible;
}

.sidebar-head,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.sidebar-head {
  padding: 12px 12px 10px;
}

.sidebar-head h1 {
  margin: 0;
  font-size: 20px;
}

.sidebar-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle-svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 0.18s ease;
}

.app-shell.sidebar-collapsed .sidebar-head {
  display: block;
  min-height: 52px;
  padding: 0;
}

.app-shell.sidebar-collapsed .sidebar-head-actions {
  display: block;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  position: absolute;
  left: 9px;
  top: 10px;
  z-index: 60;
  background: linear-gradient(135deg, var(--accent), #3e9aff);
  color: #fff;
  box-shadow: 0 12px 22px rgba(0, 113, 227, 0.28);
}

.app-shell.sidebar-collapsed .sidebar-toggle:hover {
  box-shadow: 0 16px 28px rgba(0, 113, 227, 0.34);
}

.app-shell.sidebar-collapsed .sidebar-toggle-svg {
  transform: rotate(180deg);
}

.app-shell.sidebar-collapsed .sidebar-title,
.app-shell.sidebar-collapsed .sidebar-actions,
.app-shell.sidebar-collapsed .search-box,
.app-shell.sidebar-collapsed .tree,
.app-shell.sidebar-collapsed #refreshButton {
  display: none;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 10px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.tree-action,
.select-trigger,
.segmented button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease, opacity 0.18s ease;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.danger-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.select-trigger:hover,
.segmented button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #3e9aff);
  color: #fff;
  box-shadow: 0 14px 28px rgba(0, 113, 227, 0.28);
}

.primary-button:hover:not(:disabled) {
  box-shadow: 0 18px 30px rgba(0, 113, 227, 0.34);
}

.secondary-button,
.icon-button,
.select-trigger {
  border-color: rgba(15, 23, 42, 0.12);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.secondary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.select-trigger:hover {
  border-color: var(--line-strong);
  background: #fff;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.1);
}

.danger-button {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 12px 24px rgba(220, 38, 38, 0.27);
}

.danger-button:hover:not(:disabled) {
  box-shadow: 0 16px 30px rgba(220, 38, 38, 0.32);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
  transform: none;
  box-shadow: none;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 12px 10px;
  padding: 0 13px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: var(--radius-control);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink-faint);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.search-box:focus-within {
  border-color: rgba(0, 113, 227, 0.62);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.13);
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.tree {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0 10px 12px;
}

.folder {
  margin-bottom: 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.folder-row,
.file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  border-radius: 16px;
  color: var(--ink);
}

.folder-row {
  min-height: 44px;
  padding: 6px 7px 6px 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(239, 246, 255, 0.72));
}

.file-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
  max-width: calc(100% - 12px);
  margin: 4px 6px;
  padding: 5px 7px 5px 20px;
  background: transparent;
  text-align: left;
}

.folder-row:hover,
.file-row:hover,
.file-row.active {
  background: rgba(0, 113, 227, 0.09);
}

.file-row.active {
  box-shadow: inset 0 0 0 1px rgba(0, 113, 227, 0.18);
}

.folder-toggle {
  position: relative;
  display: inline-flex;
  width: 26px;
  min-width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  color: #64748b;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.folder-toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 0.18s ease;
}

.folder-toggle:hover {
  border-color: rgba(0, 113, 227, 0.28);
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.folder-name,
.file-name {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-name {
  font-weight: 850;
}

.folder-label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.folder-icon {
  position: relative;
  width: 22px;
  height: 17px;
  flex: 0 0 22px;
  border-radius: 5px;
  background: linear-gradient(135deg, #62a8ff, #2f8cff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42), 0 6px 14px rgba(0, 113, 227, 0.18);
}

.folder-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -4px;
  width: 10px;
  height: 6px;
  border-radius: 4px 4px 0 0;
  background: #8bc1ff;
}

.folder-count {
  color: var(--ink-faint);
  font-size: 12px;
}

.file-date {
  justify-self: end;
  min-width: 0;
  max-width: 48px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  color: #748094;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  opacity: 0.68;
  padding: 5px 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row:hover .file-date,
.file-row.active .file-date {
  border-color: rgba(0, 113, 227, 0.18);
  background: rgba(255, 255, 255, 0.9);
  color: #4b5c73;
  opacity: 1;
}

.folder-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 120px;
  overflow: hidden;
}

.folder-files {
  display: grid;
  gap: 1px;
  padding: 2px 0 6px;
}

.folder.collapsed .folder-files {
  display: none;
}

.folder.collapsed .folder-toggle {
  transform: none;
}

.folder.collapsed .folder-toggle::before {
  transform: rotate(-45deg) translate(-1px, 1px);
}

.tree-action {
  width: 26px;
  min-width: 26px;
  height: 26px;
  min-height: 26px;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-faint);
  box-shadow: none;
}

.tree-action:hover {
  background: rgba(0, 113, 227, 0.1);
  color: var(--accent-strong);
}

.file-icon {
  display: inline-grid;
  width: 28px;
  height: 21px;
  place-items: center;
  border: 1px solid rgba(0, 113, 227, 0.18);
  border-radius: 8px;
  background: #e7f2ff;
  color: #0b63c2;
  font-size: 10px;
  font-weight: 900;
}

.workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.44);
}

.topbar {
  position: relative;
  z-index: 20;
  min-height: 48px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  backdrop-filter: blur(20px) saturate(145%);
  -webkit-backdrop-filter: blur(20px) saturate(145%);
}

.document-meta {
  min-width: 0;
}

.document-meta h2 {
  overflow: hidden;
  max-width: 46vw;
  margin: 0;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#saveState {
  color: var(--ink-faint);
  font-size: 11px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.toolbar .danger-button,
.toolbar .select-trigger {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(58px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.64);
}

.segmented button {
  min-height: 30px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink-faint);
  box-shadow: none;
}

.segmented button.active {
  background: #fff;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.1);
  color: var(--accent-strong);
}

.custom-select {
  position: relative;
}

.select-trigger {
  min-width: 142px;
  min-height: 34px;
  padding: 0 14px;
  justify-content: space-between;
}

.compact-select .select-trigger {
  min-width: 112px;
  min-height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.formatbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 252, 0.68);
  overflow-x: auto;
}

.formatbar .custom-select {
  flex: 0 0 auto;
}

.formatbar button {
  display: inline-flex;
  min-width: 34px;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #1f2937;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.formatbar button:hover {
  border-color: rgba(0, 113, 227, 0.3);
  background: #fff;
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.formatbar .toggle-button.active {
  border-color: rgba(0, 113, 227, 0.38);
  background: linear-gradient(135deg, var(--accent), #3e9aff);
  color: #fff;
  box-shadow: 0 10px 20px rgba(0, 113, 227, 0.22);
}

.format-spacer {
  flex: 1 1 auto;
  min-width: 8px;
}

#zoomValue {
  min-width: 44px;
  color: var(--ink-soft);
  font-size: 12px;
  text-align: center;
}

.select-caret {
  position: relative;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 50%;
  background: rgba(248, 250, 252, 0.86);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.compact-select .select-caret {
  width: 18px;
  height: 18px;
  flex-basis: 18px;
}

.select-caret::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 45%;
  width: 7px;
  height: 7px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: translate(-50%, -50%) rotate(45deg);
}

.compact-select .select-caret::before {
  width: 5px;
  height: 5px;
}

.select-trigger:hover .select-caret,
.select-trigger[aria-expanded="true"] .select-caret {
  border-color: rgba(0, 113, 227, 0.28);
  background: #fff;
}

.select-trigger[aria-expanded="true"] .select-caret {
  transform: rotate(180deg);
}

.select-menu {
  position: fixed;
  z-index: 1000;
  display: grid;
  min-width: 178px;
  max-height: min(320px, calc(100vh - 24px));
  overflow: auto;
  padding: 6px;
  border-color: rgba(15, 23, 42, 0.12);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.17);
}

.select-menu[hidden] {
  display: none;
}

.select-menu button {
  min-height: 36px;
  border-radius: 11px;
  background: transparent;
  color: #1f2937;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.select-menu button:hover,
.select-menu button[aria-selected="true"] {
  background: rgba(0, 113, 227, 0.11);
  color: var(--accent-strong);
}

.select-menu button[aria-selected="true"] {
  font-weight: 800;
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.editor-pane,
.preview-pane,
.preview-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.preview-wrap {
  position: relative;
  display: grid;
}

.editor-pane {
  border-right: 1px solid var(--line);
  background: #0f172a;
}

#sourceEditor {
  width: 100%;
  min-height: 100%;
  padding: 18px 22px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #e5edf7;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  tab-size: 2;
}

#sourceEditor::placeholder {
  color: rgba(226, 232, 240, 0.58);
}

.preview-pane {
  padding: 22px min(4vw, 44px);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

body[data-page="a4"] .preview-pane {
  background: #e9edf3;
}

body[data-page="a4"] .preview-wrap {
  grid-template-columns: minmax(0, 1fr);
  background: #e9edf3;
  overflow: auto;
}

body[data-page="a4"][data-toc="on"] .preview-wrap {
  grid-template-columns: minmax(0, 1fr) 210px;
}

body[data-page="a4"] .markdown-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, calc(210mm * var(--page-scale, 1)));
  align-content: start;
  justify-content: center;
  gap: 18px;
  width: auto;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 24px;
  border: 0;
  background: #e9edf3;
  box-shadow: none;
}

body[data-page="a4"] .app-shell.sidebar-collapsed .markdown-body {
  max-width: none;
}

body[data-page="a4"][data-view="source"] .markdown-body {
  max-width: none;
}

.a4-page {
  width: calc(210mm * var(--page-scale, 1));
  height: calc(297mm * var(--page-scale, 1));
  min-width: calc(210mm * var(--page-scale, 1));
  max-width: none;
  margin: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  break-after: page;
  page-break-after: always;
}

.a4-page-inner {
  transform: scale(var(--page-scale, 1));
  transform-origin: top left;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  padding: 20mm 18mm;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

.toc-panel {
  position: sticky;
  top: 16px;
  display: none;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 8px;
  border-left: 1px solid #d8dee8;
  background: transparent;
}

.page-zoom-control {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 40;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid #cfd7e3;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

body[data-page="a4"] .page-zoom-control {
  display: flex;
}

body[data-page="a4"][data-toc="on"] .page-zoom-control {
  right: 224px;
}

.page-zoom-control button {
  width: 24px;
  height: 22px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #1f2937;
  cursor: pointer;
  font-weight: 800;
}

.page-zoom-control button:hover {
  background: #eef3f9;
}

.page-zoom-control strong {
  min-width: 42px;
  color: #475467;
  font-size: 12px;
  text-align: center;
}

body[data-page="a4"][data-toc="on"] .toc-panel {
  display: grid;
  gap: 2px;
  align-self: start;
}

.toc-panel strong {
  padding: 4px 8px 6px;
  color: #334155;
  font-size: 12px;
}

.toc-item {
  display: block;
  width: 100%;
  min-height: 24px;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #475467;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-item:hover {
  background: #eef3f9;
  color: #0b63c2;
}

.toc-h2 { padding-left: 16px; }
.toc-h3 { padding-left: 28px; }
.toc-h4 { padding-left: 40px; }
.toc-h5 { padding-left: 52px; }
.toc-h6 { padding-left: 64px; }
.toc-h7 { padding-left: 76px; }

body[data-page="a4"] .app-shell.sidebar-collapsed .a4-page {
  max-width: calc(100vw - 124px);
}

.preview-pane[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 3px rgba(0, 113, 227, 0.16);
}

body[data-view="preview"] .editor-shell {
  grid-template-columns: 1fr;
}

body[data-view="preview"] .editor-pane,
body[data-view="source"] .preview-wrap {
  display: none;
}

body[data-view="source"] .editor-shell {
  grid-template-columns: 1fr;
}

body[data-view="source"] .editor-pane {
  border-right: 0;
}

.empty-state {
  display: grid;
  min-height: 240px;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--ink-faint);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 20px;
}

.markdown-body {
  color: #111827;
  font-family: var(--font-zh, var(--serif));
  font-size: calc(15px * var(--doc-scale, 1));
  line-height: 1.56;
}

.latin-font {
  font-family: var(--font-en, inherit);
}

.greek-font {
  font-family: var(--font-greek, inherit);
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6,
.markdown-body h7 {
  display: block;
  margin: 1.35em 0 0.55em;
  color: #0b1220;
  font-family: var(--sans);
  line-height: 1.25;
}

.heading-number {
  display: inline-block;
  margin-right: 0.18em;
  color: inherit;
  user-select: none;
}

.markdown-body h1 {
  padding-bottom: 0.28em;
  border-bottom: 1px solid rgba(15, 23, 42, 0.1);
  font-size: calc(28px * var(--doc-scale, 1));
}

.markdown-body h2 {
  font-size: calc(23px * var(--doc-scale, 1));
}

.markdown-body h3 {
  font-size: calc(19px * var(--doc-scale, 1));
}

.markdown-body h4 {
  font-size: calc(17px * var(--doc-scale, 1));
}

.markdown-body h5 {
  font-size: calc(15px * var(--doc-scale, 1));
}

.markdown-body h6,
.markdown-body h7 {
  font-size: calc(14px * var(--doc-scale, 1));
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body table,
.markdown-body pre {
  margin-bottom: 1em;
}

.markdown-body a {
  color: var(--accent-strong);
  text-underline-offset: 3px;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 13px 16px;
  border-left: 4px solid var(--accent);
  border-radius: 0 14px 14px 0;
  background: rgba(231, 242, 255, 0.72);
  color: #334155;
}

.markdown-body code {
  border-radius: 7px;
  background: rgba(0, 113, 227, 0.1);
  color: #0b63c2;
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 0.14em 0.35em;
}

.markdown-body pre {
  overflow: auto;
  padding: 16px;
  border-radius: 16px;
  background: #0f172a;
  color: #e5edf7;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.markdown-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.markdown-body table {
  display: table;
  width: auto;
  max-width: 100%;
  overflow: visible;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #d9e2ef;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.markdown-body th,
.markdown-body td {
  min-width: 78px;
  padding: 10px 16px;
  border-right: 1px solid #e3e9f2;
  border-bottom: 1px solid #e3e9f2;
  text-align: left;
  vertical-align: top;
}

.markdown-body tr > *:last-child {
  border-right: 0;
}

.markdown-body tr:last-child > * {
  border-bottom: 0;
}

.markdown-body th {
  background: linear-gradient(180deg, #f7fbff, #eef5ff);
  color: #334155;
  font-family: var(--sans);
  font-weight: 800;
}

.markdown-body tbody tr:nth-child(even) td {
  background: #fbfdff;
}

.markdown-body tbody tr:hover td {
  background: #f1f7ff;
}

.markdown-body thead tr:first-child th:first-child {
  border-top-left-radius: 12px;
}

.markdown-body thead tr:first-child th:last-child {
  border-top-right-radius: 12px;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 16px;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

.math-source {
  white-space: pre-wrap;
}

.katex {
  font-size: 1.02em;
}

.katex .katex-mathml {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  border: 0;
  padding: 0;
}

.katex .katex-html {
  display: inline-block;
}

.katex-display > .katex {
  display: block;
  text-align: center;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 40px));
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--ink);
  font-size: 14px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.17);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.error {
  border-color: rgba(220, 38, 38, 0.26);
  background: linear-gradient(165deg, #fff, var(--danger-soft));
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.dialog {
  display: grid;
  gap: 16px;
  width: min(430px, 100%);
  padding: 22px;
  border-radius: 24px;
}

.dialog h3 {
  margin: 0;
  font-size: 22px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: var(--radius-control);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  outline: 0;
  padding: 0 13px;
  font-weight: 600;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.field input:focus {
  border-color: rgba(0, 113, 227, 0.62);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.13);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

#dropdownLayer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

#dropdownLayer .select-menu {
  pointer-events: auto;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.42);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: rgba(248, 250, 252, 0.72);
}

body[data-page="a4"] .preview-pane {
  background: #e9edf3;
}

body[data-page="a4"] .a4-page,
body[data-page="a4"] .a4-page h1,
body[data-page="a4"] .a4-page h2,
body[data-page="a4"] .a4-page h3,
body[data-page="a4"] .a4-page h4,
body[data-page="a4"] .a4-page h5,
body[data-page="a4"] .a4-page h6,
body[data-page="a4"] .a4-page h7 {
  color: #111827;
}

@media (max-width: 1100px) {
  .notes-shell {
    width: 100%;
    padding: 0;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .notes-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .app-shell {
    grid-template-columns: 1fr;
    min-height: 760px;
  }

  .sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .document-meta h2 {
    max-width: 100%;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

@media (max-width: 700px) {
  .notes-shell {
    width: 100%;
    gap: 0;
    padding: 0;
  }

  .app-shell {
    border-radius: 0;
  }

  .sidebar-actions,
  .editor-shell {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .segmented,
  .custom-select {
    grid-column: 1 / -1;
  }

  .select-trigger {
    width: 100%;
  }

  body[data-view="split"] .editor-shell {
    grid-template-columns: 1fr;
  }

  body[data-view="split"] .editor-pane {
    min-height: 44vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-pane {
    padding: 24px 18px;
  }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    overflow: visible !important;
    background: #fff !important;
  }

  .bg-noise,
  .sidebar,
  .topbar,
  .formatbar,
  .toc-panel,
  .page-zoom-control,
  .editor-pane,
  .toast-region,
  .modal-backdrop,
  #dropdownLayer {
    display: none !important;
  }

  .notes-shell,
  .app-shell,
  .workspace,
  .editor-shell {
    display: block !important;
    width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  .preview-pane,
  .markdown-body {
    display: block !important;
    width: 210mm !important;
    max-width: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  .a4-page {
    width: 210mm !important;
    height: 297mm !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    border: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
    break-after: page;
    page-break-after: always;
  }

  .a4-page-inner {
    transform: none !important;
    width: 210mm !important;
    height: 297mm !important;
    padding: 20mm 18mm !important;
    border: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  .a4-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}

/* Word-like flat command surface */
.topbar {
  min-height: 38px;
  padding: 4px 8px;
  background: #fff;
  border-bottom: 1px solid #d8dee8;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.document-meta {
  display: flex;
  min-width: 120px;
  align-items: center;
}

.document-meta .eyebrow,
#saveState {
  display: none;
}

.document-meta h2 {
  max-width: 220px;
  font-size: 14px;
  font-weight: 800;
  color: #111827;
}

.toolbar,
.formatbar {
  gap: 2px;
}

.formatbar {
  min-height: 32px;
  padding: 2px 6px;
  background: #f7f9fc;
  border-bottom: 1px solid #d8dee8;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.tree-action,
.select-trigger,
.segmented button,
.formatbar button {
  min-height: 26px;
  border-radius: 4px;
  box-shadow: none;
  transform: none;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.danger-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.select-trigger:hover,
.segmented button:hover,
.formatbar button:hover {
  transform: none;
  box-shadow: none;
}

.primary-button,
.toolbar .primary-button {
  border-color: #b9d7ff;
  background: #e7f1ff;
  color: #0b63c2;
}

.secondary-button,
.icon-button,
.select-trigger,
.formatbar button {
  border-color: transparent;
  background: transparent;
  color: #1f2937;
}

.secondary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.select-trigger:hover,
.formatbar button:hover {
  border-color: #cfd7e3;
  background: #eef3f9;
}

.danger-button,
.toolbar .danger-button {
  border-color: transparent;
  background: transparent;
  color: #dc2626;
}

.danger-button:hover:not(:disabled) {
  border-color: #fecaca;
  background: #fff1f2;
  color: #b91c1c;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.toolbar .danger-button,
.toolbar .select-trigger {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.segmented {
  gap: 0;
  padding: 0;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  background: #f1f4f8;
  overflow: hidden;
}

.segmented button {
  min-height: 28px;
  border-radius: 0;
  padding: 0 10px;
}

.segmented button.active {
  background: #fff;
  color: #0b63c2;
  box-shadow: inset 0 -2px 0 #2f8cff;
}

.select-trigger {
  min-width: 118px;
  justify-content: space-between;
}

.compact-select .select-trigger {
  min-width: 94px;
}

.select-caret,
.compact-select .select-caret {
  width: 16px;
  height: 16px;
  flex-basis: 16px;
  border: 0;
  background: transparent;
}

.select-caret::before,
.compact-select .select-caret::before {
  width: 6px;
  height: 6px;
  border-width: 1.7px;
}

.formatbar button {
  min-width: 28px;
  min-height: 26px;
  padding: 0 7px;
  font-size: 12px;
}

.formatbar .toggle-button.active {
  border-color: #b9d7ff;
  background: #e7f1ff;
  color: #0b63c2;
  box-shadow: none;
}

#zoomValue {
  min-width: 38px;
  font-size: 12px;
}

.sidebar {
  background: #f8fafc;
}

.sidebar-head {
  min-height: 38px;
  padding: 6px 8px;
  border-bottom: 1px solid #e5eaf1;
}

.sidebar-head h1 {
  font-size: 15px;
}

.sidebar-actions {
  gap: 4px;
  padding: 6px 8px;
}

.search-box {
  margin: 6px 8px;
  border-radius: 6px;
  box-shadow: none;
}

.search-box input {
  height: 30px;
}

.tree {
  padding: 4px 6px 8px;
}

.folder {
  margin-bottom: 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.folder-row {
  min-height: 32px;
  padding: 3px 4px;
  border-radius: 4px;
  background: transparent;
}

.folder-icon {
  box-shadow: none;
}

.folder-files {
  padding: 0 0 2px;
}

.file-row {
  min-height: 30px;
  margin: 1px 0;
  padding: 3px 4px 3px 22px;
  border-radius: 4px;
}

.file-row.active {
  background: #e7f1ff;
  box-shadow: inset 3px 0 0 #2f8cff;
}

.file-date,
.folder-count {
  display: none;
}

.tree-action {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
}

/* Flatter Word-style ribbon refinement */
.topbar {
  min-height: 32px;
  padding: 2px 8px;
  border-bottom: 0;
  background: #fff;
}

.formatbar {
  min-height: 30px;
  padding: 1px 8px 3px;
  border-top: 1px solid #eef1f5;
  border-bottom: 0;
  background: #f8fafc;
}

.document-meta h2 {
  font-size: 13px;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.toolbar .danger-button,
.toolbar .select-trigger,
.formatbar button,
.segmented button {
  min-height: 24px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.toolbar .danger-button {
  padding: 0 7px;
}

.formatbar button {
  min-width: auto;
  padding: 0 7px;
}

.toolbar .primary-button:hover:not(:disabled),
.toolbar .secondary-button:hover:not(:disabled),
.toolbar .danger-button:hover:not(:disabled),
.formatbar button:hover,
.select-trigger:hover,
.segmented button:hover {
  background: #eef3f9;
  border: 0;
  box-shadow: none;
}

.toolbar .primary-button {
  color: #0b63c2;
  background: transparent;
}

.toolbar .primary-button:hover:not(:disabled) {
  background: #e7f1ff;
}

.toolbar .danger-button {
  color: #dc2626;
}

.toolbar .danger-button:hover:not(:disabled) {
  background: #fff1f2;
}

.segmented {
  gap: 2px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

.segmented button {
  padding: 0 10px;
  color: #475467;
}

.segmented button.active {
  background: #e7f1ff;
  color: #0b63c2;
  box-shadow: none;
}

.formatbar .toggle-button.active {
  border: 0;
  background: #e7f1ff;
  color: #0b63c2;
  box-shadow: none;
}

.select-trigger,
.compact-select .select-trigger {
  min-height: 24px;
  padding: 0 7px;
  border: 0;
}

.select-menu {
  border: 1px solid #d8dee8;
  border-radius: 6px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

.select-menu button {
  border-radius: 4px;
}

.select-caret,
.compact-select .select-caret {
  width: 14px;
  height: 14px;
  flex-basis: 14px;
}

#zoomValue {
  min-width: 34px;
}

.preview-pane {
  border-top: 1px solid #eef1f5;
}

/* Flat sidebar refinement */
.sidebar {
  background: #f8fafc;
  border-right: 1px solid #d8dee8;
}

.sidebar-head {
  min-height: 34px;
  padding: 4px 8px;
  border-bottom: 1px solid #eef1f5;
}

.sidebar-head h1 {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
  color: #111827;
}

.sidebar-head .icon-button {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
}

.sidebar-head .icon-button:hover {
  background: #eef3f9;
}

.sidebar-actions {
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid #eef1f5;
}

.sidebar-actions .primary-button,
.sidebar-actions .secondary-button {
  min-height: 28px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
  color: #1f2937;
  font-size: 13px;
}

.sidebar-actions .primary-button:hover,
.sidebar-actions .secondary-button:hover {
  background: #eef3f9;
}

.sidebar-actions .primary-button {
  color: #0b63c2;
}

.search-box {
  height: 30px;
  margin: 6px 8px;
  padding: 0 8px;
  border: 1px solid #d8dee8;
  border-radius: 3px;
  background: #fff;
  box-shadow: none;
}

.search-box:focus-within {
  border-color: #9cc8ff;
  box-shadow: none;
}

.search-box input {
  height: 28px;
  font-size: 13px;
}

.tree {
  padding: 2px 4px 8px;
}

.folder {
  margin: 0;
  border: 0;
  background: transparent;
}

.folder-row,
.file-row {
  min-height: 28px;
  border-radius: 3px;
}

.folder-row {
  padding: 2px 4px;
  background: transparent;
}

.folder-row:hover,
.file-row:hover {
  background: #eef3f9;
}

.folder-toggle {
  width: 22px;
  min-width: 22px;
  height: 22px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
}

.folder-toggle:hover {
  background: #e5ebf3;
  box-shadow: none;
}

.folder-icon {
  width: 18px;
  height: 14px;
  border-radius: 3px;
  background: #5aa2ff;
  box-shadow: none;
}

.folder-icon::before {
  top: -3px;
  width: 8px;
  height: 5px;
  background: #83bbff;
}

.folder-name,
.file-name {
  font-size: 13px;
  font-weight: 700;
}

.folder-actions {
  gap: 0;
  max-width: 82px;
}

.tree-action {
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  border-radius: 3px;
  font-size: 13px;
}

.tree-action:hover {
  background: #e5ebf3;
}

.folder-files {
  padding: 0 0 2px;
}

.file-row {
  grid-template-columns: auto minmax(0, 1fr);
  max-width: 100%;
  margin: 0;
  padding: 2px 4px 2px 34px;
}

.file-row.active {
  background: #e7f1ff;
  box-shadow: inset 3px 0 0 #2f8cff;
}

.file-icon {
  width: 24px;
  height: 18px;
  border: 1px solid #b9d7ff;
  border-radius: 4px;
  background: #eff6ff;
  color: #0b63c2;
  font-size: 10px;
}

.file-date,
.folder-count {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  left: 13px;
  top: 6px;
  border-radius: 3px;
  background: #e7f1ff;
  color: #0b63c2;
  box-shadow: none;
}

/* Polished flat workspace */
:root {
  --sidebar-width: 340px;
  --ui-bg: #edf1f6;
  --ui-panel: #ffffff;
  --ui-panel-soft: #f8fafc;
  --ui-line: #d6deea;
  --ui-line-soft: #e7ecf3;
  --ui-hover: #edf4ff;
  --ui-active: #dcecff;
  --ui-blue: #1f73d8;
  --ui-blue-strong: #155fb5;
  --ui-text: #111827;
  --ui-muted: #64748b;
  --ui-command: #ffffff;
  --ui-command-hover: #f2f6fb;
  --ui-command-active: #eaf3ff;
}

body {
  background: var(--ui-bg);
}

.bg-noise {
  display: none;
}

.app-shell {
  grid-template-columns: minmax(240px, var(--sidebar-width)) 6px minmax(0, 1fr);
  background: var(--ui-bg);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 54px 0 minmax(0, 1fr);
}

.sidebar-resizer {
  position: relative;
  z-index: 30;
  min-width: 6px;
  cursor: col-resize;
  background: transparent;
  touch-action: none;
}

.sidebar-resizer::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  border-radius: 2px;
  background: #dfe6f0;
  transition: background 0.12s ease;
}

.sidebar-resizer:hover::before,
body.resizing-sidebar .sidebar-resizer::before {
  background: #b8c7da;
}

.app-shell.sidebar-collapsed .sidebar-resizer {
  width: 0;
  min-width: 0;
  overflow: hidden;
  pointer-events: none;
}

body.resizing-sidebar,
body.resizing-sidebar * {
  cursor: col-resize !important;
  user-select: none;
}

body.resizing-sidebar .preview-pane,
body.resizing-sidebar #sourceEditor {
  pointer-events: none;
}

.sidebar {
  border-right: 0;
  background: #f7f9fc;
  box-shadow: inset -1px 0 0 var(--ui-line);
}

.workspace {
  background: var(--ui-panel);
}

.topbar {
  min-height: 38px;
  padding: 4px 10px;
  border-bottom: 0;
  background: var(--ui-command);
  box-shadow: none;
}

.document-meta h2 {
  max-width: min(360px, 34vw);
  color: var(--ui-text);
  font-size: 14px;
  font-weight: 850;
}

.document-meta + #saveState {
  margin-left: 2px;
  margin-right: 8px;
  flex: 0 0 auto;
}

.toolbar {
  gap: 4px;
}

.formatbar {
  min-height: 34px;
  padding: 3px 10px;
  border-top: 0;
  border-bottom: 1px solid var(--ui-line);
  background: var(--ui-command);
  box-shadow: none;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.toolbar .danger-button,
.toolbar .select-trigger,
.formatbar button,
.segmented button,
.select-trigger,
.compact-select .select-trigger {
  min-height: 27px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #253044;
  font-weight: 750;
  box-shadow: none;
}

.toolbar .primary-button {
  border-color: #1769c9;
  background: var(--ui-blue);
  color: #fff;
}

.toolbar .primary-button:hover:not(:disabled) {
  border-color: var(--ui-blue-strong);
  background: var(--ui-blue-strong);
}

.toolbar .danger-button {
  color: #b42318;
}

.toolbar .danger-button:hover:not(:disabled) {
  border-color: #f3c4bf;
  background: #fff1f0;
  color: #9f1f16;
}

.toolbar .secondary-button:hover:not(:disabled),
.toolbar .select-trigger:hover,
.formatbar button:hover,
.select-trigger:hover,
.segmented button:hover {
  border-color: #c7d4e5;
  background: var(--ui-command-hover);
}

.segmented {
  gap: 2px;
  padding: 2px;
  border: 1px solid #ccd6e3;
  border-radius: 6px;
  background: var(--ui-command);
}

.segmented button {
  min-height: 25px;
  padding: 0 10px;
  color: var(--ui-muted);
}

.segmented button.active {
  border-color: #b7d3f6;
  background: #fff;
  color: var(--ui-blue-strong);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.formatbar .toggle-button.active {
  border-color: #aecaee;
  background: var(--ui-command-active);
  color: var(--ui-blue-strong);
}

.select-menu {
  padding: 5px;
  border: 1px solid #cfd8e6;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
}

.select-menu button {
  min-height: 28px;
  border-radius: 5px;
  color: #253044;
  font-weight: 650;
}

.select-menu button:hover,
.select-menu button[aria-selected="true"] {
  background: var(--ui-hover);
  color: var(--ui-blue-strong);
}

.sidebar-head {
  min-height: 42px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--ui-line-soft);
  background: #fbfcfe;
}

.sidebar-head h1 {
  font-size: 20px;
  font-weight: 900;
  color: #0f172a;
}

.sidebar-head .icon-button {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 5px;
  color: #334155;
}

.sidebar-head .icon-button:hover {
  background: var(--ui-hover);
  color: var(--ui-blue-strong);
}

.sidebar-actions {
  gap: 5px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--ui-line-soft);
  background: #f7f9fc;
}

.sidebar-actions .primary-button,
.sidebar-actions .secondary-button {
  min-height: 30px;
  border: 1px solid #d6deea;
  border-radius: 6px;
  background: #fff;
  color: #253044;
  font-weight: 800;
}

.sidebar-actions .primary-button {
  border-color: #bad4f6;
  color: var(--ui-blue-strong);
}

.sidebar-actions .primary-button:hover,
.sidebar-actions .secondary-button:hover {
  border-color: #adc3dc;
  background: var(--ui-hover);
}

.search-box {
  height: 32px;
  margin: 8px 9px;
  padding: 0 9px;
  border: 1px solid #d3dce8;
  border-radius: 7px;
  background: #fff;
}

.search-box:focus-within {
  border-color: #8fbdf2;
  box-shadow: 0 0 0 2px rgba(31, 115, 216, 0.12);
}

.tree {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 2px 7px 10px;
}

.sidebar-foot {
  display: grid;
  gap: 5px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--ui-line-soft);
  background: #fbfcfe;
}

.storage-line {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #334155;
  font-size: 12px;
}

.storage-line span,
.storage-line strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.storage-line strong {
  color: var(--ui-blue-strong);
  font-weight: 850;
}

.storage-hint {
  overflow: hidden;
  color: #64748b;
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-storage="local"] .storage-line strong {
  color: #9a6700;
}

body[data-storage="local"] .storage-hint {
  color: #9a6700;
}

.app-shell.sidebar-collapsed .sidebar-foot {
  display: none;
}

.folder {
  margin: 2px 0;
}

.folder-row,
.file-row {
  min-height: 30px;
  border-radius: 6px;
}

.folder-row {
  padding: 3px 5px;
}

.folder-row:hover,
.file-row:hover {
  background: #edf3fb;
}

.folder-toggle {
  border-radius: 5px;
  color: #667085;
}

.folder-toggle:hover {
  background: #e4ebf5;
  color: var(--ui-blue-strong);
}

.folder-icon {
  width: 20px;
  height: 15px;
  border-radius: 4px;
  background: #4f94dd;
}

.folder-icon::before {
  background: #78afe8;
}

.folder-name,
.file-name {
  color: #253044;
  font-size: 13px;
  font-weight: 760;
}

.folder-actions {
  max-width: 88px;
}

.tree-action {
  width: 23px;
  min-width: 23px;
  height: 23px;
  min-height: 23px;
  border-radius: 5px;
  color: #64748b;
}

.tree-action:hover {
  background: #e4ebf5;
  color: #1f2937;
}

.file-row {
  margin: 1px 0;
  padding: 3px 5px 3px 34px;
}

.file-row.active {
  background: var(--ui-active);
  box-shadow: inset 3px 0 0 var(--ui-blue);
}

.file-row.active .file-name {
  color: #0f4f99;
}

.file-icon {
  border-color: #b8d3f5;
  background: #f5f9ff;
  color: var(--ui-blue-strong);
}

.preview-pane {
  border-top: 0;
  background: #fff;
}

body[data-page="fluid"] .preview-pane {
  padding: 24px clamp(24px, 5vw, 64px);
}

.markdown-body {
  color: #111827;
  line-height: 1.52;
}

.markdown-body h1 {
  border-bottom-color: #dbe3ef;
}

.markdown-body blockquote {
  border-left-color: var(--ui-blue);
  border-radius: 0 8px 8px 0;
  background: #f2f7ff;
}

.markdown-body pre {
  border-radius: 8px;
}

.markdown-body table {
  border-color: #d8e2ef;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.07);
}

.page-zoom-control {
  border-color: #c7d4e5;
  border-radius: 6px;
}

@media (max-width: 980px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar-resizer {
    display: none;
  }
}

/* Public share reader */
body.share-reader {
  min-height: 100vh;
  overflow: auto;
  background: #e9edf3;
}

.share-shell {
  display: grid;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
  place-items: start center;
}

.share-reader-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  width: min(210mm, calc(100vw - 36px));
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 10px;
  border: 1px solid #cfd8e6;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}

.share-reader-bar strong,
.share-reader-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-reader-bar strong {
  color: #111827;
  font-size: 14px;
}

.share-reader-bar span {
  color: #64748b;
  font-size: 12px;
}

body.share-reader[data-page="a4"] .share-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, 210mm);
  align-content: start;
  gap: 18px;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

body.share-reader[data-page="a4"] .share-pages .a4-page {
  width: 210mm;
  height: 297mm;
  min-width: 210mm;
  max-width: none;
  padding: 0;
  background: transparent;
}

body.share-reader[data-page="a4"] .share-pages .a4-page-inner {
  transform: none;
  width: 210mm;
  height: 297mm;
  padding: 20mm 18mm;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

/* Current compact command polish */
#saveState {
  display: inline-flex !important;
  min-height: 24px;
  max-width: 190px;
  align-items: center;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #64748b;
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  flex-wrap: wrap;
}

.formatbar {
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
}

.formatbar::-webkit-scrollbar {
  height: 6px;
}

.format-spacer {
  flex: 1 1 auto;
  min-width: 8px;
}

.markdown-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.markdown-body img.selected-image {
  outline: 2px solid #1f73d8;
  outline-offset: 3px;
}

.image-size-value {
  display: inline-flex;
  min-width: 64px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.markdown-body table {
  width: 100%;
}

.markdown-body th {
  background: #f3f7fc;
}

.markdown-body tbody tr:hover td {
  background: #f6faff;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  display: inline-flex;
}

/* Unified Word-like ribbon color */
.topbar,
.formatbar {
  background: var(--ui-command) !important;
  box-shadow: none !important;
}

.topbar {
  border-bottom: 0 !important;
}

.formatbar {
  border-bottom: 1px solid #edf1f6 !important;
}

.toolbar .secondary-button,
.toolbar .danger-button,
.toolbar .select-trigger,
.formatbar button,
.segmented,
#saveState {
  background-color: transparent;
}

.segmented {
  border-color: #e2e8f0 !important;
  background: #f8fafc !important;
}

.toolbar .secondary-button:hover:not(:disabled),
.toolbar .danger-button:hover:not(:disabled),
.toolbar .select-trigger:hover,
.formatbar button:hover,
.segmented button:hover {
  background: var(--ui-command-hover) !important;
}

.segmented button.active,
.formatbar .toggle-button.active {
  background: var(--ui-command-active) !important;
}

#saveState {
  border-color: transparent;
  background: transparent !important;
}

.ribbon-tabs {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-left: auto;
  overflow-x: auto;
}

.ribbon-tabs button {
  min-height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.ribbon-tabs button:hover {
  background: var(--ui-command-hover);
  color: #1f2937;
}

.ribbon-tabs button.active {
  background: var(--ui-command-active);
  color: var(--ui-blue-strong);
}

.ribbon-panel {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: visible;
}

.ribbon-panel[hidden] {
  display: none !important;
}

.ribbon-panel .primary-button {
  border-color: var(--ui-blue) !important;
  background: var(--ui-blue) !important;
  color: #fff !important;
}

.ribbon-panel .primary-button:hover:not(:disabled) {
  border-color: var(--ui-blue-strong) !important;
  background: var(--ui-blue-strong) !important;
}

.ribbon-panel .danger-button {
  color: #b42318 !important;
}

.ribbon-panel .danger-button:hover:not(:disabled) {
  background: #fff1f0 !important;
  color: #9f1f16 !important;
}

/* Harmonized left navigation */
.sidebar {
  background: #fff !important;
  box-shadow: inset -1px 0 0 #edf1f6 !important;
}

.sidebar-head,
.sidebar-actions,
.sidebar-foot {
  background: #fff !important;
  border-color: #edf1f6 !important;
}

.sidebar-head {
  min-height: 40px;
  padding: 6px 10px;
}

.sidebar-head h1 {
  color: #111827;
  font-size: 20px;
  font-weight: 900;
}

.sidebar-head .icon-button,
.sidebar-actions .primary-button,
.sidebar-actions .secondary-button,
.tree-action,
.folder-toggle {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
}

.sidebar-head .icon-button:hover,
.sidebar-actions .primary-button:hover,
.sidebar-actions .secondary-button:hover,
.tree-action:hover,
.folder-toggle:hover,
.folder-row:hover,
.file-row:hover {
  background: #f2f6fb !important;
}

.sidebar-actions {
  gap: 3px;
  padding: 5px 8px;
}

.sidebar-actions .primary-button,
.sidebar-actions .secondary-button {
  min-height: 28px;
  color: #334155 !important;
  font-size: 13px;
  font-weight: 800;
}

.sidebar-actions .primary-button {
  color: #155fb5 !important;
}

.search-box {
  height: 30px;
  margin: 7px 8px;
  border-color: #e2e8f0 !important;
  border-radius: 6px;
  background: #f8fafc !important;
}

.search-box:focus-within {
  border-color: #b7d3f6 !important;
  background: #fff !important;
  box-shadow: 0 0 0 2px rgba(31, 115, 216, 0.08) !important;
}

.tree {
  padding: 2px 6px 10px;
}

.folder {
  margin: 1px 0;
}

.folder-row,
.file-row {
  min-height: 29px;
  border-radius: 5px;
}

.folder-row {
  padding: 2px 4px;
}

.folder-icon {
  width: 19px;
  height: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #eef2f7 !important;
  box-shadow: none !important;
}

.folder-icon::before {
  top: -4px;
  left: 2px;
  width: 8px;
  height: 5px;
  border: 1px solid #cbd5e1;
  border-bottom: 0;
  background: #f8fafc !important;
}

.folder-name,
.file-name {
  color: #263244;
  font-weight: 760;
}

.file-row {
  padding-left: 32px;
}

.file-row.active {
  background: #eef6ff !important;
  box-shadow: inset 2px 0 0 var(--ui-blue) !important;
}

.file-icon {
  border-color: #d8e2ef !important;
  background: #fff !important;
  color: #64748b !important;
}

.storage-line strong,
body[data-storage="local"] .storage-line strong {
  color: #155fb5 !important;
}

.storage-hint,
body[data-storage="local"] .storage-hint {
  color: #64748b !important;
}

.sidebar-resizer::before {
  background: #edf1f6 !important;
}

.sidebar-resizer:hover::before,
body.resizing-sidebar .sidebar-resizer::before {
  background: #cbd5e1 !important;
}

@media print {
  body.share-reader {
    width: 210mm;
    background: #fff !important;
  }

  .share-shell {
    display: block;
    padding: 0;
  }

  .share-reader-bar {
    display: none;
  }

  .share-pages {
    width: 210mm !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
  }
}
