/* ================================================================
   AppShell — 左サイドバー ＋ 上部バー ＋ 本文
   （2026/09/12 SaaSリデザイン 第1段。指示書v2）

   ⚠️ style.css の後に読み込む。中身（指標・表・数字）は一切変えず、
      器と当たり判定・文字サイズだけを直す。
   ⚠️ 段階移行なので、旧 .controlbar / .topbar の指定を打ち消す形で書いている。
      最後の段階（旧CSSの削除）でここへ一本化する。
   ================================================================ */

:root {
  --sb-w: 232px;          /* サイドバーの幅 */
  --tap: 44px;            /* タップ領域の下限（指示書v2） */
  --fs-label: 12px;       /* 補助ラベルの下限。10px・11pxは使わない */
  --sb-bg: #11182a;
  --sb-fg: #b7c1d1;
  --sb-fg-on: #ffffff;
  --sb-hover: #1c2438;
  --sb-active: #242e48;
}
:root[data-theme="dark"] {
  --sb-bg: #0a0e18;
  --sb-hover: #151d2e;
  --sb-active: #1d2740;
}

/* 和文を明示する。Inter単独指定だと和欧混植でベースラインが崩れる */
body {
  font-family: "Noto Sans JP", system-ui, -apple-system, "Segoe UI",
               "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

/* 押せるものは44px以上。指で外さないための最低線 */
.ghost, button.primary, .chip, .link-btn, .custom-range input {
  min-height: var(--tap);
}
.ghost, button.primary { padding: 0 14px; display: inline-flex; align-items: center; gap: 6px; }
.chip { padding: 0 15px; display: inline-flex; align-items: center; }
.custom-range input { padding: 0 10px; }

/* 10px・11pxを使わない（指示書v2）。既存の小さすぎる文字を底上げする */
.small, .muted.small, .pill, .toc a i { font-size: var(--fs-label); }

/* ---------------- 器 ---------------- */
.app-shell { display: flex; min-height: 100vh; min-height: 100svh; }

.sidebar {
  flex: 0 0 var(--sb-w);
  display: flex; flex-direction: column;
  padding: 18px 12px 14px;
  background: var(--sb-bg); color: var(--sb-fg);
  position: sticky; top: 0; height: 100vh; height: 100svh;
  overflow-y: auto;
}
.brand-row {
  display: flex; align-items: center; gap: 10px;
  padding: 0 6px 18px; color: #fff;
}
.brand-mark {
  flex: 0 0 auto;
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 9px; background: linear-gradient(135deg, #7778f2, #4b4ccd);
  font-size: 15px; font-weight: 800; color: #fff;
}
.brand-name { font-size: 13.5px; font-weight: 700; letter-spacing: .02em; line-height: 1.35; }

/* 目次＝サイドバーのナビ。旧 .toc の横並び指定を上書きする */
.sidebar .toc { display: grid; gap: 3px; overflow: visible; }
.sidebar .toc a {
  display: flex; align-items: center; gap: 11px;
  min-height: var(--tap); padding: 0 11px;
  border: 0; border-radius: 9px;
  color: var(--sb-fg); font-size: 14px; font-weight: 600; text-decoration: none;
}
.sidebar .toc a i {
  flex: 0 0 auto;
  width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .1); color: #cfd8e6;
  font-size: var(--fs-label); font-weight: 700; font-style: normal;
}
.sidebar .toc a:hover { background: var(--sb-hover); color: var(--sb-fg-on); }
.sidebar .toc a.active,
.sidebar .toc a[aria-current="page"] {
  background: var(--sb-active); color: var(--sb-fg-on); border-bottom: 0;
}
.sidebar .toc a.active i,
.sidebar .toc a[aria-current="page"] i { background: var(--accent); color: #fff; }

.sb-foot {
  margin-top: auto; padding: 14px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, .08);
  display: grid; gap: 3px;
  font-size: var(--fs-label); line-height: 1.6; color: #8f9cb1;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ---------------- 上部バー ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 31;
  display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap;
  min-height: 60px; padding: 10px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
}
.tb-title { display: grid; gap: 1px; min-width: 0; }
.tb-eyebrow {
  font-size: var(--fs-label); font-weight: 700; letter-spacing: .1em;
  color: var(--muted);
}
.tb-title h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.01em; line-height: 1.3; }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.icon-btn {
  flex: 0 0 auto;
  width: var(--tap); height: var(--tap);
  display: none; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--text-2);
  font-size: 19px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------------- 絞り込みの行 ---------------- */
.filterbar {
  position: sticky; top: 60px; z-index: 30;
  display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap;
  padding: 10px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
}
.filterbar .period-label { margin-left: auto; }

.content { flex: 1 1 auto; min-width: 0; }
.content .report { padding-top: 18px; }

/* 章の頭が固定バーの下に隠れないように */
.chapter { scroll-margin-top: 124px; }

