/* ===========================================================================
   Responsive & accessibility fixes
   ---------------------------------------------------------------------------
   Loaded AFTER mainsite.css / admintheme.css so these rules win on equal
   specificity. Grouped by the problem they solve rather than by breakpoint,
   because each rule targets one specific issue.
   ======================================================================== */


/* ---------------------------------------------------------------------------
   1. Touch targets (WCAG 2.5.5 / Apple HIG)
   ---------------------------------------------------------------------------
   Several controls were below the 44x44px minimum:
     .menu-btn        42px
     .topbar-icon-btn 36px
     .modal-close     32px

   Scoped to (pointer: coarse) so touch devices get compliant targets while
   the desktop layout keeps its original, more compact sizing.
   ------------------------------------------------------------------------ */
@media (pointer: coarse) {
  .menu-btn {
    width: 48px;
    height: 48px;
  }

  .topbar-icon-btn {
    width: 44px;
    height: 44px;
  }

  .modal-close {
    width: 44px;
    height: 44px;
  }

  /* Inline icon buttons in table rows and cards (e.g. the admin action
     buttons) - give them a padded hit area without changing their visual
     size. */
  .btn-icon,
  .js-tooltip-enabled.btn-icon,
  .actions .btn,
  .form-actions .btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Primary call-to-action buttons should also be comfortable to hit. */
  .btn {
    min-height: 44px;
  }
}


/* ---------------------------------------------------------------------------
   2. Prevent iOS Safari focus zoom
   ---------------------------------------------------------------------------
   iOS zooms the viewport when an input's computed font-size is under 16px,
   and does NOT zoom back out on blur - leaving the user stuck on a magnified
   page. Inputs here were 14px (.textarea uses `font:500 14px ...`).

   16px is the threshold; 17px avoids the zoom entirely.
   ------------------------------------------------------------------------ */
@media (max-width: 768px) {
  input,
  select,
  textarea,
  .form-control,
  .textarea,
  .search-input,
  .form-element input,
  .form-element select,
  .form-element textarea {
    font-size: 16px;
  }

  /* Selects render their own arrow box; ensure the larger text still fits. */
  select,
  .form-control[type="select"] {
    line-height: 1.4;
  }
}


/* ---------------------------------------------------------------------------
   3. Error page on narrow screens
   ---------------------------------------------------------------------------
   .error-404 .search-box had a fixed 480px width inside a pill-shaped flex
   container, which clipped on a 360px phone.
   ------------------------------------------------------------------------ */
@media (max-width: 520px) {
  .error-404 .search-box {
    max-width: 100%;
    width: 100%;
    border-radius: 14px;
  }

  .error-404 .error-message {
    font-size: 17px;
  }
}


/* ---------------------------------------------------------------------------
   4. Honour prefers-reduced-motion
   ---------------------------------------------------------------------------
   The site animates hover transitions, a slide-in mobile nav and a
   relative-date component. Users who ask for reduced motion should not get
   them.
   ------------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* The mobile nav is positioned, not animated, so it must still appear. */
  .nav-links,
  .sidebar,
  .pagemodal,
  .modal-backdrop {
    transition: none !important;
  }
}


/* ---------------------------------------------------------------------------
   5. Prevent horizontal overflow
   ---------------------------------------------------------------------------
   Belt-and-braces: a single overflowing child (a long URL, a wide table, an
   unbroken token in a post body) otherwise makes the whole page scroll
   sideways on a phone.
   ------------------------------------------------------------------------ */
@media (max-width: 640px) {
  html,
  body {
    overflow-x: hidden;
  }

  /* Tables scroll inside their own wrapper instead of the page. */
  .table-wrap,
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Long unbroken strings (URLs, tokens) should wrap rather than overflow. */
  p,
  td,
  th,
  .card-body,
  address {
    overflow-wrap: break-word;
    word-wrap: break-word;
  }

  /* Long email addresses / URLs in tables. */
  .text-muted,
  .text-xs {
    overflow-wrap: anywhere;
  }
}


/* ---------------------------------------------------------------------------
   6. Small-screen type scaling
   ---------------------------------------------------------------------------
   Headings that only use clamp() at the very top of their range can still be
   large on a 360px device. These cap the largest size on phones.
   ------------------------------------------------------------------------ */
@media (max-width: 480px) {
  .hero h1,
  .page-title,
  .detail-title {
    font-size: 30px;
    line-height: 1.15;
  }

  .card-body h3 {
    font-size: 20px;
  }
}