/* Shared responsive guardrails for pages with their own inline layouts. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-width: 320px;
}

html {
  overflow-x: clip;
}

body {
  overflow-x: clip;
}

img,
video,
canvas {
  max-width: 100%;
}

main,
header,
section,
article,
.app,
.layout,
.grid,
.card,
.topbar,
.page-head,
.faculty-content,
.canvas,
.panel {
  min-width: 0;
  max-width: 100%;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

/* Wide data views scroll inside their own container, not the whole page. */
#content,
.table-wrap,
.adj-table-wrap,
.timetable,
.student-timetable-scroll,
#sbOfferings > div,
#sbResult > div[style*="overflow"] {
  min-width: 0;
  max-width: 100%;
}

.table-wrap,
.adj-table-wrap,
#content,
#sbOfferings > div,
#sbResult > div[style*="overflow"] {
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.notif-panel,
.profile-menu,
.admin-search-results {
  max-width: calc(100vw - 24px);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--green-600, #2f795b);
  outline-offset: 2px;
}

/* The builder needs all three work areas without squeezing its timetable on
   tablet widths. Keep the existing navigation available as a drawer. */
@media (max-width: 1100px) {
  body[data-page="schedule-builder"] .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  body[data-page="schedule-builder"] .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: min(248px, calc(100vw - 48px));
    height: 100dvh;
    grid-column: auto;
    grid-row: auto;
    transform: translateX(-100%);
    transition: transform .3s ease;
  }

  body[data-page="schedule-builder"] .sidebar.is-open {
    transform: translateX(0);
  }

  body[data-page="schedule-builder"] .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: block;
    background: var(--overlay-dark);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
  }

  body[data-page="schedule-builder"] .sidebar-scrim.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  body[data-page="schedule-builder"] .mobile-nav-toggle {
    display: inline-flex;
  }

  body[data-page="schedule-builder"] .topbar,
  body[data-page="schedule-builder"] .canvas,
  body[data-page="schedule-builder"] .panel {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
  }

  body[data-page="schedule-builder"] .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }

  body[data-page="schedule-builder"] .tb-left {
    min-width: 0;
    flex-wrap: wrap;
  }

  body[data-page="schedule-builder"] .canvas,
  body[data-page="schedule-builder"] .panel {
    overflow: visible;
  }

  body[data-page="schedule-builder"] .grid-card {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
  }
}

@media (max-width: 700px) {
  body[data-page="schedule-builder"] .topbar,
  body[data-page="schedule-builder"] .canvas,
  body[data-page="schedule-builder"] .panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  body[data-page="schedule-builder"] .tb-left h1 {
    font-size: 17px;
  }

  body[data-page="schedule-builder"] .term-pill {
    white-space: normal;
  }

  body[data-page="schedule-builder"] .formgrid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-page="schedule-builder"] .action-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 560px) {
  body[data-role="student"] header {
    flex-wrap: wrap;
    gap: 12px;
  }

  body[data-role="student"] .brand {
    min-width: 0;
    font-size: 17px;
  }

  body[data-role="student"] .topbar-right {
    margin-left: auto;
  }

  body[data-role="student"] .brand-logo {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  body[data-role="faculty"] .adj-detail-dialog,
  body[data-role="faculty"] .profile-modal {
    width: 100%;
    max-width: 100%;
  }

  body[data-role="faculty"] .adj-detail-dialog dl {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
