:root {
  --blue: #0757d8;
  --blue-strong: #004bc7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #d8e0ec;
  --panel: #f7f9fc;
  --sidebar: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f3f6fa;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f8fafc;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.35;
}

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

button {
  border: 0;
}

.wiki-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--surface-soft);
}

.create-document-dialog {
  position: fixed;
  z-index: 130;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.36);
}

.create-document-dialog[hidden],
.tree-context-menu[hidden] {
  display: none;
}

.create-document-form {
  display: grid;
  width: min(460px, 100%);
  gap: 10px;
  padding: 22px;
  border: 1px solid #d8e0ec;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.24);
}

.create-document-title {
  margin-bottom: 4px;
  color: #0f172a;
  font-size: 18px;
  font-weight: 800;
}

.create-document-form label {
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

.create-document-kind {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.create-document-kind label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #c8d3e2;
  border-radius: 4px;
  background: #f8fafc;
  cursor: pointer;
}

.create-document-screen-id,
.create-document-description {
  display: grid;
  gap: 10px;
}

.create-document-screen-id[hidden],
.create-document-description[hidden] {
  display: none;
}

.create-document-form input,
.create-document-form textarea {
  width: 100%;
  border: 1px solid #c8d3e2;
  border-radius: 4px;
  color: #111827;
  font: inherit;
}

.create-document-form input {
  min-height: 36px;
  padding: 0 10px;
}

.create-document-form .create-document-kind input {
  width: auto;
  min-height: 0;
  padding: 0;
}

.create-document-form textarea {
  resize: vertical;
  padding: 9px 10px;
}

.create-document-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.dialog-secondary,
.dialog-primary {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 800;
}

.dialog-secondary {
  border: 1px solid #c8d3e2;
  background: #fff;
  color: #334155;
}

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

.dialog-primary:hover {
  background: var(--blue-strong);
}

.wiki-sidebar {
  display: flex;
  height: 100vh;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.wiki-brand {
  flex: 0 0 auto;
  padding: 0 20px 10px;
}

.wiki-brand-logo {
  display: block;
  width: min(226px, 100%);
  height: auto;
}

.document-tree {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 16px;
  scrollbar-color: #94a3b8 #e8eef6;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

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

.tree-group {
  margin: 2px 0;
}

.tree-group summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 4px;
  color: #334155;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.tree-group summary::-webkit-details-marker {
  display: none;
}

.tree-group summary::after {
  margin-left: auto;
  color: #64748b;
  content: "v";
  font-size: 10px;
}

.tree-group:not([open]) summary::after {
  content: ">";
}

.tree-group summary:hover,
.tree-file:hover {
  background: #e3eaf4;
}

.tree-group-children {
  margin-left: 15px;
  padding-left: 8px;
  border-left: 1px solid #d2dae6;
}

.tree-folder-icon,
.tree-file-icon {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 14px;
}

.tree-folder-icon {
  border: 1.5px solid #2563eb;
  border-radius: 2px;
}

.tree-folder-icon::before {
  position: absolute;
  top: -4px;
  left: 1px;
  width: 8px;
  height: 4px;
  border: 1.5px solid #2563eb;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  content: "";
}

.tree-file-icon {
  width: 13px;
  height: 15px;
  border: 1.5px solid #50627a;
  border-radius: 2px;
  background: #fff;
}

.tree-file-icon::after {
  position: absolute;
  right: -1px;
  top: -1px;
  width: 5px;
  height: 5px;
  border-left: 1.5px solid #50627a;
  border-bottom: 1.5px solid #50627a;
  background: var(--sidebar);
  content: "";
}

.tree-file {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 29px;
  padding: 0 8px;
  border-radius: 4px;
  color: #334155;
  text-decoration: none;
}

.tree-file.is-active {
  background: #dbeafe;
  color: #073f9e;
  font-weight: 700;
}

.tree-context-menu {
  position: fixed;
  z-index: 120;
  min-width: 158px;
  padding: 5px;
  border: 1px solid #c8d3e2;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.2);
}

.tree-context-menu button {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  background: transparent;
  color: #1f2a44;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}

.tree-context-menu button:hover {
  background: #eaf0f8;
}

.tree-context-menu button:disabled {
  color: #94a3b8;
  cursor: not-allowed;
}

.tree-context-menu button:disabled:hover {
  background: transparent;
}

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

.sidebar-action {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 4px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  text-align: left;
}

.sidebar-action:hover {
  background: #e3eaf4;
}

.sidebar-action-icon {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 1.5px solid #335a8f;
  border-radius: 50%;
  color: #335a8f;
  font-size: 11px;
  font-weight: 700;
}

.wiki-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  flex-direction: column;
  background: var(--panel);
}

.wiki-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  min-height: 58px;
  padding-right: 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.document-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  padding: 0 22px;
}

.document-heading-path {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-tabs {
  display: flex;
  align-self: stretch;
  align-items: center;
  gap: 18px;
}

.topbar-tab {
  position: relative;
  align-self: stretch;
  padding: 0 1px;
  background: transparent;
  color: #0f172a;
  cursor: pointer;
  font-weight: 700;
}

.topbar-tab.is-active {
  color: var(--blue);
}

.topbar-tab.is-active::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--blue);
  content: "";
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px;
}

