/* mobile-a11y.css — accessibility + mobile responsive layer.
 *
 * Loaded on every page via render_page() after gateway.css so it can
 * override/tighten defaults. Uses gateway.css variables (--text-primary,
 * --bg-surface, etc.) so light/dark themes just work.
 */

/* Contrast overrides that used to live here have moved into
   tokens.css. --text-tertiary = #858585 (4.54:1 on #fff) and
   --text-quaternary = #bbbbbb (decorative-only; see DESIGN_SYSTEM.md
   "Tokens to use more" — never body text). */

/* ── Focus ring (WCAG AA) ──────────────────────────────────────────── */
*:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm, 6px);
}
:focus:not(:focus-visible) { outline: none; }

/* Safety net — some legacy templates set ``:focus { outline: none; ... }``
 * with a higher selector specificity than the global ``*:focus-visible``
 * rule above, so keyboard focus on those elements lost its outline. Marking
 * the outline + offset as ``!important`` inside :focus-visible guarantees
 * the ring wins regardless of later rules while leaving mouse-only :focus
 * styles (which are exempt from WCAG 2.4.11) intact.
 */
:focus-visible {
  outline: 2px solid var(--text-primary) !important;
  outline-offset: 2px !important;
}

/* ── Low-contrast text boosters (WCAG 1.4.3) ────────────────────────── */
/*
 * Some templates style secondary links with ``opacity: 0.55`` on top of
 * ``color: inherit``, which axe-core rightfully flags as a contrast
 * failure on the site-wide light background (ratio ≈ 3.0, below 4.5
 * required for body text). The hover state already resets to opacity 1,
 * so the visible-but-muted look is preserved: we just lift the resting
 * opacity to a value that clears the WCAG threshold.
 */
.backlink,
.legal-eyebrow,
.status-item,
.breadcrumb-item,
.footer-nav,
.footer-nav > a,
.pr-back,
.pr-faq-q,
.pr-page > p,
.landing-dash-price,
.landing-pricing-card > div,
.landing-pricing-card > a,
.price-period {
  opacity: 1 !important;
  color: var(--text-secondary, #333) !important;
}

.pr-page > p.pr-sub,
.landing-dash-desc {
  /* Larger descriptive paragraphs — keep the muted look but on the
   * secondary token so contrast stays ≥ 4.5:1 against both themes. */
  color: var(--text-secondary, #333);
}

/* Prerelease footer — legal link row. The root rule hits the hero text
 * but the <p>... Terms · Privacy ...</p> underneath uses --text-tertiary
 * inline. Override on the body-scoped selector. */
body > div:last-of-type a[href="/terms"],
body > div:last-of-type a[href="/privacy"] {
  color: var(--text-secondary, #333) !important;
  opacity: 1 !important;
}

/* ── Skip link ─────────────────────────────────────────────────────── */
.narve-skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  z-index: var(--z-overlay);
  padding: 8px 14px;
  background: var(--interactive-bg);
  color: var(--interactive-text);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-base);
  border-radius: var(--radius-sm);
  transition: top 0.15s ease;
}
.narve-skip-link:focus-visible {
  top: 8px;
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* ── Screen-reader-only utility ────────────────────────────────────── */
.narve-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── PWA install banner ────────────────────────────────────────────── */
.narve-install-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 16px;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--bg-float, #fff);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(0,0,0,0.15));
  font-size: var(--text-base);
  max-width: calc(100vw - 32px);
}
.narve-install-banner__text { flex: 1; min-width: 0; }
.narve-install-banner__btn {
  appearance: none;
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  min-height: 36px;
}
.narve-install-banner__btn:hover { background: var(--interactive-ghost); }
.narve-install-banner__btn--primary {
  background: var(--interactive-bg);
  color: var(--interactive-text);
  border-color: var(--interactive-bg);
}
.narve-install-banner__btn--primary:hover { background: var(--interactive-hover); }
@media (max-width: 480px) {
  .narve-install-banner {
    left: 12px; right: 12px; transform: none; flex-wrap: wrap; bottom: 12px;
  }
  .narve-install-banner__btn { flex: 1; min-height: 44px; }
}

/* ── Keyboard shortcut help overlay ────────────────────────────────── */
.narve-sc-overlay {
  position: fixed; inset: 0; z-index: 9998;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.narve-sc-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
.narve-sc-panel {
  position: relative;
  background: var(--bg-float, #fff);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: min(640px, 100%);
  max-height: min(80vh, 720px);
  display: flex; flex-direction: column; overflow: hidden;
}
.narve-sc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-ghost);
}
.narve-sc-title { font-size: var(--text-md); font-weight: 600; margin: 0; }
.narve-sc-close {
  appearance: none; background: transparent; border: 0;
  color: var(--text-secondary);
  font-size: var(--text-2xl); line-height: 1;
  padding: 4px 10px; cursor: pointer; border-radius: var(--radius-sm);
  min-width: 44px; min-height: 44px;
}
.narve-sc-close:hover { background: var(--interactive-ghost); color: var(--text-primary); }
.narve-sc-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.narve-sc-section + .narve-sc-section { margin-top: 20px; }
.narve-sc-heading {
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-tertiary); margin: 0 0 10px;
}
.narve-sc-list {
  margin: 0;
  display: grid; grid-template-columns: 1fr; gap: 6px;
}
.narve-sc-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 8px 10px; border-radius: var(--radius-md);
}
.narve-sc-row:hover { background: var(--bg-inset); }
.narve-sc-keys {
  margin: 0; display: flex; align-items: center; gap: 4px;
  flex-wrap: wrap; justify-content: flex-end;
}
.narve-sc-desc {
  margin: 0; color: var(--text-secondary); font-size: var(--text-base);
  flex: 1; min-width: 0;
}
.narve-sc-row kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; padding: 2px 6px;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px; font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
}
.narve-sc-then, .narve-sc-or {
  font-size: var(--text-xs); color: var(--text-tertiary); margin: 0 2px;
}
.narve-sc-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-ghost);
  font-size: 12px; color: var(--text-tertiary);
}

