/* === リセットとベース === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
                 "Noto Sans JP", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background: #fff;
}

/* === 3ペインレイアウト === */
#page-root { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* 上部タブバー */
#topbar {
    display: flex; gap: 0; background: #2c3e50;
    flex-shrink: 0; border-bottom: 1px solid #1a252f;
    align-items: stretch;
    /* H10 (dev45): 幅が足りないとき右端のメタリンクが画面外に切れて到達不能に
       なるのを防ぐ（メタリンクの絶対配置をやめて通常フローにしたため）。
       折り返して 2 段目に送る。

       🔴 ここに overflow(-x) を指定してはいけない: `.dropdown-menu` は
       `position: absolute; top: 100%` で topbar の**下**に出るため、
       overflow を visible 以外にすると（片軸だけ指定しても CSS 仕様で
       もう一方が auto になる）**ドロップダウンが topbar の高さでクリップされて
       開かなくなる**。dev45 で実際に一度この不具合を出した。 */
    flex-wrap: wrap;
    position: relative;  /* .dropdown-menu / 将来の絶対配置の基準 */
}
#topbar .home-link {
    display: flex; align-items: center; padding: 0 16px;
    color: #ecf0f1; text-decoration: none; font-weight: 600;
    font-size: 14px; border-right: 1px solid #3d566e; white-space: nowrap;
}
#topbar .home-link:hover { background: #34495e; }
/* 右端の補助リンク群（品質レポート一覧・横断指摘一覧等）。目立たない控えめなスタイル。
   H10 (dev45): 個々のリンクを position: absolute; right: 0 で配置すると
   リンクが 2 本以上のとき全部が同じ座標に重なって判読不能になる（dev12 当時は
   1 本だけだったため露見しなかった）。リンク群を 1 つのコンテナに入れ、
   margin-left: auto で通常フローのまま右端に寄せる（#topbar は display: flex）。
   絶対配置をやめたことで、タブが増えたときにタブの上へ被る潜在バグも解消される。 */
#topbar .meta-links {
    display: flex; margin-left: auto; align-items: stretch;
}
#topbar .meta-link {
    display: flex; align-items: center; padding: 0 14px;
    color: #95a5a6; text-decoration: none;
    font-size: 12px; white-space: nowrap;
    border-left: 1px solid #3d566e;
}
#topbar .meta-link:hover { color: #ecf0f1; background: #34495e; }
/* 生成レポート表示中はリンクを薄く表示（クリック可能だが現在地表示） */
#topbar .meta-link.active { color: #ecf0f1; background: #34495e; }
/* ページフッタ（H12・dev45）。トップページ (index.html) にのみ出す。
   個別ドキュメントページは本文だけを見せたいので付けない（`{footer}` が空文字）。 */
.page-footer {
    display: flex; align-items: center; gap: 16px;
    max-width: 1000px; margin: 48px auto 0; padding: 20px 40px 32px;
    border-top: 1px solid #e1e4e8;
    color: #6a737d; font-size: 13px; line-height: 1.7;
}
.page-footer .footer-logo {
    width: 96px; height: auto; flex-shrink: 0;
}
/* ライセンス行と帰属行を縦に積む（v1.0-dev47 patch） */
.page-footer .footer-text {
    display: flex; flex-direction: column; gap: 2px;
}
.page-footer p { margin: 0; }
.page-footer a { color: #2c3e50; text-decoration: none; font-weight: 600; }
.page-footer a:hover { text-decoration: underline; }
@media (max-width: 600px) {
    .page-footer { flex-direction: column; align-items: flex-start; gap: 12px; }
}
#topbar .tab {
    padding: 10px 20px; color: #bdc3c7; cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    font-size: 13px; white-space: nowrap; user-select: none;
}
#topbar .tab:hover { color: #ecf0f1; background: #34495e; }
#topbar .tab.active {
    color: #fff; background: #34495e;
    border-bottom-color: #3498db;
}
/* ドロップダウン */
#topbar .dropdown {
    position: relative;
}
#topbar .dropdown-toggle {
    padding: 10px 20px; color: #bdc3c7; cursor: pointer;
    font-size: 13px; white-space: nowrap; user-select: none;
    transition: color 0.15s, background 0.15s;
}
#topbar .dropdown-toggle:hover,
#topbar .dropdown.open .dropdown-toggle { color: #ecf0f1; background: #34495e; }
#topbar .dropdown-toggle.has-active { color: #fff; background: #34495e; border-bottom: 3px solid #3498db; }
#topbar .dropdown-menu {
    display: none; position: absolute; top: 100%; left: 0;
    background: #2c3e50; min-width: 220px; z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); border-radius: 0 0 4px 4px;
}
#topbar .dropdown.open .dropdown-menu { display: block; }
#topbar .dropdown-menu .tab {
    display: block; padding: 8px 20px; border-bottom: none;
}

/* メインレイアウト */
#main-layout { display: flex; flex: 1; overflow: hidden; }

/* 左サイドバー */
#sidebar {
    width: 320px; min-width: 180px; max-width: 50vw;
    display: flex; flex-direction: column;
    border-right: 1px solid #ddd; background: #fafbfc;
    flex-shrink: 0;
}
#filter-box {
    padding: 8px; border-bottom: 1px solid #e8e8e8;
    background: #f5f6f8;
}
#filter-input {
    width: 100%; padding: 6px 10px; border: 1px solid #ccc;
    border-radius: 4px; font-size: 13px; outline: none;
}
#filter-input:focus { border-color: #3498db; box-shadow: 0 0 0 2px rgba(52,152,219,0.15); }
#nav-tree { flex: 1; overflow-y: auto; padding: 4px 0; font-size: 13px; }