.save-button {
  min-width: 70px;
  min-height: 40px;
  border-radius: 4px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.save-button:hover {
  background: var(--blue-strong);
}

.save-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.editor-view,
.reader-view {
  min-height: 0;
  flex: 1;
}

.reader-view {
  display: none;
}

.wiki-shell[data-view="preview"] .editor-view {
  display: none;
}

.wiki-shell[data-view="preview"] .reader-view {
  display: block;
}

.editor-view {
  display: flex;
  overflow: hidden;
  flex-direction: column;
}

.editor-modebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.editor-mode-tabs {
  display: flex;
  height: 100%;
}

.mode-tab {
  min-width: 128px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
  background: transparent;
  color: #334155;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.mode-tab.is-active {
  color: var(--blue);
  background: #fff;
}

.modebar-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  padding: 0 16px;
  color: #475569;
  font-size: 12px;
}

#documentFileName {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#documentStatus {
  color: #0f766e;
  font-weight: 700;
  white-space: nowrap;
}

.wiki-shell.is-dirty #documentStatus {
  color: #b45309;
}

.editor-workspace {
  display: flex;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  flex: 1;
  overflow: hidden;
}

.editor-panel,
.live-preview-panel,
.history-view {
  display: flex;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  flex: 1 1 auto;
  flex-direction: column;
}

.editor-panel {
  background: #edf2f8;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 46px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.format-select {
  height: 30px;
  width: 108px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.format-select:hover,
.format-select:focus {
  border-color: #c8d3e2;
  outline: none;
}

.tool-button {
  display: grid;
  min-width: 28px;
  height: 30px;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: #1f2a44;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.tool-button:hover {
  background: #eaf0f8;
}

.tool-button.table-tool {
  min-width: 34px;
  color: #0f3f89;
}

.tool-button.italic {
  font-style: italic;
}

.tool-button.underline {
  text-decoration: underline;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: #d6deeb;
}

.visual-editor-shell {
  position: relative;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  flex: 1;
  overflow-x: auto;
  overflow-y: scroll;
  padding: 24px;
  background: #eef3fa;
  scrollbar-gutter: stable;
}

.visual-editor-shell.is-image-dragging {
  outline: 2px solid var(--blue);
  outline-offset: -8px;
}

.visual-editor-shell.is-image-dragging::after {
  position: fixed;
  z-index: 90;
  right: 28px;
  bottom: 28px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--blue);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
  color: #fff;
  content: "Drop image to insert";
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
}

.visual-editor-frame {
  display: block;
  width: min(940px, 100%);
  min-height: 100%;
  margin: 0 auto;
  border: 1px solid #cdd7e5;
  background: #fff;
  box-shadow: var(--shadow);
}

.visual-resize-overlay {
  display: none;
  position: fixed;
  z-index: 80;
  border: 2px solid var(--blue);
  box-shadow: 0 0 0 1px rgba(7, 87, 216, 0.16);
  pointer-events: none;
}

.visual-resize-overlay.is-active {
  display: block;
}

.visual-resize-label {
  position: absolute;
  top: -25px;
  left: -2px;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.visual-table-designer {
  display: none;
  position: absolute;
  top: -37px;
  left: 48px;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid #b8c7dc;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
  pointer-events: auto;
}

.visual-resize-overlay.has-table-designer .visual-table-designer {
  display: flex;
}

.visual-resize-overlay.designer-below .visual-table-designer {
  top: 8px;
  left: 8px;
}

.visual-table-designer button {
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #0f172a;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.visual-table-designer button:hover {
  border-color: #c8d3e2;
  background: #eaf0f8;
  color: var(--blue);
}

.visual-resize-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 1px 5px rgba(15, 23, 42, 0.22);
  cursor: nwse-resize;
  pointer-events: auto;
}

.visual-column-grip {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 10px;
  margin-left: -5px;
  border-radius: 999px;
  background: transparent;
  cursor: col-resize;
  pointer-events: auto;
}

.visual-column-grip::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  background: rgba(7, 87, 216, 0.68);
  content: "";
}

.visual-column-grip:hover::after,
body.is-visual-resizing .visual-column-grip::after {
  width: 3px;
  background: var(--blue);
}

body.is-visual-resizing {
  cursor: grabbing;
  user-select: none;
}

.visual-resize-shield {
  display: none;
  position: fixed;
  z-index: 70;
  inset: 0;
  background: transparent;
}

.visual-resize-shield.is-active {
  display: block;
}

