/* Responsive ERP finish. Paper documents deliberately keep their own styles. */
@media screen {
  body .app-container .main-header { gap: 16px; min-height: 70px; height: auto; padding-top: 10px; padding-bottom: 10px; }
  body .app-container .main-header .page-title { flex: 0 1 auto; min-width: 0; line-height: 1.45; }
  body .app-container .main-header .header-school-name { font-size: 14px; font-weight: 700; }
  body .app-container .main-header .page-title h1 { font-size: 12px; font-weight: 500; color: var(--ui-muted); }
  body .app-container .main-header .header-actions { flex-wrap: nowrap; gap: 8px; }
  body .app-container .main-header .header-icon-btn { width: 36px; height: 36px; }
  body .app-container .main-header #shared-export-menu { margin-right: 4px !important; }
  body .app-container .main-header .header-search-btn { min-width: 36px; flex-shrink: 0; }
  body .app-container .page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
  body .app-container :is(.page-header,.section-header) > div { min-width: 0; }
  body .app-container .page-header h1 { font-size: clamp(23px, 2vw, 30px); line-height: 1.25; margin-bottom: 8px; }
  body .app-container .page-header p { color: var(--ui-muted); font-size: 13px; line-height: 1.65; max-width: 75ch; margin-top: 6px; }
  body .app-container .page-header .eyebrow { margin-bottom: 8px; line-height: 1.5; }
  body .app-container .content-body > .card + .card { margin-top: 22px; }
  body .app-container .erp-two-col > * { min-width: 0; max-width: 100%; }
  body .app-container .erp-two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body .app-container :is(.form-grid,.stats-grid,.payroll-stat-grid,.user-stats) > * { min-width: 0; }
  body .app-container :is(.stat-value,.stat-info h3,.payroll-stat-card strong,.user-stat strong,.hr-kpis strong) { white-space: nowrap; font-variant-numeric: tabular-nums; letter-spacing: -.025em; }
  body .app-container :is(.table-container,.table-responsive,.hr-table-scroll,.tt-week-scroll,.fc-svg-scroll) { scrollbar-width: thin; scrollbar-color: #a6b7cf transparent; }
  body .app-container :is(.table-container,.table-responsive,.hr-table-scroll) { border-radius: 12px; background: var(--ui-surface); }
  body .app-container :is(.table-container,.table-responsive) table { margin: 0; }
  body .app-container :is(.table-container,.table-responsive) td { line-height: 1.6; }
  body .app-container .btn svg { flex-shrink: 0; }
  body .app-container .btn:disabled { opacity: .55; box-shadow: none; }
  body .modal .modal-content { max-height: calc(100dvh - 24px); border: 1px solid var(--ui-line, var(--border-color)); border-radius: 16px; }
  body .modal .modal-header { gap: 16px; align-items: flex-start; }
  body .modal .modal-close { flex-shrink: 0; min-width: 36px; min-height: 36px; display: grid; place-items: center; border-radius: 8px; }
  body .modal .modal-close:hover { background: var(--bg-tertiary); }
  body .modal .modal-footer { gap: 10px; flex-wrap: wrap; }
}
@media screen and (max-width: 1200px) {
  body .app-container .main-header .header-search-text,
  body .app-container .main-header .header-search-kbd,
  body .app-container .main-header .header-academic-year > span { display: none; }
  body .app-container .main-header .header-search-btn { width: 36px; padding: 8px; justify-content: center; margin: 0 0 0 auto; }
}
@media screen and (max-width: 960px) {
  body .app-container .erp-two-col { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (max-width: 768px) {
  body .app-container .main-header {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 8px 10px; padding: 10px 14px; height: auto; align-items: center;
  }
  body .app-container .main-header .mobile-menu-toggle { grid-column: 1; width: 40px; height: 40px; }
  body .app-container .main-header .page-title { grid-column: 2; text-align: left; }
  body .app-container .main-header .header-school-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body .app-container .main-header .page-title h1 { font-size: 11px; line-height: 1.5; }
  body .app-container .main-header .header-search-btn { grid-column: 3; width: 40px; height: 40px; margin: 0; }
  body .app-container .main-header .header-actions { grid-column: 1 / -1; width: 100%; justify-content: flex-end; gap: 6px; min-width: 0; }
  body .app-container .main-header .header-user-role { display: none; }
  body .app-container .main-header .header-academic-year { order: -1; margin-right: auto; padding: 0 6px; gap: 3px; min-height: 40px; background: var(--ui-surface); border-color: var(--ui-line); }
  body .app-container .main-header .header-academic-year svg { display: none; }
  body .app-container .main-header .header-academic-year select { min-height: 38px; width: 118px; min-width: 0; padding: 6px; font-size: 12px; background: transparent; border: 0; }
  body .app-container .main-header #shared-export-menu { gap: 5px !important; margin: 0 !important; }
  body .app-container .main-header #shared-export-menu .btn { padding: 7px 9px; min-height: 40px; font-size: 11px; gap: 5px; }
  body .app-container .main-header #shared-export-menu svg { display: none; }
  body .app-container .main-header .header-icon-btn { width: 36px; height: 40px; }
  body .app-container :is(.page-header,.content-body > .section-header) { padding: 20px; gap: 16px; }
  body .app-container :is(.page-header,.section-header) > .header-actions { width: 100%; }
  body .app-container .card { min-width: 0; }
  body .app-container .exam-tabs { flex-wrap: wrap; overflow: visible; gap: 6px; }
  body .app-container .exam-tabs > button { white-space: normal; flex: 1 1 100px; min-height: 44px; padding: 10px; line-height: 1.4; }
  body .app-container .payroll-stat-card { flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; }
  body .app-container .payroll-stat-card strong { font-size: 23px; }
  body .app-container .payroll-stat-card small { line-height: 1.5; }
  body .app-container .users-toolbar { padding: 12px 0; }
  body .app-container .users-toolbar select { flex: 1 1 100px; }
  body .app-container .users-toolbar > .form-group { flex: 1 1 100%; }
  body .modal { padding: 12px; }
  body .modal :is(.modal-body,.modal-header,.modal-footer) { padding: 18px; }
  body .modal .modal-header .modal-title { font-size: 19px; line-height: 1.4; }
  body .modal .form-grid { grid-template-columns: minmax(0, 1fr); }
  body .modal .form-control { min-height: 44px; font-size: 16px; }
  body .modal .btn { min-height: 44px; }
}
@media screen and (max-width: 360px) {
  body .app-container .main-header .header-actions { flex-wrap: wrap; }
  body .app-container .main-header #header-fullscreen-toggle { display: none; }
  body .app-container .payroll-stat-grid { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (prefers-reduced-motion: reduce) {
  body .app-container :is(.btn,.card,.main-wrapper) { transition: none; }
}

@media screen {
  /* A decorative pseudo-element must not become a filter-grid column. */
  body .app-container .content-body > .card::before { display: none; }
  body .app-container #management-section > .card + .card { margin-top: 22px; }
  body .app-container :is(.table-container,.table-responsive) > table { min-width: 480px; }
  body .app-container :is(.table-container,.table-responsive) > table:has(tr > :nth-child(5)) { min-width: 720px; }
  body .app-container :is(.table-container,.table-responsive) th { white-space: nowrap; overflow-wrap: normal; }
  body .app-container :is(.table-container,.table-responsive) td { overflow-wrap: normal; word-break: normal; }
  body .app-container :is(.reg-document,.adm-document) table { min-width: 0; }
}

@media screen {
  body .app-container .inquiry-report-charts > :only-child { grid-column: 1 / -1; }
  body .app-container .inquiry-report-chart { min-width: 0; max-width: 100%; }
  body .app-container .inquiry-report-chart canvas { max-width: 100%; }
  body .app-container .inq-funnel-stepper { grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) auto minmax(0,1fr); }
  body .app-container .inq-stepper-node, body .app-container .inq-stepper-info { min-width: 0; }
}
@media screen and (max-width: 1100px) {
  body .app-container .inq-funnel-stepper { grid-template-columns: minmax(0,1fr); }
  body .app-container .inq-stepper-arrow { display: none; }
}
@media screen and (max-width: 720px) {
  body .app-container .inquiry-report-charts { grid-template-columns: minmax(0,1fr); }
  /* Keep the assistant available without covering the student form's save actions. */
  body.student-form-open #bird-assistant .bird-launch { bottom: 182px; width: 48px; height: 52px; border-radius: 16px; right: 12px; animation: none; }
  body.student-form-open #bird-assistant .bird-launch svg { width: 36px; height: 36px; }
  body.student-form-open #bird-assistant .bird-launch span { display: none; }
}

@media screen {
  #student-modal .student-form-header-main { width: 100%; min-width: 0; }
  #student-modal .student-header-left { flex: 1 1 360px; }
  #student-modal .student-header-actions { flex: 0 1 auto; }
  #student-modal .student-header-title-box { min-width: 0; }
}
@media screen and (max-width: 768px) {
  #student-modal .student-form-header-main { flex-direction: column; gap: 18px; }
  #student-modal .student-header-left, #student-modal .student-header-actions { flex: none; width: 100%; }
  #student-modal .student-header-actions > .btn { flex: 1 1 100px; }
  #student-modal .student-breadcrumb { flex-wrap: wrap; }
  #student-modal .student-page-title { font-size: 23px; line-height: 1.3; }
  #student-modal .modal-header.student-page-form-header { padding: 18px !important; background: var(--student-soft) !important; }
}

/* Keep the navigation shell stable before session/profile requests finish. */
/* Let native navigation retain the previous frame until the next page paints. */
@view-transition { navigation: none; }
::view-transition-old(root), ::view-transition-new(root), ::view-transition-group(root) { animation: none; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  ::view-transition-old(root), ::view-transition-new(root), ::view-transition-group(root) { animation: none; }
}

/* Controls and the panels containing them stay in place while being used. */
@media screen {
  html body .app-container .card { transition: border-color 160ms ease, box-shadow 160ms ease; }
  html body .app-container :is(.card,.ops-card,.pipeline-card,.academic-item,.ad-panel,.ad-kpi,.ad-focus-card,.da-card,.fv-card,.hd-stat,.hd-shortcuts a):is(:hover,:active,:focus-visible) { transform:none !important; }
  html body .app-container :is(.btn,.student-icon-button,.app-tabs button),
  html body.app-mobile :is(.module-grid button,button.primary),
  html body .mobile-shell button {
    transition-property:background-color,color,border-color,box-shadow,opacity;
    transition-duration:160ms;
    transition-timing-function:ease;
  }
  html body .app-container :is(.btn,.student-icon-button,.app-tabs button):is(:hover,:active),
  html body.app-mobile :is(.module-grid button,button.primary):is(:hover,:active),
  html body .mobile-shell button:is(:hover,:active) { transform:none !important; }
  html body .modal.active .modal-content { animation:erp-dialog-appear 120ms ease-out; }
  #family-status { min-height:1.5em; line-height:1.5; }
}
@keyframes erp-dialog-appear { from { opacity:.85; } to { opacity:1; } }
@media screen and (prefers-reduced-motion:reduce) {
  html body .modal.active .modal-content { animation:none; }
  html body .app-container :is(.btn,.student-icon-button,.app-tabs button),
  html body.app-mobile :is(.module-grid button,button.primary),
  html body .mobile-shell button { transition:none; }
}
@media screen {
  body .app-container .main-wrapper { transition: none; }
  body .app-container .main-header { min-height: 78px; }
  body .app-container #header-container { min-height: 78px; }
  body .app-container .main-header .header-school-name { min-height: 20px; line-height: 20px; }
  body .app-container .main-header .header-academic-year select { width: 118px; }
  body .app-container .sidebar { transition-property: transform; }
  html { scrollbar-gutter: stable; }
}
@media screen and (max-width: 900px) {
  body:not([data-menu-position]) .app-container .main-wrapper { margin-left: 0; margin-right: 0; margin-top: 0; }
  body:not([data-menu-position]) .app-container .mobile-menu-toggle { display: grid; }
}
@media screen and (max-width: 768px) {
  body .app-container #header-container, body .app-container .main-header { min-height: 108px; }
}

@media screen {
  body .app-container i[data-lucide] { display: inline-block; width: 24px; height: 24px; flex-shrink: 0; }
  body.students-page .btn i[data-lucide] { width: 14px; height: 14px; }
  body .app-container .main-header i[data-lucide] { width: 16px; height: 16px; }
  /* Reserve the first student card while its records arrive. */
  body .app-container .students-grid:has(> .student-empty) { min-height: 420px; align-content: start; }
}

/* Device layout rules shared by every ERP workspace. Never resize paper output. */
@media screen {
  body .app-container .main-header .header-account { position: relative; margin-left: auto; flex: 0 0 44px; align-self: center; }
  body .header-account > summary { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; list-style: none; }
  body .header-account > summary::-webkit-details-marker { display: none; }
  body .header-account > summary:focus-visible { outline: 3px solid var(--ui-brand,#0b6c7a); outline-offset: 3px; }
  body .header-account-avatar { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--ui-line,#cbdbe5); border-radius: 50%; background: var(--theme-soft,#eaf5f8); color: var(--text-primary,#16344b); font-size: 16px; font-weight: 700; }
  body .header-account[open] > summary { background: var(--ui-line,#cbdbe5); }
  body .header-account-panel { position: absolute; z-index: 150; right: 0; top: calc(100% + 10px); width: 260px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 92px); overflow-y: auto; padding: 8px; background: var(--bg-secondary,#fff); color: var(--text-primary,#16344b); border: 1px solid var(--ui-line,#cbdbe5); border-radius: 14px; box-shadow: 0 12px 40px #10283e30; }
  body .header-account-identity { padding: 12px; margin-bottom: 6px; border-bottom: 1px solid var(--ui-line,#cbdbe5); overflow-wrap: anywhere; }
  body .header-account-identity strong, body .header-account-identity span { display: block; }
  body .header-account-identity strong { font-size: 14px; line-height: 1.5; }
  body .header-account-identity span { margin-top: 3px; color: var(--text-secondary,#64748b); font-size: 12px; text-transform: capitalize; }
  body .header-account-panel button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; font: inherit; font-size: 14px; text-align: left; }
  body .header-account-panel button:is(:hover,:focus-visible) { background: var(--theme-soft,#eaf5f8); outline-offset: -2px; }
  body .header-account-panel button svg { width: 18px; height: 18px; }
  body .header-account-panel #logout-btn { border-top: 1px solid var(--ui-line,#cbdbe5); border-radius: 0 0 8px 8px; margin-top: 6px; color: var(--accent-danger,#c2413a); }
  body .account-profile-dialog { width: 440px; padding: 24px; border: 1px solid var(--ui-line,#cbdbe5); border-radius: 16px; background: var(--bg-secondary,#fff); color: var(--text-primary,#16344b); margin: auto; }
  body #account-password-dialog { margin: auto; background: var(--bg-secondary,#fff); color: var(--text-primary,#16344b); }
  body #account-password-dialog h2 { margin-bottom: 20px; }
  body #account-password-dialog::backdrop { background: #10283e80; }
  body #account-password-status { margin: 12px 0; font-size: 14px; line-height: 1.5; }
  body .account-profile-dialog::backdrop { background: #10283e80; }
  body .account-profile-dialog h2 { margin: 0 0 20px; font-size: 22px; }
  body .account-profile-dialog dl { margin: 0 0 22px; }
  body .account-profile-dialog dl > div { padding: 12px 0; border-bottom: 1px solid var(--ui-line,#cbdbe5); }
  body .account-profile-dialog dt { font-size: 12px; color: var(--text-secondary,#64748b); margin-bottom: 5px; }
  body .account-profile-dialog dd { margin: 0; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
  body .account-profile-actions { display: flex; flex-wrap: wrap; gap: 10px; }
  body .app-container { width: 100%; min-width: 0; }
  body .app-container .main-wrapper { flex: 1 1 0; min-width: 0; }
  body .app-container :is(.content-body,.ad-content,.rd-content) { min-width: 0; max-width: 100%; }
  body .app-container :is(.card,.form-group,.form-section,.report-main,.report-directory,.fr-card,.af-layout,.af-layout>*,.student-fee-profile>*) { min-width: 0; }
  body .app-container :is(.form-grid,.form-grid-3,.form-grid-4,.stats-grid,.charts-grid,.erp-two-col) > * { min-width: 0; }
  body .app-container :is(.form-control,.form-select,input,select,textarea) { max-width: 100%; }
  body .app-container fieldset { min-inline-size: 0; }
  body .app-container :is(.page-header,.section-header,.students-page-heading,.ad-page-heading,.fc-heading) { flex-wrap: wrap; }
  body .app-container :is(.page-header,.section-header,.students-page-heading,.ad-page-heading,.fc-heading) > * { min-width: 0; }
  body .app-container :is(.table-container,.table-responsive,.table-wrap,.table-scroll,.hr-table-scroll,.access-table-scroll,.report-data,.fr-table-wrap,.tt-week-scroll,.fc-svg-scroll) {
    min-width: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch;
  }
  body .app-container :is(.content-body,.ad-content,.rd-content) :is(img,video,iframe) { max-width: 100%; }
  body .app-container :is(.student-breadcrumb,.erp-action-row,.filter-controls,.card-actions) { flex-wrap: wrap; }
  body .app-container :is(.stat-value,.stat-info h3,.user-stat strong,.payroll-stat-card strong) { overflow-wrap: anywhere; }
  body .sidebar-close { display: none; }
  body :is(.modal-content,dialog) { overscroll-behavior: contain; }
  body dialog { max-inline-size: calc(100vw - 24px); max-block-size: calc(100dvh - 24px); overflow: auto; }
  body .modal .modal-content { min-width: 0; max-height: calc(100dvh - 24px); }
  body .modal :is(.modal-header,.modal-footer) { flex-shrink: 0; }
  body .modal .modal-body { min-height: 0; overflow-y: auto; }
  body .command-palette-dialog { max-height: calc(100dvh - 48px); }
  body .command-palette-results { min-height: 0; overflow-y: auto; }
  body .platform-layout, body .platform-main, body .saas-workspace main { min-width: 0; }
  body.app-mobile :is(.app-shell,main,section,article,.profile-list,.app-stats) { min-width: 0; max-width: 100%; }
  body.app-mobile :is(.table-scroll,.table-container) { min-width: 0; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body.saas-workspace :is(.directory-filters,.page-title,.section-heading,.workspace-meta,.dialog-footer,.enquiry-filters,.access-actions) { flex-wrap: wrap; }
  body.saas-workspace :is(.form-grid,.account-form,.module-price-row,.detail-grid) > * { min-width: 0; }
}

@media screen and (min-width: 901px) and (max-width: 1200px) {
  html body .app-container .main-header { flex-wrap: wrap; gap: 12px; }
  html body .app-container .main-header .page-title { flex: 1 1 240px; }
  html body .app-container .main-header .header-actions { margin-left: auto; flex-wrap: wrap; }
  html body .app-container .main-header .header-user-role { display: none; }
  body .app-container :is(.content-body,.ad-content,.rd-content) { padding-inline: 22px; }
  body .app-container .form-grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media screen and (max-width: 900px) {
  html body .app-container .main-header {
    display: grid; grid-template-columns: 44px minmax(0,1fr) 44px;
    gap: 8px 10px; padding: 10px 14px; height: auto;
  }
  html body .app-container .main-header .mobile-menu-toggle { display: grid; grid-column: 1; place-items: center; width: 44px; height: 44px; }
  html body .app-container .main-header .page-title { grid-column: 2; min-width: 0; }
  html body .app-container .main-header .header-school-copy { min-width: 0; }
  html body .app-container #header-container .main-header .header-school-name { white-space: normal; overflow-wrap: anywhere; line-height: 1.3; font-size: 15px; }
  html body .app-container .main-header .page-title h1 { font-size: 12px; }
  html body .app-container .main-header .header-search-btn { grid-column: 3; width: 44px; height: 44px; margin: 0; }
  html body .app-container .main-header .header-actions { grid-column: 1 / -1; flex-wrap: wrap; width: 100%; gap: 8px; }
  html body .app-container .main-header .header-account { grid-column: 3; grid-row: 1; }
  html body .app-container .main-header .header-user-role { display: none; }
  html body .app-container .main-header .header-academic-year { margin-right: auto; min-height: 44px; }
  html body .app-container .main-header .header-academic-year > span { display: none; }
  html body .app-container .main-header .header-academic-year select { min-height: 42px; width: 126px; max-width: 100%; font-size: 14px; }
  html body .app-container .main-header .header-icon-btn { display: grid; place-items: center; width: 44px; height: 44px; }
  body.sidebar-open { overflow: hidden; }
  html body .app-container .sidebar { max-width: calc(100vw - 24px); height: 100dvh; min-height: 0; padding-bottom: env(safe-area-inset-bottom,0px); }
  html body .app-container #sidebar-container .sidebar .sidebar-brand { padding: 18px 52px 18px 12px; gap: 8px; justify-content: flex-start; flex-shrink: 0; }
  body .sidebar .campus-brand-symbol { flex-basis: 38px; width: 38px; height: 44px; background-size: 238px 79px; background-position: -12px -17px; }
  body .sidebar .campus-brand-wordmark strong { font-size: 17px; letter-spacing: -.5px; }
  body .sidebar .campus-brand-wordmark small { font-size: 9px; letter-spacing: 2px; }
  body.sidebar-open #bird-assistant { visibility: hidden; pointer-events: none; }
  html body .app-container .sidebar-menu { min-height: 0; overscroll-behavior: contain; }
  html body .app-container .sidebar-close {
    display: grid; place-items: center; position: absolute; top: 12px; right: 10px;
    width: 40px; height: 40px; padding: 8px; color: #fff; background: #ffffff14;
    border: 1px solid #ffffff40; border-radius: 9px; cursor: pointer; z-index: 1;
  }
  body .sidebar-close:focus-visible { outline: 3px solid #7dd3fc; outline-offset: 2px; }
  body .app-container :is(.content-body,.ad-content,.rd-content) { padding-inline: 18px; }
  body .app-container :is(.form-grid,.form-grid-3,.form-grid-4) { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body .app-container :is(.charts-grid,.report-details-grid,.erp-two-col) { grid-template-columns: minmax(0,1fr) !important; }
  body .app-container .student-fee-profile { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body.saas-workspace .platform-main > main { padding-inline: 18px; }
}

@media screen and (max-width: 600px) {
  html { scroll-padding-bottom: 96px; }
  body #bird-assistant .bird-launch { width: 48px; height: 48px; right: 12px; bottom: max(12px,env(safe-area-inset-bottom,0px)); border-radius: 50%; place-items: center; animation: none; }
  body #bird-assistant .bird-launch svg { width: 34px; height: 34px; }
  body #bird-assistant .bird-launch span { display: none; }
  body #bird-panel { right: 12px; bottom: calc(72px + env(safe-area-inset-bottom,0px)); max-height: calc(100dvh - 96px - env(safe-area-inset-bottom,0px)); }
  body .app-container :is(.content-body,.ad-content,.rd-content) { padding: 16px 12px; }
  body .app-container :is(.form-grid,.form-grid-3,.form-grid-4,.month-checkbox-grid,.report-metrics-grid) { grid-template-columns: minmax(0,1fr) !important; }
  body .app-container :is(.form-grid,.form-grid-3,.form-grid-4) > [style*="grid-column"] { grid-column: 1 / -1 !important; }
  body .app-container :is(.page-header,.content-body > .section-header) { padding: 18px 16px; }
  body .app-container :is(.page-header,.section-header,.students-page-heading,.fc-heading) .btn { white-space: normal; line-height: 1.4; }
  body .app-container :is(.card-actions,.erp-action-row,.header-actions) > .btn { flex: 1 1 auto; }
  html body .app-container :is(.form-control,.form-select,input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea),
  body .modal :is(input:not([type=checkbox]):not([type=radio]),select,textarea),
  body.app-mobile :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea),
  body.saas-workspace :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea) { font-size: 16px; min-height: 44px; }
  html body .app-container .main-header .header-academic-year select { font-size: 16px; }
  body .app-container :is(.btn,.tabs button,.tab-nav button,.exam-tabs button) { min-height: 44px; }
  body .app-container :is(.stat-value,.stat-info h3,.user-stat strong,.payroll-stat-card strong) { white-space: normal; }
  body .app-container .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 12px; }
  body .app-container .student-fee-profile { grid-template-columns: minmax(0,1fr); }
  body .modal { padding: 12px; padding-block-end: max(12px,env(safe-area-inset-bottom,0px)); }
  body .modal .modal-content { width: 100%; max-width: calc(100vw - 24px) !important; max-height: calc(100dvh - 24px); }
  body .modal :is(.modal-header,.modal-body,.modal-footer) { padding: 16px; }
  body .modal .modal-footer > .btn { flex: 1 1 120px; min-height: 44px; white-space: normal; }
  body .modal :is(.form-grid,.form-grid-3,.form-grid-4) { grid-template-columns: minmax(0,1fr) !important; }
  body .command-palette-backdrop { padding: 12px; padding-top: max(12px,env(safe-area-inset-top,0px)); }
  body .command-palette-header { padding: 14px; gap: 8px; }
  body .command-palette-input { min-width: 0; font-size: 16px; }
  body .command-palette-footer { flex-wrap: wrap; gap: 8px; }
  body.saas-workspace .platform-main > main { padding: 16px 12px; }
  body.saas-workspace :is(.page-title,#school-register,#domain-register,#subscription-register,#audit-register,#owner-account) { padding: 18px 14px; }
  body.saas-workspace .directory-filters { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; }
  body.saas-workspace .directory-filters .search-field { min-width: 0; grid-column: 1 / -1; }
  body.saas-workspace .directory-filters :is(select,#school-sort) { width: 100%; min-width: 0; }
  body.saas-workspace :is(.dialog-header,.dialog-body,.dialog-footer) { padding: 18px 14px; }
  body.saas-workspace .form-grid { grid-template-columns: minmax(0,1fr); }
  body.saas-workspace .form-grid > .full { grid-column: 1; }
  body.saas-workspace .platform-sidebar nav button { min-height: 44px; }
  body.saas-workspace .page-title > .primary { width: 100%; }
  body.login-page .form-control { font-size: 16px; min-height: 44px; }
  body.login-page .password-toggle-btn { width: 44px; height: 44px; top: 3px; right: 3px; }
  body :is(#account-password-dialog,.account-profile-dialog) .btn { min-height: 44px; }
  body #account-password-dialog .form-control { min-height: 44px; font-size: 16px; }
  /* Coarse-pointer slide buttons need room to wrap on narrow school websites. */
  body .slider-controls-wrap { width: calc(100% - 32px); padding: 0; flex-wrap: wrap; gap: 12px; }
  body .slider-indicators { min-width: 0; flex-wrap: wrap; }
  body .slider-status { flex-shrink: 0; margin-left: auto; }
  body .slide-counter { white-space: nowrap; }
  body.app-mobile :is(button,.primary,.secondary) { min-height: 44px; }
  body.app-mobile .bottom-nav { padding-bottom: max(10px,env(safe-area-inset-bottom,0px)); }
}

@media screen and (max-width: 360px) {
  html body .app-container .main-header { padding-inline: 10px; column-gap: 8px; }
  html body .app-container .main-header .header-school-emblem { display: none; }
  body .app-container .stats-grid { grid-template-columns: minmax(0,1fr) !important; }
}

@media screen and (max-width:900px) and (max-height:500px) {
  html body .app-container .sidebar { overflow-y: auto; }
  html body .app-container .sidebar-menu { flex: 0 0 auto; overflow: visible; }
  html body .app-container .sidebar-footer { flex-shrink: 0; }
  body .command-palette-dialog { max-height: calc(100dvh - 24px); }
}

/* Consistent touch controls, including page-specific chips and row actions. */
@media screen and (max-width: 600px) {
  html body .app-container :is(button,.btn),
  html body .modal button,
  html body dialog button,
  html body.saas-workspace button,
  html body.demo-page button,
  html body .toast-dismiss,
  html body .consent-dialog button,
  html body :is(#select-all,#privacy-open) { min-height: 44px !important; }
  html body .app-container :is(.student-icon-button,.modal-close,.rd-calendar-heading button),
  html body.saas-workspace .icon-button { min-width: 44px; }
  html body .toast-dismiss { min-width:44px; }
  html body .app-container #driver-password-toggle { padding-block: 10px; }
  html body.saas-workspace #school-status,
  html body .app-container #school-logo { font-size: 16px; }
  html body dialog :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea) { font-size: 16px; min-height: 44px; }
  html body .app-container .user-row-menu summary { min-height: 44px; display: grid; place-items: center; }
  html body.demo-page .login-container { min-width: 0; padding: 28px 20px; }
  html body.demo-page .demo-chips-title { flex-wrap: wrap; gap: 5px; }
  html body.demo-page .demo-pill { min-width: 0; padding-inline: 6px; }
  html body.demo-page .form-control { min-height: 48px; font-size: 16px; }
  html body.demo-page .password-toggle-btn { width: 44px; right: 2px; }
  html body.demo-page #password { padding-right: 48px; }
  html body .mobile-admin .application-grid { grid-template-columns: minmax(0,1fr); }
}

@media screen {
  body.demo-page .login-container { color: #e2e8f0; }
  body.demo-page :is(.form-group label,.remember-me-label) { color: #cbd5e1; }
  body.demo-page .login-header p { color: #b7c5d8; }
  body.demo-page .demo-pill:focus-visible { outline: 3px solid #67e8f9; outline-offset: 2px; }
  /* Preserve legible columns and scroll the directory within its card. */
  html body.access-page .access-table { min-width: 900px; }
  html body.access-page .user-actions > .btn { white-space: nowrap; flex-shrink: 0; }
  body .app-container .mobile-admin .app-form > * { min-width:0; }
  body .app-container .mobile-admin .app-form :is(input:not([type=checkbox]):not([type=radio]),select) { width:100%; min-width:0; }
  body .app-container .mobile-admin #capability-options label { flex:1 1 160px; min-width:0; min-height:44px; padding:8px; }
  body .app-container .mobile-admin #capability-options input[type=checkbox] { width:18px; height:18px; min-height:18px; flex:0 0 18px; }
  body .app-container .mobile-admin .application-grid h2 { margin:12px 0 18px; }
}

@media screen and (min-width: 601px) {
  body .mobile-admin .application-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media screen and (max-width:360px) {
  body.access-page .user-stat { flex-direction:column; align-items:flex-start; }
}

/* Paper receipt copies stack for screen review; print styles keep the paper layout. */
@media screen and (max-width:900px) {
  html body #receipt-modal #receipt-content:not([data-format^="thermal"]) { width:100%; grid-template-columns:minmax(0,1fr); gap:24px; }
  html body #receipt-content:not([data-format^="thermal"]) .fee-receipt { width:100%; min-width:0; }
  html body #receipt-content:not([data-format^="thermal"]) .fr-table-wrap { min-width:0; max-width:100%; overflow-x:auto; }
  html body #receipt-content:not([data-format^="thermal"]) table { min-width:560px; table-layout:auto; }
  html body #receipt-content:not([data-format^="thermal"]) :is(th,td) { white-space:normal; overflow-wrap:normal; }
  html body #receipt-content:not([data-format^="thermal"]) :is(th,td[data-label]) { white-space:nowrap; }
}
@media screen and (max-width:600px) {
  html body #receipt-content:not([data-format^="thermal"]) .fr-details-compact { grid-template-columns:minmax(0,1fr); gap:10px; }
  html body #receipt-content:not([data-format^="thermal"]) .fr-footer { flex-direction:column; }
  html body #receipt-content:not([data-format^="thermal"]) .fr-table-wrap::before { content:"Swipe to view all columns"; display:block; font:11px/1.5 Arial,sans-serif; color:#536b7c; padding-bottom:8px; }
}

/* Touch tablets and landscape phones keep comfortable controls at wider widths. */
@media screen and (max-width:900px) and (pointer:coarse) {
  html body .app-container :is(button,.btn),
  html body :is(.modal,dialog) button,
  html body.saas-workspace button,
  html body .toast-dismiss { min-height:44px !important; }
  html body .app-container :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea),
  html body :is(.modal,dialog) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea) { font-size:16px; min-height:44px; }
  html body .app-container .main-header .header-academic-year select,
  html body .app-container #school-logo,
  html body.saas-workspace #school-status { font-size:16px; }
  html body .toast-dismiss,
  html body .app-container :is(.student-icon-button,.modal-close,.rd-calendar-heading button,#ad-prev-month,#ad-next-month),
  html body.saas-workspace .icon-button { min-width:44px; }
}
