/* 統合販売管理システム - スマホ最適化スタイル
 * 適用範囲: 767.98px以下のみ（768pxちょうどはBootstrap mdと重なるため .98 とする）
 * PC表示には一切影響させないこと。app.css の後に読み込む。 */

@media (max-width: 767.98px) {

  /* ---- レイアウト: サイドバー・ハンバーガーを廃止し下部タブへ ---- */
  #sidebar, #toggle-sidebar { display: none !important; }
  #main { margin-left: 0; }
  #content {
    padding: 12px;
    /* 横画面のノッチ領域対策（viewport-fit=coverのため左右safe areaを考慮） */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    /* 下部タブ(56px)＋ホームインジケーター(safe area)と重ならない余白 */
    padding-bottom: calc(56px + env(safe-area-inset-bottom) + 16px);
  }
  .section-card { padding: 14px; margin-bottom: 14px; }
  .kpi-card { padding: 14px; }
  /* KPIカードはスマホ2列前提: 数字をやや縮め、装飾アイコンは隠して幅を確保 */
  .kpi-card .kpi-value { font-size: 22px; }
  .kpi-card .kpi-icon { display: none; }
  .table-sm th, .table-sm td { font-size: 14px; }

  /* ---- トップバー ---- */
  #topbar {
    padding: 10px 12px; gap: 8px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  #topbar h5 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* スマホでは年度・月セレクトとログアウトを隠し、期間チップ＋メニューシートに集約 */
  #year-select, #month-select, #neppan-fy-select, #logout-btn { display: none !important; }
  #period-chip { white-space: nowrap; min-height: 40px; font-size: 13px; }

  /* ---- 期間シート ---- */
  .period-label { font-size: 12px; color: var(--muted); margin: 10px 2px 6px; font-weight: 600; }
  .period-fy-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
  .period-fy-btn {
    flex: 0 0 auto; border: 1px solid #e6e9ee; border-radius: 20px; background: #fff;
    min-height: 40px; padding: 6px 16px; font-size: 14px; color: var(--text); cursor: pointer;
  }
  .period-fy-btn.selected { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
  .period-month-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .period-month-btn {
    border: 1px solid #e6e9ee; border-radius: 10px; background: #fff;
    min-height: 44px; font-size: 15px; color: var(--text); cursor: pointer;
  }
  .period-month-btn.selected { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }

  /* ---- タップ領域・iOS自動ズーム防止 ---- */
  /* フォーカス可能なinput/selectを16px未満にするとiOSが自動ズームするため16px固定 */
  input.form-control, select.form-select, textarea.form-control { font-size: 16px; }
  .form-select, .btn:not(.btn-sm) { min-height: 44px; }

  /* ---- ログイン画面（380px固定幅が375px端末ではみ出す問題の修正） ---- */
  .login-box { width: min(380px, calc(100vw - 32px)); padding: 32px 24px; }

  /* ---- 下部タブナビ ---- */
  #tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1039;
    display: flex; background: #fff; border-top: 1px solid #e0e0e0;
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .tab-item {
    flex: 1; min-height: 56px; border: none; background: none; padding: 6px 0 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer;
  }
  .tab-item i { font-size: 20px; line-height: 1; }
  .tab-item.active { color: var(--primary); font-weight: 700; }

  /* ---- ボトムシート（Bootstrap Offcanvas bottom） ---- */
  .mobile-sheet {
    height: auto;
    max-height: 85vh;   /* dvh未対応の旧iOS向けfallback */
    max-height: 85dvh;
    border-radius: 16px 16px 0 0;
  }
  .mobile-sheet .offcanvas-header { padding: 14px 16px 6px; }
  .mobile-sheet .offcanvas-body {
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .sheet-item {
    border: 1px solid #e6e9ee; border-radius: 12px; background: #fff;
    min-height: 76px; padding: 8px 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; text-align: center;
  }
  .sheet-item i { font-size: 22px; color: var(--secondary); }
  .sheet-item:active { background: #f0f4f8; }
  /* メニューシートのユーザー情報＋ログアウト行 */
  .sheet-user {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 12px 4px 0; border-top: 1px solid #eee; margin-top: 14px;
    font-size: 14px;
  }

  /* ---- Toast: 下部タブより上に表示 ---- */
  #toast-container {
    bottom: calc(56px + env(safe-area-inset-bottom) + 12px);
    left: 12px; right: 12px;
  }
  .toast-msg { min-width: 0; }

  /* ---- グラフ ---- */
  .chart-wrap { height: 220px; }
}
