/* Phones (iPhone and Android). Loaded after every feature stylesheet so these win.
   Found by a page-by-page audit at 320–412px wide in Safari's engine and Chrome. */

/* Typing into a box under 16px makes iPhone zoom the whole page in (and it stays zoomed). */
@media (pointer: coarse) {
  input:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color]), select, textarea { font-size: 16px !important; }
}

/* Small text links ("Manage ›", "Calendar ›", "How to pay ›") get a finger-sized tap area without moving anything. */
@media (pointer: coarse) {
  :is(a.chev, .row-meta > a, .section-head > a, .st-acts > a, .ph-actions > a.chev, .card > a.chev, .vol-coord > a, .pm-foot > a):not(.btn) {
    display: inline-block; padding-block: .65rem; margin-block: -.65rem; }
  .row-split > a.quiet, .row-actions > a.quiet, .res-csv > button.quiet { min-width: 44px; justify-content: center; }
}

@media (max-width: 720px) {
  /* Less empty space above the page title, so more of the page fits on the first screen. */
  .page { padding-top: 1.1rem; }
  /* Admin pages used the computer's 32px side margins on phones too; phones get the same 16px as member pages. */
  body.ad-on .shell-main .page, body.ad-on .shell-main .ad-tabs { padding-inline-start: 1rem; padding-inline-end: 1rem; }
  .home, .home-main { grid-template-columns: minmax(0, 1fr); }
  .home-main > *, .home > * { min-width: 0; }
  body.ad-on:has(.ad-tabs:not([hidden])) .page { padding-top: 1rem; }
  .ad-tabs { padding-top: .75rem; }
  h1 { font-size: 1.85rem; letter-spacing: -.015em; }
  .subtitle { margin-bottom: 1.25rem; }
  .ph { margin-bottom: 1.1rem; }

  /* Tab bar: one short word under each icon, like iPhone and Android apps. */
  .tabbar a span { font-size: .8125rem; letter-spacing: 0; }
  .tabbar a[aria-current] span { font-weight: 700; }
  .tabbar svg { width: 25px; height: 25px; }
  /* Solid bars on phones: page text showing through the header and tab bar is hard to read in sunlight. */
  .tabbar, .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .tabbar { box-shadow: 0 -.5px 0 var(--sep); }
  /* Messages and confirmations float above the tab bar, not on top of it. */
  body:has(.tabbar:not([hidden])) .toast { bottom: calc(5.25rem + env(safe-area-inset-bottom)); }

  /* Section tabs (Payments · Deposits · Fee setup): one even row; more tabs wrap into even rows, all still visible. */
  .ad-tabs-inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(5.25rem, 1fr)); width: 100%; }
  .ad-tabs a { font-size: .875rem; padding: .35rem .5rem; white-space: normal; text-align: center; line-height: 1.2; }
  /* A page with its own tabs (Volunteer hours, Waitlist) would stack two tab bars: the area's pages become one
     picker ("Volunteering: Volunteer hours ⌄") and the page's tabs are the only tab bar. */
  body:has(#app :is(.vol-tabs, .wl-tabs)) .ad-tabs-inner { display: none; }
  body:has(#app :is(.vol-tabs, .wl-tabs)) .ad-pick { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9375rem; }
  .ad-pick select { width: auto; min-width: 0; max-width: 70%; min-height: 44px; padding-block: .3rem; border-radius: 10px;
    background-color: var(--fill); border-color: transparent; color: var(--ink); font-weight: 600; }

  /* Segmented switches never push the page sideways: equal parts that may wrap their own words. */
  .segmented { grid-auto-columns: minmax(0, 1fr); max-width: 100%; }
  .segmented button { white-space: normal; line-height: 1.2; padding-inline: .4rem; overflow-wrap: anywhere; }
  /* Five or more choices (Members: Active · Volunteers · Inactive · All · Not finished registering): they wrap onto
     a second row, each label whole, instead of squeezing into columns that run together. Every choice stays visible. */
  .segmented:has(> :nth-child(5)) { display: flex; flex-wrap: wrap; gap: 2px; overflow: visible; }
  .segmented:has(> :nth-child(5)) > button { flex: 1 1 auto; white-space: nowrap; overflow-wrap: normal; padding-inline: .75rem; }
  .toolbar:has(.segmented > :nth-child(5)) .segmented { flex: 1 1 100%; min-width: 0; max-width: none; }
  .st-title-row { flex-wrap: wrap; row-gap: .4rem; }

  /* Rows of actions wrap instead of running off the right edge. */
  .row-actions { flex-wrap: wrap; white-space: normal; row-gap: .5rem; }
  .mg-row > *, .st-row > * { min-width: 0; }
  .pp-tl { flex-wrap: wrap; max-width: 100%; }
  .pp-tl input { min-width: 0; max-width: 100%; }

  /* Coming up: the RSVP button goes under the event, so the title keeps a full line instead of one word per line. */
  .ev-list > li.ev-has-go { flex-wrap: wrap; row-gap: 0; }
  .ev-list > li.ev-has-go > .ev-row { flex: 1 1 100%; }
  .ev-list > li.ev-has-go > .ev-go { margin: 0 0 .6rem calc(3.1rem + 1.1rem); }
  [dir="rtl"] .ev-list > li.ev-has-go > .ev-go { margin: 0 calc(3.1rem + 1.1rem) .6rem 0; }

  /* Report bars: long answers wrap onto a second line rather than being cut off. */
  .res-bar-label { white-space: normal; overflow: visible; text-overflow: clip; }

  /* Map editor "Add" menu: a sheet above the tab bar, never off the edge of the screen. */
  .me-menu-list { position: fixed; inset-inline-start: .75rem; inset-inline-end: .75rem; top: auto; min-width: 0;
    bottom: calc(5.25rem + env(safe-area-inset-bottom)); max-height: 60vh; overflow-y: auto; overscroll-behavior: contain;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .22), 0 0 0 .5px var(--sep); }
  .me-menu-list button { min-height: 44px; }
  .money-menu { max-width: calc(100vw - 1rem); max-height: calc(100dvh - 7rem); overflow-y: auto; }
  .money-menu button { white-space: normal; }
}

