/* ==========================================================================
   Accessibility and mobile layer. Loaded after app.css in every layout.
   Owns: skip link, focus rings, contrast fixes for text that sits on
   tokens, guest menu, customer bottom tab bar, touch targets and overflow.
   Colours are derived from the tokens with color-mix so they follow the
   token layer (and dark mode) instead of hard-coding a second palette.
   Measured ratios are in plans/reports/phase4c-a11y-mobile-261201.md.
   ========================================================================== */

/* ---------- Skip link: hidden until focused, first stop on every page ---------- */
.skip-link{position:absolute;left:.75rem;top:-100px;z-index:2000;display:inline-flex;align-items:center;min-height:44px;padding:0 1rem;border-radius:var(--radius-sm);
  background:var(--fg);color:var(--bg);font-weight:700;font-size:.9rem;text-decoration:none}
.skip-link:focus,.skip-link:focus-visible{top:.75rem;outline:2px solid var(--primary);outline-offset:2px;text-decoration:none}
main:focus{outline:none}

/* ---------- Focus rings: always visible for keyboard users ---------- */
:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
.btn:focus-visible,.chip:focus-visible,summary:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
input:focus-visible,select:focus-visible,textarea:focus-visible{outline:2px solid var(--primary);outline-offset:1px}
/* Dark rail: the brand blue is only 2.7:1 on ink, a light blue ring is 8.4:1 */
.sidebar :focus-visible{outline-color:#8fb0ff}
.palette-box input:focus-visible{outline:2px solid var(--primary);outline-offset:-2px}
.skip-link:focus-visible{outline-color:var(--primary)}

/* ---------- Contrast: status pills, quiet text, sidebar headings, charts ---------- */
/* Pill text is mixed 25% toward the page text colour: 5.5:1 or better on its soft background. */
.pill-ok{color:color-mix(in srgb,var(--success) 75%,var(--fg))}
.pill-warn{color:color-mix(in srgb,var(--warning) 75%,var(--fg))}
.pill-danger{color:color-mix(in srgb,var(--danger) 75%,var(--fg))}
.pill-info{color:color-mix(in srgb,var(--info) 75%,var(--fg))}
.pill-ok::before,.pill-warn::before,.pill-danger::before,.pill-info::before{background:currentColor}
.prio-warn{color:color-mix(in srgb,var(--warning) 75%,var(--fg))}
.prio-danger{color:color-mix(in srgb,var(--danger) 75%,var(--fg))}
.prio-muted{color:var(--fg-muted)}
.field-error,.due-late{color:color-mix(in srgb,var(--danger) 75%,var(--fg))}
/* Text that used --fg-subtle (3.3:1) moves to --fg-muted (6.6:1). Placeholders stay quiet but readable. */
.footer,.apptop-meta,.minichart-axis span,.chart-label{color:var(--fg-muted)}
.chart-label{fill:var(--fg-muted)}
input::placeholder,textarea::placeholder{color:var(--fg-muted);opacity:.85}
.sidenav-heading{color:color-mix(in srgb,var(--chrome-fg) 80%,var(--chrome-bg))}
.brand-sub{opacity:1;color:color-mix(in srgb,var(--chrome-fg) 85%,var(--chrome-bg))}
/* Past-month bars: 3:1 against the card (non-text contrast), the current month stays solid primary. */
.minichart rect{fill:color-mix(in srgb,var(--primary) 65%,var(--bg-elevated))}
.minichart rect.now{fill:var(--primary)}
/* Links inside running text need more than colour to stand out from muted text. */
.help a:not(.btn),p.muted a:not(.btn),.sub a:not(.btn),.muted > a:not(.btn),.empty a:not(.btn),.alert a:not(.btn),.post-text a:not(.btn),.faq-item a:not(.btn){text-decoration:underline;text-underline-offset:2px}

/* Sign-in pages (auth.css): quiet text and the verified tick were 3.3:1 and 4.4:1 */
.auth-legal{color:var(--fg-muted)}
.auth-verified-success,.up,.stat-foot.up{color:color-mix(in srgb,var(--success) 75%,var(--fg))}
.auth-verified-warning{color:color-mix(in srgb,var(--warning) 75%,var(--fg))}

/* ---------- Menu button (real <button>, aria-expanded kept in sync by ui-behaviors.js) ---------- */
button.nav-button{font:inherit;padding:0}

/* ---------- Guest header: compact links + menu on phones ---------- */
.topbar-guest{gap:1rem}
.guest-actions{display:flex;align-items:center;gap:.5rem;margin-left:auto}
.guest-actions a{display:inline-flex;align-items:center;gap:.4rem;min-height:40px;padding:0 .75rem;border-radius:var(--radius-sm);
  color:var(--fg);font-weight:650;font-size:.88rem}
.guest-actions a:hover{background:var(--bg-subtle);text-decoration:none}
.guest-actions a.is-primary{background:var(--primary);color:var(--primary-fg)}
.guest-actions a.is-primary:hover{background:var(--primary-hover)}
.guest-actions svg{width:16px;height:16px}
.guest-count{font-family:var(--font-mono);font-size:.72rem;min-width:1.3rem;padding:0 .35rem;border-radius:999px;background:var(--primary-soft);
  color:color-mix(in srgb,var(--primary) 75%,var(--fg));text-align:center;line-height:1.3rem}
.guest-menu{position:relative;display:none}
.guest-menu > summary{list-style:none;display:grid;place-items:center;width:44px;height:44px;border:1px solid var(--line-strong);
  border-radius:var(--radius-sm);background:var(--bg-elevated);color:var(--fg);cursor:pointer}
.guest-menu > summary::-webkit-details-marker{display:none}
.guest-menu > summary svg{width:18px;height:18px}
.guest-menu-list{position:absolute;right:0;top:calc(100% + 6px);z-index:40;min-width:220px;display:flex;flex-direction:column;padding:.35rem;
  background:var(--bg-elevated);border:1px solid var(--line-strong);border-radius:var(--radius);box-shadow:var(--shadow-lg)}
.guest-menu-list a{display:flex;align-items:center;gap:.6rem;min-height:44px;padding:0 .75rem;border-radius:var(--radius-sm);color:var(--fg);font-weight:600}
.guest-menu-list a:hover{background:var(--bg-subtle);text-decoration:none}
.guest-menu-list svg{width:16px;height:16px;color:var(--fg-muted)}
@media(max-width:760px){
  .topbar-guest{padding:0 1rem;gap:.5rem}
  .topbar-guest .topnav{display:none}
  .topbar-guest .brand{min-width:0;flex:1}
  .topbar-guest .brand a{min-width:0}
  .topbar-guest .brand a > span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .guest-actions{margin-left:0;gap:.35rem}
  .guest-actions a{min-height:44px;padding:0 .6rem}
  .guest-actions .ga-label-long{display:none}
  .guest-menu{display:block}
}

/* ---------- Customer bottom tab bar (phones only) ---------- */
.tabbar{display:none}
@media(max-width:900px){
  .tabbar{position:fixed;left:0;right:0;bottom:0;z-index:25;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));
    background:var(--bg-elevated);border-top:1px solid var(--line);padding:0 0 env(safe-area-inset-bottom);
    padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right)}
  .tabbar a{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:.15rem;min-height:56px;padding:.35rem .1rem;
    color:var(--fg-muted);font-size:.68rem;font-weight:650;text-decoration:none;line-height:1.1;text-align:center}
  .tabbar a svg{width:20px;height:20px}
  .tabbar a[aria-current=page]{color:var(--primary)}
  .tabbar a[aria-current=page]::before{content:"";position:absolute;top:0;left:25%;right:25%;height:2px;border-radius:0 0 2px 2px;background:var(--primary)}
  .tabbar a:hover{text-decoration:none;color:var(--fg)}
  .tabbar-badge{position:absolute;top:.3rem;left:calc(50% + 4px);min-width:1.1rem;padding:0 .3rem;border-radius:999px;background:var(--danger);
    color:#fff;font-size:.62rem;font-weight:750;line-height:1.1rem}
  body.has-tabbar .shell-main{padding-bottom:calc(56px + env(safe-area-inset-bottom))}
  body.has-tabbar .live-ticker{bottom:calc(64px + env(safe-area-inset-bottom))}
}

