/* ナビ：PC の左の帯／狭い画面の下のタブバー・ページ上部のタブ・⌘K */

/* ============================================================
   ナビ（5つの大分類）
   ------------------------------------------------------------
   PC は左の細い帯（大分類）＋ページ上部のタブ（画面）＋切り替え（見方）、
   狭い画面は同じ帯を下のタブバーに置き換える（同じ要素＝頭の中の地図が1つ）。
   以前は20行のサイドバーにサブメニューが開閉し、低い画面では下の設定が押し出されていた。
   中身は js/nav.js の NAV から描く。
   ============================================================ */
#sidebar {
  width: 84px;
  flex-shrink: 0;
  background: var(--color-sidebar);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px 0 14px;
  box-sizing: border-box;
  z-index: 50;
}
#tabBar { flex: 1; flex-direction: column; align-items: center; width: 100%; min-height: 0; }
#rail-spaces { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.nav-ic { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.rail-btn {
  position: relative; width: 64px; height: 60px; padding: 0;
  border: 0; border-radius: 14px; background: transparent; color: rgba(255, 255, 255, 0.58);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-family: var(--font); cursor: pointer; transition: background 0.15s, color 0.12s;
}
.rail-btn:hover { background: rgba(255, 255, 255, 0.07); color: rgba(255, 255, 255, 0.92); }
.rail-btn.active { background: rgba(75, 124, 243, 0.22); color: #fff; }
.rail-btn.active .nav-ic { stroke-width: 2; }
.rail-btn:focus-visible { outline: 2px solid #8fb6ff; outline-offset: 2px; }
.rail-btn--sm { height: 50px; }
.rail-lbl { font-size: 10.5px; font-weight: var(--fw-medium); letter-spacing: 0.02em; }
.rail-btn.active .rail-lbl { font-weight: var(--fw-bold); }
.nav-badge {
  position: absolute; top: 3px; right: 9px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
  border-radius: 9px; background: var(--color-warning); color: #1f1400; box-shadow: 0 0 0 2px var(--color-sidebar);
  font-size: 10.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.nav-badge--inline { position: static; box-shadow: none; margin-left: 6px; display: inline-flex; }

/* 帯に乗せたときの一覧＝大分類→タブの2手を1手にする（ホバーできる広い画面だけ） */
#rail-fly {
  position: fixed; left: 92px; top: 0; width: 340px; z-index: 900; box-sizing: border-box;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 16px;
  box-shadow: var(--shadow-xl); padding: 14px 16px 6px;
  opacity: 0; pointer-events: none; transform: translateX(-4px); transition: opacity 0.12s, transform 0.12s;
}
#rail-fly.open { opacity: 1; pointer-events: auto; transform: none; }
.fly-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding-bottom: 2px; }
.fly-head b { font-size: var(--text-md); font-weight: 800; }
.fly-head span { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-2xs); color: var(--color-text-subtle); }
.fly-row { padding: 9px 0; border-bottom: 1px solid var(--color-row-line); }
.fly-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fly-stat { font-size: var(--text-sm); font-weight: var(--fw-bold); color: var(--color-text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fly-stat--up { color: var(--color-success-text); }
.fly-stat--down { color: var(--color-danger-text); }
.fly-stat--warn { color: var(--color-warning-text); }
.fly-row:last-child { border-bottom: 0; }
.fly-page {
  display: inline-flex; align-items: center; border: 0; background: none; padding: 3px 6px; margin-left: -6px;
  border-radius: 8px; font-family: var(--font); font-size: var(--text-base); font-weight: var(--fw-bold);
  color: var(--color-text); cursor: pointer;
}
.fly-page:hover, .fly-page.active { color: var(--color-primary); }
.fly-views { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.fly-view {
  height: 26px; padding: 0 10px; border: 0; border-radius: 8px; background: var(--color-bg); color: #47516a;
  font-family: var(--font); font-size: var(--text-xs); cursor: pointer;
}
.fly-view:hover { background: var(--color-row-hover); color: var(--color-primary); }
.fly-view.active { background: var(--color-primary-light); color: var(--color-primary); font-weight: var(--fw-bold); }

/* 設定のメニュー（マスタ管理・通知・セキュリティ・ログアウト） */
#nav-menu {
  position: fixed; z-index: 950; min-width: 200px; display: none; padding: 6px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
#nav-menu.open { display: block; }
.nav-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 12px;
  border: 0; background: none; border-radius: 8px; text-align: left; cursor: pointer;
  font-family: var(--font); font-size: var(--text-sm); color: var(--color-text);
}
.nav-menu-item:hover { background: var(--color-row-hover); }
.nav-menu-item .nav-ic { color: var(--color-text-muted); }

/* ページ上部：大分類の名前・画面のタブ・見方の切り替え */
#page-head { margin-bottom: var(--sp-5); }
.ph-row { display: flex; align-items: center; gap: 24px; min-height: 56px; border-bottom: 1px solid var(--color-border); }
#ph-space { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap; }
/* 横スクロールを付けると overflow-y も auto になる（片方だけ visible にはできない）。下線を
   枠の外（bottom:-1px）に出すと、それが縦に1pxはみ出して「要らないのに少しスクロールできる」
   箱になっていた。**枠ごと1px下げて行の境界線に重ね、下線は枠の内側に置く**＝はみ出しが無い。 */
#ph-tabs { display: flex; gap: 22px; align-self: stretch; margin-bottom: -1px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#ph-tabs::-webkit-scrollbar { display: none; }
.ph-tab {
  position: relative; display: inline-flex; align-items: center; padding: 0 2px; border: 0; background: none;
  font-family: var(--font); font-size: var(--text-base); font-weight: var(--fw-medium); color: var(--color-text-muted);
  white-space: nowrap; cursor: pointer;
}
.ph-tab:hover { color: var(--color-text); }
.ph-tab.active { color: var(--color-text); font-weight: var(--fw-bold); }
.ph-tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px; background: var(--color-primary);
}
.ph-grow { flex: 1; }
.ph-search {
  display: inline-flex; align-items: center; gap: 8px; width: 240px; height: 36px; padding: 0 8px 0 12px; flex-shrink: 0;
  border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-surface); color: var(--color-text-muted);
  font-family: var(--font); font-size: var(--text-sm); cursor: pointer;
}
.ph-search:hover { border-color: var(--color-primary-border); }
.ph-search-lbl { flex: 1; text-align: left; }
.ph-search kbd, .pal-box kbd {
  font-family: var(--font); font-size: 11px; padding: 1px 6px; border-radius: 6px;
  background: var(--color-bg); border: 1px solid var(--color-border); color: var(--color-text-muted);
}
.ph-gear { display: none; }
#ph-views { display: inline-flex; gap: 2px; padding: 3px; margin-top: 14px; border-radius: 10px; background: #e9edf4; }
.ph-view {
  height: 30px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; white-space: nowrap; cursor: pointer;
  font-family: var(--font); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--color-text-muted);
}
.ph-view:hover { color: var(--color-text); }
.ph-view.active { background: var(--color-surface); color: var(--color-text); font-weight: var(--fw-bold); box-shadow: 0 1px 2px rgba(20, 30, 60, 0.10); }

