/* ============================================================================
   os-mobile.css — the phone layer for Animal Friends OS
   ----------------------------------------------------------------------------
   WHO THIS IS FOR
   A groomer at a tub with a wet dog, a kennel manager walking a run, a mobile
   groomer in a van between stops. One hand, in a hurry, on cellular, in a metal
   building. They are NOT doing desk work. Desk work stays reachable, never
   prominent.

   WHY THIS IS A SEPARATE FILE, LOADED LAST
   Every page in this app builds its own <style> block inside a template literal
   and re-declares the whole shell (.layout/.sidebar/.main/.hamburger) — 45-odd
   times, with drifting values (see helpers/mobile_shell.js). A rule in
   /os-global.css therefore LOSES to the page's own copy on equal specificity,
   because the page block comes later in <head>.
   helpers/mobile_shell.js injects this file immediately before </head>, i.e.
   AFTER every page's own <style>, so equal-specificity ties resolve here. That
   is the whole reason this is not appended to os-global.css.

   SCOPE — everything below 1024px only.
   Not one byte of this file applies at desktop widths. The desktop app is where
   the work happens and it already works; `@media (max-width:1023px)` wraps every
   layout rule so a 1440px viewport computes identically to before.

   DARK MODE
   Colours are taken from the existing --os-* tokens with light-mode fallbacks,
   and dark overrides hang off `body.dark-theme` exactly like the rest of the
   app. Nothing here defines a colour that only exists inside a media query, so
   there is no path to a half-themed control.
   ============================================================================ */

/* ─── tokens (defined unconditionally so dark can only ever OVERRIDE) ─────── */
:root {
  --os-tabbar-h: 56px;
  --os-safe-b: env(safe-area-inset-bottom, 0px);
  --os-safe-t: env(safe-area-inset-top, 0px);
  --os-safe-l: env(safe-area-inset-left, 0px);
  --os-safe-r: env(safe-area-inset-right, 0px);
  --os-tabbar-bg: rgba(255, 255, 255, 0.92);
  --os-tabbar-border: rgba(0, 0, 0, 0.08);
  --os-tabbar-ink: #6e6e73;
  --os-tabbar-ink-active: #1a7a5a;
  --os-sheet-bg: #ffffff;
  --os-sheet-ink: #1d1d1f;
}
body.dark-theme {
  --os-tabbar-bg: rgba(22, 22, 26, 0.94);
  --os-tabbar-border: rgba(255, 255, 255, 0.14);
  --os-tabbar-ink: #a1a1aa;
  --os-tabbar-ink-active: #34d399;
  --os-sheet-bg: #16161a;
  --os-sheet-ink: #f5f5f7;
}

/* The tab bar and sheet are rendered on every sidebar page but are desktop-
   invisible. Hidden by default; the media query below turns them on. */
.os-tabbar,
.os-sheet-scrim,
.os-sheet { display: none; }

