/* doc-manage-system — 標準CSS（Tailwind不使用: CLAUDE.md の方針）
   Pencil デザイン（Japanese Modern）のトークンをそのまま移した。 */

:root {
  --bg: #f4f6f5;
  --surface: #fff;
  --surface-2: #ecf0ee;
  --ink: #15211e;
  --muted: #5c6b67;
  --faint: #8fa09b;
  --rule: #dce3e0;
  --rule-strong: #c3cfcb;
  --accent: #0e5b55;
  --accent-soft: #e2efec;
  --accent-ink: #fff;
  --amber: #7e5c12;
  --amber-soft: #f6eedc;
  --brick: #97392a;
  --brick-soft: #f7e8e4;
  --sidebar-bg: #0f1e1b;
  --sidebar-ink: #d9e4e1;
  --sidebar-muted: #7e948f;
  --sidebar-active: rgb(255 255 255 / 8%);

  --font-display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-ui: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --sidebar-w: 248px;
  --radius: 10px;
  --tabbar-h: 58px;
}

/* 起床直後のスマホ閲覧で眩しくないよう OS 設定に連動（トグルUIは作らない） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --surface: #161e1c;
    --surface-2: #1c2624;
    --ink: #e7edea;
    --muted: #96a5a1;
    --faint: #71827d;
    --rule: #293734;
    --rule-strong: #3a4a46;
    --accent: #5cc7ba;
    --accent-soft: #14312d;
    --accent-ink: #06201d;
    --amber: #d3a346;
    --amber-soft: #2c2412;
    --brick: #e0836f;
    --brick-soft: #2e1b16;
    --sidebar-bg: #0a110f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 0.18em; }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.45; margin: 0; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- アプリシェル ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 20px 0 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .logo { padding: 0 20px 14px; display: block; text-decoration: none; }
.sidebar .logo b { display: block; font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: #fff; letter-spacing: 0.5px; }
.sidebar .logo span { font-family: var(--font-mono); font-size: 9px; color: var(--sidebar-muted); letter-spacing: 0.5px; }

.sidebar nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 1px; }
.sidebar .navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  color: var(--sidebar-ink); text-decoration: none; font-size: 13px;
}
.sidebar .navitem:hover { background: rgb(255 255 255 / 5%); }
.sidebar .navitem[aria-current] { background: var(--sidebar-active); color: #fff; font-weight: 700; }
.sidebar .navitem .ic { width: 15px; text-align: center; opacity: 0.85; }

.sidebar .sect { padding: 14px 20px 6px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px; color: var(--sidebar-muted); }
.sidebar .projlist { padding: 0 10px; display: flex; flex-direction: column; gap: 1px; }
.sidebar .proj {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 10px; border-radius: 6px;
  color: var(--sidebar-ink); text-decoration: none; font-size: 12.5px;
}
.sidebar .proj:hover { background: rgb(255 255 255 / 5%); }
.sidebar .proj[aria-current] { background: var(--sidebar-active); color: #fff; }
.sidebar .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.sidebar .tree { padding: 6px 10px 0; display: flex; flex-direction: column; gap: 1px; }
.sidebar .tree a {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border-radius: 6px;
  color: var(--sidebar-ink); text-decoration: none; font-size: 12.5px;
}
.sidebar .tree a:hover { background: rgb(255 255 255 / 5%); }
.sidebar .tree a[aria-current] { background: var(--sidebar-active); color: #fff; }
.sidebar .tree a.drop-target { background: var(--accent); color: #fff; }
.sidebar .count { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--sidebar-muted); }

.main { flex: 1; min-width: 0; padding: 24px 36px 64px; }
.tabbar { display: none; }

/* ---------- 共通パーツ ---------- */

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 0; }
.page-head h1 { font-size: 26px; }
.page-head .sub { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; margin-bottom: 4px; }
.breadcrumb .sep { color: var(--faint); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 7px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: 13px; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--rule-strong); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-danger { color: var(--brick); border-color: var(--brick); background: var(--brick-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 11px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-ai { background: var(--amber-soft); color: var(--amber); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.empty { padding: 48px 24px; text-align: center; color: var(--faint); font-size: 13px; }
.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-err { background: var(--brick-soft); color: var(--brick); }

/* ---------- プロジェクト一覧 ---------- */

.projgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 14px; }
.projcard { display: flex; text-decoration: none; color: inherit; min-height: 108px; }
.projcard .stripe { width: 4px; flex: none; }
.projcard .body { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.projcard .name { font-size: 14.5px; font-weight: 700; }
.projcard .meta { display: flex; gap: 10px; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.projcard .upd { font-size: 11px; color: var(--faint); margin-top: auto; }

/* ---------- ファイル表 ---------- */

.filetable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.filetable thead th {
  text-align: left; padding: 9px 16px; background: var(--surface-2);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1px; font-weight: 500;
  color: var(--muted); border-bottom: 1px solid var(--rule-strong); white-space: nowrap;
}
.filetable thead th a { color: inherit; text-decoration: none; }
.filetable td { padding: 10px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.filetable tr:last-child td { border-bottom: 0; }
.filetable tr.selected td { background: var(--accent-soft); }
.filetable .name a { font-weight: 500; color: var(--ink); text-decoration: none; }
.filetable .name a:hover { color: var(--accent); }
.filetable .fname { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); }
.filetable .num { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.filetable .ic { width: 22px; text-align: center; }

.dropzone {
  margin-top: 16px; padding: 14px; border: 1.5px dashed var(--rule-strong);
  border-radius: var(--radius); text-align: center; color: var(--faint); font-size: 12px;
}
.dropzone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* hidden 属性は display 指定に負けるので、明示的に打ち消す */
[hidden] { display: none !important; }

.bulkbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 16px; border-radius: 8px; margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.bulkbar .n { font-weight: 700; color: var(--accent); font-size: 13px; }
.bulkbar .grow { flex: 1; }

/* ---------- 文書表示 ---------- */

.metaband { padding: 16px 20px; margin-bottom: 16px; }
.metaband .top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.metaband h1 { font-size: 22px; flex: 1; min-width: 240px; }
.metaband .badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.metaband .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.doclayout { display: flex; gap: 16px; align-items: flex-start; }
.doclayout .body { flex: 1; min-width: 0; padding: 28px 32px; }
.toc { width: 216px; flex: none; display: flex; flex-direction: column; gap: 2px; }
.toc .head { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1.5px; color: var(--muted); padding: 4px 10px; }
.toc a { display: block; padding: 6px 10px; border-radius: 6px; font-size: 12.5px; color: var(--muted); text-decoration: none; border-left: 2.5px solid var(--rule); }
.toc a:hover { background: var(--surface-2); color: var(--ink); }

.md { font-size: 14.5px; line-height: 1.95; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { font-family: var(--font-display); margin: 1.8em 0 0.6em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md h1:first-child, .md h2:first-child { margin-top: 0; }
.md p { margin: 0 0 1.1em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.md li { margin-bottom: 0.3em; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md pre { background: var(--surface-2); padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; }
.md code { font-family: var(--font-mono); font-size: 0.88em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 3px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 1.1em; padding: 2px 16px; border-left: 3px solid var(--rule-strong); color: var(--muted); }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; margin-bottom: 1.1em; }
.md th, .md td { border: 1px solid var(--rule); padding: 7px 10px; text-align: left; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }

.viewer-frame { width: 100%; height: 78vh; border: 0; border-radius: 8px; background: var(--surface-2); }
.image-view { text-align: center; padding: 24px; }
.image-view img { max-width: 100%; max-height: 72vh; border-radius: 8px; }

/* ---------- 検索・更新一覧 ---------- */

.searchbox {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--accent); margin-bottom: 14px;
}
.searchbox input { flex: 1; border: 0; background: none; font-family: var(--font-ui); font-size: 15px; color: var(--ink); }
.searchbox input:focus { outline: none; }
.searchbox .kbd { font-family: var(--font-mono); font-size: 11px; color: var(--faint); background: var(--surface-2); padding: 3px 8px; border-radius: 5px; }

.chips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 99px; font-size: 12px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--muted); text-decoration: none;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chips .grow { flex: 1; }
.chips .count { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

.hitlist .hit { padding: 13px 18px; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 5px; }
.hitlist .hit:last-child { border-bottom: 0; }
.hit .l1 { display: flex; align-items: center; gap: 10px; }
.hit .l1 a { font-size: 14px; font-weight: 700; color: var(--ink); text-decoration: none; }
.hit .l1 a:hover { color: var(--accent); }
.hit .l1 .when { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.hit .path { display: flex; align-items: center; gap: 7px; font-size: 11.5px; }
.hit .path a { color: var(--accent); }
.hit .ex { font-size: 12.5px; color: var(--muted); line-height: 1.7; }

.updlist .upd { display: flex; gap: 10px; align-items: flex-start; padding: 11px 16px; border-bottom: 1px solid var(--rule); }
.updlist .upd:last-child { border-bottom: 0; }
.updlist .upd.read { opacity: 0.58; }
.updlist .unread { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; margin-top: 8px; }
.updlist .upd.read .unread { background: var(--rule-strong); }
.updlist .col { flex: 1; min-width: 0; }
.updlist .t { font-size: 13.5px; font-weight: 700; color: var(--ink); text-decoration: none; }
.updlist .upd.read .t { font-weight: 400; }
.updlist .p { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--faint); }
.updlist .r { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.daygroup { font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px; color: var(--muted); margin: 16px 0 6px; }
.daygroup:first-child { margin-top: 0; }

.recent { margin-top: 24px; }
.recent .head { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 8px; }
.recent .row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--rule); }
.recent .row:last-child { border-bottom: 0; }
.recent .row a { font-size: 13px; color: var(--ink); text-decoration: none; }
.recent .row .path { font-size: 11px; color: var(--faint); }
.recent .row .when { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

/* ---------- フォーム・ダイアログ ---------- */

.form { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--rule-strong); border-radius: 7px;
  background: var(--surface); color: var(--ink); font-family: var(--font-ui); font-size: 14px;
}
.field textarea { min-height: 90px; resize: vertical; }

dialog {
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--ink); max-width: 480px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog .dlg-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 17px; }
dialog p { margin: 0; font-size: 13.5px; color: var(--muted); }
dialog .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.editor { display: flex; flex-direction: column; gap: 12px; }
.editor textarea {
  width: 100%; min-height: 62vh; padding: 20px 22px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.85; resize: vertical;
}

.diff { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; overflow-x: auto; }
.diff .ln { display: block; padding: 1px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff .add { background: var(--accent-soft); color: var(--accent); }
.diff .del { background: var(--brick-soft); color: var(--brick); }
.diff .same { color: var(--muted); }

/* ---------- モバイル ---------- */

@media (width <= 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.18s ease;
    box-shadow: 0 0 40px rgb(0 0 0 / 30%);
  }
  .sidebar.open { transform: none; }
  .main { padding: 16px 16px calc(var(--tabbar-h) + 20px); }
  .page-head h1 { font-size: 20px; }

  .tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; height: var(--tabbar-h); z-index: 30;
    background: var(--surface); border-top: 1px solid var(--rule); padding: 6px 12px 10px;
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; text-decoration: none; color: var(--faint); font-size: 10px;
  }
  .tabbar a[aria-current] { color: var(--accent); font-weight: 700; }
  .tabbar .ic { font-size: 17px; line-height: 1; }

  .doclayout { flex-direction: column; }
  .doclayout .body { padding: 18px; width: 100%; }
  .toc { width: 100%; }
  .filetable .hide-sp { display: none; }
  .metaband h1 { font-size: 19px; }
  .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 39; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 公開ページ（Phase 4）でナビを消すための最小限のフック */
.public .sidebar, .public .tabbar { display: none; }
.public .main { padding: 32px 24px 64px; max-width: 900px; margin: 0 auto; }
