/* Yechiva: layouts follow available CSS width, without device identification.
   No route changes, reloads or form reconstruction when folding / rotating. */
@media screen {
  .body-area, .page, .detail-main, .detail-aside,
  .registrations-page, .toolbar > *, .page-heading > * { min-width: 0; }
  .table-scroll, .registrations-matrix-scroll { max-width: 100%; overscroll-behavior-x: contain; }
  .tabs-bar { max-width: 100%; overflow-x: auto; }
  .tabs-bar > .tab { flex-shrink: 0; }
  .modal { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .modal-body { overscroll-behavior-y: contain; }
  /* Match the actual compact sidebar rather than the former 240px rail. */
  @media (min-width: 1001px) {
    .shell:has(> .sidebar-compact) .limoud-dock {
      left: calc(50% + 32px); width: min(560px, calc(100% - 88px));
    }
  }
  @media (max-width: 1000px) {
    .page { padding-left: clamp(12px, 2.3vw, 24px); padding-right: clamp(12px, 2.3vw, 24px); }
    .page-heading { flex-wrap: wrap; }
    .heading-actions { max-width: 100%; }
    .toolbar .search-box { min-width: 0; }
    .toolbar .filter-select { max-width: 100%; }
    .profile-header, .profile-meta { flex-wrap: wrap; }
    .profile-name, .record-info { min-width: 0; overflow-wrap: anywhere; }
    .pagination { flex-wrap: wrap; gap: 12px; }
    .modal-footer { flex-wrap: wrap; gap: 10px; }
  }
  /* A wide phone or unfolded screen can show two complete records at once. */
  @media (min-width: 680px) and (max-width: 900px) {
    .family-directory-mobile { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .family-directory-card { border: 0; border-bottom: 1px solid var(--line); }
    .family-directory-card:nth-child(odd) { border-right: 1px solid var(--line); }
    .family-directory-card:last-child { border-bottom: 1px solid var(--line); }
    .family-directory-disclosure[open] .family-directory-expanded {
      display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
    }
    .family-directory-section + .family-directory-section { margin-top: 0; }
  }
  @media (min-width: 680px) and (max-width: 1000px) {
    .registrations-case-list, .registrations-campaign-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .registrations-case-list > *, .registrations-campaign-list > * { min-width: 0; overflow-wrap: anywhere; }
    .detail-layout { grid-template-columns: minmax(0, 1fr); }
    .detail-aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-aside > .panel:only-child { grid-column: 1 / -1; }
  }
  /* Keep the pupil's identity visible while the document columns scroll. */
  @media (max-width: 1099px) {
    .registrations-overview .registrations-matrix .registrations-matrix-pupil {
      position: sticky; left: 0; z-index: 1; background: var(--surface, #fff);
      box-shadow: 2px 0 0 var(--line);
    }
    .registrations-overview .registrations-matrix-scroll { scroll-padding-left: 200px; }
  }
  @media (max-width: 679px) {
    .family-directory-mobile { display: block; }
    .detail-aside { display: flex; flex-direction: column; }
    .detail-aside > * { width: 100%; }
    .toolbar .filter-select { min-width: 0; }
    .page-heading .heading-actions .button { white-space: normal; text-align: center; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .form-grid > .full { grid-column: 1 / -1; }
    .family-directory-card-footer a { display: inline-flex; align-items: center; min-height: 44px; }
    .registrations-overview .registrations-matrix .registrations-matrix-pupil { max-width: 180px; }
    .registrations-overview .registrations-matrix-scroll { scroll-padding-left: 180px; }
  }
  /* Safari must not zoom a form field merely because a wide phone was opened. */
  @media (pointer: coarse) and (max-width: 1200px) {
    input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea {
      font-size: 16px; max-width: 100%;
    }
    .button, .icon-button, .mobile-toggle, .year-picker,
    .registrations-overview .registrations-square.button,
    .registrations-overview .registrations-matrix-document {
      min-width: 44px; min-height: 44px;
    }
    .button { white-space: normal; }
    .registrations-overview .registrations-square.button,
    .registrations-overview .registrations-matrix-document { height: auto; }
    .family-directory-disclosure summary { min-height: 64px; }
  }
}
