/* Mobile layout layer: keep readable fields, compact lists, and one scroll surface. */
.mobile-only, .mobile-more-backdrop { display: none; }
.mobile-student-filters, .mobile-student-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.mobile-student-filters .field { flex: 1; }
.mobile-work-section { display: contents; }
.mobile-work-section > summary { display: none; }
@media (max-width: 767px) {
  [hidden] { display: none !important; }
  html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { height: 100dvh; overflow: hidden; font-size: 14px; line-height: 1.45; }
  .app { height: 100%; min-height: 0; overflow: hidden; }
  main { height: 100%; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; padding: 12px 12px calc(80px + env(safe-area-inset-bottom)); }
  .page { min-width: 0; }
  body > .site-icp { display: none; }
  .top { margin-bottom: 10px; }
  .top h1, h1 { font-size: 20px; line-height: 1.3; }
  h2 { font-size: 16px; margin-bottom: 10px; }
  .sub, .hint, .label { font-size: 12px; }
  .hint { padding: 8px 10px; margin-bottom: 10px; }
  .cards { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-bottom: 10px; }
  .card, .panel { padding: 11px; border-radius: 10px; box-shadow: none; }
  .metric { font-size: 23px; margin-top: 2px; }
  .btn, button { font-size: 14px; }
  .btn, .btn.small { min-height: 40px; padding: 8px 10px; }
  .btn:hover { transform: none; }
  /* 16px form fields avoid focus zoom in Safari. */
  input, select, textarea { font-size: 16px; min-height: 40px; max-width: 100%; }
  input[type=checkbox], input[type=radio] { min-height: 20px; width: 20px; }
  .field { min-width: 0; gap: 4px; }
  .field span { font-size: 12px; }
  .field input, .field select, .field textarea { min-height: 40px; }
  .toolbar { display: flex; flex-wrap: wrap; position: static; padding: 0; gap: 8px; margin-bottom: 10px; background: transparent; }
  .toolbar > .field { flex: 1 1 130px; width: auto; }
  .toolbar > .field.grow { flex-basis: 100%; }
  .quick-actions { gap: 6px; flex-wrap: wrap; }
  .table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  th, td { padding: 7px; font-size: 13px; }
  .grid2, .dashboard-main, .dashboard-row, .simple-charts { gap: 10px; }
  .mobile-bottom-nav { position: fixed; inset: auto 0 0; z-index: 900; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 3px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); transform: none; background: #fff; }
  .mobile-bottom-nav button { font-size: 13px; min-height: 44px; border-radius: 9px; padding: 4px 2px; }
  .mobile-more-sheet { bottom: calc(66px + env(safe-area-inset-bottom)); max-height: calc(100dvh - 100px - env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 14px; }
  .mobile-more-sheet.open { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .mobile-more-sheet button { font-size: 14px; min-height: 44px; padding: 8px 10px; }
  .mobile-sheet-title { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; }
  .mobile-menu-open .mobile-more-backdrop { display: block; position: fixed; inset: 0; border: 0; background: #0005; z-index: 890; }
  .mobile-menu-open main { overflow-y: hidden; }
  .mobile-keyboard-open .mobile-bottom-nav, .mobile-keyboard-open .mobile-more-sheet { display: none; }
  #mobileSaveStatus { display: none !important; }
  #cloudStatus { bottom: calc(66px + env(safe-area-inset-bottom)); left: 12px; right: 12px; padding: 8px 10px; font-size: 12px; text-align: center; z-index: 960; }
  #cloudStatus[hidden] { display: none; }
  .mobile-only { display: block; }
  #students > .table-wrap { display: none !important; }
  #mobileStudentCards { display: grid; gap: 7px; }
  #mobileStudentCards .compact-student { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 10px; text-align: left; color: var(--cr-text); font: inherit; width: 100%; margin: 0; padding: 11px 12px; border-radius: 10px; box-shadow: none; }
  .compact-student-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
  .compact-student-hours { color: var(--cr-green); font-size: 12px; white-space: nowrap; }
  .compact-student-hours b { font-size: 18px; }
  .compact-student-class, .compact-student-package { grid-column: 1 / -1; font-size: 12px; color: #555; overflow-wrap: anywhere; }
  .compact-student-package { display: flex; justify-content: space-between; }
  #studentSearch { position: static; }
  #students .student-search-toolbar { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; }
  #students .student-search-toolbar .field { width: 100%; }
  .mobile-student-filters { display: grid; grid-template-columns: minmax(0,1fr) 110px; gap: 8px; margin-bottom: 6px; }
  .mobile-student-tools { gap: 6px; margin-bottom: 10px; }
  .mobile-student-tools .btn { font-size: 12px; }
  .mobile-list-count { font-size: 12px; color: #666; margin: 8px 0; }
  #weekly .panel { position: static; }
  #weekly .week-actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
  #weekly .week-actions > .field { grid-column: 1 / -1; }
  #weekly .week-actions > .pill, #restDayToggle { display: none; }
  #weekly .mobile-day-switch { grid-column: 1 / -1; margin-top: 2px; display: grid; grid-template-columns: 72px minmax(0,1fr) 72px; gap: 6px; }
  #weekBoard .day-column.mobile-active-day { display: block !important; }
  .day-column { padding: 8px; }
  .day-head { font-size: 14px; padding: 3px 2px 7px; }
  .session-card, .class-block, .today-course { padding: 10px; margin-bottom: 8px; border-radius: 10px; }
  .session-card::after { content: none; }
  .session-students { margin-top: 5px; gap: 4px; }
  .session-meta { margin-top: 5px; gap: 4px; }
  .session-meta .pill, .student-name-chip { font-size: 12px; padding: 2px 6px; }
  .mobile-attendance-date { display: grid; grid-template-columns: 40px minmax(0,1fr) 40px 54px; gap: 6px; }
  .mobile-attendance-card { display: grid; gap: 7px; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin: 7px 0; padding: 12px; text-align: left; color: #222; }
  .mobile-attendance-card > span:first-child { display: flex; justify-content: space-between; gap: 8px; }
  .mobile-attendance-card small { color: #666; }
  .mobile-attendance-link { font-size: 13px; color: var(--cr-green); }
  dialog { margin: 0; top: 0; left: 0; padding: 0; height: 100dvh !important; max-height: 100dvh !important; overflow: auto; }
  dialog[open] { display: flex; flex-direction: column; }
  dialog > form { display: flex; flex-direction: column; height: 100%; min-height: 0; }
  dialog .modal-head { flex: 0 0 auto; padding: 12px; font-size: 16px; }
  dialog .modal-body, #workbenchDlg .modal-body, #studentDetailDlg .modal-body { flex: 1 1 auto; min-height: 0; max-height: none; overflow: auto; padding: 12px; }
  dialog .modal-actions { flex: 0 0 auto; position: static; display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  dialog .modal-actions .btn { flex: 1 1 auto; min-height: 44px; }
  dialog .field { margin-bottom: 10px; }
  .mobile-detail-actions { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; margin-bottom: 10px; }
  .mobile-detail-actions .btn { font-size: 12px; padding: 6px 2px; }
  #studentTabs { display: flex; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 10px; gap: 5px; }
  #studentTabs button { white-space: nowrap; min-height: 40px; font-size: 13px; padding: 6px 10px; }
  #studentTabContent p { margin: 7px 0; }
  #studentTabContent .panel { margin-bottom: 8px; }
  .mobile-work-section { display: block; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
  .mobile-work-section > summary { display: list-item; cursor: pointer; font-size: 13px; min-height: 40px; padding: 10px 4px; color: var(--cr-green); }
  .mobile-work-section:not([open]) > :not(summary) { display: none; }
  .mobile-work-section[open] > .work-head { margin-top: 8px; }
  #wbStudents .attendance-item { grid-template-columns: minmax(0,1fr) 114px 58px !important; align-items: center; margin: 6px 0; padding: 10px; border-radius: 10px; gap: 7px; }
  #wbStudents .attendance-item > div:first-child { font-size: 14px; overflow-wrap: anywhere; }
  #wbStudents .attendance-item > div:first-child br { display: none; }
  #wbStudents .attendance-item .work-status { font-size: 16px; padding: 6px; }
  .mobile-row-extras { grid-column: 1 / -1; margin: 0; border-bottom: 0; }
  .mobile-row-extras > summary { min-height: 32px; padding: 6px 0; font-size: 12px; }
  .mobile-row-extras .photo-cell { margin: 8px 0; }
  .mobile-row-extras label { font-size: 12px; display: flex; align-items: center; gap: 6px; }
  .media-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .batch-row { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .batch-row > * { min-width: 0; }
}
