/* wchaos-docs — 界面样式
   单文件、无框架。明暗两套由 data-theme 驱动，默认跟随系统。 */

:root {
  --bg: #f7f8fa;
  --bg-panel: #ffffff;
  --bg-soft: #f1f3f7;
  --bg-hover: #eceff5;
  --bg-active: #e4ebfa;
  --border: #e2e6ee;
  --border-strong: #ccd3e0;
  --text: #1c2230;
  --text-soft: #5b6478;
  --text-faint: #939cb0;
  --accent: #2f6fed;
  --accent-soft: #e8f0ff;
  --danger: #d93b3b;
  --ok: #1f9d55;
  --warn: #b7791f;
  --shadow: 0 6px 24px rgba(20, 28, 48, .13);
  --radius: 9px;
  --sidebar-w: 268px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-panel: #161923;
  --bg-soft: #1b1f2b;
  --bg-hover: #222736;
  --bg-active: #253052;
  --border: #272d3d;
  --border-strong: #3a4356;
  --text: #d7dae0;
  --text-soft: #98a1b3;
  --text-faint: #6b748a;
  --accent: #6f9dff;
  --accent-soft: #1d2740;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #f0b849;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input { font-family: inherit; font-size: inherit; color: inherit; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: .6;
  margin-left: 2px;
}

/* ── 登录 ─────────────────────────────────────────────── */
#login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-panel) 0%, var(--bg) 60%);
  z-index: 100;
}
#login[hidden] { display: none; }
.login-card {
  width: min(340px, calc(100vw - 40px));
  padding: 34px 30px 26px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  width: 46px; height: 46px; margin: 0 auto 14px;
  display: grid; place-items: center;
  font-size: 24px; color: #fff;
  background: linear-gradient(140deg, var(--accent), #7a4de8);
  border-radius: 13px;
}
.login-card h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: .2px; }
.login-sub { margin: 4px 0 22px; font-size: 12px; color: var(--text-faint); font-family: var(--mono); }
.login-card input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  transition: filter .15s;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card button:disabled { opacity: .6; cursor: wait; }
.login-err { min-height: 18px; margin: 10px 0 0; font-size: 12px; color: var(--danger); }

/* ── 布局 ─────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 4px 1fr;
  height: 100vh;
  height: 100dvh;
}
#app[hidden] { display: none; }
#app.side-hidden { grid-template-columns: 0 0 1fr; }
#app.side-hidden #sidebar { display: none; }
#app.side-hidden #gutter { display: none; }

#gutter { cursor: col-resize; background: transparent; transition: background .15s; }
#gutter:hover, #gutter.dragging { background: var(--accent); }

/* ── 侧栏 ─────────────────────────────────────────────── */
#sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}
.side-head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 9px 8px 7px;
  border-bottom: 1px solid var(--border);
}
.side-title {
  flex: 1;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .6px;
  color: var(--text-soft);
  text-transform: uppercase;
}
.side-search { position: relative; padding: 8px 10px 4px; }
.side-search input {
  width: 100%;
  padding: 7px 26px 7px 10px;
  font-size: 13px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}
.side-search input:focus { border-color: var(--accent); background: var(--bg-panel); }
.side-search input::-webkit-search-cancel-button { display: none; }
#btn-search-clear { position: absolute; right: 15px; top: 50%; transform: translateY(-40%); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  font-size: 14px;
  color: var(--text-soft);
  background: transparent;
  border: none;
  border-radius: 6px;
  transition: background .12s, color .12s;
  flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.tiny { width: 20px; height: 20px; font-size: 13px; }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }

.side-foot {
  padding: 7px 12px;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
}

/* ── 目录树 ───────────────────────────────────────────── */
.tree {
  flex: 1;
  overflow: auto;
  padding: 6px 6px 14px;
  outline: none;
}
.tree-empty { padding: 26px 16px; text-align: center; font-size: 12.5px; color: var(--text-faint); }