@media (max-width: 1023px) {

  /* ── 1. THE SHELL ───────────────────────────────────────────────────────
     12 of the 32 sidebar pages ship NO mobile CSS at all (account, daycare,
     deposits, notifications, payroll, reports, staff, support, training,
     waitlist, billing, bug-report). On those, `.main{margin-left:260px}` and a
     260px-wide `position:fixed` sidebar both stay live on a 393px phone: the
     content is shoved most of the way off the screen and the nav sits on top of
     what is left. Measured before this file: /dashboard/daycare had a
     scrollWidth of 748px inside a 393px viewport.
     These three rules fix all 12 at once, and are no-ops on the 20 pages that
     already got it right. !important is load-bearing here — several page blocks
     declare the margin with !important of their own. */
  .main,
  .main-content,
  .content-wrap { margin-left: 0 !important; width: auto !important; max-width: 100% !important; }

  .sidebar {
    transform: translateX(-100%) !important;
    width: 82vw !important;
    max-width: 320px !important;
    padding-top: var(--os-safe-t) !important;
    padding-left: var(--os-safe-l) !important;
    /* momentum scroll: a 28-item nav does not fit on a phone screen */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .sidebar.open { transform: translateX(0) !important; }
  .hamburger { display: inline-flex !important; }

  /* ── 2. NO HORIZONTAL SCROLL ────────────────────────────────────────────
     A page that scrolls sideways is unusable one-handed: every vertical swipe
     drifts and the layout shifts under the thumb. The body is pinned; anything
     that genuinely must be wider than the screen (a data table, a calendar
     grid) gets its OWN scroll container in section 5 rather than dragging the
     whole document sideways. */
  html, body { max-width: 100%; overflow-x: hidden; }
  .content { padding: 14px var(--os-safe-r) calc(var(--os-tabbar-h) + var(--os-safe-b) + 20px) var(--os-safe-l) !important; }
  .content, .card, .os-card, .panel, .stat-card, .welcome-card, .section-card {
    max-width: 100%;
    box-sizing: border-box;
  }
  /* long unbroken strings (emails, URLs, tokens) are a classic overflow source */
  .card, .os-card, .panel, .section-card, td, th, li, p { overflow-wrap: anywhere; }
  /* images and embeds must never set the page width */
  img, video, iframe, canvas, svg { max-width: 100%; height: auto; }

  /* ── 3. iOS ZOOM-ON-FOCUS ───────────────────────────────────────────────
     Mobile Safari zooms the whole page when a focused input's font-size is
     under 16px, and it does not zoom back out. Measured before this file:
     /dashboard/settings had 11 such inputs, so tapping any field threw the
     groomer into a zoomed viewport they then had to pinch out of, one-handed,
     mid-form. 16px is the fix and it is not negotiable. */
  input, select, textarea {
    font-size: 16px !important;
    max-width: 100%;
    box-sizing: border-box;
  }
  /* a 44pt target per Apple's HIG; WCAG 2.5.8 AA only asks 24px, so this is the
     stricter of the two on purpose — wet hands, moving animal */
  input:not([type="checkbox"]):not([type="radio"]),
  select, textarea, button, .btn, .os-btn, .action-btn {
    min-height: 44px;
  }
  input[type="checkbox"], input[type="radio"] { min-width: 24px; min-height: 24px; }

  /* The drawer's own nav rows measured 241x22px — under half the 44pt target,
     on the one surface whose entire job is being tapped. Found at 320px, where
     a page-level media query tightens their padding further. */
  .sidebar .nav-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  /* The 2026-08-15 collapsible group headers (Communication/Money/Media/Team)
     are also reachable from this same drawer — same 44pt target as a nav row. */
  .sidebar .nav-group-header {
    min-height: 44px;
  }
  /* The drawer toggle measured 36x44 / 40x44 depending on the page -- tall
     enough, too narrow. Roughly 45 routes each re-declare .hamburger in their
     own inline <style>, so the fix belongs here, once, rather than in every
     one of them. min-width only: nothing about the icon or its position moves,
     the hit area just reaches the platform minimum on both axes. */
  .hamburger {
    min-width: 44px !important;
    min-height: 44px !important;
  }
  /* An 18x18 label acting as a button on every client card. Padding rather than
     a fixed box, so the icon does not move — only the hit area grows. */
  .photo-upload-btn, .icon-btn, .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ── 4. THUMB ZONE ──────────────────────────────────────────────────────
     Primary navigation moves to the bottom of the screen where a thumb rests.
     Apple's own apps put it there; a hamburger in the top-left corner is the
     single hardest pixel to reach on a 6.7" phone held in one hand. */
  .os-tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1000;
    height: calc(var(--os-tabbar-h) + var(--os-safe-b));
    padding-bottom: var(--os-safe-b);      /* clears the home indicator */
    padding-left: var(--os-safe-l);
    padding-right: var(--os-safe-r);
    background: var(--os-tabbar-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--os-tabbar-border);
    align-items: stretch;
    justify-content: space-around;
  }
  .os-tabbar__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;                       /* HIG touch target */
    padding: 6px 2px;
    text-decoration: none;
    color: var(--os-tabbar-ink);
    font-size: 10px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.01em;
    background: none;
    border: 0;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .os-tabbar__item svg { width: 22px; height: 22px; display: block; }
  .os-tabbar__item[aria-current="page"] { color: var(--os-tabbar-ink-active); }
  /* Labels are ALWAYS rendered, never icon-only. A bare-icon tab bar is the
     classic screen-reader failure and it is also just guessy for a new hire on
     their second shift. */
  .os-tabbar__label { display: block; }
  .os-tabbar__item:focus-visible {
    outline: 2px solid var(--os-tabbar-ink-active);
    outline-offset: -3px;
    border-radius: 8px;
  }
  .os-tabbar__badge {
    position: absolute;
    transform: translate(12px, -10px);
    min-width: 16px; height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #ff3b30;
    color: #fff;
    font-size: 10px; font-weight: 700;
    line-height: 16px; text-align: center;
  }

  /* ── 5. WIDE TABLES BECOME CARDS ────────────────────────────────────────
     A 9-column payroll table on a 393px screen is a pinch-zoom grid, which is
     exactly what the owner said not to ship. os-mobile.js copies each column's
     <th> onto its <td> as data-label; these rules then stack every row into a
     labelled card. Tables that are genuinely a grid (the boarding occupancy
     chart, the calendar) are skipped by the JS and keep a real scroll container
     instead — a card list would destroy the one thing a grid is for. */
  table.os-mtable, table.os-mtable thead, table.os-mtable tbody,
  table.os-mtable tr, table.os-mtable td { display: block; width: auto; }
  table.os-mtable thead { position: absolute; left: -9999px; }  /* headers move into data-label */
  table.os-mtable tr {
    margin: 0 0 10px;
    padding: 12px 14px;
    border: 1px solid var(--os-border, rgba(0,0,0,0.08));
    border-radius: 12px;
    background: var(--os-card, #fff);
  }
  table.os-mtable td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 5px 0;
    border: 0;
    text-align: right;
    font-size: 14px;
  }
  table.os-mtable td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--os-text-secondary, #6e6e73);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  table.os-mtable td:empty { display: none; }

  /* grids and anything opted out of carding scroll inside their own box */
  .os-table-wrap, .os-scroll-x, .boarding-grid, .grid-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;   /* momentum, not a dead drag */
    overscroll-behavior-x: contain;
  }

  /* ── 6. THINGS THAT COLLIDE WITH A BOTTOM BAR ───────────────────────────
     helpers/sidebar.js pins the "Report an Issue" button at top:16px;left:50%,
     directly under the notch and on top of the page header. The toast sits at
     bottom:24px, i.e. behind the new tab bar. */
  #afos-hazard-btn {
    top: auto !important;
    bottom: calc(var(--os-tabbar-h) + var(--os-safe-b) + 12px) !important;
    max-width: calc(100vw - 32px);
  }
  #afos-toast {
    right: 12px !important;
    left: 12px !important;
    max-width: none !important;
    bottom: calc(var(--os-tabbar-h) + var(--os-safe-b) + 12px) !important;
  }
  .os-page-header { padding-top: calc(10px + var(--os-safe-t)) !important; }

  /* ── 7. NO HOVER-ONLY CONTROLS ──────────────────────────────────────────
     Anything revealed by :hover is unreachable on a touchscreen — there is no
     hover state, so the control simply does not exist for a phone user. Any
     row-action that the desktop reveals on hover is made permanently visible. */
  .row-actions, .hover-actions, .card-actions,
  .os-row__actions, .actions-on-hover {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  /* ── 8. THE "MORE" SHEET — desk work lives here ─────────────────────────
     Reports, payroll, billing, settings, exports, integrations. Reachable in
     two taps, never occupying a tab. */
  .os-sheet-scrim {
    display: block;
    position: fixed; inset: 0;
    z-index: 1001;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  .os-sheet-scrim.open { opacity: 1; pointer-events: auto; }
  .os-sheet {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1002;
    max-height: 78vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: var(--os-sheet-bg);
    color: var(--os-sheet-ink);
    border-radius: 18px 18px 0 0;
    padding: 8px 16px calc(20px + var(--os-safe-b));
    transform: translateY(101%);
    transition: transform .26s cubic-bezier(.32,.72,0,1);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
  }
  .os-sheet.open { transform: translateY(0); }
  .os-sheet__grab {
    width: 36px; height: 5px; border-radius: 3px;
    background: var(--os-tabbar-border);
    margin: 6px auto 12px;
  }
  .os-sheet__title {
    font-size: 13px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--os-text-secondary, #6e6e73);
    margin: 14px 0 6px;
  }
  .os-sheet__link {
    display: flex; align-items: center; gap: 12px;
    min-height: 48px;                      /* comfortably over 44 */
    padding: 6px 4px;
    color: var(--os-sheet-ink);
    text-decoration: none;
    font-size: 16px;
    border-bottom: 1px solid var(--os-tabbar-border);
  }
  .os-sheet__link:last-child { border-bottom: 0; }
  .os-sheet__link .nav-item__label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* [navpolish] the sheet links had no focus ring at all -- a keyboard/
     switch-control user tabbing through the "More" sheet could not tell
     which row was focused. Same ring language as the desktop .nav-item. */
  .os-sheet__link:focus-visible {
    outline: 0;
    box-shadow: inset 0 0 0 2px var(--os-accent-ring, rgba(26,122,90,0.35));
    border-radius: 10px;
  }
  .os-sheet__link[aria-current="page"] {
    color: var(--os-accent-text, #1a7a5a);
    font-weight: 600;
  }
  body.dark-theme .os-sheet__link[aria-current="page"] {
    color: var(--os-green-light, #28c98e);
  }
  .os-sheet__link .nav-icon,
  .os-sheet__link svg { width: 20px; height: 20px; flex: 0 0 20px; opacity: .8; }
  /* [2026-09-21 NAVFIX] Same off/locked gating as the desktop sidebar --
     see helpers/sidebar.js navItemState() -- for the "More" sheet, which is
     where a gated item lands once it is no longer one of the 4 primary
     tabs (see buildMobileTabBar). */
  .os-sheet__link--gated { opacity: 0.66; }
  .os-sheet__link .nav-item__state-pill {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(120,120,128,0.16);
    color: rgba(60,60,67,0.75);
  }
  .os-sheet__link .nav-item__state-pill--locked {
    background: rgba(191,144,0,0.18);
    color: #8a6300;
  }
  /* [navpolish] same dark-mode legibility fix as the desktop pill -- the
     sheet is presented over the dark theme's tab bar surface too. */
  body.dark-theme .os-sheet__link .nav-item__state-pill {
    background: rgba(255,255,255,0.12);
    color: rgba(235,235,245,0.75);
  }
  body.dark-theme .os-sheet__link .nav-item__state-pill--locked {
    background: rgba(255,196,0,0.2);
    color: #ffcf40;
  }


  /* ── 9. DENSITY ─────────────────────────────────────────────────────────
     Multi-column desktop grids collapse rather than shrinking to unreadable. */
  .os-metrics-row, .stats-grid, .stat-grid, .cards-grid, .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    display: grid !important;
  }
  .os-details-panel { display: none; }
  .topbar-user-pill { display: none; }
}

/* ─── 320px reflow (WCAG 1.4.10 AA) ────────────────────────────────────────
   iPhone SE in landscape-split and any user at 400% zoom land here. Five tabs
   at 320px gives 64px each, still over the 44pt target. */
@media (max-width: 360px) {
  .os-tabbar__item { font-size: 9px; padding: 6px 0; }
  .os-tabbar__item svg { width: 20px; height: 20px; }
  .content { padding-left: 10px !important; padding-right: 10px !important; }
  table.os-mtable td { flex-wrap: wrap; }
  table.os-mtable td::before { flex-basis: 100%; }
}

/* ─── respect the user's motion setting ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .os-sheet, .os-sheet-scrim, .sidebar { transition: none !important; }
}

/* [ospolish 2026-11-08] stat rows (os-metrics-row): two per row on phones and tablets. One full-width
   row per stat pushed the calendar below the first screen. Other grids above keep their one column. */
@media (max-width: 1023px) {
  .os-metrics-row { grid-template-columns: 1fr 1fr !important; }
  .os-metrics-row__cell { min-width: 0; border-right: none; }
  .os-metrics-row__cell:nth-child(odd):not(:last-child) { border-right: 1px solid rgba(0,0,0,0.06); }
  .os-metrics-row__cell:nth-last-child(2):nth-child(odd) { border-bottom: none; }
}

/* [ospolish m5] a spanning row (empty state, subtotal) in a phone card table reads centred, not as a right-aligned value */
@media (max-width: 1023px) { table.os-mtable td[colspan] { justify-content: center; text-align: center; } table.os-mtable td[colspan]::before { content: none; } }
/* [p2r1 P2-06] a row that is a single spanning cell (empty / loading state) is a block, not a flex row of its own children */
@media (max-width: 1023px) { table.os-mtable td[colspan]:only-child { display: block; text-align: center; } }

/* [ospolish6 R6-09] bare text outside a card keeps a side margin on phones (cards stay full-bleed) */
@media (max-width: 1023px) {
  .os-breadcrumb { padding-left: 14px; padding-right: 14px; box-sizing: border-box; }
  .container > .os-hint { margin-left: 14px; margin-right: 14px; }
}


/* ─── p2r2 P2R2-06a: iPad landscape / small laptop (1024-1180px) ───────────────
   The page header's action row (buttons + user + log out) is flex-shrink:0 and wider than the room beside the 260px sidebar, so Clients / Invoices / Payments
   grew sideways as a whole page. In this band only: the header may wrap, the action row may wrap and shrink, the content column may be narrower than its widest child. */
@media (min-width: 1024px) and (max-width: 1180px) {
  .os-page-header { flex-wrap: wrap; }
  .os-page-header__actions { flex-shrink: 1; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
  .layout > .main { min-width: 0; }
}
