/* ============================================
   響應式介面：手機 + 桌面 1920×1080
   ============================================ */

/* 桌面：僅顯示橫向分頁列，手機導向用下拉隱藏 */
.main-nav-mobile {
  display: none;
}

/* ----- 手機 / 小平板 (≤768px)；html.sw-mobile-ui 時由 mobile-app.css 接管 ----- */
@media (max-width: 768px) {
  html.sw-mobile-ui body,
  html.sw-mobile-ui .wrap,
  html.sw-mobile-ui .hdr,
  html.sw-mobile-ui .body,
  html.sw-mobile-ui nav.tabs,
  html.sw-mobile-ui .main-nav-mobile {
    /* 殼層專用樣式見 mobile-app.css */
  }

  html.sw-mobile-ui .main-nav-mobile {
    display: none !important;
  }
}

@media (max-width: 768px) {
  html:not(.sw-mobile-ui) body {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-overflow-scrolling: touch;
  }

  .wrap {
    border-radius: 12px;
    max-width: 100%;
  }

  /* 手機：主分頁改下拉，免長距離橫向捲動 */
  .main-nav-mobile {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 10px 12px;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    border-bottom: 3px solid #0284c7;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  }

  .main-nav-mobile__label {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
  }

  .main-nav-mobile__select {
    flex: 1;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  }

  nav.tabs {
    display: none !important;
  }

  .logo-icon svg {
    width: 40px;
    height: 40px;
  }

  .hdr {
    border-radius: 12px 12px 0 0;
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .hdr > div:first-child {
    text-align: center;
  }

  .hdr h1 {
    font-size: 18px;
    line-height: 1.3;
  }

  .hdr small {
    font-size: 11px;
    display: block;
    margin-top: 4px;
  }

  .hdr-btns {
    justify-content: center;
    gap: 6px;
  }

  .hdr-btn {
    padding: 10px 12px;
    font-size: 12px;
    flex: 1;
    min-width: 0;
  }

  .tabs {
    padding: 0 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .tab {
    padding: 12px 14px;
    font-size: 13px;
    min-width: max-content;
  }

  .body {
    padding: 14px;
    max-height: none;
    overflow: visible;
    border-radius: 0 0 12px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .pane h2 {
    font-size: 18px;
    margin-bottom: 12px;
  }

  .pane-page__title,
  .students-page__title,
  .coaches-page__title,
  .booking-page__title,
  .students-progress__title,
  .sched-subsection__title {
    font-size: 1.1rem;
  }

  .pane-page__lead,
  .students-page__lead,
  .coaches-page__lead,
  .booking-page__lead,
  .students-progress__hint {
    font-size: 13px;
  }

  /* 表單：手機改單欄 */
  .row2 {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .fg {
    margin-bottom: 12px;
  }

  .fg input,
  .fg select,
  .fg textarea {
    padding: 10px 12px;
    font-size: 16px; /* 減少 iOS 縮放 */
  }

  .btn {
    padding: 14px 20px;
    font-size: 15px;
    min-height: 48px; /* 觸控友善 */
  }

  /* 自訂時間列：手機改直排 */
  .custom-time-row {
    flex-direction: column;
    align-items: stretch;
  }

  .custom-time-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .custom-time-inner label {
    min-width: 0;
  }

  .btn-custom-time {
    width: 100%;
  }

  .notice-actions {
    flex-direction: column;
  }

  .notice-actions .btn {
    width: 100%;
  }

  /* 日曆 */
  .cal-hdr {
    flex-wrap: wrap;
    gap: 8px;
  }

  .cal-hdr button {
    padding: 8px 12px;
    font-size: 12px;
  }

  .cal-grid {
    gap: 2px;
  }

  .cd {
    padding: 6px 2px;
    font-size: 11px;
  }

  /* 時段格線：手機 2 欄 */
  .ts-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .ts {
    padding: 10px 6px;
    font-size: 11px;
  }

  /* SEN / 收費方式格線 */
  .sen-grid {
    grid-template-columns: 1fr;
  }

  .pm-grid {
    grid-template-columns: 1fr;
  }

  .sn, .pm {
    padding: 10px;
  }

  /* 卡片：手機 2 欄或 1 欄 */
  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .card {
    padding: 12px;
  }

  .card h3 {
    font-size: 11px;
  }

  .card .val {
    font-size: 18px;
  }

  /* 搜尋列 */
  .sb {
    flex-direction: column;
    gap: 8px;
  }

  .sb input,
  .sb select {
    width: 100%;
  }

  .confirmations-toolbar,
  .progress-toolbar:not(.progress-toolbar--compact),
  .pane-action-bar,
  .coach-tab-nav,
  .coach-modal-footer,
  .notice-action-row,
  .notice-recipient-toolbar,
  .batch-att-actions,
  .pane-panel-options {
    flex-direction: column;
    align-items: stretch;
  }

  /* 教練／學生／點名工具列維持橫向捲動，避免每鍵獨佔一整列 */
  .coach-actions-bar,
  .student-actions-bar,
  .attend-actions-bar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sched-footer-actions--compact {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
  }

  .sched-footer-actions--compact .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }

  /* 課程表頂部三鍵維持橫向並排，避免佔滿螢幕高度 */
  .sched-subsection__actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
  }

  .sched-subsection__actions .btn--sched-toolbar,
  .sched-subsection__actions .btn--compact-toolbar {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
  }

  .sched-controls-merge {
    align-items: flex-start;
  }

  .sched-week-inline {
    width: 100%;
    min-width: 0;
  }

  .sched-week-inline .sched-week-select {
    max-width: none;
  }

  .quick-attend-buttons {
    grid-template-columns: 1fr;
  }

  #coachModal .tab-btn {
    width: 100%;
  }

  .confirmations-toolbar select,
  .confirmations-page .student-control-panel .student-filter-select,
  .progress-toolbar__level {
    width: 100%;
  }

  /* 表格：保持橫向捲動，加大觸控區；右側漸層提示可橫捲 */
  .tbl-wrap {
    position: relative;
    margin-left: -14px;
    margin-right: -14px;
    padding: 0 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tbl-wrap::after {
    content: none;
    display: none;
  }

  /* 學生列表：隱藏聯絡欄，避免橫捲時姓名與分類之間出現空白直條 */
  #students .student-list-container .student-table.attendance-table th:nth-child(2),
  #students .student-list-container .student-table.attendance-table td:nth-child(2) {
    display: none;
  }

  table {
    font-size: 12px;
    min-width: 700px;
  }

  th, td {
    padding: 10px 8px;
    min-width: 70px;
  }

  .bs {
    padding: 10px 12px;
    font-size: 12px;
    min-height: 44px;
  }

  /* 首欄凍結：橫向捲動時固定識別欄（姓名／日期／類型等第一欄） */
  .tbl-wrap.student-table-wrap .student-table > thead > tr > th:first-child,
  .tbl-wrap.student-table-wrap .student-table > tbody > tr > td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: none;
    border-right: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .tbl-wrap.student-table-wrap .student-table > thead > tr > th:first-child {
    z-index: 3;
    background: #f8fafc;
  }

  .tbl-wrap.student-table-wrap .student-table > tbody > tr > td:first-child {
    background: #fff;
  }

  .tbl-wrap.student-table-wrap .student-table > tbody > tr.student-row:hover > td:first-child,
  .tbl-wrap.student-table-wrap .student-table > tbody > tr:hover > td:first-child {
    background: #f8fafc;
  }

  .tbl-wrap.coach-table-wrap .coach-table > thead > tr > th:first-child,
  .tbl-wrap.coach-table-wrap .coach-table > tbody > tr > td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: none;
    border-right: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .tbl-wrap.coach-table-wrap .coach-table > thead > tr > th:first-child {
    z-index: 3;
    background: #f8fafc;
  }

  .tbl-wrap.coach-table-wrap .coach-table > tbody > tr > td:first-child {
    background: #fff;
  }

  .tbl-wrap.coach-table-wrap .coach-table > tbody > tr.coach-row:hover > td:first-child {
    background: #f8fafc;
  }

  /* Modal 手機全寬 */
  .mc {
    width: 96%;
    max-width: none;
    max-height: 90vh;
    padding: 18px;
    margin: 10px;
  }

  .dynamic-modal__card {
    width: calc(100vw - 16px);
    margin: 8px;
  }

  .mh h3 {
    font-size: 16px;
  }

  .notif {
    left: 10px;
    right: 10px;
    top: 10px;
    max-width: none;
  }
}

/* ----- 通告頁：手機改單欄 ----- */
@media (max-width: 768px) {
  #notices .row2 {
    grid-template-columns: 1fr;
  }

  #notices .fg textarea {
    min-height: 120px;
  }

  #notices .notice-template-card.template-item {
    padding: 14px;
  }

}

