/*
 * k0nsult-responsive-a11y.css — MEXEC #593 (CSS-only)
 * Shared overlay for the envois/* page templates (ipIII, Common-Source-of-Truth, ai-truth).
 * Root causes fixed: tables wider than the viewport, non-wrapping header nav, long unbroken
 * strings (code/URL/hash), unbounded media. Adds :focus-visible + prefers-reduced-motion.
 * Loaded AFTER each page's inline <style>, so equal-specificity rules here win.
 */

/* 1. Nothing may be wider than its container; flex/grid children may shrink. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
.wrap, .grid > *, .stats > *, .flow > *, .hero, .card, .stat { min-width: 0; max-width: 100%; }

body { overflow-wrap: break-word; }
[class*="legend"], [class*="metric"], [class*="meta-"], .cover { min-width: 0; max-width: 100%; }
[class*="legend"] { flex-wrap: wrap; }

/* 2. Long unbroken strings (hashes, URLs, identifiers) wrap instead of widening the page. */
p, li, dd, dt, td, th, h1, h2, h3, h4, a, code, .lede, .card, .stat, .hero, .pb-step, .principle, .disclaimer {
  overflow-wrap: anywhere;
}
pre { max-width: 100%; overflow-x: auto; }
pre code { overflow-wrap: normal; }
.st, .tag { white-space: normal; }

/* 3. Auto-fit grids: the 240/170px minimum must not exceed a 320px viewport. */
.grid  { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.stats { grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); }

/* 4. Header nav wraps instead of running off-screen; links get a touch-sized hit area. */
header .wrap { min-width: 0; }
header nav, body > nav, .wrap > nav {
  display: flex; flex-wrap: wrap; gap: .1rem .9rem; max-width: 100%; min-width: 0;
}
header nav a, body > nav a, .wrap > nav a { margin-left: 0; }
@media (max-width: 720px) {
  header nav a, body > nav a, .wrap > nav a {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 .25rem;
  }
  .subnav a { display: inline-flex; align-items: center; min-height: 44px; }
}

/* 5. Tables: scroll inside their own box on narrow screens (page never scrolls sideways). */
table { max-width: 100%; }
@media (max-width: 900px) {
  table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { min-width: 5.5rem; }
}

/* 6. Keyboard focus: always visible, never colour-only. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, [role="button"]:focus-visible,
[tabindex]:focus-visible, table:focus-visible {
  outline: 2px solid #ffb700; outline-offset: 2px; border-radius: 2px;
}

/* 7. Honour reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