/* ---------------- サイドバーをドロワーにする（720px以下） ---------------- */
.sb-scrim { display: none; }

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: min(84vw, 300px); height: 100vh; height: 100svh;
    transform: translateX(-102%);
    transition: transform .18s ease-out;
  }
  .sidebar.is-open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .sb-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(10, 14, 24, .5);
  }
  .sb-scrim[hidden] { display: none; }
  .icon-btn { display: grid; }
  .topbar { padding: 8px 14px; min-height: 56px; }
  .filterbar { top: 56px; padding: 8px 14px; }
  .tb-title h1 { font-size: 17px; }
  .content .report { padding: 14px 14px 32px; }
  .chapter { padding: 18px 15px 20px; border-radius: 12px; scroll-margin-top: 116px; }
}

/* 390px以下：ラベルを折り返さずに収める */
@media (max-width: 390px) {
  .tb-actions { width: 100%; margin-left: 0; }
  .topbar { gap: 8px; }
  .filterbar .period-label { margin-left: 0; width: 100%; }
}

@media print {
  .app-shell { display: block; }
  .sidebar, .sb-scrim, .icon-btn, .topbar, .filterbar { display: none !important; }
}

/* ================================================================
   章の中身 — パネル規則（全章共通）
   ================================================================ */

/* 章＝カードの集まり。見出しは番号バッジではなく小見出し＋説明にする */
.chapter .ch-head { align-items: center; gap: 12px; }
.chapter .ch-no {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #7778f2, #4b4ccd);
  font-size: 14px;
}
.chapter .ch-head h2 { font-size: 19px; font-weight: 800; }
#sec-brief .ch-sub { font-size: 13px; }

/* 章の中の小見出し。SaaSらしく「EYEBROW + 見出し」の2段にする */
.chapter h3.sec {
  font-size: 15px; font-weight: 800; color: var(--text);
  letter-spacing: 0; margin: 26px 0 4px;
  padding-bottom: 0; border-bottom: 0;
}
.chapter h3.sec + .muted.small { margin: 0 0 14px; font-size: var(--fs-label); }

/* 表と要点をパネルに載せる */
#diagTable {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel);
}

/* 数字は必ず等幅。桁が揃わないと比べられない */
.chapter, .chapter table { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .chapter h3.sec { margin-top: 20px; }
}

/* ================================================================
   文字サイズとタップ領域の底上げ（指示書v2「10px・11pxは使わない」）

   ⚠️ 個別セレクタを34か所直すのではなく、ここで一括して下限を引き上げる。
      旧CSSの該当行は最後の段階でまとめて消す。
      値を変えているだけで、どの数字を出すかは一切変えていない。
   ================================================================ */

/* 11px前後で書かれていた補助ラベル群 */
.pill, .itag, .diag-tag, .tag-est,
.card-subs .base, .card-subs .s.note .base,
.fl-tree .t-h, .drill-h, .bstep-l, .stat-l, .stat-s,
.rank-name small, .rank-cell .d, .rank-cell .k, .rank-head,
.sm-sub, .store-sec-h small, .diag-detail,
.drawer > summary::before, tr.drill .caret,
.cmp td small.muted, .ot-legend, .ot-card i,
table.ot-year thead th small, table.ot .ot-rate small,
.f-box i, .ex-minus-lab, .ex-wd u,
#dailyTable table.grid thead th .arrow,
tr.row-worst small.down,
.ot-mem-v i, .ot-diff.mini, .ot-repeat,
.mix-legend, .mix-val, .mix-when, .calc-w, .cmp-h, .cmp-s,
.lv-card small, .ex-flow .fb span, .bstep-v, .ex-note {
  font-size: var(--fs-label);
}

/* 表の見出しは本文より1段小さい程度に留める */
table.grid thead th, table thead th { font-size: 12.5px; }

/* 章の小見出しの補足 */
h3.sec { font-size: 13px; }

/* リンク扱いのボタンも44px。業績レポートへの導線がここに該当した */
.switcher-other, .link-btn, .toc-ap {
  min-height: var(--tap);
  display: inline-flex; align-items: center;
}
.switcher-other { padding: 0 14px; }

/* スマホの最小幅で、数値の桁が折り返して読めなくなるのを防ぐ */
@media (max-width: 390px) {
  .card-value, .stat-v { white-space: nowrap; }
}

/* ================================================================
   スマホの上部バーを1行に収める

   ⚠️ 操作は消さない（指示書v2 最優先ルール6）。アイコンだけのボタンを
      正方形にして詰める。ラベルのあるボタンはそのまま残す。
   ================================================================ */
@media (max-width: 720px) {
  /* 印刷・更新・テーマはアイコンだけ。44×44を保ったまま幅を詰める */
  .tb-actions #printBtn,
  .tb-actions #refreshBtn,
  .tb-actions #themeBtn {
    width: var(--tap); padding: 0; justify-content: center; font-size: 17px;
  }
  .tb-actions { gap: 6px; }
  .tb-actions #userName { order: 9; }
  .tb-actions #logoutBtn { order: 10; padding: 0 12px; }
  .tb-eyebrow { display: none; }        /* 見出しの上の小さいラベルだけ省く */
}
@media (max-width: 390px) {
  .tb-title h1 { font-size: 16px; }
  .tb-actions #userName { display: none; }   /* 氏名はサイドバーの下に出す */
}

