/* ============================================================================
   Responsive hardening — loaded last, after liquid-glass.css.

   This layer changes layout and sizing only: no colour, no focus style, no
   typography scale, no JavaScript. It exists because a measured audit (40
   pages × 320/390/768/1280 in both roles) found two document-level overflows
   and several touch targets under 44 px. Everything else on the site already
   reflows correctly, so the rules below are deliberately narrow.
   ========================================================================== */

/* ---------------------------------------------------------------- gutters */
/* Notched phones in landscape get their content clear of the sensor housing;
   every other device keeps the existing 1rem gutter. */
.wrap {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* The narrowest phones (320–380 px) gain a little reading width. */
@media (max-width: 380px) {
  .wrap {
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
  }
}

/* ------------------------------------------------------- overflow guards */
/* A fieldset's UA min-inline-size is min-content, so one long, unbreakable
   setting key could push the whole page sideways (/admin/settings at 320 px).
   Let the fieldset shrink and let long machine names break. */
fieldset {
  min-inline-size: 0;
}
fieldset,
.field,
.form-row > *,
.checkbox-field,
.checkbox-field > label {
  min-width: 0;
}
.input,
.select,
.textarea {
  min-width: 0;
  max-width: 100%;
}
code {
  overflow-wrap: break-word;
}

/* Contact rows put a label beside one long address (/support). Wrap the row
   instead of bleeding past the card. */
.metric-list li {
  flex-wrap: wrap;
}
.metric-list li > * {
  min-width: 0;
}
.metric-list a,
.metric-list strong,
a[href^="mailto:"],
a[href^="tel:"] {
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ table width */
/* Tables with five or more columns were squeezed illegibly at phone width.
   Give them a readable minimum inside the existing .table-wrap scroller,
   so the page itself never scrolls sideways. Falls back to today's behaviour
   in browsers without :has(). */
@media (max-width: 640px) {
  .table-wrap {
    overscroll-behavior-x: contain;
  }
  table:has(thead th:nth-child(5)) {
    min-width: 34rem;
  }
}

/* --------------------------------------------------------- touch targets */
/* Fine pointers keep the compact desktop sizing. Coarse pointers get at least
   44 px of height on the controls that were measured smaller. */
@media (pointer: coarse) {
  .btn-sm {
    min-height: 44px;
    padding-block: 0.55rem;
  }
  .link-button,
  .admin-nav a,
  .admin-subnav a,
  .tabs a,
  .todo-strip a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  /* summary is display:list-item, so min-height grows the hit area without
     removing the disclosure marker. */
  summary {
    min-height: 44px;
  }
  .audio-title {
    display: flex;
    align-items: center;
    min-height: 44px;
  }
}

/* ------------------------------------------------------ fluid density */
/* Section breathing room scales with the viewport instead of a fixed 2.2rem
   top and bottom on every screen. */
.section {
  padding-top: clamp(1.5rem, 5vw, 2.2rem);
  padding-bottom: clamp(1.5rem, 5vw, 2.2rem);
}

@media (max-width: 400px) {
  .card,
  .plan-card {
    padding: 0.9rem;
  }
  .stat {
    padding: 0.7rem 0.5rem;
  }
  .stat-value {
    font-size: 1.45rem;
  }
  .callout {
    padding: 0.75rem 0.85rem;
  }
}

/* ------------------------------------------------------ short landscape */
/* A phone held sideways loses its sticky app chrome height to the shorter
   viewport; keep the dock and back-to-top from covering the page content. */
@media (max-height: 460px) and (orientation: landscape) {
  .app-layout {
    --app-header-row: 3.25rem;
    --app-dock-row: 3.25rem;
  }
}
