:root {
  --brand: #ea7317; --brand-dark: #c65c0c; --brand-light: #fdf0e4; --brand-text: #b45309;
  --head: #efede0; --head-line: #ddd9c6;
  --side: #4f4f4f; --side-hover: #5f5f5f; --side-ink: #e6e6e6;
  --ink: #3c4a60; --muted: #7b8798; --line: #e5e7eb; --bg: #f8fafc; --white: #fff;
  --danger: #b91c1c; --warn-bg: #fff8e1; --warn-line: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 15px/1.75 -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f3f4f6; padding: 0 .3em; border-radius: 3px; font-size: .92em; }
.svg-sprite { display: none; }

/* 上部バー（全幅） */
.appbar { position: sticky; top: 0; z-index: 20; height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--head); border-bottom: 1px solid var(--head-line); }
.appbar__brand { display: flex; align-items: center; gap: 7px; color: var(--ink); font-weight: 700; flex: none; }
.appbar__brand:hover { text-decoration: none; opacity: .8; }
.appbar__mark { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--brand); stroke-width: 1.7; stroke-linejoin: round; }
.appbar__name { font-size: 15px; }
.appbar__me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.appbar__user { font-weight: 600; color: var(--ink); }
.search { flex: 1; max-width: 620px; position: relative; display: flex; align-items: center; }
.search__icon { position: absolute; left: 10px; width: 15px; height: 15px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input { width: 100%; padding: 6px 12px 6px 32px; border: 1px solid var(--head-line); border-radius: 4px; background: rgba(255,255,255,.65); font-size: 13px; color: var(--ink); }
.search input:focus { background: #fff; outline: 2px solid rgba(234,115,23,.4); outline-offset: -1px; }

/* 本体3カラム */
.app { display: grid; grid-template-columns: 80px 264px minmax(0, 1fr); min-height: calc(100vh - 46px); }
.app--bare { grid-template-columns: 1fr; }
.app--bare .rail, .app--bare .tree { display: none; }

/* 左レール */
.rail { background: var(--brand); color: #fff; display: flex; flex-direction: column; align-items: stretch; padding: 14px 0 10px; position: sticky; top: 46px; height: calc(100vh - 46px); overflow-y: auto; }
.rail__item { color: rgba(255,255,255,.88); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; font-size: 11px; line-height: 1.3; border-left: 3px solid transparent; }
.rail__item:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.rail__item.is-active { background: var(--brand-dark); border-left-color: #fff; color: #fff; }
.rail__item--bottom { margin-top: auto; }
.rail__icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail__label { display: block; white-space: nowrap; }
.rail__item--new { padding: 0 4px 18px; }
.rail__item--new .rail__icon { width: 22px; height: 22px; padding: 11px; box-sizing: content-box; background: #fff; stroke: var(--brand); border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.rail__item--new .rail__label { font-weight: 700; color: #fff; }
.rail__item--new:hover, .rail__item--new.is-active { background: none; border-left-color: transparent; }
.rail__item--new:hover .rail__icon { background: var(--brand-light); box-shadow: 0 3px 10px rgba(0,0,0,.28); }
.rail__item--new.is-active .rail__icon { background: var(--brand-light); }

/* カテゴリ（濃色） */
.tree { background: var(--side); color: var(--side-ink); padding: 6px 0 24px; position: sticky; top: 46px; height: calc(100vh - 46px); overflow-y: auto; }
.tree__head { font-size: 11px; letter-spacing: .08em; color: rgba(255,255,255,.5); padding: 10px 16px 6px; }
.tree__list { list-style: none; margin: 0; padding: 0; }
.tree__list .tree__list { padding-left: 15px; }
.tree__row { display: flex; align-items: center; gap: 7px; padding: 5px 12px; font-size: 13px; line-height: 1.6; }
summary.tree__row { list-style: none; cursor: pointer; }
summary.tree__row::-webkit-details-marker { display: none; }
.tree__row::before { content: "+"; flex: none; width: 15px; height: 15px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.35); border-radius: 2px; font-size: 12px; line-height: 1; color: rgba(255,255,255,.7); }
.tree__node[open] > .tree__row::before { content: "−"; }
.tree__row--leaf::before { content: ""; border-color: transparent; }
.tree__row:hover { background: var(--side-hover); }
.tree__row.is-current { background: var(--brand); }
.tree__name { flex: 1; min-width: 0; color: var(--side-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree__row:hover .tree__name, .tree__row.is-current .tree__name { color: #fff; text-decoration: none; }
.tree__row.is-current .tree__name { font-weight: 600; }
.tree__count { flex: none; font-size: 11px; background: rgba(0,0,0,.28); color: rgba(255,255,255,.8); border-radius: 3px; padding: 0 6px; }
.tree__empty { color: rgba(255,255,255,.5); font-size: 13px; padding: 6px 16px; }
.tree__list--wide { padding-left: 0; }
.depth-1 { padding-left: 22px; } .depth-2 { padding-left: 44px; } .depth-3 { padding-left: 66px; } .depth-4 { padding-left: 88px; }

.main { background: var(--white); min-width: 0; }
.content { padding: 26px 34px 64px; max-width: 1040px; }
.inline { display: inline; }
.linklike { background: none; border: 0; color: var(--brand-text); cursor: pointer; font: inherit; padding: 0; }
.linklike.danger { color: var(--danger); }
.flash { margin: 12px 34px 0; padding: 10px 14px; background: var(--brand-light); border-left: 4px solid var(--brand); border-radius: 4px; }
.error { color: var(--danger); background: #fef2f2; border-left: 4px solid var(--danger); padding: 10px 14px; border-radius: 4px; }
.notice { background: var(--warn-bg); border-left: 4px solid var(--warn-line); padding: 10px 14px; border-radius: 4px; }
.hint, .muted { color: var(--muted); font-size: 13px; }

/* ホーム（本文＋右カラム） */
.home { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 36px; align-items: start; }
.home__side { border-left: 1px solid var(--line); padding-left: 22px; }
.home__side-head { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .04em; margin: 4px 0 6px; }
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.6; }
.recent li:last-child { border-bottom: 0; }
.recent__meta { display: block; color: var(--muted); font-size: 12px; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.crumbs__id { margin-right: 10px; }
.crumbs__sep { margin: 0 6px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 30px; margin: 2px 0; font-weight: 700; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.page-meta { color: var(--muted); font-size: 13px; margin: 8px 0 18px; padding: 8px 12px; background: var(--bg); border-radius: 6px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.badge--public { background: var(--brand-light); color: var(--brand-text); }
.badge--limited { background: #fff1f2; color: #9f1239; }
.badge--auto { background: #fef3c7; color: #92400e; }
.badge--ai { background: #ecfdf5; color: #047857; }
.badge--noai { background: #f3f4f6; color: #4b5563; }

.aichoice { margin: 16px 0 0; padding: 12px 16px; border: 1px solid var(--warn-line); border-radius: 6px; background: var(--warn-bg); }
.aichoice__legend { font-weight: 700; padding: 0 6px; }
.aichoice__hint { margin: 0 0 8px; font-size: 13px; color: var(--ink); }
.aichoice .aichoice__opt { display: flex; align-items: center; gap: 7px; margin: 4px 0; cursor: pointer; width: fit-content; }
.aichoice__opt input { margin: 0; }
.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line); background: var(--white); color: var(--ink); cursor: pointer; font: inherit; }
.btn:hover { text-decoration: none; background: var(--bg); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; }
.menu[open] > :not(summary) { display: block; }
.menu a, .menu form { display: block; padding: 6px 12px; }
.menu > *:not(summary) { position: absolute; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08); min-width: 180px; z-index: 5; }

.toc { background: var(--bg); border-radius: 8px; padding: 10px 14px; margin: 12px 0 20px; font-size: 14px; }
.toc a { margin-left: 12px; }
.toc__l2 { margin-left: 20px !important; } .toc__l3 { margin-left: 28px !important; }
.md h1, .md h2, .md h3 { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 28px; }
.md h1 { font-size: 24px; } .md h2 { font-size: 20px; } .md h3 { font-size: 17px; }
.md table { border-collapse: collapse; margin: 12px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 12px; }
.md th { background: var(--bg); }
.md img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.md blockquote { margin: 12px 0; padding: 8px 14px; background: var(--warn-bg); border-left: 4px solid var(--warn-line); }
.md pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; color: inherit; }

.editor__title { width: 100%; font-size: 22px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
.editor__pane { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor__body { width: 100%; font: 14px/1.6 ui-monospace, Consolas, "Courier New", monospace; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.editor__preview { border: 1px dashed var(--line); border-radius: 6px; padding: 10px 14px; overflow: auto; background: var(--bg); }
.editor__actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
.editor__status { color: var(--muted); font-size: 13px; margin-left: auto; }

.diff { font: 13px/1.5 ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-radius: 8px; overflow: auto; margin: 8px 0 16px; }
.diff__line { padding: 1px 10px; white-space: pre-wrap; }
.diff__line--add { background: #dcfce7; }
.diff__line--del { background: #fee2e2; text-decoration: line-through; }
.diff__line--ctx { color: var(--muted); }
.plain { white-space: pre-wrap; background: var(--bg); padding: 12px; border-radius: 8px; }

.table { border-collapse: collapse; width: 100%; margin: 8px 0 16px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.table--dense td, .table--dense th { padding: 4px 8px; font-size: 13px; }
.results, .members { list-style: none; padding: 0; }
.result { padding: 12px 0; border-bottom: 1px solid var(--line); }
.result__title { font-size: 17px; font-weight: 600; }
mark { background: #fde68a; padding: 0 2px; }
.attachments { margin-top: 32px; border-top: 1px solid var(--line); padding-top: 12px; }
.attachment { display: flex; gap: 12px; align-items: center; padding: 6px 0; flex-wrap: wrap; }
.copyable { user-select: all; }
.upload { margin-top: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.row input[type=text], .row input:not([type]) { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; }
.group { margin: 16px 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; }
.members li { display: inline-block; margin: 2px 8px 2px 0; }
.is-member { font-weight: 700; }
.login { max-width: 360px; margin: 80px auto; padding: 28px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.login label, .content form label, .plain-page form label { display: block; margin: 10px 0 4px; }
.login input, .content form input[type=password], .content form input[type=text], .plain-page form input[type=password], .plain-page form input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.plain-page { max-width: 480px; margin: 60px auto; padding: 0 24px; }
.plain-page .login { margin: 0 auto; }

@media (max-width: 1100px) {
  .home { grid-template-columns: 1fr; gap: 8px; }
  .home__side { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 20px; }
}
@media (max-width: 900px) {
  .appbar { gap: 10px; padding: 0 10px; }
  .appbar__name { display: none; }
  .app { grid-template-columns: 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; padding: 6px; position: static; height: auto; }
  .rail__item { flex-direction: row; gap: 6px; padding: 8px 10px; }
  .rail__item--bottom { margin-top: 0; }
  .rail__icon { width: 18px; height: 18px; }
  .rail__item--new { padding: 8px 10px; }
  .rail__item--new .rail__icon { padding: 6px; }
  .tree { display: none; }
  .editor__pane { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
