/* =============================================================
   FMS モバイル対応スタイル
   breakpoint: max-width 767px
============================================================= */

/* ── ハンバーガーボタン（常に定義、表示はメディアクエリで制御）── */
.fms-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: #475569;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.fms-hamburger:active {
  background: #f1f5f9;
}

/* ── モバイルドロワー（display:noneがデフォルト）── */
#fmsMobileDrawer {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  border-bottom: 2px solid #4f46e5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 200;
  flex-direction: column;
}
#fmsMobileDrawer.open {
  display: flex;
}
#fmsMobileDrawer a {
  display: block;
  padding: 14px 20px;
  color: #374151;
  text-decoration: none;
  font-size: 15px;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s;
}
#fmsMobileDrawer a:last-child {
  border-bottom: none;
}
#fmsMobileDrawer a:active {
  background: #f8fafc;
}
#fmsMobileDrawer a.active {
  color: #4f46e5;
  font-weight: 600;
  background: #eef2ff;
}

/* dark theme */
body[data-theme="dark"] #fmsMobileDrawer {
  background: #1e293b;
  border-top-color: #334155;
  border-bottom-color: #818cf8;
}
body[data-theme="dark"] #fmsMobileDrawer a {
  color: #cbd5e1;
  border-bottom-color: #334155;
}
body[data-theme="dark"] #fmsMobileDrawer a:active {
  background: #334155;
}
body[data-theme="dark"] #fmsMobileDrawer a.active {
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.15);
}
body[data-theme="dark"] .fms-hamburger {
  border-color: #334155;
  color: #94a3b8;
}

/* ================================================================
   メディアクエリ: 767px 以下
================================================================ */
@media (max-width: 767px) {
  /* ── ナビ Row 1 ── */
  .fms-hamburger {
    display: flex;
  }
  /* デスクトップ用ナビリンクを非表示 */
  .fms-nav-r1 nav {
    display: none !important;
  }
  .fms-nav-r1 {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  /* ユーティリティ: Guide / Contact はモバイルで非表示 */
  .fms-nav-util-hide-mobile {
    display: none !important;
  }
  /* Preset / Guide / Contact をID・属性セレクターで非表示（全ページ共通） */
  #btnOpenPreset,
  #btnOpenGuide,
  a.fms-nav-util[href*="fms-contact"] {
    display: none !important;
  }
  /* ユーティリティ右ブロックの flex-shrink を解除してはみ出しを防止 */
  .fms-nav-r1 .flex-shrink-0.ml-4 {
    flex-shrink: 1 !important;
    min-width: 0;
  }

  /* ── ナビ Row 2: 横スクロール ── */
  .fms-nav-r2 {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
  }
  .fms-nav-r2::-webkit-scrollbar {
    display: none;
  }
  /* Row 2 内アイテムが折り返さないよう強制 */
  .fms-nav-r2 > * {
    flex-shrink: 0;
  }

  /* ── スクリーナー レイアウト ── */
  body.fms-page-screener {
    height: auto !important;
    overflow: auto !important;
  }
  body.fms-page-screener main#screenerMain {
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }
  body.fms-page-screener .fms-header-spacer {
    height: 92px !important; /* 変わらず */
  }

  /* フィルターサイドバー: デフォルト非表示・折りたたみ */
  #screenerFilterAside {
    width: 100% !important;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    flex-shrink: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid #e2e8f0;
  }
  #screenerFilterAside.mobile-open {
    max-height: 70vh;
    overflow-y: auto;
  }

  /* モバイル用フィルタートグルボタン */
  #mobileFilterToggle {
    display: block !important;
  }

  /* 結果セクション */
  body.fms-page-screener section#screenerResultSection {
    overflow: visible !important;
    flex: none !important;
    width: 100%;
    min-height: 50vh;
  }

  /* シングル/ペアパネル: 縦積みに */
  body.fms-page-screener #singleScreenerPanel,
  body.fms-page-screener #pairScreenerPanel {
    overflow: visible !important;
    flex: none !important;
    height: auto !important;
    min-height: 50vh;
    padding-bottom: 40px !important;
    flex-direction: column !important;
  }
  /* その直下の flex コンテナ（テーブル+詳細の並列ラッパー）も縦積みに */
  body.fms-page-screener #singleScreenerPanel > div,
  body.fms-page-screener #pairScreenerPanel > div {
    flex-direction: column !important;
    overflow: visible !important;
    height: auto !important;
    flex: none !important;
  }

  /* 結果テーブルラップ: 縦横スクロール */
  body.fms-page-screener #resultsTableWrap {
    max-height: 60vh;
    overflow-x: auto !important;
    overflow-y: auto !important;
    flex: none !important;
    -webkit-overflow-scrolling: touch;
  }

  /* 詳細パネル: 全幅 */
  body.fms-page-screener #detailPanel {
    width: 100% !important;
    min-height: 350px;
    margin-right: 0 !important;
    margin-top: 8px;
  }
  /* テーブルカードの右余白を削除 */
  body.fms-page-screener #singleScreenerPanel .mr-3,
  body.fms-page-screener #pairScreenerPanel .mr-3 {
    margin-right: 0 !important;
  }

  /* ペアトレードモードタブ */
  body.fms-page-screener #screenerModeTabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  body.fms-page-screener #screenerModeTabs::-webkit-scrollbar {
    display: none;
  }

  /* ── 株シムRT ── */
  body.fms-page-trading {
    overflow: auto !important;
  }

  /* ── 汎用テーブル横スクロール ── */
  .fms-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── モーダル: 全幅近くに ── */
  .bg-white.rounded-xl[class*="w-["] {
    width: 96vw !important;
    max-width: 96vw !important;
  }

  /* ── バックテスト/要因探索サイドバー ── */
  .fms-sidebar-desktop {
    width: 100% !important;
    max-width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid #e2e8f0;
  }

  /* ── フォントサイズ調整 ── */
  .fms-nav-logo {
    font-size: 1rem !important;
  }

  /* 小さい入力欄のタッチ操作性向上 */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px !important; /* iOS ズーム防止 */
  }
  input[type="range"] {
    height: 24px;
    width: 100%;
  }
}