/* ---------- Touch targets: 44px on phones and tablets, desktop density unchanged ---------- */
@media(max-width:900px){
  .btn,.btn-sm{min-height:44px}
  .btn-sm{padding-top:.4rem;padding-bottom:.4rem}
  .nav-button{width:44px!important;height:44px!important}
  .apptop a.chip,.apptop button.chip{height:44px;min-width:44px;justify-content:center}
  /* Icon-only chips keep a name for screen readers (the label is visually hidden, not removed). */
  .apptop a.chip span,.apptop button.chip span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;display:block!important}
  .sidenav a{min-height:44px}
  .sidebar-brand a{min-height:44px}
  .sidebar-user button{width:44px;height:44px}
  .sidebar-user .who a{display:inline-flex;align-items:center;min-height:44px}
  input,select{min-height:44px}
  input[type=checkbox],input[type=radio]{min-height:0}
  label:has(> input[type=checkbox]),label:has(> input[type=radio]),.check,.check-row{min-height:44px}
  .switch{margin:10px 0}
  .tabs a{min-height:44px}
  .settings-nav a,.store-cats a{min-height:44px}
  details.row-menu > summary{min-width:44px;min-height:44px;display:inline-flex;align-items:center;justify-content:center}
  .row-menu-list a,.row-menu-list button,.more-list a,.more-list button{min-height:44px;display:flex;align-items:center}
  .live-toast-close{width:44px;height:44px;top:0;right:0}
  .saved-view a,.saved-view button,.chip-link{min-height:44px;display:inline-flex;align-items:center}
  .back-link{display:inline-flex;align-items:center;min-height:44px;margin-bottom:0}
  .card-head > a,.list-head-row > a{display:inline-flex;align-items:center;min-height:44px}
  .segmented label,.segmented button,.segmented .seg-link{min-height:44px;display:inline-flex;align-items:center}
  .pager-size select{min-height:44px}
  .copy-field input,.facts dd input[readonly],.cart-cycle select,.cart-domain input,.view-name input{min-height:44px}
  .impersonate-link,.impersonate-exit{min-height:44px;display:inline-flex;align-items:center}
  .topnav a{display:inline-flex;align-items:center;min-height:44px}
  .crypto-coin > span{min-height:44px}
  .brand a,.auth-logo{min-height:44px}
  /* Row links (the name that opens a record) get a full-height hit area; sort links in headers get 32px. */
  td > a:not(.btn),.person-text > a{display:inline-flex;align-items:center;min-height:44px}
  th a.sort{display:inline-flex;align-items:center;min-height:32px}
  details > summary{min-height:44px;display:flex;align-items:center}
  .more-menu > summary,details.row-menu > summary{display:inline-flex}
  .auth-eye-btn{width:44px;height:44px}
  .auth-forgot-link{display:inline-flex;align-items:center;min-height:44px}
}