/* ⌘K：検索して移動 */
#nav-pal {
  position: fixed; inset: 0; z-index: 1000; display: none; align-items: flex-start; justify-content: center;
  padding-top: 12vh; background: rgba(20, 29, 43, 0.42);
}
#nav-pal.open { display: flex; }
.pal-box {
  width: min(640px, calc(100vw - 32px)); max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--color-surface); border-radius: 18px; box-shadow: 0 24px 64px -12px rgba(20, 30, 60, 0.40);
}
.pal-input { display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 18px; flex-shrink: 0; border-bottom: 1px solid var(--color-row-line); color: var(--color-text-muted); }
.pal-input input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-family: var(--font); font-size: 16px; color: var(--color-text); }
#nav-pal-list { overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 8px; }
.pal-head { padding: 10px 12px 4px; font-size: 11px; font-weight: var(--fw-bold); letter-spacing: 0.06em; color: var(--color-text-subtle); }
.pal-item {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer;
  font-family: var(--font); color: var(--color-text);
}
.pal-item.sel { background: var(--color-row-hover); }
.pal-ic { width: 28px; height: 28px; flex-shrink: 0; border-radius: 8px; background: var(--color-bg); color: var(--color-text-muted); display: flex; align-items: center; justify-content: center; }
.pal-item.sel .pal-ic { background: var(--color-primary); color: #fff; }
.pal-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-base); }
.pal-item.sel .pal-label { font-weight: var(--fw-semibold); }
.pal-sub { font-size: var(--text-xs); color: var(--color-text-subtle); }
.pal-enter { display: none; color: var(--color-primary); }
.pal-item.sel .pal-enter { display: flex; }
.pal-empty { padding: 24px; text-align: center; font-size: var(--text-sm); color: var(--color-text-subtle); }
.pal-foot {
  display: flex; align-items: center; gap: 16px; height: 42px; padding: 0 18px; flex-shrink: 0;
  background: #f8fafd; border-top: 1px solid var(--color-row-line); font-size: var(--text-xs); color: var(--color-text-muted);
}
.pal-foot span { display: inline-flex; align-items: center; gap: 5px; }
.pal-foot-hint { margin-left: auto; }