/* ----- 儀表板：手機圖表與表格 ----- */
@media (max-width: 768px) {
  .dashboard-charts {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  #dashboard #studentGrowthChart,
  #dashboard #incomeChart {
    height: 220px;
  }

  .progress-chart {
    width: 100%;
  }
}

/* ----- 桌面 1920×1080：善用寬度 ----- */
@media (min-width: 769px) and (max-width: 1920px) {
  body {
    padding: 20px;
  }

  .wrap {
    max-width: 1600px;
    margin: 0 auto;
  }

  .body {
    max-height: none;
  }
}

@media (min-width: 1921px) {
  body {
    padding: 24px;
  }

  .wrap {
    max-width: 1800px;
    margin: 0 auto;
  }

  .hdr {
    padding: 22px 36px;
  }

  .hdr h1 {
    font-size: 26px;
  }

  .body {
    padding: 28px;
    max-height: none;
  }

  .pane h2 {
    font-size: 22px;
  }
}

/* ----- 1080p 全螢幕優化 (寬度 1920) ----- */
@media (min-width: 1200px) {
  .cards {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
  }

  .card .val {
    font-size: 26px;
  }

  .dashboard-charts {
    gap: 20px;
  }

  #dashboard #studentGrowthChart,
  #dashboard #incomeChart {
    height: 280px;
  }
}

/* ----- 觸控裝置：加大可點擊區 ----- */
@media (hover: none) and (pointer: coarse) {
  .tab {
    min-height: 48px;
    padding: 14px 16px;
  }

  .hdr-btn {
    min-height: 44px;
  }

  .ts, .sn, .pm, .rf {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sn {
    justify-content: flex-start;
  }
}
