/* ================================================================
   App Shell — ヘッダー + 左サイドバー + 本体（全ページ共通の外枠）
   - PC: 画面幅いっぱい。サイドバーと本体はそれぞれ内部でスクロールする
   - .shell.split : 本体を列分割するページ（列ごとにスクロール。余白なし）
   - .shell.no-side : ログイン画面など、サイドバーを出さないページ
   - ≤1024px: サイドバーはドロワー（ハンバーガーで開閉）、セクション内ナビは上部チップ
   ================================================================ */

.shell {
  display: flex;
  height: calc(100dvh - var(--header-h));
}

/* ── Sidebar ── */
.shell-side {
  width: var(--side-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.side-body {
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--space-md);
}

.side-title {
  padding: 16px 16px 8px;
  font-size: 1rem;
  font-weight: 700;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px 12px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  text-align: left;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.side-link:hover { background: var(--accent-soft); color: var(--accent); }
.side-link.active { background: var(--accent); color: var(--text-inv); }
.side-link.child { padding-left: 32px; font-weight: 500; }
/* 子を開いているグループの親（子のページを表示中） */
.side-link.open { color: var(--accent); }
.side-sep { margin: 6px 4px; border: none; border-top: 1px solid var(--border); }
/* ページ移動ではなく、ページ内の絞り込み・表示切替（選択状態を淡色で示す） */
.side-link.side-filter.active { background: var(--accent-soft); color: var(--accent); }
.side-link.empty { opacity: .45; }

.side-icon { flex-shrink: 0; width: 1.2em; text-align: center; }
.side-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-count {
  margin-left: auto;
  font-size: .7rem;
  font-weight: 600;
  opacity: .7;
  font-variant-numeric: tabular-nums;
}

.side-section {
  margin-top: 8px;
  padding: 4px 16px;
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* 見出しの右端に小さな操作ボタンを置く場合 */
.side-section-row { display: flex; align-items: center; justify-content: space-between; }
.side-section-btn { font-size: .6rem; padding: 1px 8px; text-transform: none; letter-spacing: 0; font-weight: 500; }

/* チップ・セレクト・ボタン等を置く汎用の余白付きブロック */
.side-group { padding: 4px 12px 8px; }

.side-sec-nav {
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.shell-side .site-footer {
  flex-shrink: 0;
  padding: var(--space-sm) 16px;
  border-top: 1px solid var(--border);
  font-size: .65rem;
  color: var(--text-muted);
}

/* スマホ用（グロナビの複製）・上部チップは PC では出さない */
.side-gnav, .shell-top, .shell-scrim { display: none; }

/* ── Main ── */
.shell-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: var(--space-lg) var(--space-xl) var(--space-2xl);
}

.shell.split .shell-main {
  display: flex;
  padding: 0;
  overflow: hidden;
}

/* 列分割ページの列の中身（ページ固有のレイアウト要素）を本体いっぱいに広げる */
.shell.split .shell-main > * { flex: 1; min-width: 0; }

.shell.no-side { height: auto; min-height: calc(100dvh - var(--header-h)); }
.shell.no-side .shell-main { overflow: visible; }

/* ── Scrollbar（サイドバー・列スクロール共通） ── */
.side-body, .shell-main, .scroll-thin {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Tablet / Mobile ── */
@media (max-width: 1024px) {
  :root { --side-w: 280px; }

  .shell { flex-direction: column; }

  .shell-top {
    display: block;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .shell-top:empty { display: none; }

  .sec-chips {
    display: flex;
    gap: var(--space-sm);
    padding: 8px 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sec-chip {
    flex-shrink: 0;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: all .15s;
  }
  .sec-chip:hover { border-color: var(--accent); color: var(--accent); }
  .sec-chip.active { background: var(--accent); border-color: var(--accent); color: var(--text-inv); }
  .sec-chip.open { border-color: var(--accent); color: var(--accent); }
  .sec-chip.child { border-style: dashed; font-weight: 500; }

  /* サイドバーはドロワー化 */
  .shell-side {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 90;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,.2);
  }
  body.side-open .shell-side { transform: translateX(0); }
  body.side-open .shell-scrim {
    display: block;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    z-index: 80;
    background: rgba(0,0,0,.35);
  }
  /* セクション内ナビは上部チップで出しているためドロワーでは省く */
  .side-sec-nav { display: none; }

  .shell-main { flex: 1; min-height: 0; padding: var(--space-lg); }
}

@media (max-width: 768px) {
  .side-gnav {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    padding: 12px;
    background: var(--header-bg);
  }
  .side-gnav-link {
    padding: .35rem .65rem;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.05);
    color: var(--header-text);
    font-size: .72rem;
    font-weight: 600;
    text-decoration: none;
    opacity: .7;
  }
  .side-gnav-link.active { opacity: 1; background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.18); }

  /* スマホはページ全体をスクロール（列分割ページも縦積み） */
  .shell { height: auto; min-height: calc(100dvh - var(--header-h)); }
  .shell-main { overflow: visible; padding: var(--space-md); }
  .shell.split .shell-main { overflow: visible; }

  /* 地図など、スマホでも画面に固定して中でスクロールするページ */
  .shell.fixed-mobile { height: calc(100dvh - var(--header-h)); }
  .shell.fixed-mobile .shell-main { overflow: hidden; }
}

@media print {
  .shell { display: block; height: auto; }
  .shell-side, .shell-top, .shell-scrim { display: none !important; }
  .shell-main { overflow: visible; padding: 0; }
}
