/*
Theme Name: PB-HAL Wiki
Theme URI: https://wiki.pb-hal.net
Author: 株式会社ハル
Description: 社内マニュアル特化のオリジナルテーマ（業務バインダー意匠 / 階層索引ナビ / 追従TOC / 手順ステップ / 全文検索 / パンくず / 印刷対応）。Cocoon非依存。
Version: 0.3.0
Requires at least: 6.0
Requires PHP: 8.2
Text Domain: pb-hal-wiki
*/

/* ============================================================
   Tokens
   ============================================================ */
:root {
  --ink:#1b2733; --ink-soft:#5a6b7b; --paper:#ffffff;
  --wash:#eef2f5; --wash-2:#f7f9fb; --line:#dde5ec; --line-strong:#c7d3dc;
  --brand:#0d5c75; --brand-ink:#0a4658; --brand-tint:#e3eef2;
  --accent:#c9772d; --accent-tint:#f6e9dc;
  --warn:#b5480f; --warn-bg:#fbeee6; --ok:#2f6b3f; --ok-bg:#e8f2ea;
  --radius:8px; --radius-sm:5px; --shell-max:1360px; --side-w:264px; --toc-w:236px;
  --font-jp:"Hiragino Kaku Gothic ProN","Hiragino Sans","Noto Sans JP","Yu Gothic",Meiryo,sans-serif;
  --font-mono:"SFMono-Regular",Menlo,Consolas,"Liberation Mono",monospace;
  --topbar-h:56px;
  --read:780px; --list-max:880px;
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-jp);
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  background: var(--wash);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; }
a { color: var(--brand-ink); }

/* Accessibility helpers */
.screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--brand); color: #fff;
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
  font-size: 0.9rem; text-decoration: none;
}
.skip-link:focus { left: 8px; top: 8px; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 2px;
}
#main:focus { outline: none; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex: none; }
.brand-mark {
  font-family: var(--font-mono); font-weight: 700; letter-spacing: 0.06em;
  background: var(--brand); color: #fff; padding: 4px 8px;
  border-radius: var(--radius-sm); font-size: 0.82rem;
}
.brand-name { font-weight: 700; font-size: 0.98rem; letter-spacing: 0.02em; }
.topbar-search { flex: 1 1 auto; display: flex; justify-content: flex-end; min-width: 0; }
.print-btn {
  flex: none; border: 1px solid var(--line-strong); background: var(--paper);
  color: var(--ink-soft); padding: 7px 13px; border-radius: var(--radius-sm);
  font: inherit; font-size: 0.82rem; cursor: pointer;
}
.print-btn:hover { border-color: var(--brand); color: var(--brand); }

.nav-toggle {
  display: none; flex: none; width: 40px; height: 36px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--paper); cursor: pointer; padding: 0;
  align-items: center; justify-content: center; flex-direction: column; gap: 4px;
}
.nav-toggle-bar { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }

/* Search form */
.search-form { display: flex; align-items: center; width: 100%; max-width: 420px; }
.search-form label { flex: 1; min-width: 0; margin: 0; }
.search-field {
  width: 100%; min-width: 0;
  border: 1px solid var(--line-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 7px 12px; font: inherit; font-size: 0.9rem;
  background: var(--wash-2); color: var(--ink);
}
.search-field::placeholder { color: var(--ink-soft); }
.search-field:focus { outline: none; border-color: var(--brand); background: #fff; }
.search-submit {
  flex: none; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 7px 15px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.search-submit:hover { background: var(--brand-ink); border-color: var(--brand-ink); }

/* ============================================================
   App shell (3-column binder)
   ============================================================ */
.app-shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  align-items: start;
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(27,39,51,0.06);
}
body.has-toc .app-shell {
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--toc-w);
}

/* ---- Left binder index nav ---- */
.side-nav { align-self: stretch; min-width: 0; }
.side-inner {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 22px 14px 48px;
  border-right: 1px solid var(--line);
}
.side-title {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-soft);
  margin: 0 0 12px; padding: 0 10px 10px;
  border-bottom: 1px solid var(--line);
}
.cat-tree, .cat-tree ul { list-style: none; margin: 0; padding: 0; }
.cat-tree li { margin: 1px 0; }
.cat-tree a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 6px 10px 6px 11px;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-soft); font-size: 0.9rem; line-height: 1.4;
  text-decoration: none;
}
.cat-tree a:hover { background: var(--wash-2); color: var(--ink); }
.cat-count {
  flex: none;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-soft);
  background: var(--wash); border-radius: 10px;
  padding: 0 7px; min-width: 1.5em; text-align: center;
}
/* nested levels: indent + hairline */
.cat-tree ul { margin-left: 11px; padding-left: 4px; border-left: 1px solid var(--line); }
/* current location: thick amber binder tab + bold (signature #1) */
.cat-tree .current-cat > a {
  border-left-color: var(--accent);
  background: var(--accent-tint);
  color: var(--ink); font-weight: 700;
}
.cat-tree .current-cat > a .cat-count { background: #fff; color: var(--accent); }
.cat-tree .current-cat-ancestor > a { color: var(--ink); font-weight: 600; }

.nav-scrim { display: none; }

/* ============================================================
   Content column
   ============================================================ */
.content { padding: 28px 40px 96px; min-width: 0; }
.content-home { padding: 40px 40px 96px; }

/* reading width for document / list templates */
.content > .crumbs,
.content > .list-head,
.content > .doc-list,
.content > .related,
.content > .empty-state,
.content > .navigation { max-width: var(--list-max); }
.content > .doc { max-width: var(--read); }

/* ---- Breadcrumbs (ledger utility) ---- */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.75rem; color: var(--ink-soft);
  margin: 0 0 22px;
}
.crumbs a { color: var(--ink-soft); text-decoration: none; }
.crumbs a:hover { color: var(--brand); text-decoration: underline; }
.crumbs .sep { color: var(--line-strong); }
.crumbs [aria-current="page"] { color: var(--ink); font-weight: 600; }

/* ============================================================
   Document (single / page)
   ============================================================ */
.doc-head { margin: 0 0 26px; padding-bottom: 20px; border-bottom: 2px solid var(--line-strong); }
.doc-title { font-size: 1.85rem; font-weight: 700; line-height: 1.3; letter-spacing: -0.01em; margin: 0 0 14px; }
.doc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.meta-item { font-family: var(--font-mono); font-size: 0.76rem; color: var(--ink-soft); }
.meta-updated { display: inline-flex; align-items: center; gap: 6px; }
.meta-cat {
  background: var(--brand-tint); color: var(--brand-ink);
  padding: 3px 11px; border-radius: 20px; text-decoration: none; font-weight: 600;
}
.meta-cat:hover { background: var(--brand); color: #fff; }
.doc-thumb { margin: 0 0 24px; }
.doc-thumb img { border: 1px solid var(--line); border-radius: var(--radius-sm); }

/* inline TOC (mobile / narrow) */
.toc-inline {
  display: none;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--wash-2); margin: 0 0 28px; padding: 2px 6px;
}
.toc-inline summary {
  cursor: pointer; padding: 10px;
  font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-soft);
}
.toc-inline-list { list-style: none; margin: 0; padding: 2px 0 8px; }
.toc-inline-list a { display: block; padding: 4px 12px; font-size: 0.9rem; color: var(--brand-ink); text-decoration: none; }
.toc-inline-list a:hover { text-decoration: underline; }
.toc-inline-list li.lvl-3 a { padding-left: 28px; font-size: 0.85rem; color: var(--ink-soft); }

/* ---- doc body typography ---- */
.doc-body { font-size: 1rem; }
.doc-body > *:first-child { margin-top: 0; }
.doc-body p { margin: 0 0 1.15em; }
.doc-body h2 {
  font-size: 1.3rem; font-weight: 700; line-height: 1.4; letter-spacing: -0.005em;
  margin: 2.1em 0 0.8em; padding-bottom: 8px; border-bottom: 1px solid var(--line-strong);
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.doc-body h3 {
  font-size: 1.08rem; font-weight: 700; line-height: 1.45; margin: 1.8em 0 0.6em;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.doc-body h4 { font-size: 1rem; font-weight: 700; margin: 1.5em 0 0.5em; }
.doc-body a { color: var(--brand-ink); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--line-strong); word-break: break-word; }
.doc-body a:hover { text-decoration-color: var(--brand); }
.doc-body strong { font-weight: 700; }
.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.doc-body figure { margin: 1.5em 0; }
.doc-body figcaption { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-soft); margin-top: 6px; text-align: center; }
.doc-body img { border-radius: var(--radius-sm); }
.doc-body .wp-block-image img { border: 1px solid var(--line); }
.doc-body video { width: 100%; max-width: 100%; border-radius: var(--radius-sm); background: #000; }

/* bullets */
.doc-body ul { margin: 1.15em 0; padding-left: 1.4em; }
.doc-body ul li { margin: 0.3em 0; }

/* ---- Procedure steps: number badges (signature #2) ---- */
.doc-body ol { counter-reset: pbstep; list-style: none; margin: 1.5em 0; padding-left: 0; }
.doc-body ol > li {
  counter-increment: pbstep;
  position: relative;
  padding-left: 3.25rem;
  min-height: 2rem;
  margin: 0 0 0.95em;
}
.doc-body ol > li::before {
  content: counter(pbstep);
  position: absolute; left: 0; top: 0.05em;
  width: 2rem; height: 2rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  font-family: var(--font-mono); font-weight: 700; font-size: 0.9rem;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}

/* ---- Callout (blockquote = メモ) ---- */
.doc-body blockquote {
  margin: 1.5em 0; padding: 14px 18px;
  border-left: 4px solid var(--brand); background: var(--brand-tint);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--ink);
}
.doc-body blockquote > *:last-child { margin-bottom: 0; }