/* Take several payments, on a phone: the name gets its own line; amount, how and check number sit under it. */
@media (max-width: 600px) {
  .money-takerow { row-gap: .5rem; }
  .money-takerow > label.grow { flex: 1 1 100%; }
  .money-takerow > .money-in, .money-takerow > .money-takehow { flex: 1 1 0; width: auto; min-width: 0; }
  .money-takerow > .money-in { margin-inline-start: 2rem; }
  .money-takerow > .money-in > .money-takeamt { width: 100%; }
  .money-takerow > .money-takeck { flex: 1 1 100%; width: auto; margin-inline-start: 2rem; }
  #markpaid-panel, #takings-panel { scroll-margin-top: 64px; }
}

/* The account circle stays green when tapped (a phone keeps the hover look after a tap); open, it gets a ring. */
.avatar:hover { background: var(--tint); }
.avatar[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px color-mix(in srgb, var(--tint) 45%, transparent); }

@media (max-width: 720px) {
  /* Every tab is a full 44px target. */
  .tabbar a { min-height: 44px; }
  /* Home's To do / Completed switch and the language picker: finger-sized. */
  .st-switch button { min-height: 40px; padding-inline: .9rem; }
  .st-switch { padding: 2px; }
  .lang-pick select { min-height: 44px; }
  /* Edit and Delete on an hours entry: more room between them, so a thumb doesn't hit the wrong one. */
  .row-actions:has(> [data-del]) { gap: 1.5rem; }
  /* Contract: the rules use the card's full width instead of sitting in a second inset box. */
  .card .contract { margin-inline: -.5rem; padding: .85rem .9rem; }
  .contract :is(ol, ul) { padding-inline-start: 1.35rem; margin-block: .25rem; }
}

@media (max-width: 600px) {
  /* A form's buttons, the same on every page: the main one full width, the others full width under it. */
  .page form .actions > :is(button, .btn), .page .card > .actions > :is(button, .btn) { flex: 1 1 100%; justify-content: center; }
}
/* A just-saved row lights up for a moment, so you see where it went. */
.just-saved { animation: just-saved 2.4s cubic-bezier(.2, .8, .2, 1); }
@keyframes just-saved { 0%, 35% { background: var(--tint-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .just-saved { animation: none; outline: 2px solid var(--tint-soft); } }

/* "‹ Home" / "‹ Me" at the top of pages below a tab: phones only (computers have the full menu). */
.phone-back { display: none; }
@media (max-width: 720px) {
  .phone-back { display: block; margin: -.35rem 0 .35rem; }
  .phone-back a { display: inline-flex; align-items: center; min-height: 44px; font-size: 1rem; font-weight: 500; }
}

@media (max-width: 600px) {
  /* The payments list grows with the page instead of scrolling inside its own little box. */
  .money-takelist { max-height: none; overflow: visible; }
  #markpaid-form:not(:has(#mp-diffhow:checked)) .money-takerow > .money-in { flex: 0 1 11rem; }
}
@media (max-width: 720px) {
  /* The last 40px controls get the full 44px: RSVP, shift buttons, To do / Completed, row buttons, switches. */
  .ev-go, .vol-toggle, .st-switch button, .row-actions :is(button, .btn), .segmented button, .chip-btn { min-height: 44px; }
  /* Audit 2026-11-10: tick lines on Fees and Details (26px), the map's Show whole garden, the Fees season picker */
  label.check, .pm-zoom, .money-ph select { min-height: 44px; }
  label.check:not(:has(.help, br, .check-note, .money-note)) { align-items: center; }
}
@media (pointer: coarse) {
  /* Tick boxes: the whole line is the tap target, at least 44px tall. */
  label.check { min-height: 44px; }
  label.check:not(:has(.help, br)) { align-items: center; }
}

@media (max-width: 720px) {
  /* The last small ones: Hours chips (Today, 1 h…), Approve on each entry, Take it on Home. */
  .vol-pick, .vol-actions button, .home-grabs button, .home-grab button { min-height: 44px; }
  .vol-actions button.quiet { padding-inline: .5rem; }
}

/* Critique round 5 (detector): the last small targets, and no lone words at the end of a line. */
@media (pointer: coarse) {
  .topbar a.brand { min-height: 44px; }
  .crumb-back > a, .st-oneline .st-title > a { display: inline-block; padding-block: .8rem; margin-block: -.8rem; }
  :is(a.chev, .row-meta > a):not(.btn) { padding-block: .8rem; margin-block: -.8rem; }
}
@media (max-width: 720px) {
  .vol-actions button.quiet, span.row-actions > button.quiet, .rr-more, .vol-pick { min-height: 44px; min-width: 44px; justify-content: center; }
}
.subtitle, .help, #mg-sub, .money-facts, .row-meta { text-wrap: pretty; }
.st-title, h1, h2 { text-wrap: balance; }
