/* Phone presentation is isolated from the existing desktop layout. */
.mobile-only { display: none; }
.mobile-card-table .mobile-record-toggle,
.mobile-card-table .mobile-record-details { display: none; }
#mobile-pdf-sheet { display: contents; }

@media (max-width: 767px), (max-width: 960px) and (pointer: coarse) {
  html { scroll-padding-top: 90px; }
  body { font-size: 15px; }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  button, .downloads a, .mini-actions a { min-height: 44px; }
  input, select, textarea { font-size: 16px; min-width: 0; max-width: 100%; }
  input:not([type=checkbox]), select { min-height: 44px; }
  input[type=checkbox] { width: 20px; height: 20px; flex: 0 0 20px; }
  label { font-size: 13px; }
  small, .hint { font-size: 13px; }
  h1 { font-size: 25px; }
  h2 { font-size: 20px; }
  h3 { font-size: 16px; overflow-wrap: anywhere; }
  .badge { font-size: 12px; white-space: normal; }

  #shell > aside {
    position: sticky; top: 0; z-index: 5; width: 100%; height: auto;
    max-height: 100vh; max-height: 100dvh;
    padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 12px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { grid-column: 2; grid-row: 1; justify-self: end; font-size: 18px; gap: 10px; }
  .brand small { font-size: 11px; }
  .brand-icon { width: 36px; height: 36px; flex-shrink: 0; }
  #mobile-menu-toggle { grid-column: 1; grid-row: 1; justify-self: start; gap: 7px; padding: 7px 13px; }
  #main-nav { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 12px; gap: 6px; }
  #main-nav .nav { padding: 10px; gap: 8px; min-width: 0; white-space: normal; }
  #main-nav .nav span { font-size: 14px; }
  .sidebar-bottom { grid-column: 1 / -1; display: block; padding-top: 12px; }
  .sidebar-bottom small { letter-spacing: 0; font-size: 11px; }
  .mobile-enhanced aside:not([data-mobile-open]) #main-nav,
  .mobile-enhanced aside:not([data-mobile-open]) .sidebar-bottom { display: none; }
  main { margin-left: 0; width: 100%; padding: 18px max(16px, env(safe-area-inset-right)) 36px max(16px, env(safe-area-inset-left)); }
  header { margin-bottom: 18px; }
  .eyebrow { margin-bottom: 5px; }
  .notice { padding: 10px 12px; overflow-wrap: anywhere; }
  #local-preview-notice { font-size: 11px; line-height: 1.5; margin-bottom: 14px; }
  .section-top { gap: 12px; align-items: flex-start; margin-bottom: 16px; }
  .section-top > div { display: flex; flex-wrap: wrap; gap: 8px; }
  .section-top .hint { width: 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; gap: 8px; }
  .chips > * { flex-shrink: 0; }
  .chip { padding: 8px 13px; font-size: 14px; }
  .toolbar { gap: 10px; margin-bottom: 14px; }
  .toolbar input, .toolbar select { min-width: 0; }
  .record-search input { margin: 0; }
  #mobile-filter-toggle { width: 100%; justify-content: space-between; margin-bottom: 14px; }
  #mobile-filter-toggle::after { content: '+'; font-size: 20px; }
  #mobile-filter-toggle[aria-expanded=true]::after { content: '−'; }
  .record-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .record-filters label { min-width: 0; }
  .record-filters select, .record-filters .year, .record-filters #level-filter { width: 100%; max-width: 100%; }
  .mobile-enhanced .record-filters:not([data-mobile-open]) { display: none; }
  .record-filters .text-button { margin-bottom: 0; justify-self: start; padding: 8px 12px; }
  #sort-hint:empty { display: none; }
  html[data-mobile-record-view=list] .record-title-edit-hint { display: none; }

  /* Keep every column, with labels, inside each achievement card. */
  .table-wrap:has(.mobile-card-table) { background: transparent; border: 0; overflow: visible; }
  .mobile-card-table { display: block; width: 100%; min-width: 0; table-layout: auto; font-size: 14px; }
  .mobile-card-table > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .mobile-card-table > tbody { display: grid; gap: 12px; }
  .mobile-card-table > tbody > tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: white; }
  .mobile-card-table > tbody > tr > td { display: block; padding: 0; border: 0; min-width: 0; max-width: none; white-space: normal; overflow-wrap: anywhere; }
  .mobile-card-table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
  .mobile-card-table td.mobile-card-title { grid-column: 1 / -1; padding-bottom: 12px; border-bottom: 1px solid #eef0eb; }
  .mobile-card-table td.mobile-card-title::before, .mobile-card-table td.mobile-card-actions::before { display: none; }
  .mobile-card-table .title, .mobile-card-table .document-title { font-size: 16px; line-height: 1.65; min-height: 0; width: 100%; text-align: left; }
  .mobile-card-table td small { margin-top: 5px; font-size: 13px; }
  .mobile-card-table td.mobile-card-wide { grid-column: 1 / -1; }
  .mobile-card-table td.mobile-card-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding-top: 10px; border-top: 1px solid #eef0eb; }
  .mobile-card-actions > .text-button, .mobile-card-actions .downloads > * { display: inline-flex; align-items: center; justify-content: center; padding: 7px 16px; min-height: 44px; border: 1px solid var(--line); border-radius: 7px; background: #f8faf7; }
  .mobile-card-actions .downloads { margin: 0; gap: 10px; }
  .mobile-card-table select { width: 100%; max-width: 100%; font-size: 16px; }
  .mobile-card-table > thead.mobile-selection-head { position: static; width: 100%; height: auto; clip-path: none; display: block; margin-bottom: 12px; }
  .mobile-selection-head tr { display: block; }
  .mobile-selection-head th:not(:first-child) { display: none; }
  .mobile-selection-head th:first-child { display: block; padding: 10px 12px; font-size: 14px; }
  .mobile-selection-head label { display: inline-flex; align-items: center; min-height: 24px; }

  .mobile-view-toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
  .mobile-view-options { display: inline-flex; padding: 3px; gap: 3px; border: 1px solid var(--line); border-radius: 9px; background: white; }
  .mobile-view-options button { min-width: 74px; min-height: 44px; padding: 8px 14px; color: var(--muted); background: transparent; font-size: 14px; }
  .mobile-view-options button[aria-pressed=true] { color: white; background: var(--green); }
  .mobile-view-options button:focus-visible, .mobile-record-toggle:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
  .mobile-card-table[data-mobile-view=list] > tbody { gap: 8px; }
  .mobile-card-table[data-mobile-view=list] > tbody > tr[data-mobile-expanded] { padding: 12px 14px; }
  .mobile-card-table[data-mobile-view=list] .mobile-record-original { display: none; }
  .mobile-card-table[data-mobile-view=list] .mobile-record-toggle { display: grid; grid-template-columns: minmax(0, 1fr) 12px; align-items: center; gap: 14px; width: 100%; min-height: 44px; padding: 0; background: transparent; color: var(--ink); font-size: 15px; font-weight: 600; line-height: 1.65; text-align: left; }
  .mobile-record-heading { min-width: 0; overflow-wrap: anywhere; }
  .mobile-record-arrow { width: 8px; height: 8px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); }
  .mobile-record-toggle[aria-expanded=true] .mobile-record-arrow { transform: rotate(225deg); }
  .mobile-card-table[data-mobile-view=list] > tbody > tr[data-mobile-expanded=false] { gap: 0; }
  .mobile-card-table[data-mobile-view=list] > tbody > tr[data-mobile-expanded=false] > td:not(.mobile-card-title),
  .mobile-card-table[data-mobile-view=list] > tbody > tr[data-mobile-expanded=false] > .mobile-card-title > :not(.mobile-record-toggle) { display: none; }
  .mobile-card-table[data-mobile-view=list] > tbody > tr[data-mobile-expanded=false] > .mobile-card-title { padding-bottom: 0; border-bottom: 0; }
  .mobile-card-table[data-mobile-view=list] .mobile-record-details { display: inline-flex; }
  .mobile-card-table:not([data-mobile-view=list]) .mobile-record-details { display: none; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; min-width: 0; }
  .stat strong { font-size: 25px; overflow-wrap: anywhere; }
  .two-col, .form-grid, .report-filters, .report-groups, .document-picker { grid-template-columns: minmax(0, 1fr); }
  .span2, .report-search { grid-column: auto; }
  .panel-pad, .job { padding: 18px 16px; }
  .welcome { padding: 22px; }
  .mini-actions, .downloads { gap: 10px; flex-wrap: wrap; }
  .downloads > a, .downloads > button { display: inline-flex; align-items: center; min-height: 44px; }
  .job-head > div { min-width: 0; overflow-wrap: anywhere; }
  .job-head > .badge { flex-shrink: 0; }
  .item-list li { display: flex; flex-wrap: wrap; align-items: center; }
  .item-list li > div { flex: 1 0 100%; min-width: 0; overflow-wrap: anywhere; }
  .item-list input { width: 100%; font-size: 16px; }
  .item-list button { min-width: 44px; }
  .selection-bar { flex-wrap: wrap; bottom: 10px; padding: 12px; }
  .saved-filter-row label { min-width: 0; width: 100%; }
  .unclaimed .claim-row { grid-template-columns: minmax(0, 1fr); }
  #batch-picker { max-width: 100%; width: 100%; }
  .material-output-options { margin: 0 0 16px; padding: 12px; min-width: 0; }
  .material-output-options label, .material-candidate-list label, .document-picker label { min-height: 44px; }
  .college-authors { padding: 12px; min-width: 0; }
  .college-author-row { gap: 10px; }
  .college-author-row label { min-width: 0; flex-basis: 40%; }
  .college-author-row button { margin-bottom: 0; }
  .multi-tags label { font-size: 13px; padding: 8px; }
  /* A zero-minimum grid track keeps the desktop card width from widening phones. */
  .login {
    width: 100%; grid-template-columns: minmax(0, 1fr);
    min-height: 100vh; min-height: 100dvh;
    padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  }
  .login-card { width: 100%; min-width: 0; max-width: 470px; padding: 28px 24px; overflow-wrap: anywhere; }
  .login-card h1 { font-size: 25px; }
  .login-card form { margin: 22px 0; }
  .login-card form > label + label { margin-top: 14px; }
  .toast { max-width: calc(100vw - 32px); width: max-content; bottom: max(20px, env(safe-area-inset-bottom)); overflow-wrap: anywhere; }

  .mobile-dialog-open, .mobile-dialog-open body { overflow: hidden; }
  dialog { width: calc(100% - 16px); max-width: calc(100% - 16px); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding: 16px; border-radius: 12px; overscroll-behavior: contain; }
  dialog .dialog-head { gap: 10px; margin-bottom: 16px; }
  .icon-button { min-width: 44px; min-height: 44px; flex-shrink: 0; }
  .dialog-footer { position: sticky; bottom: -16px; background: white; padding: 12px 0 max(12px, env(safe-area-inset-bottom)); z-index: 2; }
  .dialog-footer button { flex: 1; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .detail-grid dd { padding-bottom: 12px; }
  #preview { width: calc(100% - 12px); max-width: calc(100% - 12px); height: calc(100vh - 12px); height: calc(100dvh - 12px); max-height: calc(100dvh - 12px); padding: 10px; }
  #preview .dialog-head { margin-bottom: 4px; }
  #preview .dialog-head h2 { font-size: 18px; }
  #preview .preview-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) 50px 54px minmax(0, 1fr); gap: 6px; }
  .preview-toolbar button, .preview-toolbar a { font-size: 13px; padding: 6px; }
  #prev-page { grid-column: 1; grid-row: 1; }
  #preview .preview-toolbar label { grid-column: 2; grid-row: 1; font-size: 0; }
  #preview-page { width: 50px; padding: 6px; text-align: center; font-size: 16px; }
  #preview-total { grid-column: 3; grid-row: 1; font-size: 12px; text-align: center; }
  #next-page { grid-column: 4; grid-row: 1; }
  #rotate-pdf { grid-column: 1; grid-row: 2; }
  #mobile-pdf-zoom { grid-column: 2 / 4; grid-row: 2; }
  #original-pdf { grid-column: 4; grid-row: 2; display: flex; align-items: center; justify-content: center; margin: 0; min-height: 44px; white-space: nowrap; }
  #preview .preview-meta { height: 36px; min-height: 36px; gap: 8px; }
  #preview #preview-name { font-size: 11px; }
  #preview-error { flex: 0 0 110px; min-width: 0; font-size: 11px; line-height: 1.4; max-height: 32px; overflow: auto; }
  #preview .pdf-canvas { display: block; overflow: auto; padding: 6px; overscroll-behavior: contain; }
  #mobile-pdf-sheet { display: block; position: relative; margin: 0 auto; }
  #pdf-image { flex-shrink: 0; }
}

/* A phone in landscape has enough width for one row of PDF controls. */
@media (min-width: 700px) and (max-width: 960px) and (max-height: 500px) and (pointer: coarse) {
  #preview .dialog-head { position: absolute; top: 10px; right: 10px; margin: 0; }
  #preview .dialog-head h2 { display: none; }
  #preview .preview-toolbar { grid-template-columns: minmax(60px, 1fr) 50px 54px minmax(60px, 1fr) 66px 96px 94px; padding-right: 50px; }
  #rotate-pdf { grid-column: 5; grid-row: 1; }
  #mobile-pdf-zoom { grid-column: 6; grid-row: 1; }
  #original-pdf { grid-column: 7; grid-row: 1; }
}
