/* SATprep responsive layer v1
   Loaded after main.css. Desktop remains unchanged; overrides apply only at
   viewport/capability breakpoints. */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  overflow-x: hidden;
}

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

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

/* Touch-capable devices need reliable tap targets without changing desktop. */
@media (pointer: coarse) {
  button,
  select,
  input,
  textarea,
  .choice-item,
  .nav-btn,
  .filter-pill {
    min-height: 44px;
  }

  .crossout-btn {
    opacity: 1;
  }
}

/* Tablet landscape / compact laptop */
@media (max-width: 1179px) {
  .site-header {
    height: auto;
    min-height: 68px;
    padding: 10px max(20px, var(--safe-right)) 10px max(20px, var(--safe-left));
    gap: 14px;
  }

  .nav-links {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .page-container {
    max-width: 100%;
    padding: 36px max(24px, var(--safe-right)) calc(72px + var(--safe-bottom)) max(24px, var(--safe-left));
  }

  .hero-section {
    gap: 32px;
  }

  .catalog-grid,
  .catalog-offering-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .test-card {
    min-width: 0;
  }

  .admin-shell,
  .admin-main,
  .admin-panel,
  .admin-card {
    min-width: 0;
  }

  .admin-nav,
  .admin-tabs {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    white-space: nowrap;
    scrollbar-width: thin;
  }

  .admin-toolbar,
  .admin-workflow-bar,
  .admin-workflow-group {
    flex-wrap: wrap;
  }

  .admin-table-wrap,
  .admin-table-container,
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .admin-table,
  table.admin-table {
    min-width: 980px;
  }

  /* Keep split Proctor on iPad landscape, but make both panes flexible. */
  .proctor-workspace {
    grid-template-columns: minmax(0, 58fr) minmax(340px, 42fr);
  }

  .passage-pane,
  .question-pane {
    min-width: 0;
    padding: 28px 30px;
  }

  .proctor-header {
    height: auto;
    min-height: 64px;
    padding: 8px max(18px, var(--safe-right)) 8px max(18px, var(--safe-left));
    gap: 12px;
  }

  .proctor-title {
    max-width: 30vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .proctor-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .proctor-footer {
    height: auto;
    min-height: 64px;
    padding: 8px max(18px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(18px, var(--safe-left));
    gap: 12px;
  }

  .question-nav-grid {
    max-width: 52%;
    max-height: 76px;
    overflow-y: auto;
  }
}

/* Tablet portrait / narrow split-screen */
@media (max-width: 899px) {
  .hero-section {
    grid-template-columns: 1fr;
    gap: 26px;
    padding-bottom: 38px;
    margin-bottom: 36px;
  }

  .hero-card {
    max-width: 680px;
  }

  .catalog-grid,
  .catalog-offering-grid,
  .score-breakdown-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .section-header > button,
  .section-header .btn-primary,
  .section-header .btn-secondary {
    width: 100%;
  }

  .filter-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-pills,
  .assessment-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    overscroll-behavior-inline: contain;
  }

  .filter-pill,
  .assessment-tabs button {
    flex: 0 0 auto;
  }

  .search-input-wrapper {
    min-width: 0;
    width: 100%;
  }

  .history-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-card-result {
    width: 100%;
    min-width: 0;
    justify-items: start;
    text-align: left;
  }

  .history-card-result button {
    width: 100%;
  }

  .score-hero {
    padding: 30px 22px;
  }

  .total-score-badge {
    font-size: clamp(46px, 12vw, 64px);
  }

  .review-answer-line {
    flex-direction: column;
    gap: 8px;
  }

  /* Stack the exam vertically. This is CSS-only, so timer and answer state do
     not reset when orientation changes. */
  .proctor-shell {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .proctor-header {
    position: sticky;
    top: 0;
    z-index: 120;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .proctor-info {
    min-width: 0;
  }

  .proctor-title {
    max-width: 46vw;
  }

  .timer-box {
    justify-self: end;
  }

  .proctor-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    width: 100%;
  }

  .proctor-workspace {
    display: block;
    height: auto;
    min-height: calc(100dvh - 150px);
    overflow: visible;
  }

  .passage-pane,
  .question-pane {
    width: 100%;
    overflow: visible;
    padding: 24px max(22px, var(--safe-right)) 24px max(22px, var(--safe-left));
  }

  .passage-pane {
    min-height: auto;
    border-right: 0;
    border-bottom: 2px solid var(--text-main);
  }

  .question-pane {
    min-height: 280px;
    padding-bottom: 104px;
  }

  .question-figure-image,
  .question-figure-wrap img,
  .passage-content img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  .choices-list {
    margin-bottom: 12px;
  }

  .choice-item {
    min-height: 52px;
  }

  .student-response-input,
  .spr-input,
  .answer-input,
  .question-pane input[type="text"],
  .question-pane input[type="number"] {
    width: 100%;
    min-height: 52px;
    font-size: 18px;
  }

  .proctor-footer {
    position: sticky;
    bottom: 0;
    z-index: 120;
    flex-wrap: wrap;
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(8px);
  }

  .question-nav-grid {
    order: 3;
    width: 100%;
    max-width: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
  }

  .q-dot {
    flex: 0 0 34px;
  }

  .modal-card {
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }
}

/* Phone */
@media (max-width: 599px) {
  body {
    background-size: 32px 32px;
  }

  .site-header {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 10px max(14px, var(--safe-right)) 10px max(14px, var(--safe-left));
  }

  .brand {
    gap: 9px;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }

  .brand-text {
    font-size: 15px;
  }

  .header-right {
    margin-left: auto;
    gap: 8px;
  }

  .nav-links {
    order: 3;
    width: 100%;
    border-top: 1px solid var(--border-subtle);
    padding-top: 6px;
  }

  .nav-btn {
    padding: 9px 12px;
  }

  .dev-badge {
    max-width: 46vw;
    overflow: hidden;
  }

  .page-container {
    padding: 24px max(14px, var(--safe-right)) calc(64px + var(--safe-bottom)) max(14px, var(--safe-left));
  }

  .hero-section {
    padding-top: 0;
  }

  .hero-title {
    font-size: clamp(30px, 10vw, 40px);
  }

  .hero-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .hero-actions > *,
  .card-btn,
  .btn-primary,
  .btn-secondary {
    width: 100%;
  }

  .hero-card,
  .test-card,
  .history-card,
  .review-item,
  .score-hero {
    padding: 18px;
  }

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

  .catalog-grid,
  .catalog-offering-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .catalog-offering-head {
    align-items: flex-start;
    gap: 12px;
  }

  .catalog-custom-controls {
    grid-template-columns: 1fr !important;
  }

  .catalog-custom-count {
    grid-column: 1 !important;
  }

  .history-card {
    padding: 18px;
    gap: 16px;
  }

  .history-card-tags {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-card-result strong {
    font-size: 20px;
  }

  .score-hero::before {
    display: none;
  }

  .score-hero {
    margin-bottom: 24px;
  }

  .review-item-head {
    align-items: flex-start;
    gap: 10px;
  }

  .review-meta-line {
    align-items: flex-start;
  }

  .rationale-image-wrap,
  .math-rationale-primary,
  .review-question-image-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .page-scroll-controls {
    right: max(10px, var(--safe-right));
    bottom: calc(74px + var(--safe-bottom));
  }

  .proctor-header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: calc(8px + var(--safe-top)) max(12px, var(--safe-right)) 8px max(12px, var(--safe-left));
  }

  .proctor-title {
    max-width: 52vw;
    font-size: 13px;
  }

  .module-badge {
    display: none;
  }

  .timer-box > span:first-child,
  .timer-toggle {
    display: none;
  }

  .timer-clock {
    font-size: 16px;
    padding: 5px 9px;
  }

  .proctor-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .proctor-actions > * {
    flex: 0 0 auto;
  }

  .tool-btn {
    min-height: 44px;
    padding: 8px 11px;
  }

  .passage-pane,
  .question-pane {
    padding: 18px max(14px, var(--safe-right)) 22px max(14px, var(--safe-left));
  }

  .pane-header {
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }

  .passage-content {
    font-size: 15px;
    line-height: 1.65;
  }

  .question-prompt {
    font-size: 16px;
    margin-bottom: 18px;
  }

  .choice-item {
    align-items: flex-start;
    padding: 13px 12px;
  }

  .choice-left {
    align-items: flex-start;
    gap: 10px;
  }

  .choice-key {
    width: 30px;
    height: 30px;
  }

  .choice-text {
    font-size: 14px;
    line-height: 1.45;
  }

  .crossout-btn {
    padding: 4px 6px;
    font-size: 10px;
  }

  .proctor-footer {
    padding: 8px max(10px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(10px, var(--safe-left));
  }

  .proctor-footer > div:first-child {
    gap: 6px !important;
  }

  .proctor-footer .flag-btn,
  .proctor-footer .tool-btn,
  .proctor-footer .btn-primary {
    font-size: 12px;
    padding: 8px 10px;
    width: auto;
  }

  .question-nav-grid {
    max-height: none;
  }

  .modal-overlay {
    align-items: end;
    padding: 12px max(10px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(10px, var(--safe-left));
  }

  .modal-card {
    padding: 20px 16px;
  }

  .admin-table,
  table.admin-table {
    min-width: 900px;
  }
}

/* Very short landscape phones: protect usable exam height. */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 899px) {
  .proctor-header {
    position: static;
  }

  .proctor-actions {
    display: none;
  }

  .passage-pane,
  .question-pane {
    padding-top: 14px;
    padding-bottom: 14px;
  }
}

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

/* responsive-tabs-visibility-v2
   Keep every assessment/admin option visible on narrow viewports.
   Wide data tables still scroll horizontally. */
@media (max-width: 899px) {
  /* Catalog assessment selector: show every exam instead of clipping the row. */
  .assessment-tabs,
  .assessment-selector,
  .assessment-filter-tabs,
  .exam-tabs,
  .catalog-tabs {
    display: flex;
    flex-wrap: wrap !important;
    width: 100%;
    max-width: 100%;
    gap: 10px;
    overflow-x: visible !important;
    overflow-y: visible !important;
    white-space: normal !important;
    padding-bottom: 0;
  }

  .assessment-tabs > *,
  .assessment-selector > *,
  .assessment-filter-tabs > *,
  .exam-tabs > *,
  .catalog-tabs > * {
    flex: 0 1 auto !important;
    max-width: 100%;
    white-space: normal;
  }

  /* Admin navigation: grow vertically so every option is immediately visible. */
  .admin-nav,
  .admin-tabs,
  .admin-tab-list,
  .admin-workspace-tabs {
    display: flex;
    flex-wrap: wrap !important;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    gap: 6px;
    overflow-x: visible !important;
    overflow-y: visible !important;
    white-space: normal !important;
  }

  .admin-nav > *,
  .admin-tabs > *,
  .admin-tab-list > *,
  .admin-workspace-tabs > * {
    flex: 0 1 auto !important;
    min-width: max-content;
  }

  /* Data tables remain horizontally scrollable; only navigation wraps. */
  .admin-table-wrap,
  .admin-table-container,
  .table-wrap {
    overflow-x: auto !important;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 599px) {
  .assessment-tabs > *,
  .assessment-selector > *,
  .assessment-filter-tabs > *,
  .exam-tabs > *,
  .catalog-tabs > * {
    flex: 1 1 calc(50% - 10px) !important;
    min-width: 150px;
  }

  .admin-nav > *,
  .admin-tabs > *,
  .admin-tab-list > *,
  .admin-workspace-tabs > * {
    flex: 1 1 calc(50% - 6px) !important;
    min-width: 145px;
    text-align: center;
  }
}

/* === proctor mobile controls alignment v3: start === */
@media (max-width: 599px) {
  /* Do not hide or horizontally clip Auto-saved on phones. */
  .proctor-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: stretch;
    gap: 8px;
    width: 100%;
    overflow: visible;
    padding-bottom: 0;
  }

  .proctor-actions > .tool-btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .proctor-actions > .save-indicator {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    min-height: 28px;
    justify-content: flex-end;
    white-space: nowrap;
    overflow: visible;
  }

  /* Each footer action pair uses equal columns regardless of label length. */
  .proctor-footer > div:first-child,
  .proctor-footer > div:last-child {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch !important;
    gap: 8px !important;
    width: 100%;
  }

  .proctor-footer > div:first-child > button,
  .proctor-footer > div:last-child > button {
    width: 100% !important;
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 9px 8px !important;
    justify-content: center;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }

  .proctor-footer .flag-btn span {
    display: inline;
  }
}
/* === proctor mobile controls alignment v3: end === */