/* ---------- No sideways page scroll at 390px ---------- */
html,body{max-width:100%}
.shell-main{overflow-x:clip}
@media(max-width:900px){
  /* Wide tables scroll inside their own box, never the page. */
  .table-wrap{max-width:100%}
  .card > table,.list-card > table,.card-pad > table,main > table{display:block;max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
  .card{min-width:0}
  .toolbar form,.search-wide,.domain-add,.secret-form,.promo-entry,.aff-link,.scrape-row{max-width:100%;min-width:0}
  .card-head{flex-wrap:wrap}
  .card-head .search input{min-width:0;width:100%;min-height:44px}
  .card-head .search{flex:1 1 100%}
  .apptop-left{flex:1}
  pre,code{overflow-wrap:anywhere}
  .facts{grid-template-columns:minmax(0,auto) minmax(0,1fr)}
}

/* ---------- Mobile order page: category chips instead of a tall side menu ---------- */
@media(max-width:860px){
  .store{grid-template-columns:minmax(0,1fr)}
  .store-side,.store-side .store-box,.store-main{min-width:0}
  .store-side{flex-direction:column;flex-wrap:nowrap;gap:.5rem;position:sticky;top:58px;z-index:5;margin:0 -1rem;padding:.4rem 1rem;background:var(--bg)}
  .shell-main .store-side{top:54px}
  .store-side .store-box{flex:none;padding:0;border:0;background:none}
  .store-side .panel-title{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
  .store-side .store-cats{flex-direction:row;gap:.4rem;margin:0;overflow-x:auto;scrollbar-width:none;padding-bottom:2px}
  .store-side .store-cats::-webkit-scrollbar{display:none}
  .store-side .store-cats a{flex:none;border:1px solid var(--line-strong);border-radius:999px;padding:0 .9rem;background:var(--bg-elevated);white-space:nowrap}
  .store-side .store-cats a.active{box-shadow:none;border-color:var(--primary);background:var(--primary-soft)}
  /* Cart and sign in live in the header on phones, so the Actions box goes. */
  .store-side .store-box-actions{display:none}
}

/* ---------- Live alert toast on phones: top, one at a time, with a count ---------- */
@media(max-width:640px){
  .live-ticker{top:calc(62px + env(safe-area-inset-top));bottom:auto!important;left:.75rem;right:.75rem;width:auto;flex-direction:column}
  .is-impersonating .live-ticker{top:calc(98px + env(safe-area-inset-top))}
  .live-toast:not(:first-child){display:none}
  .live-ticker[data-more]::after{content:"+" attr(data-more) " more";align-self:flex-end;pointer-events:none;padding:.15rem .55rem;border-radius:999px;
    background:var(--fg);color:var(--bg);font-size:.72rem;font-weight:700}
  .live-toast{border-radius:var(--radius-lg)}
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion:reduce){.skip-link,.tabbar a{transition:none}}

/* ---------- Closed phone sidebar is out of the tab order ---------- */
@media(max-width:900px){
  .nav-toggle:not(:checked) ~ .sidebar{visibility:hidden;transition:transform .22s var(--ease-out),visibility 0s linear .22s}
  .nav-toggle:checked ~ .sidebar{visibility:visible;transition:transform .22s var(--ease-out)}
}
