/* ===========================================================
   mobile.css — スマホ表示用（案1a：下タブバー）
   既存 assets/style.css の変数（--brand 等）をそのまま使用。
   すべて @media (max-width:820px) の中だけに効く（PCの表示は一切変えない）。
   ほとんどは body.mobile-ui 配下なので、mobile.js が読み込めなければ
   従来の表示に自動的にフォールバックする。
   ただし「0. JSが無くても効く最低限」だけは body.mobile-ui を付けない。
   これが無いと、mobile.js を読まない画面で見出しが1文字ずつ縦に折り返す
   （flex の行に「折り返さない要素」を置くと隣が幅0pxに潰れるため）。
   =========================================================== */

@media (max-width: 820px) {

/* --- 0. JSが無くても効く最低限（body.mobile-ui を付けない） ---
   flex の行（.row / .appbar）の中で、伸びる側に min-width を許す。
   既定の min-width:auto は「中身より狭くならない」ため、隣に
   white-space:nowrap の要素があると伸びる側が0pxに潰れる。 */
.row > .grow,
.appbar .title { min-width: 0; }
.appbar .title { overflow: hidden; text-overflow: ellipsis; }
.appbar .badge {
  flex: 0 1 auto; min-width: 0; max-width: 42vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row > .grow > h1, .row > .grow > h2, .row > .grow > h3 { overflow-wrap: anywhere; }


/* --- 1. ヘッダを1段に畳む（リンク類は mobile.js がメニューへ移動） --- */
body.mobile-ui .appbar {
  flex-wrap: nowrap; gap: 10px; padding: 8px 12px;
}
body.mobile-ui .appbar .title {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-heading); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.mobile-ui .appbar .title small {
  font-size: var(--fs-label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.mobile-ui .appbar .badge { padding: 5px 11px; font-size: var(--fs-label); }
/* AI本部の切替はPCで操作する（ヘッダーの幅を見出しへ回す） */
body.mobile-ui .appbar .hdr-chk { display: none; }
/* 本部の折りたたみメニューと版の表示は、mobile.js の「⋯」メニューに一本化する。
   残すと 33px 幅のボタンに文字が縦積みされ、ヘッダーが93pxになる */
body.mobile-ui .appbar .hdr-menu-btn,
body.mobile-ui .appbar .hdr-links,
body.mobile-ui .appbar .app-ver { display: none; }
body.mobile-ui .appbar .spacer { display: none; }
/* ヘッダーに残した操作は折り返さない（狭い幅で文字が縦積みになると高さが3倍になる） */
body.mobile-ui .appbar > .btn { flex: 0 0 auto; white-space: nowrap; }
/* メニューへ退避しきれなかった要素は隠す（保険） */
body.mobile-ui .appbar > a.btn-ghost,
body.mobile-ui .appbar > .hdr-select,
body.mobile-ui .appbar > .home-badge { display: none; }

/* 災害モード・訓練・災害レベル・倍速は「ヘッダーには」出さない。
   本体は 7.63 で 🎓訓練・災害モード のカードへ移し、スマホからも操作できる */
body.mobile-ui .appbar .mode-controls,
body.mobile-ui .appbar #deptLevel,
body.mobile-ui .appbar #deptSpeed,
body.mobile-ui .appbar #deptTrainBtn,
body.mobile-ui .appbar #deptPauseBtn { display: none !important; }

/* --- 🎓 訓練・災害モードのカード（7.63） --- */
body.mobile-ui .m-mode { border: 2px solid var(--brand, #0369a1); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: #fff; }
body.mobile-ui .m-mode h2 { margin: 0; font-size: var(--fs-heading); }
body.mobile-ui .m-mode-sub { margin: 2px 0 10px; font-size: var(--fs-label); color: var(--muted); }
body.mobile-ui .m-mode-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
body.mobile-ui .m-mode-row .mode-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
body.mobile-ui .m-mode-row .mode-div { display: none; }
body.mobile-ui .m-mode-row .btn { min-height: 44px; white-space: nowrap; font-size: var(--fs-body); }
/* ヘッダー用の select は「白い文字」なので、白いカードの上では見えない。
   カードの中では普通のフォームの見た目に戻す（7.63） */
body.mobile-ui .m-mode-row select,
body.mobile-ui .m-mode-row select.hdr-select {
  width: auto; min-width: 7em; min-height: 44px; font-size: var(--fs-body);
  color: var(--ink, #0f172a); background: #fff; border: 1px solid var(--line, #e2e8f0);
}
body.mobile-ui .m-mode-row .hdr-chk { display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  font-size: var(--fs-label); color: var(--ink, #0f172a); }
/* 訓練中しか使わない項目は、平常時は空白を作らない（hq.js が .hidden を付け外しする） */
body.mobile-ui .m-mode-row > select,
body.mobile-ui .m-mode-row .mode-controls > select { flex: 0 1 auto; }

body.mobile-ui .m-kebab {
  flex: none; width: 44px; height: 44px; border: none; border-radius: 12px;
  background: rgba(255,255,255,.16); color: #fff; font-size: 18px; cursor: pointer;
}

/* --- 2. 本文：2カラムを解除し、下部バーぶんの余白を確保 --- */
body.mobile-ui .wrap { padding: 12px 10px 24px; }
body.mobile-ui.has-tabs .wrap { padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
body.mobile-ui .row { display: block; }
body.mobile-ui .grow.card { min-width: 0 !important; margin-bottom: 12px; padding: 14px; }
body.mobile-ui .card h2 { font-size: var(--fs-heading); }
body.mobile-ui .m-hide { display: none !important; }

/* --- 3. 下タブバー --- */
.m-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  height: calc(58px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.m-tabs button {
  border: none; background: none; font: inherit; cursor: pointer; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: .8125rem; font-weight: 600; color: var(--muted); position: relative;
}
.m-tabs button .ic { font-size: 19px; line-height: 1; }
/* 5タブ（7.64③）でも文字が潰れないように、左右の余白だけ詰める（文字は13px下限のまま） */
.m-tabs button { padding-left: 2px; padding-right: 2px; min-width: 0; }
.m-tabs button .lb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.m-tabs button.on { color: var(--brand); }
.m-tabs button .bdg {
  position: absolute; top: 5px; right: 50%; margin-right: -22px;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: .8125rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* --- 4. 選択肢：プルダウン → 並列ボタン（値は reportSchema と同一） --- */
body.mobile-ui .m-seg { display: grid; gap: 5px; }
body.mobile-ui .m-seg[data-n="3"] { grid-template-columns: repeat(3, 1fr); }
body.mobile-ui .m-seg[data-n="4"] { grid-template-columns: repeat(4, 1fr); }
body.mobile-ui .m-seg[data-n="5"] { grid-template-columns: repeat(3, 1fr); }
body.mobile-ui .m-seg button {
  min-height: 46px; padding: 4px 2px; border: 1.5px solid var(--line); border-radius: 11px;
  background: #fff; color: var(--muted); font: inherit; font-size: .875rem; font-weight: 700;
  cursor: pointer; line-height: 1.25;
}
body.mobile-ui .m-seg.m-lv button { min-height: 52px; font-size: .9375rem; }
body.mobile-ui .m-seg button:disabled { opacity: .45; }
body.mobile-ui .m-seg button.on[data-v="green"],
body.mobile-ui .m-seg button.on[data-v="ok"] { background: var(--green); border-color: var(--green); color: #fff; }
body.mobile-ui .m-seg button.on[data-v="yellow"],
body.mobile-ui .m-seg button.on[data-v="partial"],
body.mobile-ui .m-seg button.on[data-v="checking"] { background: var(--yellow); border-color: var(--yellow); color: #fff; }
body.mobile-ui .m-seg button.on[data-v="red"],
body.mobile-ui .m-seg button.on[data-v="ng"],
body.mobile-ui .m-seg button.on[data-v="injury"] { background: var(--red); border-color: var(--red); color: #fff; }
body.mobile-ui .m-seg button.on[data-v="unknown"] { background: var(--gray); border-color: var(--gray); color: #fff; }
body.mobile-ui .m-seg + .m-seg-note { margin-top: 8px; }
body.mobile-ui select.m-replaced { display: none; }

/* --- 5. 設備・資器材：1項目 = 1カード --- */
body.mobile-ui .equip-list { gap: 8px; }
body.mobile-ui .equip-row {
  display: block; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; background: #fff;
}
body.mobile-ui .equip-row.m-bad { border-color: #fecaca; background: #fffafa; }
body.mobile-ui .equip-row .equip-name {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: .9375rem; font-weight: 600; margin-bottom: 8px;
}
body.mobile-ui .equip-row .m-count { font-size: .8125rem; font-weight: 700; color: var(--red); white-space: nowrap; }
body.mobile-ui .equip-row input[type=text] { margin-top: 8px; padding: 10px 12px; font-size: .9375rem; min-height: 46px; }
body.mobile-ui .equip-row.hl { padding: 10px 12px; }

/* --- 6. 写真（設備の「不可／一部可」を選んだ行にだけ出る） --- */
.m-photo-add {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; margin-top: 8px; cursor: pointer;
  border: 1.5px dashed var(--brand); border-radius: 12px;
  background: #f0f9ff; color: var(--brand-dark); font: inherit; font-size: .875rem; font-weight: 700;
}
.m-photo-add:disabled { opacity: .45; }
.m-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.m-thumb { position: relative; width: 78px; }
.m-thumb img {
  display: block; width: 78px; height: 78px; object-fit: cover;
  border-radius: 10px; border: 1px solid #cbd5e1; background: #eef2f7;
}
.m-thumb .m-at { display: block; text-align: center; font-size: .8125rem; color: var(--muted); margin-top: 2px; }
.m-thumb .m-x {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 999px;
  border: none; background: #0f172a; color: #fff; font-size: .875rem; line-height: 1; cursor: pointer;
}
.m-thumb.m-pending img { opacity: .55; }
.m-thumb.m-pending .m-at { color: var(--yellow); font-weight: 700; }

/* --- 7. 送信バー（フォーム末尾の送信ボタンは隠して常駐化） --- */
body.mobile-ui #reportForm #submitBtn { display: none; }
.m-sendbar {
  position: fixed; left: 0; right: 0; z-index: 88;
  bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.m-sendbar .btn { flex: 1; min-height: 52px; font-size: .9375rem; }
.m-sendbar .m-meta { font-size: .8125rem; color: var(--muted); white-space: nowrap; }

/* --- 7b. 送信完了トースト（送信バー・タブバーの上に大きく表示） --- */
.m-toast {
  position: fixed; left: 12px; right: 12px; z-index: 110;
  bottom: calc(58px + 74px + env(safe-area-inset-bottom, 0px));
  display: none; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 16px; border-radius: 12px; text-align: center;
  font-size: .9375rem; font-weight: 700; color: #fff;
  box-shadow: 0 8px 28px rgba(15,23,42,.28);
}
.m-toast.m-show { display: flex; }
.m-toast.m-ok { background: var(--green); }
.m-toast.m-pending { background: #0f172a; }

/* --- 8. シート（カメラ／ライブラリの選択）とメニュー --- */
.m-scrim { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 95; }
.m-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 96;
  background: #fff; border-radius: 22px 22px 0 0;
  padding: 10px 14px calc(26px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 40px rgba(15,23,42,.28); max-height: 82vh; overflow: auto;
}
.m-sheet .m-grab { width: 38px; height: 5px; border-radius: 999px; background: #cbd5e1; margin: 0 auto 12px; }
.m-sheet .m-ttl { font-weight: 700; font-size: .9375rem; margin: 0 0 2px; }
.m-sheet .m-sub { font-size: .8125rem; color: var(--muted); margin: 0 0 10px; }
.m-sheet .m-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px;
  border: none; border-top: 1px solid var(--line); background: none; cursor: pointer;
  font: inherit; font-size: .9375rem; font-weight: 600; color: var(--brand); text-align: left; text-decoration: none;
}
.m-sheet .m-opt .ic { font-size: 21px; }
.m-sheet .m-opt.m-quiet { color: var(--muted); font-weight: 500; }
.m-sheet .m-grp { font-size: .8125rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; padding: 14px 0 2px; }
/* メニューへ移動した既存のリンク・操作をリスト行として見せる */
.m-sheet .m-moved > * { display: flex; align-items: center; min-height: 54px; width: 100%; }
.m-sheet .m-moved a.btn-ghost {
  color: var(--ink); border: none; border-top: 1px solid var(--line); border-radius: 0;
  padding: 0; font-size: .9375rem; font-weight: 600;
}
.m-sheet .m-moved .btn { width: 100%; margin: 8px 0 0; min-height: 50px; }
.m-sheet .m-moved .hdr-select {
  width: 100%; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 10px; min-height: 48px; margin-top: 8px; padding: 0 10px;
}
.m-sheet .m-moved .home-badge { color: var(--muted); background: none; padding: 0; }
.m-sheet .m-moved .home-badge a { color: var(--brand); }

/* --- 9. 送信キュー（圏外→再接続で自動送信） --- */
.m-queue {
  display: flex; gap: 9px; align-items: flex-start; margin-bottom: 12px;
  border-radius: 12px; padding: 10px 12px; font-size: .8125rem;
  background: #eff6ff; border: 1px solid #bfdbfe; color: var(--brand-dark);
}
.m-queue.m-off { background: #fff7ed; border-color: #fdba74; color: #9a3412; }
.m-queue .m-qrow { display: flex; gap: 8px; align-items: center; padding: 6px 0 0; }
.m-queue .m-qrow .m-st { margin-left: auto; font-weight: 700; font-size: .8125rem; }

/* --- 10. 共有ボード（overview / hq）の表 → カード --- */
body.mobile-ui .table-scroll { max-height: none; border: none; border-radius: 0; overflow: visible; }
body.mobile-ui table.hq { background: none; box-shadow: none; }
body.mobile-ui table.hq thead { display: none; }
body.mobile-ui table.hq tbody, body.mobile-ui table.hq tr, body.mobile-ui table.hq td { display: block; width: auto; }
body.mobile-ui table.hq tr {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; box-shadow: var(--shadow);
}
body.mobile-ui table.hq tr.red-row { border-color: #fecaca; background: #fef2f2; }
body.mobile-ui table.hq tr.yellow-row { border-color: #fde68a; background: #fffbeb; }
body.mobile-ui table.hq td {
  border: none; padding: 2px 0; font-size: .875rem; white-space: normal;
  display: grid; grid-template-columns: 5.2em 1fr; gap: 10px; align-items: baseline;
}
body.mobile-ui table.hq td::before {
  content: attr(data-label); font-size: .8125rem; font-weight: 600; color: var(--muted);
}
body.mobile-ui table.hq td:first-child {
  display: block; font-size: .9375rem; margin-bottom: 6px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
body.mobile-ui table.hq td:first-child::before { content: none; }
body.mobile-ui .stat-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
body.mobile-ui .stat { padding: 10px; }
body.mobile-ui .stat .n { font-size: 1.5rem; }

/* --- 11. その他のスマホ調整 --- */
body.mobile-ui .tabbtns button { min-height: 44px; }
body.mobile-ui .phasebar button { min-height: 44px; }
body.mobile-ui .action-item { padding: 13px 4px; }
body.mobile-ui .action-item input[type=checkbox] { width: 24px; height: 24px; }
body.mobile-ui .issue-btns .btn { min-height: 44px; }
body.mobile-ui .modal-overlay { padding: 12px 8px 90px; }
body.mobile-ui .modal-box { padding: 14px; }
body.mobile-ui input, body.mobile-ui select, body.mobile-ui textarea { font-size: 16px; } /* iOSの自動ズーム防止 */

/* --- 12. 写真の全画面表示（mobile.js が生成） --- */
.m-lightbox {
  position: fixed; inset: 0; z-index: 120; background: rgba(15,23,42,.92);
  display: flex; align-items: center; justify-content: center; padding: 12px;
}
.m-lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.m-lightbox .m-lb-x {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px;
  width: 44px; height: 44px; border: none; border-radius: 999px;
  background: rgba(255,255,255,.2); color: #fff; font-size: 18px;
}

/* --- 13. 設備ごとの写真（部署詳細モーダル・報告一覧）のスマホ調整 --- */
body.mobile-ui .eq-item { display: block; margin: 0 0 10px; }
body.mobile-ui .eq-item .rep-photo,
body.mobile-ui .rs-v .rep-photo { width: 68px; height: 68px; }


/* --- 8. 本部（hq.html）の4タブ（7.60 第2段） -----------------------------
   PCの3ペイン（.hq-shell）はそのまま。スマホでは mobile.js が中身を
   4つの .m-sec へ移し、下タブで切り替える。 */
body.mobile-ui .hq-shell { display: block; }
body.mobile-ui #hqSide,            /* 左の要約列（中身はタブへ移した） */
body.mobile-ui #splitBar,          /* 左右の幅を変えるつまみ */
body.mobile-ui .pane-toggle,       /* 各ペインの開閉ボタン */
body.mobile-ui #scrollMirror,      /* 表の上の横スクロールバー（表自体が横に動く） */
body.mobile-ui #hqSplit { display: none; }
body.mobile-ui .m-sec.m-hide { display: none; }
body.mobile-ui .m-sec > * { margin-bottom: 12px; }
/* 左右分割のために付いていた幅の指定を解く */
body.mobile-ui .split-pane {
  flex: none !important; width: auto !important; max-width: none !important;
  min-width: 0 !important; margin: 0;
}
body.mobile-ui .m-sec .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.mobile-ui .m-sec .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }


/* --- 9. 長い管理画面はカードを畳む（7.60.3） ---------------------------
   設定・平時点検・講評レポートは縦が2万px前後ある。見出しだけを並べ、
   押した節だけ開く。DOMは動かさず、中身をここで隠す。 */
body.mobile-ui .m-foldable.m-folded > *:not(.m-fold-head) { display: none; }
body.mobile-ui .m-foldable.m-folded { padding-bottom: 6px; }
body.mobile-ui .m-fold-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0;
}
body.mobile-ui .m-fold-head > h2,
body.mobile-ui .m-fold-head > h3 { flex: 1 1 auto; min-width: 0; margin: 0; }
body.mobile-ui .m-fold-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--muted); font-size: var(--fs-body); line-height: 1; cursor: pointer;
}
body.mobile-ui .m-fold-all {
  display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px;
}


/* ===== 訓練の時間割（7.66）：スマホでは「実時間」列を省く ===== */
body.mobile-ui .tl-tbl th:nth-child(2),
body.mobile-ui .tl-tbl td.tl-rt { display: none; }
body.mobile-ui .tl-tbl .tl-at { white-space: normal; }
body.mobile-ui .tr-box .tr-tl-body { max-height: 40vh; }
body.mobile-ui .tr-box .tr-haz { max-height: 32vh; }
}