/* ================================================================
   パネル・カード・表（全章）

   ⚠️ 中身は変えない。枠・余白・見出しの出し方だけを揃える。
   ================================================================ */

/* 箱の見出しは「小さい大文字ラベル」ではなく、読める見出しにする */
.chart-box h2, .table-box h2, .notes-box h2 {
  font-size: 15px; font-weight: 800; letter-spacing: -.01em;
  padding: 14px 18px 13px;
}
.chart-box, .table-box, .notes-box {
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* KPIカード。ラベル／値／増減 の3段をはっきり分ける */
.card { border-radius: var(--radius); padding: 15px 17px 14px; box-shadow: var(--shadow); }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.card-value { font-size: 27px; font-weight: 800; letter-spacing: -.025em; margin: 6px 0 8px; }
.card-subs { font-size: 12.5px; }
.cards { gap: 14px; }

/* 要点の帯 */
.insight-box { border-radius: var(--radius); }
.insight-box h2 {
  font-size: 13px; font-weight: 800; color: var(--text);
  letter-spacing: 0; padding: 12px 18px 2px;
}
.insight-fact { font-size: 14px; line-height: 1.7; }
.insight-act { font-size: 13px; line-height: 1.65; }
.itag { padding: 3px 9px; border-radius: 5px; }

/* 表。見出し行は固定、数値は右寄せ＋等幅（指示書v2 テーブル仕様） */
table.grid { font-size: 13.5px; }
table.grid th, table.grid td { padding: 11px 14px; }
table.grid thead th {
  font-size: 12.5px; font-weight: 700; color: var(--text-2);
  position: sticky; top: 0; z-index: 1;
}
table.grid td.r, table.grid th.r { font-variant-numeric: tabular-nums; }

/* 横スクロールする表は1列目を固定する。氏名・店舗が消えると読めない */
.scroll-x table.grid tbody th:first-child,
.scroll-x table.ot tbody td:nth-child(3) { background: var(--paper); }

/* 章の見出し。番号バッジは小さく、見出しを主役にする */
.chapter .ch-head { padding-bottom: 15px; }
.chapter .ch-sub { font-size: 13px; line-height: 1.7; }

/* 折りたたみの見出しも押せる大きさにする */
.drawer > summary, details > summary {
  min-height: var(--tap); display: flex; align-items: center;
}

/* ================================================================
   状態表示（読み込み中／データなし／エラー）

   ⚠️ 読み込み中はレイアウトを動かさない。スピナーだけだと、
      数字が入った瞬間に画面が飛んで読む位置を見失う（指示書v2）。
   ================================================================ */
.skeleton { display: grid; gap: 14px; padding: 18px 20px 4px; max-width: 1280px; margin: 0 auto; }
.sk-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.sk-box {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); padding: 16px;
}
.sk-line {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--border-2), var(--border), var(--border-2));
  background-size: 200% 100%;
  animation: sk-shimmer 1.3s linear infinite;
}
.sk-line + .sk-line { margin-top: 11px; }
.sk-line.w40 { width: 40%; }
.sk-line.w60 { width: 60%; }
.sk-line.tall { height: 28px; }
.sk-panel { min-height: 220px; }
@keyframes sk-shimmer { to { background-position: -200% 0; } }
/* 動きが苦手な人の設定では光らせない */
@media (prefers-reduced-motion: reduce) { .sk-line { animation: none; } }

.state-box {
  display: grid; gap: 10px; justify-items: start;
  max-width: 1280px; margin: 18px auto; padding: 20px 22px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow);
}
.state-box h3 { margin: 0; font-size: 16px; font-weight: 800; }
.state-box p { margin: 0; font-size: 14px; line-height: 1.75; color: var(--text-2); }
.state-box .state-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.state-code { font-size: var(--fs-label); color: var(--muted); }
/* 色だけで伝えない。見出しの文言で何が起きたか分かるようにしてある */
.state-box.is-error { border-color: #f2c6b6; background: #fdeae3; }
.state-box.is-error h3 { color: #9e3317; }
.state-box.is-error p { color: #7a3a26; }
:root[data-theme="dark"] .state-box.is-error { border-color: #5c2a1c; background: #2a1410; }
:root[data-theme="dark"] .state-box.is-error h3 { color: #f3a58c; }
:root[data-theme="dark"] .state-box.is-error p { color: #e0b3a4; }

@media (max-width: 720px) {
  .skeleton { padding: 14px 14px 4px; }
  .sk-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .state-box { margin: 14px; padding: 16px 16px 18px; }
}
@media (max-width: 390px) {
  .sk-row { grid-template-columns: minmax(0, 1fr); }
}