.source-editor {
  display: none;
  width: 100%;
  min-height: 0;
  flex: 1;
  resize: none;
  border: 0;
  background: #eef3fa;
  color: #111827;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  padding: 22px;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  tab-size: 2;
}

.wiki-shell[data-editor-mode="code"] .visual-editor-shell {
  display: none;
}

.wiki-shell[data-editor-mode="code"] .source-editor {
  display: block;
}

.live-preview-panel {
  display: none;
}

.wiki-shell[data-editor-mode="preview"] .toolbar,
.wiki-shell[data-editor-mode="preview"] .visual-editor-shell,
.wiki-shell[data-editor-mode="preview"] .source-editor {
  display: none;
}

.wiki-shell[data-editor-mode="preview"] .live-preview-panel {
  display: flex;
}

.history-view {
  display: none;
  overflow-y: scroll;
  background: #fff;
  scrollbar-gutter: stable;
}

.wiki-shell[data-editor-mode="history"] .editor-panel {
  display: none;
}

.wiki-shell[data-editor-mode="history"] .history-view {
  display: block;
}

.panel-titlebar {
  display: flex;
  position: sticky;
  z-index: 2;
  top: 0;
  align-items: center;
  min-height: 36px;
  flex: 0 0 auto;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.panel-kicker {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.preview-frame,
.reader-frame {
  display: block;
  width: 100%;
  min-height: 0;
  flex: 0 0 auto;
  border: 0;
  background: #fff;
}

.live-preview-panel,
.reader-view {
  height: 100%;
  max-height: 100%;
  overflow-x: auto;
  overflow-y: scroll;
  background: #fff;
  scrollbar-gutter: stable;
}

.live-preview-panel .preview-frame {
  min-height: calc(100vh - 130px);
}

.reader-frame {
  min-height: 100%;
}

.document-tree::-webkit-scrollbar,
.visual-editor-shell::-webkit-scrollbar,
.source-editor::-webkit-scrollbar,
.live-preview-panel::-webkit-scrollbar,
.reader-view::-webkit-scrollbar,
.history-view::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.document-tree::-webkit-scrollbar-thumb,
.visual-editor-shell::-webkit-scrollbar-thumb,
.source-editor::-webkit-scrollbar-thumb,
.live-preview-panel::-webkit-scrollbar-thumb,
.reader-view::-webkit-scrollbar-thumb,
.history-view::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 8px;
  background: #94a3b8;
  background-clip: content-box;
}

.document-tree::-webkit-scrollbar-track,
.visual-editor-shell::-webkit-scrollbar-track,
.source-editor::-webkit-scrollbar-track,
.live-preview-panel::-webkit-scrollbar-track,
.reader-view::-webkit-scrollbar-track,
.history-view::-webkit-scrollbar-track {
  background: #e8eef6;
}

.history-panel {
  max-width: 920px;
  padding: 42px 48px;
}

.history-panel h2 {
  margin: 0 0 18px;
  font-size: 28px;
}

.history-list {
  margin: 0;
  padding-left: 18px;
  color: #334155;
}

.history-list li {
  margin: 8px 0;
}

.history-entry-button {
  padding: 6px 0;
  background: transparent;
  color: #0757d8;
  cursor: pointer;
  font-weight: 700;
  text-align: left;
}

.history-entry-button:hover {
  text-decoration: underline;
}

.history-diff {
  margin-top: 22px;
  overflow: auto;
  border: 1px solid #d8e0ec;
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.diff-title {
  padding: 10px 12px;
  border-bottom: 1px solid #334155;
  color: #f8fafc;
  font-family: "Segoe UI", Arial, sans-serif;
  font-weight: 800;
}

.diff-line {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  min-height: 24px;
  padding: 3px 10px;
}

.diff-line code {
  overflow: hidden;
  color: inherit;
  text-overflow: ellipsis;
  white-space: pre;
}

.diff-line-add {
  background: rgba(22, 163, 74, 0.18);
  color: #bbf7d0;
}

.diff-line-remove {
  background: rgba(220, 38, 38, 0.18);
  color: #fecaca;
}

.diff-line-note {
  display: block;
  padding: 10px 12px;
  color: #facc15;
}

@media (max-width: 1060px) {
  .wiki-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .wiki-topbar {
    grid-template-columns: minmax(180px, 1fr);
    gap: 8px;
    padding: 10px 28px 10px 0;
  }

  .topbar-tabs,
  .topbar-actions {
    padding: 0 22px;
    justify-content: flex-start;
  }

  .editor-panel {
    min-height: 52vh;
  }
}

@media (max-width: 760px) {
  .wiki-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

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

  .wiki-brand {
    padding: 0 18px 10px;
  }

  .document-tree {
    padding: 0 12px 12px;
  }

  .sidebar-actions {
    display: none;
  }

  .wiki-main {
    min-height: 0;
  }

  .editor-modebar,
  .toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
    height: auto;
  }

  .modebar-meta {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 12px;
  }
}
