:root {
  --fg: #1f2328;
  --muted: #656d76;
  --line: #d8dee4;
  --bg-soft: #f6f8fa;
  --accent: #6d4c41;
  --accent-soft: #efebe9;
  --danger: #b42318;
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--fg);
}

* { box-sizing: border-box; }
body { margin: 0; height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 4px 10px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--bg-soft); }
button:disabled { opacity: .5; cursor: default; }
button.primary, a.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #5d4037; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--muted); padding: 0; }
a { color: var(--accent); }
.spacer { flex: 1; }

/* ヘッダー */
.top {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.brand { font-weight: 700; }
.workspace { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.workspace select { max-width: 320px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.user { color: var(--muted); }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); white-space: nowrap; }
.badge.draft { color: var(--muted); }
.badge.review { color: #9a6700; border-color: #d4a72c; }
.badge.published { color: #1a7f37; border-color: #4ac26b; }
.badge.withdrawn { color: var(--muted); }

/* 全体の配置 */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 280px; border-right: 1px solid var(--line); overflow: auto; padding: 8px 0 24px; }
.workspace-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ページの木 */
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
#tree > .tree > ul { padding-left: 8px; }
.tree li { margin: 0; }
.tree .item {
  display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 4px;
  cursor: pointer; overflow: hidden; text-overflow: ellipsis;
}
.tree .item:hover { background: var(--bg-soft); }
.tree .item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree .item.external { color: var(--muted); cursor: default; }
.tree .item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree summary { list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary .item::before { content: "▸"; color: var(--muted); width: 10px; display: inline-block; }
.tree details[open] > summary .item::before { content: "▾"; }
.tree .add {
  margin-left: auto; visibility: hidden; border: none; background: none; color: var(--muted);
  padding: 0 4px; font-size: 13px;
}
.tree .item:hover .add { visibility: visible; }
.tree .group-title { color: var(--muted); font-size: 12px; padding: 12px 16px 4px; }

/* ツールバーと編集欄 */
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.tools { display: flex; gap: 4px; }
.tools button { padding: 2px 8px; font-size: 13px; }
.toggle { color: var(--muted); display: flex; align-items: center; gap: 4px; }
.panes { flex: 1; display: flex; min-height: 0; }
.editor { flex: 1; min-width: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; font-size: 14px; }
.editor .cm-scroller { font-family: ui-monospace, SFMono-Regular, Menlo, "Noto Sans Mono CJK JP", monospace; line-height: 1.6; }
.editor .cm-editor.cm-focused { outline: none; }
.preview { flex: 1; min-width: 0; border: none; border-left: 1px solid var(--line); background: #fff; }
.panes.no-preview .preview { display: none; }
.empty { color: var(--muted); padding: 32px; }
.statusbar { border-top: 1px solid var(--line); padding: 4px 12px; color: var(--muted); font-size: 12px; }
.statusbar .error { color: var(--danger); }

/* ダイアログ */
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 20px 24px; width: min(520px, 92vw); }
dialog.wide { width: min(860px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .25); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog h3 { margin: 20px 0 8px; font-size: 15px; }
dialog p { color: var(--muted); margin: 0 0 12px; line-height: 1.6; }
dialog label { display: block; margin: 12px 0; }
dialog input, dialog textarea {
  display: block; width: 100%; margin-top: 4px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px;
}
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 20px 0 0; }
.hint { font-size: 12px; }

/* 変更リクエストの表 */
table.changes { width: 100%; border-collapse: collapse; }
table.changes th, table.changes td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.changes th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.changes td.actions { white-space: nowrap; text-align: right; }
table.changes td.actions > * { margin-left: 4px; }

/* ログイン画面 */
main.login { max-width: 480px; margin: 15vh auto; padding: 0 24px; line-height: 1.8; }
main.login h1 { font-size: 22px; }
a.button { display: inline-block; padding: 8px 16px; border-radius: 6px; text-decoration: none; }