/* 狭い画面：帯を下のタブバーにする。上部は大分類の名前＋検索・設定、画面は丸いボタンの列、
   見方は下線のタブ（どちらも横にスクロール）。以前の ☰ の引き出しは、未確認まで2タップ要った */
@media (max-width: 900px) {
  #sidebar {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 45;
    width: auto; height: calc(64px + env(safe-area-inset-bottom)); padding: 4px 6px env(safe-area-inset-bottom);
    flex-direction: row; background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--color-border);
    -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
  }
  .rail-foot, #rail-fly { display: none; }
  #tabBar { flex-direction: row; }
  #rail-spaces { flex-direction: row; width: 100%; gap: 0; }
  .rail-btn { flex: 1 1 0; width: auto; height: 56px; border-radius: 12px; color: #8a93a3; }
  .rail-btn:hover { background: transparent; color: #8a93a3; }
  .rail-btn.active { background: transparent; color: var(--color-primary); }
  .nav-badge { right: calc(50% - 24px); box-shadow: 0 0 0 2px #fff; }
  .nav-badge--inline { box-shadow: none; }
  #main-content { padding: var(--sp-3) var(--sp-3) calc(84px + env(safe-area-inset-bottom)); }

  .ph-row { flex-wrap: wrap; gap: 10px 8px; min-height: 0; border-bottom: 0; }
  #ph-space { flex: 1; font-size: 24px; }
  .ph-grow { display: none; }
  .ph-search { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 22px; }
  .ph-search-lbl, .ph-search kbd { display: none; }
  .ph-gear {
    display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; cursor: pointer;
    border: 1px solid var(--color-border); border-radius: 22px; background: var(--color-surface); color: #47516a;
  }
  #ph-tabs { order: 5; flex-basis: 100%; gap: 8px; align-self: auto; margin-bottom: 0; }
  .ph-tab { flex-shrink: 0; height: 36px; padding: 0 14px; border: 1px solid var(--color-border); border-radius: 18px; background: var(--color-surface); color: #47516a; }
  .ph-tab.active { background: var(--color-sidebar); border-color: var(--color-sidebar); color: #fff; }
  .ph-tab.active::after { display: none; }
  #ph-views { display: flex; gap: 20px; margin-top: 10px; padding: 0; border-radius: 0; background: none; border-bottom: 1px solid var(--color-border); overflow-x: auto; scrollbar-width: none; }
  #ph-views::-webkit-scrollbar { display: none; }
  .ph-view { position: relative; flex-shrink: 0; height: 38px; padding: 0 2px; border-radius: 0; }
  .ph-view.active { background: none; box-shadow: none; }
  .ph-view.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px; background: var(--color-primary); }
  #nav-pal { padding-top: 8vh; }
  .pal-box { max-height: 80vh; }
  .pal-foot { display: none; }
  /* 画面下に固定していたものはタブバーの上へ（未確認の入力の「保存して次へ」・取り消しトースト・ライブ更新）。
     シート（.uim-sheet・z-index 60）はタブバー（45）ごと覆う */
  body .uim-fix { bottom: calc(64px + env(safe-area-inset-bottom)); padding-bottom: 10px; }
  #unconfirmedPanel .uim-body { padding-bottom: 72px; }
  body .row-toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
  body .live-pill-el { bottom: calc(78px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  #rail-fly, .rail-btn { transition: none; }
}