.node {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 6px 0 4px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
}
.node:hover { background: var(--bg-hover); }
.node.active { background: var(--bg-active); color: var(--accent); font-weight: 600; }
.node.dim { opacity: .45; }
.node.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.node .caret {
  width: 15px; flex: none;
  font-size: 9px; color: var(--text-faint);
  transition: transform .13s;
  text-align: center;
}
.node .caret.open { transform: rotate(90deg); }
.node .caret.leaf { visibility: hidden; }
.node .ico { flex: none; font-size: 12.5px; width: 15px; text-align: center; opacity: .85; }
.node .label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.node .badge { flex: none; font-size: 10px; color: var(--danger); }
.node .label mark { background: rgba(255, 214, 0, .38); color: inherit; border-radius: 2px; padding: 0 1px; }
.node.dirty .label::after { content: '●'; margin-left: 4px; font-size: 9px; color: var(--warn); }

.children { overflow: hidden; }
.children.collapsed { display: none; }

/* 搜索结果 */
.search-results {
  flex: 1;
  overflow: auto;
  padding: 4px 6px 14px;
  border-top: 1px solid var(--border);
}
.sr-head { padding: 8px 8px 4px; font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; }
.sr-item { padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.sr-item:hover { background: var(--bg-hover); }
.sr-name { font-size: 13px; font-weight: 600; }
.sr-path { font-size: 11px; color: var(--text-faint); font-family: var(--mono); margin-top: 1px; word-break: break-all; }
.sr-snippet { font-size: 11.5px; color: var(--text-soft); margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sr-snippet mark { background: rgba(255, 214, 0, .38); color: inherit; }

/* ── 主区 ─────────────────────────────────────────────── */
#main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-height: 50px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
#doc-info { min-width: 0; max-width: 40%; }
#doc-title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-path {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  direction: rtl; text-align: left;
}
#doc-badges { display: flex; gap: 4px; align-items: center; }
.badge-pill {
  font-size: 10.5px; padding: 2px 7px; border-radius: 20px;
  background: var(--bg-soft); color: var(--text-soft); border: 1px solid var(--border);
}
.badge-pill.dirty { background: rgba(183, 121, 31, .14); color: var(--warn); border-color: transparent; }
.badge-pill.saved { background: rgba(31, 157, 85, .14); color: var(--ok); border-color: transparent; }

.toolbar-spacer { flex: 1; }

.btn-group { display: flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 7px; padding: 2px; }
.btn-group button {
  padding: 4px 11px;
  font-size: 12.5px;
  color: var(--text-soft);
  background: transparent;
  border: none;
  border-radius: 5px;
}
.btn-group button:hover { color: var(--text); }
.btn-group button.on { background: var(--bg-panel); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.09); }

.btn-primary {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 12px;
  font-size: 13px; font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  transition: filter .15s, opacity .15s;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .42; cursor: default; }

/* ── 工作区 / 编辑 / 预览 ─────────────────────────────── */
#workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
  position: relative;
}
#workspace[data-view="source"] { grid-template-columns: 1fr 0; }
#workspace[data-view="preview"] { grid-template-columns: 0 1fr; }
#workspace[data-view="source"] #preview-pane,
#workspace[data-view="preview"] #editor-pane { display: none; }

#editor-pane { min-width: 0; overflow: hidden; border-right: 1px solid var(--border); }
#editor-host, #editor-host .cm-editor { height: 100%; }
#editor-host .cm-scroller { font-family: var(--mono); font-size: 13.5px; line-height: 1.72; }
#editor-host .cm-content { padding: 16px 0 40vh; }
#editor-host .cm-gutters { border-right: 1px solid var(--border); }

#preview-pane { min-width: 0; overflow: auto; }
#preview { padding: 22px 30px 40vh; max-width: 900px; margin: 0 auto; }

#empty-state { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); }
.empty-inner { text-align: center; color: var(--text-faint); }
.empty-icon { font-size: 34px; margin-bottom: 12px; opacity: .35; }
.empty-hint { font-size: 12px; margin-top: -6px; }