/* ---- Code ---- */
.doc-body code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: var(--wash); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 4px;
}
.doc-body pre {
  background: var(--wash-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; overflow-x: auto; margin: 1.5em 0;
  font-family: var(--font-mono); font-size: 0.86rem; line-height: 1.6;
}
.doc-body pre code { background: none; border: 0; padding: 0; font-size: inherit; }

/* ---- Tables (scroll-safe) ---- */
.doc-body .wp-block-table { overflow-x: auto; margin: 1.5em 0; }
.doc-body table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.doc-body thead th, .doc-body table th { background: var(--wash); font-weight: 700; }

/* ---- doc footer (tags) ---- */
.doc-foot { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.doc-foot-label { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); }
.doc-tags a { display: inline-block; margin: 0 6px 6px 0; padding: 3px 10px; background: var(--wash); border-radius: 4px; font-size: 0.8rem; color: var(--ink-soft); text-decoration: none; }
.doc-tags a:hover { background: var(--accent-tint); color: var(--warn); }

/* ---- Related ---- */
.related { margin-top: 48px; padding-top: 24px; border-top: 2px solid var(--line-strong); }
.related-title { font-size: 1.1rem; font-weight: 700; margin: 0 0 10px; }

/* ============================================================
   Right TOC rail (signature-adjacent; scroll-spy)
   ============================================================ */
.toc-rail { align-self: stretch; min-width: 0; }
.toc {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto; padding: 26px 18px 40px;
}
.toc-title {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-soft); margin: 0 0 12px; padding-left: 12px;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block; padding: 4px 12px; border-left: 2px solid var(--line);
  color: var(--ink-soft); font-size: 0.83rem; line-height: 1.5; text-decoration: none;
}
.toc a:hover { color: var(--ink); border-left-color: var(--line-strong); }
.toc a.active { color: var(--brand-ink); border-left-color: var(--brand); font-weight: 600; background: var(--brand-tint); }
.toc li.lvl-3 a { padding-left: 24px; font-size: 0.8rem; }

/* ============================================================
   Lists (index / category / search / related)
   ============================================================ */
.list-head { margin: 0 0 22px; padding-bottom: 16px; border-bottom: 2px solid var(--line-strong); }
.list-title { font-size: 1.5rem; font-weight: 700; margin: 0; line-height: 1.35; }
.search-term { color: var(--brand-ink); }
.search-count { font-family: var(--font-mono); font-size: 0.95rem; color: var(--ink-soft); }
.cat-description { margin-top: 12px; color: var(--ink-soft); font-size: 0.95rem; }

.subcat-chips { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.subcat-chips li { margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; background: var(--wash); border: 1px solid var(--line);
  border-radius: 20px; color: var(--ink); text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.chip:hover { border-color: var(--brand); background: var(--brand-tint); color: var(--brand-ink); }
.chip-count { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft); font-weight: 400; }

.doc-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.doc-card {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 12px 8px 12px 14px;
  border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.doc-card:hover { background: var(--wash-2); border-left-color: var(--brand); }
.doc-card-link { font-size: 1rem; font-weight: 600; color: var(--ink); text-decoration: none; line-height: 1.5; }
.doc-card-link:hover { color: var(--brand-ink); }
.doc-card-date { flex: none; font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-soft); white-space: nowrap; }

.empty-state { color: var(--ink-soft); }
.empty-state .search-form { max-width: 420px; margin-top: 18px; }

/* pagination */
.navigation.pagination { margin-top: 32px; }
.navigation.pagination .nav-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 0.85rem; }
.navigation.pagination a,
.navigation.pagination .current {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  text-decoration: none; color: var(--ink);
}
.navigation.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.navigation.pagination a:hover { border-color: var(--brand); color: var(--brand); }

