/* =============================================================================
 * kireinavi-docs — docs-theme.css
 *
 * docsify vue.css をベースに、ARB 水準の navigation / reading UX を実装。
 * Phase 構成は CLAUDE.md § ナビゲーション仕様 を参照。
 *
 * 依存: docsify@4 vue.css (先にロード)
 * ============================================================================= */


/* =============================================================================
 * Phase F: Polish — 全画面サイズ共通の読みやすさ改善
 * ============================================================================= */

html {
  scroll-behavior: smooth;
}

/* アンカー遷移時、固定ヘッダーや hamburger に見出しが隠れないよう余白確保 */
.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  scroll-margin-top: 80px;
}

/* prefers-reduced-motion: すべての animation / transition を抑制 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* =============================================================================
 * Phase B: Sidebar — collapsible + アクティブ強調
 * docsify-sidebar-collapse plugin の class を前提にスタイリング
 * ============================================================================= */

/* 現在ページ (active link): 青帯 + 背景 + bold で明確化 */
.sidebar-nav li.active > a {
  background: #ddf4ff;
  color: #0969da;
  font-weight: 600;
  border-left: 3px solid #0969da;
  padding-left: 9px; /* デフォルト 12px から 3px border を引いた値 */
}

.sidebar-nav li.active > a:hover {
  background: #b6e3ff;
}

/* カテゴリ折り畳み: ▸ / ▾ アイコン */
.sidebar-nav .section-link.collapse::before,
.sidebar-nav p.section-title.collapse::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  color: #656d76;
  transition: transform 0.2s ease-out;
}
.sidebar-nav .open > .section-link.collapse::before,
.sidebar-nav .open > p.section-title.collapse::before {
  transform: rotate(90deg);
}

/* ネスト (サブカテゴリ): 左側に薄いボーダーで階層感 */
.sidebar-nav ul.app-sub-sidebar {
  border-left: 2px solid #eaeef2;
  margin-left: 12px;
  padding-left: 4px;
}


/* =============================================================================
 * Phase A: SP ハンバーガー — backdrop / body lock / X morph / animation
 * ============================================================================= */

/* Hamburger button: docsify default の位置を上書きし、投資家グレードのフローティング */
@media (max-width: 768px) {
  .sidebar-toggle {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    bottom: auto;
    width: 44px;
    height: 44px;
    padding: 0;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d0d7de;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001; /* backdrop (998) + sidebar (999) より上 */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
  }

  .sidebar-toggle:hover,
  .sidebar-toggle:active {
    background: #f6f8fa;
  }

  .sidebar-toggle:focus-visible {
    outline: 2px solid #0969da;
    outline-offset: 2px;
  }

  .sidebar-toggle .sidebar-toggle-button {
    position: static;
    margin: 0;
  }

  /* 3 本線の基本スタイル + transition */
  .sidebar-toggle .sidebar-toggle-button span {
    background-color: #24292f;
    height: 2px;
    border-radius: 1px;
    transition: transform 0.25s ease-out, opacity 0.15s ease-out, background-color 0.15s ease;
    transform-origin: center;
  }

  /* Sidebar z-index: backdrop より上 */
  .sidebar {
    z-index: 999;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Backdrop overlay — sidebar 開いている間、body::before で半透明レイヤー */
  body:not(.close)::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    animation: docs-backdrop-fade-in 0.25s ease-out;
    pointer-events: auto;
  }

  /* backdrop-filter: blur はサポート環境のみ (iOS 9+, Chrome 76+) */
  @supports (backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px)) {
    body:not(.close)::before {
      -webkit-backdrop-filter: blur(2px);
      backdrop-filter: blur(2px);
    }
  }

  @keyframes docs-backdrop-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  /* Body scroll lock: sidebar 開いている間は背景スクロール禁止 */
  body:not(.close) {
    overflow: hidden;
  }

  /* Hamburger → X morph: 1 本目と 3 本目が 45°/-45° 回転、2 本目が透明化 */
  body:not(.close) .sidebar-toggle .sidebar-toggle-button span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  body:not(.close) .sidebar-toggle .sidebar-toggle-button span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
  }
  body:not(.close) .sidebar-toggle .sidebar-toggle-button span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* Sidebar 開いた時、ハンバーガーボタン背景を反転 (開閉状態の視覚化) */
  body:not(.close) .sidebar-toggle {
    background: #24292f;
    border-color: #24292f;
  }
  body:not(.close) .sidebar-toggle .sidebar-toggle-button span {
    background-color: #fff;
  }

  /* Content top padding: hamburger とコンテンツ見出しの重複回避 */
  .content {
    padding-top: max(56px, calc(env(safe-area-inset-top) + 44px));
  }
}

/* PC (769px+): hamburger を完全非表示 (サイドバー常時表示のため不要) */
@media (min-width: 769px) {
  .sidebar-toggle {
    display: none !important;
  }
}


/* =============================================================================
 * Phase C: 前/次ページ Pagination
 * docsify-pagination plugin スタイリング
 * ============================================================================= */

.docsify-pagination-container {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid #d0d7de;
}
.docsify-pagination-container .pagination-item-label {
  color: #656d76;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.docsify-pagination-container .pagination-item-title {
  color: #0969da;
  font-weight: 600;
  font-size: 15px;
}
.docsify-pagination-container a:hover .pagination-item-title {
  text-decoration: underline;
}


/* =============================================================================
 * Phase D-1: 右側 TOC (1440px+、mermaid 衝突回避のため content 幅確保)
 * ============================================================================= */

#docs-toc {
  display: none; /* default は非表示、JS が breakpoint で切り替え */
}

@media (min-width: 1440px) {
  #docs-toc {
    display: block;
    position: fixed;
    top: 80px;
    right: 24px;
    width: 200px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    border-left: 1px solid #eaeef2;
    z-index: 10;
  }

  .docs-toc-label {
    font-weight: 600;
    font-size: 11px;
    color: #656d76;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    text-transform: uppercase;
  }

  #docs-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  #docs-toc li {
    margin: 0;
    padding: 0;
  }

  #docs-toc .toc-h3 {
    padding-left: 12px;
  }

  #docs-toc a {
    color: #656d76;
    text-decoration: none;
    display: block;
    padding: 4px 8px;
    border-left: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
  }

  #docs-toc a:hover {
    color: #0969da;
  }

  #docs-toc a.active {
    color: #0969da;
    font-weight: 600;
    border-left-color: #0969da;
    background: #ddf4ff;
  }
}


/* =============================================================================
 * Phase D-2: Back-to-top フローティングボタン
 * ============================================================================= */

.back-to-top {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  right: max(24px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #24292f;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 997;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  background: #0969da;
  transform: translateY(-2px);
}
.back-to-top:focus-visible {
  outline: 2px solid #0969da;
  outline-offset: 2px;
}


/* =============================================================================
 * Phase D-3: リーディング進捗バー (上部固定)
 * ============================================================================= */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #0969da, #58a6ff);
  z-index: 1002;
  width: 0%;
  transition: width 0.1s ease-out;
  pointer-events: none;
}


/* =============================================================================
 * 戻るボタン: 各ページ上部の「← ドキュメント一覧に戻る」
 * ============================================================================= */

.back-to-list {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #656d76;
  font-size: 13px;
  text-decoration: none;
  margin-bottom: 16px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.back-to-list:hover {
  background: #eaeef2;
  color: #0969da;
  border-color: #0969da;
}
.back-to-list:focus-visible {
  outline: 2px solid #0969da;
  outline-offset: 2px;
}