/* 状态栏 */
#statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 14px;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-faint);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}
#status-save.dirty { color: var(--warn); }
#status-save.saved { color: var(--ok); }
#status-save.error { color: var(--danger); }

/* ── Markdown 排版 ────────────────────────────────────── */
.markdown-body { font-size: 15px; line-height: 1.78; word-wrap: break-word; }
.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 {
  margin: 1.6em 0 .6em;
  font-weight: 650;
  line-height: 1.32;
}
.markdown-body h1 { font-size: 1.85em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 1.42em; padding-bottom: .28em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 1.2em; }
.markdown-body h4 { font-size: 1.05em; }
.markdown-body h5, .markdown-body h6 { font-size: .95em; color: var(--text-soft); }
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body table { margin: 0 0 1em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.6em; }
.markdown-body li { margin: .3em 0; }
.markdown-body li.task-done { color: var(--text-soft); }
.markdown-body .task-box {
  display: inline-block;
  width: 1.1em;
  margin-right: .35em;
  color: var(--accent);
  font-size: 1.05em;
  line-height: 1;
  user-select: none;
}
.markdown-body li.task-done .task-box { color: var(--ok); }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: .3em 0;
  background: var(--bg-soft);
}
.markdown-body blockquote {
  padding: .3em 1em;
  color: var(--text-soft);
  border-left: 3px solid var(--border-strong);
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}
.markdown-body hr { height: 1px; margin: 1.8em 0; background: var(--border); border: none; }
.markdown-body code {
  font-family: var(--mono);
  font-size: .875em;
  padding: .16em .38em;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.markdown-body pre {
  margin: 0 0 1em;
  padding: 13px 15px;
  overflow: auto;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.8px;
  line-height: 1.6;
}
.markdown-body pre code { padding: 0; background: none; border: none; font-size: inherit; }
.markdown-body table { border-collapse: collapse; display: block; overflow: auto; max-width: 100%; }
.markdown-body th, .markdown-body td { padding: 6px 13px; border: 1px solid var(--border); }
.markdown-body th { background: var(--bg-soft); font-weight: 650; }
.markdown-body tbody tr:nth-child(2n) { background: color-mix(in srgb, var(--bg-soft) 55%, transparent); }
.markdown-body .img-uploading {
  display: inline-block; padding: 6px 12px; font-size: 12px;
  color: var(--text-soft); background: var(--bg-soft);
  border: 1px dashed var(--border-strong); border-radius: 7px;
}

/* ── 右键菜单 / 提示 / 拖放 ───────────────────────────── */
#ctxmenu {
  position: fixed;
  z-index: 60;
  min-width: 168px;
  padding: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
#ctxmenu[hidden] { display: none; }
.ctx-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-item .k { margin-left: auto; font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--border); }

#toasts {
  position: fixed;
  right: 16px; bottom: 16px;
  z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  max-width: 340px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#drop-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
#drop-overlay[hidden] { display: none; }
#drop-overlay > div {
  padding: 16px 30px;
  font-size: 15px; font-weight: 600; color: var(--accent);
  background: var(--bg-panel);
  border: 2px dashed var(--accent);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* ── 窄屏 ─────────────────────────────────────────────── */
@media (max-width: 860px) {
  #app { grid-template-columns: 0 0 1fr; }
  #sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(84vw, var(--sidebar-w));
    z-index: 50;
    box-shadow: var(--shadow);
    transform: translateX(0);
    transition: transform .2s ease;
  }
  #gutter { display: none; }
  #app.side-hidden #sidebar { display: flex; transform: translateX(-102%); }
  #app:not(.side-hidden)::after {
    content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 40;
  }
  #workspace { grid-template-columns: 1fr; }
  #workspace[data-view="split"] #preview-pane { display: none; }
  #doc-info { max-width: 30%; }
  .btn-group { display: none; }
}