/* ============================================================
   Front page
   ============================================================ */
.home-hero { max-width: 720px; margin: 4px 0 44px; }
.home-title { font-size: 2rem; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 12px; }
.home-lead { color: var(--ink-soft); font-size: 1.02rem; line-height: 1.8; margin: 0 0 24px; max-width: 62ch; }
.home-search .search-form { max-width: 560px; }
.home-search .search-field { padding: 12px 16px; font-size: 1rem; }
.home-search .search-submit { padding: 12px 22px; font-size: 0.95rem; }

.home-section { margin-top: 44px; }
.home-section-title { font-size: 1.15rem; font-weight: 700; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.cat-tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.cat-tiles li { margin: 0; }
.cat-tile-link {
  display: block; height: 100%; padding: 16px 18px;
  border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm); background: var(--paper);
  text-decoration: none; color: var(--ink);
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
.cat-tile-link:hover { box-shadow: 0 4px 16px rgba(27,39,51,0.08); border-left-color: var(--accent); }
.cat-tile-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.cat-tile-name { font-weight: 700; font-size: 1rem; }
.cat-tile-count { flex: none; font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-soft); background: var(--wash); padding: 1px 8px; border-radius: 10px; }
.cat-tile-subs { display: block; font-size: 0.8rem; color: var(--ink-soft); line-height: 1.6; }

/* ============================================================
   Footer
   ============================================================ */
.site-foot { border-top: 1px solid var(--line); padding: 24px 20px; text-align: center; }
.site-foot p { margin: 0; font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-soft); letter-spacing: 0.03em; }

/* ============================================================
   Responsive
   ============================================================ */
/* right TOC collapses into inline details */
@media (max-width: 1200px) {
  .toc-rail { display: none; }
  body.has-toc .app-shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .toc-inline { display: block; }
}

/* left nav becomes a drawer */
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .print-btn { display: none; }
  .app-shell,
  body.has-toc .app-shell { display: block; }
  .content, .content-home { padding: 24px 20px 72px; }

  .side-nav {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(84vw, 320px); z-index: 60;
    background: var(--paper);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    box-shadow: 2px 0 18px rgba(15,23,32,0.18);
  }
  .side-inner { position: static; max-height: none; height: 100%; border-right: 0; padding-top: 18px; }
  body.nav-open .side-nav { transform: translateX(0); }

  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(15,23,32,0.45);
    opacity: 0; visibility: hidden; transition: opacity 0.22s ease, visibility 0.22s ease;
  }
  body.nav-open .nav-scrim { opacity: 1; visibility: visible; }
}

@media (max-width: 560px) {
  .brand-name { display: none; }
  .topbar { gap: 10px; padding: 0 14px; }
  .search-field { font-size: 0.85rem; }
  .doc-title { font-size: 1.5rem; }
  .home-title { font-size: 1.6rem; }
  .list-title { font-size: 1.25rem; }
  .doc-card { flex-direction: column; gap: 4px; }
}

/* ============================================================
   Motion / print
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body { background: #fff; color: #000; }
  .topbar, .side-nav, .nav-scrim, .toc-rail, .toc-inline,
  .print-btn, .nav-toggle, .site-foot, .skip-link,
  .related, .navigation.pagination { display: none !important; }
  .app-shell,
  body.has-toc .app-shell { display: block; max-width: none; margin: 0; box-shadow: none; background: #fff; }
  .content { padding: 0; }
  .content > .doc { max-width: none; }
  .doc-body a { color: #000 !important; text-decoration: underline; }
  .doc-body h2 { border-bottom-color: #000; }
  .doc-body ol > li::before { background: #000 !important; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ============================================================
   未ログイン（認証ページ）: アプリ枠を出さずロゴ＋フォームのみ
   ============================================================ */
.topbar--minimal { justify-content: center; }
.topbar--minimal .brand { margin: 0; }
body.auth-view { background: var(--wash); }
.app-shell--auth {
  display: block;
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  background: transparent;
  box-shadow: none;
}
.app-shell--auth .content {
  max-width: none;
  margin: 0;
  padding: 0;
}
