/* Phone-first layout overrides. Dense tables keep their own local scrolling. */
.mobile-nav-toggle,
.sidebar-backdrop { display: none; }

@media (max-width: 760px) {
  html, body { width: 100%; min-width: 0; max-width: 100%; overflow-x: hidden; }
  .app-shell { display: block; width: 100%; min-width: 0; }
  .sidebar {
    position: fixed; z-index: 1001; inset: 0 auto 0 0;
    width: min(84vw, 300px); height: 100dvh; min-height: 100dvh;
    overflow-y: auto; overscroll-behavior: contain;
    padding: 22px 14px 16px;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 12px 0 32px #0b1e3826;
  }
  body.mobile-nav-open { overflow: hidden; }
  body.mobile-nav-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop:not([hidden]) {
    display: block; position: fixed; z-index: 1000; inset: 0;
    width: 100%; height: 100%; padding: 0; border: 0; background: #0a183866;
  }
  .mobile-nav-toggle {
    display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px;
    border: 1px solid #dce5f0; border-radius: 10px; background: #fff;
    color: #27456b; font: inherit; font-size: 19px; cursor: pointer;
  }
  .main-content { width: 100%; min-width: 0; padding: 0 14px 28px; }
  .topbar { display: flex; height: auto; min-height: 58px; gap: 8px; padding: 8px 0; }
  .global-search { flex: 1 1 auto; width: auto; min-width: 0; margin: 0; }
  .global-search input { height: 38px; padding-left: 34px; font-size: 12px; }
  .global-search-icon { left: 9px; font-size: 18px; }
  .account-area { flex: 0 0 auto; gap: 5px; }
  .notification-dot, .account-area #teacherName { display: none; }
  .account-area .avatar { width: 30px; height: 30px; }
  .edit-name-button { padding: 6px 8px; font-size: 11px; white-space: nowrap; }
  .page { min-width: 0; padding-top: 20px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 12px; margin-bottom: 16px; }
  .page-heading h1 { font-size: 27px; line-height: 1.25; }
  .page-heading p { font-size: 13px; line-height: 1.55; }
  .page-heading > .primary-button, .page-heading > .page-actions, .page-heading .page-actions { width: 100%; }
  .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-actions > button { flex: 1 1 auto; }
  .content-card { min-width: 0; padding: 15px; border-radius: 14px; }
  .feature-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .feature-card { min-height: 0; padding: 18px 16px; }
  .feature-heading h2 { font-size: 19px; }
  .feature-heading p { font-size: 12px; }
  .metric-box { min-height: 130px; margin: 20px 0 16px; }
  .metric-box strong { font-size: 54px; }
  .card-toolbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .toolbar-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .toolbar-actions > * { max-width: 100%; }
  .timetable-wrap, .analysis-table, .analysis-multiple-table, .student-list,
  .homework-list-card, .points-record-list, .resource-items { max-width: 100%; overflow-x: auto; }
  .timetable { min-width: 760px; }
  .resource-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .resource-card { min-height: 150px; padding: 15px; }
  .resource-card h2 { margin-top: 12px; font-size: 16px; }
  .resource-card p { font-size: 12px; }
  .student-list-grid, .points-student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .student-title-line, .page-title-with-classes { align-items: flex-start; flex-wrap: wrap; gap: 8px; }
  .timetable-title-line { align-items: center; flex-wrap: nowrap; gap: 6px; }
  .class-tabs { max-width: 100%; overflow-x: auto; }
  .timetable-inline-classes { max-width: calc(100vw - 150px); min-width: 0; }
  .timetable-inline-classes .class-tabs { flex-wrap: nowrap; min-width: 0; overflow-x: auto; }
  .timetable-inline-classes .class-tab { flex: 0 0 auto; white-space: nowrap; }
  .attendance-card { padding: 13px; }
  .attendance-toolbar { align-items: flex-start; }
  .attendance-inline-stats { width: 100%; }
  .attendance-date-label { margin-left: 0; }
  .attendance-list-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .attendance-student-card { min-width: 0; padding: 6px 4px; }
  .attendance-student-card strong { font-size: 12px; }
  .attendance-student-card span { font-size: 10px; }
  .submission-student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .submission-student-button { min-width: 0; }
  .homework-check-mode .submission-toolbar { display: flex; flex-wrap: wrap; align-items: stretch; }
  .homework-check-mode .submission-toolbar > div, .homework-check-mode .submission-toolbar > select,
  .homework-check-mode .submission-toolbar > input, .homework-check-mode .submission-toolbar > button {
    width: 100%; max-width: 100%; min-width: 0;
  }
  .homework-evaluation-summary { width: 100%; }
  .analysis-overview .analysis-filter-bar { align-items: stretch; }
  .analysis-filter-bar label { min-width: 0; flex: 1 1 100%; }
  .analysis-filter-bar select { width: 100%; max-width: 100%; }
  .analysis-overview .analysis-summary-card { max-width: 100%; }
  .backup-grid { grid-template-columns: minmax(0, 1fr); }
  .modal-card, .modal-dialog, .modal-content {
    width: calc(100vw - 24px); max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px); overflow: auto;
  }
  .modal-backdrop { padding: 12px; overflow-y: auto; }
  .modal { width: 100%; max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px 16px; }
  .timetable-mode { overflow: auto !important; }
  .timetable-mode .app-shell, .timetable-mode .main-content { height: auto; min-height: 100dvh; overflow: visible; }
  .timetable-mode .main-content { padding-bottom: 24px; }
  .timetable-mode #timetablePage { height: auto; min-height: 0; overflow: visible; padding-top: 16px; }
  .timetable-mode #timetablePage .page-heading { flex-direction: column; align-items: flex-start; }
  .timetable-mode #timetablePage .content-card { height: auto; min-height: 0; overflow: visible; }
  .timetable-mode #timetablePage .timetable-wrap { min-height: 0; overflow-x: auto; overflow-y: hidden; }
  .timetable-mode #timetablePage .timetable-grid { height: auto; grid-template-rows: none; }
  #timetablePage .timetable-grid { gap: 4px; }
  #timetablePage .grid-header { height: 36px; min-height: 36px; border-radius: 9px; font-size: 12px; }
  #timetablePage .grid-period,
  #timetablePage .timetable-grid .lesson-cell { height: auto !important; min-height: 50px !important; border-radius: 9px !important; }
  #timetablePage .grid-period { justify-content: center; padding: 5px 4px; }
  #timetablePage .period-name { font-size: 11px; line-height: 1.2; }
  #timetablePage .period-time { margin-top: 2px; font-size: 8px; line-height: 1.15; white-space: nowrap; }
  #timetablePage .timetable-grid .lesson-cell { padding: 5px 2px !important; font-size: 12px; line-height: 1.15; }
  #timetablePage .timetable-grid .lesson-cell small { margin-top: 2px; font-size: 10px; line-height: 1.1; }
  #studentList { width: 100%; max-width: 100%; overflow-x: hidden; }
  #studentList .student-table { width: 100%; min-width: 0; }
  #studentList .student-table-row {
    width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr) 34px 48px minmax(88px, 1.15fr);
    gap: 4px; padding: 9px 6px; align-items: center; font-size: 11px;
  }
  #studentList .student-table-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #studentList .student-table-row > span:nth-child(5) { display: none; }
  #studentList .student-table-head > span:nth-child(4) { font-size: 0; }
  #studentList .student-table-head > span:nth-child(4)::after { content: "电话"; font-size: 11px; }
}

@media (max-width: 420px) {
  .main-content { padding-right: 10px; padding-left: 10px; }
  .topbar { gap: 6px; }
  .edit-name-button { font-size: 10px; padding: 5px 6px; }
  .resource-grid { grid-template-columns: minmax(0, 1fr); }
  .resource-card { min-height: 0; }
  .attendance-list-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .attendance-student-card { padding: 5px 3px; }
  .attendance-student-card strong { font-size: 11px; }
  .attendance-student-card span { font-size: 9px; }
  .submission-student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .homework-evaluation-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .term-progress-heading { align-items: flex-start; flex-direction: column; }
}