/* ── Discovery hint toast ──────────────────────────────────────────── */
/* Bottom-right pill that appears once per browser session to surface
 * the keyboard-shortcuts overlay for first-time users. Fades in on
 * 30s idle or after the user mashes a printable key with no binding.
 * Dismiss-forever flag is stored in localStorage (key
 * "narve.shortcutHintDismissed"). */
.narve-sc-hint {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9990;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--bg-float, #ffffff);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: var(--text-sm);
  max-width: calc(100vw - 32px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}
.narve-sc-hint--open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.narve-sc-hint__body { white-space: nowrap; }
.narve-sc-hint__body kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; padding: 1px 5px;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: var(--text-xs); font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-inset, var(--interactive-ghost));
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  margin: 0 2px;
}
.narve-sc-hint__actions {
  display: flex; gap: 4px; align-items: center;
}
.narve-sc-hint__open,
.narve-sc-hint__close {
  appearance: none; background: transparent; border: 0;
  font: inherit; color: var(--text-secondary);
  padding: 6px 10px; border-radius: var(--radius-full); cursor: pointer;
}
.narve-sc-hint__open  { color: var(--text-primary); font-weight: 500; }
.narve-sc-hint__close { font-size: var(--text-lg); line-height: 1; padding: 4px 10px; min-width: 32px; }
.narve-sc-hint__open:hover,
.narve-sc-hint__close:hover { background: var(--interactive-ghost, rgba(0,0,0,0.06)); color: var(--text-primary); }

