:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #fbfcfd;
  --surface-muted: #f1f3f5;
  --line: #e6e9ee;
  --line-strong: #d7dde6;
  --text: #1f2937;
  --text-soft: #4b5563;
  --text-muted: #8a94a6;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-strong: #1d4ed8;
  --danger: #c2410c;
  --danger-soft: #fff7ed;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #f4f6f8 100%);
  color: var(--text);
  font: 13px/1.55 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 260px minmax(280px, 560px) 1fr;
  align-items: center;
  gap: 18px;
  height: 64px;
  padding: 0 max(24px, calc((100vw - 1380px) / 2));
  border-bottom: 1px solid rgba(230, 233, 238, 0.95);
  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.brand-copy h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.brand-copy p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.search-field input {
  height: 40px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
}

.top-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  justify-content: flex-end;
}

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 600;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button:disabled {
  cursor: default;
  opacity: 0.45;
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-secondary {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: #dbeafe;
}

.button-ghost {
  background: rgba(255, 255, 255, 0.82);
  border-color: var(--line);
  color: var(--text-soft);
}

.button-ghost:hover {
  background: var(--surface);
  border-color: var(--line-strong);
}

.button-danger {
  color: var(--danger);
}

.button-small {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 12px;
}

.count-pill {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.layout {
  width: min(1380px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr) 248px;
  gap: 26px;
  padding: 24px;
}

.sidebar,
.inspector {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 108px);
  overflow: auto;
}

.sidebar {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.03);
}

.sidebar-head,
.panel-head,
.detail-head,
.editor-head,
.dialog-head,
.trash-head,
.trash-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-head {
  margin-bottom: 10px;
}

.eyebrow {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-head strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  font-weight: 700;
}

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

.tree-folder,
.tree-doc {
  width: 100%;
  min-height: 34px;
  display: grid;
  align-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
}

.tree-folder:hover,
.tree-doc:hover,
.toc-link:hover,
.version-open:hover {
  background: var(--surface-soft);
}

.tree-folder.active,
.tree-doc.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tree-folder {
  padding: 0 10px 0 12px;
}

.tree-doc {
  padding: 6px 10px 6px 12px;
}

.tree-folder-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tree-toggle {
  width: 14px;
  color: var(--text-muted);
  flex: 0 0 14px;
}

.tree-folder-name,
.tree-doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-doc {
  gap: 1px;
}

.tree-doc-meta {
  color: var(--text-muted);
  font-size: 11px;
}

.content {
  min-width: 0;
}

.empty-panel {
  min-height: calc(100vh - 132px);
  display: grid;
  align-content: start;
}

.preview-sheet,
.preview-sheet-empty {
  width: min(840px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preview-sheet {
  min-height: 720px;
  padding: 40px 48px;
}

.detail-shell {
  padding: 0;
  overflow: hidden;
}

.preview-body {
  min-height: 620px;
  padding: 28px 42px 40px;
}

.preview-sheet-empty {
  min-height: 760px;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.92) 0%, rgba(255, 255, 255, 0.98) 100%);
}

.detail,
.editor {
  width: min(840px, 100%);
  margin: 0 auto;
}

.detail-head,
.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.detail-header {
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(251, 252, 253, 0.96) 0%, rgba(255, 255, 255, 0.98) 100%);
}

.detail-title-wrap {
  min-width: 0;
}

.detail-title-wrap h2 {
  margin: 0;
  max-width: 720px;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0;
}

