:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #dfe5eb;
  --text: #1f2933;
  --muted: #687482;
  --blue: #1f7aec;
  --green: #2f9e6d;
  --amber: #b7791f;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  min-height: 34px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: #b7c2cf;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

#app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #202a35;
  color: #f8fafc;
  padding: 20px 16px;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  font-weight: 800;
}

.brand h1,
.brand p,
.sidebar h2 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.sidebar h2,
.search span {
  color: #aeb8c4;
  font-size: 12px;
}

.sidebar section {
  margin-top: 22px;
}

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

.search input {
  width: 100%;
  border: 1px solid #3b4652;
  background: #121a22;
  color: #fff;
  border-radius: 6px;
  padding: 10px 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.tab {
  background: #2d3845;
  border-color: #3b4652;
  color: #d8dee6;
  font-size: 12px;
}

.tab.active {
  background: #fff;
  color: #1f2933;
}

.bases,
.tags {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.base {
  text-align: left;
  background: transparent;
  color: #d8dee6;
  border-color: #3b4652;
  padding: 10px;
}

.base.active {
  background: #324152;
  color: #fff;
}

.base small {
  display: block;
  color: #aeb8c4;
}

.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid #3b4652;
  border-radius: 999px;
  padding: 5px 8px;
  background: transparent;
  color: #d8dee6;
  font-size: 12px;
  min-height: 28px;
}

.tag.active,
.tag:hover {
  background: #fff;
  color: #1f2933;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 78px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
}

.crumbs {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  min-width: 42px;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 280px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

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

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

.layout.hide-tree.hide-meta {
  grid-template-columns: minmax(0, 1fr);
}

.layout.hide-tree .tree-panel,
.layout.hide-meta .meta-panel {
  display: none;
}

.tree-panel,
.article-panel,
.meta-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 0;
}

.tree-panel,
.meta-panel {
  overflow: auto;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-head h3,
.meta-panel h3 {
  margin: 0;
  font-size: 14px;
}

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

.tree-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
  padding-left: calc(var(--depth, 0) * 18px);
}

.tree-toggle,
.tree-toggle-placeholder {
  width: 24px;
  min-width: 24px;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.tree-toggle:hover {
  background: #eef3f8;
}

.tree-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 8px 9px;
  color: var(--text);
  line-height: 1.35;
}

.tree-item:hover {
  background: #f0f4f8;
}

.tree-item.active {
  background: #e8f1ff;
  color: #135db6;
}

.tree-row:has(.tree-item.active) {
  background: #e8f1ff;
  border-radius: 6px;
}

.tree-empty {
  color: var(--muted);
  padding: 12px 4px;
}

.article-panel {
  overflow: auto;
}

.article {
  max-width: 920px;
  margin: 0 auto;
  padding: 34px 44px 60px;
}

.editor {
  padding: 24px;
  display: grid;
  gap: 14px;
  max-width: 980px;
  margin: 0 auto;
}

.editor.hidden {
  display: none;
}

.editor-head,
.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.editor-head h3 {
  margin: 0;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-actions button {
  min-width: 36px;
  font-weight: 700;
}

.editor label {
  display: grid;
  gap: 6px;
}

.editor label span {
  color: var(--muted);
  font-size: 13px;
}

.editor input,
.editor select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-height: 40px;
  background: #fff;
}

.editor-content {
  min-height: 380px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  line-height: 1.65;
  background: #fff;
  overflow: auto;
}

.editor-content:focus {
  outline: 2px solid #b9d6ff;
  outline-offset: 1px;
}

.article h1 {
  margin: 0 0 12px;
  font-size: 30px;
  line-height: 1.2;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  background: #eaf7f1;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 13px;
  margin-bottom: 26px;
}

.content {
  line-height: 1.68;
  font-size: 16px;
}

.content img,
.content table {
  max-width: 100%;
}

.content table {
  border-collapse: collapse;
}

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

.content .content-button,
.editor-content .content-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin: 8px 8px 8px 0;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.content img {
  display: block;
  height: auto;
  margin: 14px auto;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.content td,
.content th {
  border: 1px solid var(--line);
  padding: 8px;
}

.child-section h2 {
  margin-top: 0;
}

.child-grid {
  display: grid;
  gap: 10px;
}

.child-card {
  text-align: left;
  min-height: 62px;
  padding: 12px;
}

.child-card span,
.child-card small {
  display: block;
}

.child-card small {
  color: var(--muted);
  margin-top: 5px;
}

.empty {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.hidden {
  display: none;
}

.meta-panel dl {
  display: grid;
  gap: 12px;
  margin: 14px 0 20px;
}

.meta-panel dt {
  color: var(--muted);
  font-size: 12px;
}

.meta-panel dd {
  margin: 4px 0 0;
  word-break: break-word;
}

.neighbors {
  display: grid;
  gap: 8px;
  margin-bottom: 24px;
}

.neighbor {
  text-align: left;
  padding: 10px;
}

.neighbor small {
  display: block;
  color: var(--muted);
}

.comments {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.comments textarea {
  width: 100%;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  resize: vertical;
}

.comment-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

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

  .layout.hide-tree,
  .layout.hide-meta,
  .layout.hide-tree.hide-meta {
    grid-template-columns: 1fr;
  }

  .tree-panel,
  .meta-panel {
    max-height: none;
  }
}
