:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1e242c;
  --muted: #66717f;
  --line: #d9dee7;
  --accent: #1769aa;
  --danger: #b42318;
  --ok: #13795b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}

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

.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.danger {
  background: #fff;
  color: var(--danger);
  border-color: #efb5ad;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.mount-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  flex-shrink: 0;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 14px;
}

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

.brand-logo {
  flex-shrink: 0;
  border-radius: 9px;
}

.login-panel h1 {
  margin: 0;
  font-size: 24px;
}

.toolbar-logo {
  flex-shrink: 0;
  border-radius: 6px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

.shell {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
}

.shell.collapsed {
  grid-template-columns: 0 1fr;
}

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

.shell.collapsed .sidebar {
  border-right: 0;
}

.toolbar, .detail-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar strong {
  flex: 1;
}

.meta-panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  padding-top: 4px;
}

#toggle-meta[aria-expanded="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.selectors {
  padding: 8px 16px 8px;
}

.search {
  margin: 0 16px 10px;
}


.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  padding: 0 16px 8px;
  font-size: 12px;
}

.folder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
  font-size: 12px;
  color: var(--muted);
}

.folder-path {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feedback, .status, .error {
  color: var(--danger);
}

.feedback {
  padding: 0 16px 8px;
}

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: auto;
}

.doc-item {
  border-top: 1px solid var(--line);
  padding: 11px 16px;
  cursor: pointer;
}

.doc-item:hover, .doc-item.active {
  background: #eef5fb;
}

.doc-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-item span, #doc-path {
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.detail {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.detail-header {
  background: var(--panel);
  justify-content: space-between;
}

.detail-header h2 {
  margin: 0;
  font-size: 18px;
}

.detail-header p {
  margin: 2px 0 0;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status {
  min-height: 28px;
  padding: 6px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.empty {
  margin: auto;
  color: var(--muted);
}

.preview-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  overflow: hidden;
  position: relative;
}

.detail.toc-panel-open .preview-wrap {
  grid-template-columns: minmax(0, 980px) minmax(220px, 260px);
}

.preview {
  overflow: auto;
  min-height: 0;
  padding: 24px 32px 80px;
  max-width: 980px;
  width: 100%;
}

.preview-wrap > .preview,
.split .preview {
  height: 100%;
  max-width: none;
}

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  line-height: 1.25;
  margin-top: 1.4em;
  margin-bottom: .4em;
}

.preview h1 { font-size: 1.9em; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.preview h2 { font-size: 1.5em; border-bottom: 1px solid var(--line); padding-bottom: .2em; }
.preview h3 { font-size: 1.2em; }

.preview p { margin: .6em 0 .8em; }

.preview a { color: var(--accent); text-decoration: none; }
.preview a:hover { text-decoration: underline; }

.preview ul, .preview ol {
  padding-left: 1.8em;
  margin: .4em 0 .8em;
}

.preview li { margin: .25em 0; }

.preview li input[type="checkbox"] {
  margin-right: .4em;
}

.preview blockquote {
  margin: .8em 0;
  padding: .4em 1em;
  border-left: 4px solid var(--line);
  color: var(--muted);
  background: #f9fbfd;
  border-radius: 0 4px 4px 0;
}

.preview blockquote p { margin: .2em 0; }

.preview pre, .diff {
  background: #101820;
  color: #e8eef6;
  border-radius: 6px;
  padding: 14px;
  overflow: auto;
}

.preview pre code {
  background: none;
  padding: 0;
  font-size: .9em;
}

.preview.json-preview {
  padding: 18px 24px 80px;
  max-width: none;
}

.json-viewer {
  margin: 0;
  min-height: 100%;
  white-space: pre;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.preview .json-viewer code {
  display: block;
  background: none;
  color: inherit;
  padding: 0;
  font: inherit;
}

.json-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #efb5ad;
  border-radius: 6px;
  background: #fff4f2;
  color: var(--danger);
}

.json-viewer-invalid {
  border: 1px solid #efb5ad;
}

.json-key { color: #8ad5ff; }
.json-string { color: #a7e3a0; }
.json-number { color: #ffcf70; }
.json-boolean { color: #ff9f9f; }
.json-null { color: #c9b6ff; }

.preview code {
  background: #eef1f6;
  color: #c7254e;
  padding: .15em .35em;
  border-radius: 4px;
  font: 87.5%/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.preview table {
  border-collapse: collapse;
  width: 100%;
  margin: .8em 0;
  font-size: .95em;
}

.preview th, .preview td {
  border: 1px solid var(--line);
  padding: 7px 12px;
  text-align: left;
}

.preview th {
  background: #f0f4f8;
  font-weight: 600;
}

.preview tr:nth-child(even) td {
  background: #f9fbfd;
}

.preview hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.5em 0;
}

.preview img {
  max-width: 100%;
  border-radius: 4px;
}

.toc-panel-toggle {
  position: absolute;
  top: 16px;
  right: 24px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(30, 36, 44, .14);
}

.toc-panel {
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 132px);
  margin: 24px 24px 24px 0;
  padding: 4px 0 12px 14px;
  overflow: auto;
  border-left: 1px solid var(--line);
}

.toc-panel-header {
  margin: 0 0 8px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toc-title {
  flex: 1;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.toc-panel-close {
  padding: 4px 8px;
  font-size: 12px;
}

.toc-list {
  display: grid;
  gap: 2px;
}

.toc-link {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  padding: 5px 8px;
  text-align: left;
  line-height: 1.35;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-link:hover,
.toc-link.active {
  background: #eef5fb;
  color: var(--text);
  border-left-color: var(--accent);
}

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

.toc-float {
  display: none;
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(30, 36, 44, .18);
}

.detail.toc-ready.toc-editing .toc-float {
  display: block;
}

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(16, 24, 32, .28);
}

.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: min(360px, calc(100vw - 32px));
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(30, 36, 44, .18);
  display: flex;
  flex-direction: column;
}

.toc-drawer-header {
  min-height: 56px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toc-drawer-header h2 {
  margin: 0;
  font-size: 16px;
}

.toc-drawer .toc-list {
  overflow: auto;
  padding: 10px 14px 18px;
}

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
}

#editor {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  resize: none;
  padding: 18px;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.diff {
  margin: 18px;
  flex: 1;
}

@media (max-width: 1120px) {
  .preview-wrap {
    grid-template-columns: minmax(0, 1fr);
  }
  .toc-panel,
  .toc-panel-toggle {
    display: none;
  }
  .detail.toc-ready.toc-previewing .toc-float {
    display: block;
  }
}

@media (max-width: 820px) {
  .shell {
    height: auto;
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .shell.collapsed .sidebar {
    display: none;
  }
  .split {
    grid-template-columns: 1fr;
  }
  .preview {
    padding: 18px 18px 72px;
  }
  #editor {
    min-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .toc-float {
    right: 16px;
    bottom: 16px;
  }
  .toc-drawer {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    max-height: 72vh;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