.detail-meta {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.doc-toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.button-tool {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}

.button-tool:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.button-tool-primary {
  border-color: #dbe7ff;
  background: #f7faff;
  color: var(--accent-strong);
}

.rendered-doc {
  color: #3f4a5a;
  font-size: 14px;
  line-height: 1.82;
}

.rendered-doc h1,
.rendered-doc h2,
.rendered-doc h3 {
  color: #182230;
  font-weight: 700;
  scroll-margin-top: 92px;
}

.rendered-doc h1 {
  margin: 0 0 12px;
  font-size: 18px;
}

.rendered-doc h2 {
  margin: 30px 0 12px;
  font-size: 18px;
}

.rendered-doc h3 {
  margin: 24px 0 10px;
  font-size: 16px;
}

.rendered-doc .doc-subheading {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 15px;
  font-weight: 600;
}

.rendered-doc p {
  margin: 12px 0;
}

.rendered-doc ul {
  margin: 12px 0;
  padding-left: 22px;
}

.rendered-doc pre,
.text-preview {
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.7;
}

.html-preview,
.pdf-preview {
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.editor {
  display: grid;
  gap: 14px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}

.field-title {
  flex: 1 1 auto;
}

.field-compact {
  width: 180px;
}

.field-content {
  gap: 10px;
}

.content-editor {
  min-height: 420px;
  border-radius: 14px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.7;
}

.preview-sheet-editor {
  min-height: 220px;
}

.preview-placeholder {
  min-height: 140px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.save-state,
.muted,
.dialog-note {
  color: var(--text-muted);
  font-size: 12px;
}

.inspector {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
}

.toc,
.versions,
.trash-list {
  display: grid;
  gap: 6px;
}

.toc-link {
  display: block;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text-soft);
  text-decoration: none;
}

.toc-level-2 {
  padding-left: 18px;
}

.toc-level-3 {
  padding-left: 28px;
}

.version-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.version-item.active {
  background: var(--surface);
  border-color: #cdd9f8;
}

.version-open {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  color: inherit;
}

.version-open span {
  color: var(--text-muted);
  font-size: 12px;
}

.version-restore {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
}

.dialog,
.context-menu {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.dialog::backdrop,
.context-menu::backdrop {
  background: rgba(15, 23, 42, 0.16);
}

.dialog {
  width: min(460px, calc(100vw - 28px));
  padding: 18px;
}

.dialog-wide {
  width: min(960px, calc(100vw - 28px));
}

.dialog form,
.trash-layout {
  display: grid;
  gap: 16px;
}

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

.button-row-end {
  justify-content: flex-end;
}

.context-menu {
  width: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  border: 0;
}

.context-menu-panel {
  position: fixed;
  width: 192px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
}

.context-menu-panel button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  padding: 0 10px;
}

.context-menu-panel button:hover:not(:disabled) {
  background: var(--surface-muted);
}

.context-menu-panel .danger {
  color: var(--danger);
}

.trash-layout {
  gap: 18px;
}

.trash-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel-trash {
  min-height: 320px;
}

.trash-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.trash-copy strong {
  display: block;
  margin-bottom: 3px;
}

.trash-copy span {
  color: var(--text-muted);
  font-size: 12px;
}

@media (max-width: 1200px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 14px 18px;
  }

  .layout {
    grid-template-columns: 288px minmax(0, 1fr);
  }

  .inspector {
    display: none;
  }
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .inspector {
    position: static;
    max-height: none;
  }

  .detail-head,
  .detail-header,
  .editor-head,
  .sidebar-head,
  .trash-head {
    flex-direction: column;
  }

  .detail-head,
  .detail-header {
    grid-template-columns: 1fr;
  }

  .preview-sheet,
  .preview-sheet-empty,
  .detail,
  .editor {
    width: 100%;
  }

  .preview-sheet {
    padding: 24px;
    min-height: 520px;
  }

  .detail-shell {
    padding: 0;
  }

  .detail-header {
    padding: 16px 18px 14px;
  }

  .preview-body {
    min-height: 420px;
    padding: 20px 18px 24px;
  }

  .preview-sheet-empty {
    min-height: 520px;
  }

  .html-preview,
  .pdf-preview {
    min-height: 520px;
  }

  .trash-columns {
    grid-template-columns: 1fr;
  }
}