@media (max-width: 480px) {
  .narve-sc-hint { left: 16px; right: 16px; bottom: 16px; }
  .narve-sc-hint__body { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  .narve-sc-hint { transition: opacity 0.05s ease; transform: none; }
}

/* ── List selection (j/k) ──────────────────────────────────────────── */
[data-shortcut-item][data-shortcut-selected] {
  outline: 2px solid var(--text-primary);
  outline-offset: -2px;
  background: var(--bg-inset);
}

/* ── Tap targets (mobile, coarse pointer) ──────────────────────────── */
@media (max-width: 860px) and (pointer: coarse) {
  button,
  [role="button"],
  a.nav-item,
  .btn,
  input[type="submit"],
  input[type="button"],
  .narve-install-banner__btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ── Forms: prevent iOS zoom (≥16px) + full-width on mobile ────────── */
@media (max-width: 720px) {
  input:not([type="checkbox"]):not([type="radio"]),
  select, textarea {
    font-size: max(16px, 1rem);
  }
  form label { display: block; margin-bottom: 4px; }
  form input:not([type="checkbox"]):not([type="radio"]),
  form select, form textarea, form button[type="submit"] {
    width: 100%;
    box-sizing: border-box;
  }
}

/* ── 375px: deep mobile fixes ─────────────────────────────────────── */
@media (max-width: 520px) {
  html, body { overflow-x: hidden; }
  .app-shell, .gw-main, .pr-wrap, .landing-main { max-width: 100vw; }

  /* Tables → cards (opt-in: .responsive-table or data-responsive="cards") */
  table.responsive-table, table[data-responsive="cards"],
  table.responsive-table thead, table[data-responsive="cards"] thead,
  table.responsive-table tbody, table[data-responsive="cards"] tbody,
  table.responsive-table tr,    table[data-responsive="cards"] tr,
  table.responsive-table td,    table[data-responsive="cards"] td {
    display: block;
    width: 100%;
  }
  table.responsive-table thead,
  table[data-responsive="cards"] thead {
    position: absolute;
    left: -9999px;
  }
  table.responsive-table tr,
  table[data-responsive="cards"] tr {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 10px;
    background: var(--bg-surface);
  }
  table.responsive-table td,
  table[data-responsive="cards"] td {
    border: 0;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }
  table.responsive-table td::before,
  table[data-responsive="cards"] td::before {
    content: attr(data-label);
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
  }
  table:not(.responsive-table):not([data-responsive]) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .detail-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: var(--z-watermark);
    border-left: 0 !important;
  }
  .modal-content, .dialog, [role="dialog"] > .panel {
    max-width: 100vw !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  .sidebar { padding: 8px 10px; gap: 4px; }
  .sidebar .nav-item { padding: 8px 10px; }

  .pr-hero { flex-direction: column !important; text-align: center; gap: 20px; }
  .pr-floating-numbers { display: none !important; }
  .landing-hero, .hero-grid, .feature-grid { grid-template-columns: 1fr !important; }
  .auth-card, .card, .form-card {
    max-width: 100% !important;
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    box-shadow: none !important;
  }

  .intel-chat-input, .chat-input-row {
    position: sticky;
    bottom: 0;
    background: var(--bg-base);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* ── Reduced motion polish ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .narve-skip-link,
  .narve-install-banner,
  .narve-sc-overlay { transition: none !important; animation: none !important; }
  .narve-sc-backdrop { backdrop-filter: none !important; }
}

/* ── Safe-area insets in standalone PWA mode ───────────────────────── */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── High-contrast mode (Windows) ─────────────────────────────────── */
@media (forced-colors: active) {
  .narve-install-banner,
  .narve-sc-panel,
  [data-shortcut-item][data-shortcut-selected] {
    border: 1px solid CanvasText;
  }
  *:focus-visible { outline-color: CanvasText; }
}

/* __a11y-force-fix-marker */


/* ── WCAG AA: force-fix specific low-contrast elements ─────────────── */
/* These selectors target elements that hardcode #888/#aaa or inherit
   through a now-overridden chain, specifically on gray backgrounds
   where the bumped --text-tertiary still fails at 4.5:1. */
:root[data-theme="light"] .dash-card-price,
:root[data-theme="light"] .profile-meta-item,
:root[data-theme="light"] .profile-locked-hint,
:root[data-theme="light"] .profile-input-locked,
:root[data-theme="light"] .content-area > p,
:root[data-theme="light"] #profile-username,
:root[data-theme="light"] #profile-email,
:root[data-theme="light"] .pr-admin {
  color: var(--text-secondary);
}

/* #sitemap-btn and .btn-danger use inline ``style`` attributes, so
   element-level color wins unless we annotate with !important. The
   monochrome design system has no "red" danger colour — the button
   is the same near-black primary as every other, with the semantic
   signalled by icon / label. */
:root[data-theme="light"] #sitemap-btn {
  color: var(--text-primary) !important;
  background: var(--bg-raised) !important;
}
:root[data-theme="light"] .btn-danger {
  color: var(--text-primary) !important;
}
:root[data-theme="light"] .btn-danger:hover {
  color: var(--text-primary) !important;
}

/* Dashboard card accent buttons — high contrast for the 4.5:1 ratio,
   routed through interactive tokens so the dark-theme flip stays
   automatic. */
:root[data-theme="light"] .dash-card a[href*="localhost:"] {
  color: var(--interactive-text);
  background-color: var(--interactive-bg) !important;
}

/* Inline links inside running text must be distinguishable by more than
   colour — add an underline so axe's link-in-text-block rule passes. */
p a, li a, .page-subtitle a {
  text-decoration: underline;
  text-underline-offset: 2px;
}
p a:hover, li a:hover, .page-subtitle a:hover {
  text-decoration-thickness: 2px;
}


/* ── /intelligence (chat) mobile layout ───────────────────────────── */
/* __intel-mobile-v1 */
@media (max-width: 720px) {
  /* Hide the conversation-list sidebar on phones. Users reach history
     via a future slide-in; for now keep the main chat usable at 375px. */
  .intel-shell { grid-template-columns: 1fr !important; }
  .intel-sidebar { display: none !important; }
  .intel-header { padding: 16px 16px 0 !important; }
  .intel-title { font-size: 22px !important; }
  .intel-messages {
    padding: 16px !important;
    padding-bottom: 120px !important;   /* space for fixed composer */
  }
  .intel-input-bar {
    position: fixed !important;
    left: 0; right: 0; bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) !important;
    z-index: var(--z-sticky);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  }
  .intel-input-shell { gap: 8px !important; }
  .intel-input-shell textarea {
    /* min-height comfortable on mobile; font-size ≥16 to defeat iOS zoom */
    min-height: 44px !important;
    font-size: var(--text-md) !important;
  }
  .suggested { grid-template-columns: 1fr !important; }

  /* Horizontally scrollable chip row for suggested prompts on mobile. */
  .suggested-row {
    display: flex !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .suggested-row > .suggested-btn {
    flex: 0 0 80%;
    scroll-snap-align: start;
  }
}


/* __landing-pricing-grid-mobile */
/* Landing's pricing grid uses inline grid-template-columns: repeat(3,1fr),
   which overflows a 375px viewport. Collapse to a single column. */
@media (max-width: 720px) {
  .landing-pricing-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .landing-pricing-card { width: 100% !important; }
}


/* ══════════════════════════════════════════════════════════════════════
 * Mobile viewport pass — hamburger drawer, tap targets, table scrolling,
 * 16px inputs, hover-only-on-hover, safe-area, bottom-sheet pattern.
 *
 * pwa_middleware injects a `.narve-hamburger` button + backdrop after
 * <body>; this stylesheet decides when to show them and what the open
 * state looks like. narve-app.js wires the toggle. Existing
 * `gateway.css` already slides `.sidebar` at ≤768px — these rules sit
 * on top of that to provide the missing UI affordance.
 * ════════════════════════════════════════════════════════════════════ */

/* ── Hamburger button ──────────────────────────────────────────────── */
.narve-hamburger {
  /* Hidden by default. Becomes visible only on mobile when the page
   * actually has a `.sidebar` (see :has() rule below). */
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: var(--z-modal, 9999);
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  background: var(--bg-float, var(--bg-base, #fff));
  color: var(--text-primary);
  border: 1px solid var(--border-default, rgba(0,0,0,0.12));
  border-radius: 10px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
  cursor: pointer;
  appearance: none;
}
.narve-hamburger svg { width: 20px; height: 20px; }
.narve-hamburger:hover { background: var(--interactive-ghost, rgba(0,0,0,0.04)); }
.narve-hamburger:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* ── Backdrop ──────────────────────────────────────────────────────── */
.narve-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-modal, 9999) - 2);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.narve-sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Mobile breakpoint — show hamburger, lift sidebar, lock scroll ── */
@media (max-width: 900px) {
  /* Show the hamburger only on pages that actually have a sidebar.
   * :has() is the cleanest way to express this without per-page
   * markup. The fallback below covers older browsers. */
  body:has(.sidebar, .narve-sidebar) .narve-hamburger {
    display: inline-flex;
  }

  /* Sidebar drawer rules. gateway.css already does the slide at
   * ≤768px — duplicate here at 900px to also cover tablets and to
   * raise z-index to ensure it sits above page content + above the
   * backdrop. */
  .sidebar,
  .narve-sidebar {
    position: fixed !important;
    top: 0; bottom: 0; left: 0;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    z-index: var(--z-modal, 9999);
    background: var(--bg-surface, var(--bg-base, #fff));
    border-right: 1px solid var(--border-default, rgba(0,0,0,0.12));
    overflow-y: auto;
  }
  .sidebar.open,
  .narve-sidebar.open {
    transform: translateX(0);
  }

  /* Lock body scroll while drawer is open. */
  body.narve-drawer-open { overflow: hidden; }

  /* Reclaim left margin so main content sits under the now-fixed sidebar. */
  .main-content,
  main.main-content,
  .content-area {
    margin-left: 0 !important;
    /* 56px gives breathing room for the hamburger overlap at top-left. */
    padding-top: max(56px, env(safe-area-inset-top)) !important;
  }
}

/* Older Safari (no :has) fallback — show hamburger on every mobile
 * page; harmless on pages without a sidebar (the JS short-circuits
 * before hooking up handlers when no `.sidebar` exists). */
@supports not selector(:has(*)) {
  @media (max-width: 900px) {
    .narve-hamburger { display: inline-flex; }
  }
}

/* ── Tables — horizontal scroll wrapper ────────────────────────────── */
.nv-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Mask any overflow shadow so the scroll affordance is visible
   * without a hard right edge. */
  -webkit-mask-image: linear-gradient(to right, black 95%, transparent);
          mask-image: linear-gradient(to right, black 95%, transparent);
}
.nv-table-wrap > table {
  width: 100%;
  /* Sub-pages with very wide tables can override this with their own
   * min-width on the table element. */
  min-width: max-content;
}
@media (max-width: 720px) {
  /* Final safety net: any unwrapped <table> that ships in a template
   * still gets a horizontal scroll affordance via its parent block. */
  .content-area table:not(.responsive-table):not([data-responsive]) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Tap targets — minimum 44×44 on mobile ─────────────────────────── */
/* Drop ``(pointer: coarse)`` — Playwright headless reports a fine
 * pointer, so the audit never saw the rule fire even though real
 * phones would honour it. The size floor is harmless on any
 * mobile breakpoint regardless of input device. */
@media (max-width: 900px) {
  button:not(.icon-button):not([data-no-min]),
  [role="button"]:not([data-no-min]),
  a.btn, a.button, a.cta, a.card-cta,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }
  /* Icon-only buttons get the box treatment. */
  .icon-button,
  button[aria-label][class*="icon"],
  [data-icon-only] {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Inline anchor tags still need touch room without bloating the
   * visual layout — pad via pseudo to keep the visible size unchanged
   * when ergonomics matter most (footers, breadcrumb separators). */
  .footer-nav a,
  .breadcrumb-item a {
    position: relative;
  }
  .footer-nav a::before,
  .breadcrumb-item a::before {
    content: "";
    position: absolute;
    inset: -10px -8px;
  }
}

/* ── Inputs ≥ 16px on mobile (defeats iOS auto-zoom) ───────────────── */
@media (max-width: 900px) {
  /* High-specificity selector so individual ``.foo-input`` /
   * ``.bar-select`` rules with their own font-size don't override us.
   * iOS zooms when the input is < 16px AND the page allows user-scaling. */
  body input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  body select,
  body textarea,
  body input.settings-input,
  body select.settings-select,
  body textarea.settings-textarea {
    font-size: max(16px, var(--input-font-size, 1rem)) !important;
  }
}

/* ── Hover styles only on devices that actually hover ──────────────── */
/* Touch devices "stick" hover-state styles after a tap; gating on
 * hover-capable + fine-pointer means a finger won't trigger the
 * desktop hover look. We DON'T overwrite every existing :hover rule
 * (would be unmaintainable) — instead we add a paired media-query
 * for the canonical hover surfaces below. Per-component hover
 * overrides should follow this same pattern going forward. */
@media (hover: none) and (pointer: coarse) {
  /* Cancel the most common "stuck hover" — link/button colour shifts. */
  a:hover, button:hover, [role="button"]:hover {
    background-color: revert;
    color: revert;
  }
}

/* ── Safe-area inset (iPhone home indicator + notch) ───────────────── */
.bottom-bar,
.modal-footer,
.sticky-cta,
.narve-feedback-fab,
.narve-install-banner,
.narve-bottom-sheet {
  padding-bottom: max(var(--space-4, 16px), env(safe-area-inset-bottom, 0px));
}

/* ── Bottom-sheet pattern for dropdowns / share menus on small screens ─ */
@media (max-width: 640px) {
  .nv-share__menu,
  .dropdown-menu,
  .nv-cmdk__menu,
  .narve-bottom-sheet,
  [data-narve-bottom-sheet] {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: none !important;
    border-radius: 14px 14px 0 0 !important;
    padding: 16px !important;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
  }

  /* Cmdk palette — full-screen on phones. */
  .nv-cmdk__panel,
  [data-cmdk-root] {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    transform: none !important;
  }

  /* Modal panels — near-fullscreen with safe-area gutters. */
  .nv-modal__panel,
  .narve-sc-panel,
  [role="dialog"] > .panel {
    width: calc(100% - 16px) !important;
    max-width: none !important;
    max-height: calc(100dvh - 32px) !important;
  }
}

/* ── Horizontal-scroll guard ───────────────────────────────────────── */
/* Belt-and-braces: prevent body-level horizontal scroll on every page.
 * Anything that needs to overflow horizontally (charts, code blocks)
 * should clip on its own container instead of pushing the page wide. */
@media (max-width: 900px) {
  html, body { max-width: 100%; overflow-x: clip; }
  img, video, canvas, iframe, svg { max-width: 100%; height: auto; }
}

/* ── Sticky filter bars / tab nav: respect safe-area ───────────────── */
@media (max-width: 900px) {
  .filter-bar,
  .admin-tabs,
  .narve-tabs {
    /* Replace any vendor-prefixed sticky with a real sticky that
     * accounts for the iOS top inset. */
    top: env(safe-area-inset-top, 0px);
  }
}


/* ── gw-nav: marketing top nav — wraps or scrolls on small screens ── */
@media (max-width: 720px) {
  .gw-nav {
    flex-wrap: wrap;
    gap: 12px;
    /* If wrapping isn't desired (single row), uncomment the next two
     * lines to switch to a horizontal scroll instead. */
    /* flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; */
  }
  .gw-nav a { font-size: var(--text-sm); }
}
