/* 手機版樣式 (owner, 2026-08-20) — 家長多用手機查看落點分析。
 *
 * 原則：
 *  1. 只在 ≤720px 生效，桌機完全不受影響。
 *  2. 不改任何 HTML 結構——純樣式層，所以功能邏輯零風險。
 *  3. 多欄版面攤平成單欄；寬表格自己橫向捲動，頁面本身永不橫捲。
 *  4. 觸控目標 ≥40px；輸入框字級 ≥16px（iOS 小於 16px 會自動放大整頁）。
 */

@media (max-width: 720px) {
  /* ── 全域：杜絕橫向捲動 ── */
  html, body { max-width: 100%; overflow-x: hidden; }
  img, svg, video, canvas { max-width: 100%; height: auto; }

  /* ── 版面：所有多欄一律攤平 ── */
  .page-cols, .layout, .dr-grid, .info-grid, .adv-grid, .school-grid, .svc-grid,
  .stat-grid, .course-stats, .student-grid, .user-cols, .cols, .two-col {
    grid-template-columns: minmax(0, 1fr) !important;
    display: grid !important;
    gap: 12px !important;
  }
  .page-cols, .page { padding: 12px !important; }
  .panel, .card, .stat-card, .u-col { border-radius: 12px !important; }

  /* 落點分析（trip.com 式兩視圖）：手機一律單欄，篩選欄置頂不黏 */
  .page-cols[data-view="list"], .page-cols[data-view="detail"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .filterrail {
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
    gap: 10px !important;
  }
  /* 篩選收合鈕（僅手機顯示）——收起時只佔一行，結果卡立刻可見 */
  .frail-toggle {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 12px;
    padding: 13px 16px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    color: #33221F;
    cursor: pointer;
  }
  .frail-toggle .chev { transition: transform .15s; color: #99807C; }
  .filterrail.collapsed .frail-toggle .chev { transform: rotate(-90deg); }
  .filterrail.collapsed .frail-card { display: none !important; }
  .rcard { flex-wrap: wrap !important; gap: 10px !important; padding: 14px !important; }
  .rcard-main { flex: 1 1 100% !important; }
  .rcard-right { width: 100%; justify-content: flex-end; }
  .rcard-prob .n { font-size: 30px !important; }
  .rcard-go { display: none; }
  .resbar { position: sticky; top: 0; z-index: 5; }

  /* 右側模擬器/側欄：不再黏頂，改為隨頁面流動 */
  .simrail, .sidebar, .rail {
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
    width: auto !important;
  }

  /* ── 頁首／導覽：可換行，不擠壓 ── */
  .top, .topbar, .admin-topbar {
    flex-wrap: wrap !important;
    height: auto !important;
    padding: 8px 12px !important;
    gap: 6px 10px !important;
  }
  .top .nav, .topbar .nav {
    width: 100%;
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 13.5px;
  }
  .top .brand small { display: block; }

  /* ── 分頁列：橫向捲動而非擠成兩行 ── */
  .tabs, .dr-tabs, .mem-tabs, .chips {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar, .dr-tabs::-webkit-scrollbar, .mem-tabs::-webkit-scrollbar { display: none; }
  .tab, .dtab { white-space: nowrap; flex: 0 0 auto; }

  /* ── 表格：容器橫捲，頁面不動 ── */
  .panel > table, .score-table, table.wide, .dr-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }

  /* ── 字級與觸控目標 ── */
  h1 { font-size: clamp(22px, 6vw, 30px) !important; line-height: 1.4 !important; }
  h2 { font-size: clamp(19px, 5vw, 24px) !important; }
  h3 { font-size: 17px !important; }
  body { font-size: 15px; }
  button, .btn, .btn-primary, .btn-ghost, .back-btn, select, a.btn {
    min-height: 42px;
    font-size: 15px !important;
  }
  /* iOS 會在 font-size < 16px 的輸入框聚焦時放大整頁——一律 16px */
  input, select, textarea { font-size: 16px !important; min-height: 42px; }
  input[type="range"] { min-height: 32px; }

  /* ── 落點分析：學校卡片、模擬器 ── */
  .chance, .sch-card, .grp { margin-bottom: 10px; }
  .sim-row { flex-wrap: wrap !important; gap: 6px !important; }
  .sim-row label { flex: 0 0 100%; }
  .sim-row input[type="range"] { flex: 1 1 auto; min-width: 0; }
  .sim-row input[type="number"], .sim-row select { flex: 0 0 auto; width: auto; min-width: 84px; }
  .sim-dims .sim-dim { font-size: 12.5px; }

  /* ── 後台：使用者看板在手機上一行一類 ── */
  .u-acts { gap: 8px !important; }
  .u-acts select, .u-acts button { flex: 1 1 auto; }

  /* ── 落點報告：A4 尺寸在手機上改為滿版 ── */
  .sheet { width: 100% !important; min-height: 0 !important; }
  .sheet .head, .sheet .bodyx, .sheet .foot { padding-left: 16px !important; padding-right: 16px !important; }
  .two-col { flex-direction: column !important; }
  .cta { flex-direction: column !important; align-items: flex-start !important; gap: 12px !important; }
  .cta .act { text-align: left !important; }

  /* ── 彈窗：滿版好按 ── */
  .modal, .overlay .modal {
    width: calc(100vw - 24px) !important;
    max-width: none !important;
    max-height: 88vh;
    overflow-y: auto;
  }
}

/* 極窄機（iPhone SE 等） */
@media (max-width: 380px) {
  .chip, .pchip { font-size: 12.5px !important; }
  .u-acts select, .u-acts button { flex: 1 1 100%; }
}