/* リサイザー */
#resizer {
    width: 5px; cursor: col-resize; background: transparent;
    flex-shrink: 0; transition: background 0.15s;
}
#resizer:hover, #resizer.dragging { background: #3498db; }

/* メインコンテンツ */
#content {
    flex: 1; overflow-y: auto; padding: 24px 40px;
    min-width: 0;
}

/* === ツリーナビゲーション === */
.tree-item { user-select: none; }

/* ディレクトリノード */
.tree-dir > .tree-label {
    display: flex; align-items: center; padding: 3px 8px;
    cursor: pointer; gap: 4px; border-radius: 3px;
}
.tree-dir > .tree-label:hover { background: #e8eaed; }
.tree-dir > .tree-label .arrow {
    display: inline-block; width: 14px; font-size: 10px;
    transition: transform 0.12s; color: #666; flex-shrink: 0;
    text-align: center;
}
.tree-dir.expanded > .tree-label .arrow { transform: rotate(90deg); }
.tree-dir > .tree-label .dir-icon { margin-right: 4px; font-size: 14px; }
.tree-dir > .tree-label .dir-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-dir > .tree-label .dir-name.has-doc { color: #2980b9; cursor: pointer; }
.tree-dir > .tree-label .dir-name.has-doc:hover { text-decoration: underline; }
.tree-dir > .tree-children { display: none; padding-left: 16px; }
.tree-dir.expanded > .tree-children { display: block; }

/* ファイルノード */
.tree-file {
    display: block; padding: 3px 8px 3px 30px;
    cursor: pointer; border-radius: 3px; text-decoration: none; color: inherit;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-file:hover { background: #e8eaed; }

/* フラットリストアイテム */
.nav-list-item {
    display: block; padding: 6px 12px;
    cursor: pointer; border-radius: 3px; text-decoration: none; color: inherit;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-list-item:hover { background: #e8eaed; }

/* アクティブ状態 */
.tree-file.active, .tree-dir > .tree-label.active,
.nav-list-item.active { background: #d4e6f7; color: #1a5276; }

/* フィルタで非表示 */
.tree-hidden { display: none !important; }

/* === ドキュメントコンテンツ === */
.doc-content { max-width: 960px; }
.doc-content h1 {
    font-size: 1.6em; margin: 0 0 0.5em; padding-bottom: 0.3em;
    border-bottom: 2px solid #e8e8e8; color: #2c3e50;
}
.doc-content h2 {
    font-size: 1.3em; margin: 1.2em 0 0.4em; padding-bottom: 0.2em;
    border-bottom: 1px solid #eee; color: #34495e;
}
.doc-content h3 { font-size: 1.1em; margin: 1em 0 0.3em; color: #34495e; }
.doc-content h4 { font-size: 1em; margin: 0.8em 0 0.2em; color: #555; }
.doc-content p { margin: 0.6em 0; }
.doc-content ul, .doc-content ol { margin: 0.5em 0; padding-left: 1.5em; }
.doc-content li { margin: 0.2em 0; }
.doc-content blockquote {
    margin: 0.8em 0; padding: 0.5em 1em;
    border-left: 4px solid #3498db; background: #f8f9fa; color: #555;
}

/* テーブル */
.doc-content table {
    border-collapse: collapse; width: 100%; margin: 1em 0;
    font-size: 13px;
}
.doc-content th, .doc-content td {
    border: 1px solid #ddd; padding: 8px 12px; text-align: left;
}
.doc-content th { background: #f5f6f8; font-weight: 600; white-space: nowrap; }
.doc-content tr:nth-child(even) { background: #fafbfc; }

/* コード */
.doc-content code {
    background: #f0f2f4; padding: 2px 6px; border-radius: 3px;
    font-size: 0.9em; font-family: "SF Mono", "Fira Code", Consolas, monospace;
}
.doc-content pre {
    background: #f8f9fa; padding: 16px; border-radius: 6px;
    overflow-x: auto; margin: 1em 0; border: 1px solid #e8e8e8;
}
.doc-content pre code { background: none; padding: 0; font-size: 13px; }

/* リンク */
.doc-content a { color: #2980b9; text-decoration: none; }
.doc-content a:hover { text-decoration: underline; color: #1a5276; }

/* Mermaid 図（ズーム対応） */
.mermaid-container {
    position: relative; margin: 1em 0; border: 1px solid #e0e0e0;
    border-radius: 6px; overflow: hidden; background: #fafbfc;
}
.mermaid-viewport {
    overflow: hidden; cursor: grab; min-height: 100px;
}
.mermaid-viewport.dragging { cursor: grabbing; }
.mermaid-viewport .mermaid {
    background: #fff; text-align: center; padding: 16px;
    transform-origin: 0 0; display: inline-block; min-width: 100%;
}
.mermaid-controls {
    position: absolute; top: 8px; right: 8px; display: flex; gap: 4px;
    z-index: 10; opacity: 0.7; transition: opacity 0.15s;
}
.mermaid-container:hover .mermaid-controls { opacity: 1; }
.mermaid-controls button {
    width: 30px; height: 30px; border: 1px solid #ccc; border-radius: 4px;
    background: #fff; cursor: pointer; font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    color: #555; box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.mermaid-controls button:hover { background: #f0f0f0; color: #333; }

/* エラー表示 */
.doc-content .convert-error {
    background: #fef0f0; border: 1px solid #f5c6cb;
    border-radius: 4px; padding: 12px; color: #721c24; margin: 1em 0;
}
