/* ==========================================================================
   Lighthouse Rural Community — The Foundation Library
   mobile.css — phone & tablet layer

   WHY THIS FILE EXISTS
   These pages were exported from the design tool with their styling written
   directly onto each element ("inline styles"). Inline styles beat normal
   stylesheet rules, so every rule below that overrides one is marked
   !important. That is deliberate, not sloppiness.

   WHY EVERY SELECTOR IS WRITTEN TWICE
   21 of the 52 pages are re-rendered in the browser by support.js. That
   runtime rewrites the style attribute in canonical form — "repeat(3,1fr)"
   as authored becomes "repeat(3, 1fr)" in the live DOM. The other 31 pages
   keep the authored spacing. So each selector is listed in both forms;
   matching only one would silently miss half the site.

   HOW THIS LAYERS WITH lh-glossary.js  (READ BEFORE EDITING)
   26 of the 52 pages load lh-glossary.js, which already injects its own
   mobile layer at run time — it collapses every inline grid to one column
   at <=900px, makes tables scroll, sets h1/h2 sizes, and shrinks .page.
   That script appends its <style> to <head> AFTER this file's <link>, so
   when a rule here ties with one of its !important rules on specificity,
   the script wins. That is intentional and this file is built around it:

     - Generic grid rules here are deliberately left at plain [style*=]
       specificity, so on glossary pages the script's blanket 1fr wins and
       existing behaviour is preserved. They only take effect on the 26
       pages that do NOT load the script.
     - Rules that MUST win regardless (the index-table restack and the
       navigation strip) are prefixed with `html` to outrank it.
     - The .page rule carries no !important, so the script's better-tuned
       .page sizing always wins where the script is present, and this only
       acts as a fallback on the pages without it.

   Nothing here changes the desktop design. Every rule lives inside a
   @media query, so it only switches on at tablet width and below.

   BREAKPOINTS
     <= 900px   tablet — 3-, 4- and 5-column grids drop to 2
     <= 640px   phone  — everything drops to a single column
     <= 480px   small phone — tighter padding

   Added 2026-08-04.
   ========================================================================== */


/* ==========================================================================
   1. TABLET — wide grids step down to two columns
   ========================================================================== */
@media (max-width: 900px) {

  [style*="grid-template-columns:repeat(5,1fr)"],
  [style*="grid-template-columns: repeat(5, 1fr)"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Lopsided two-column splits even out */
  [style*="grid-template-columns:1.55fr 1fr"],
  [style*="grid-template-columns: 1.55fr 1fr"],
  [style*="grid-template-columns:1.5fr 1fr"],
  [style*="grid-template-columns: 1.5fr 1fr"],
  [style*="grid-template-columns:1.3fr 1fr 1fr"],
  [style*="grid-template-columns: 1.3fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 40px 1.3fr"],
  [style*="grid-template-columns: 1fr 40px 1.3fr"] {
    grid-template-columns: 1fr 1fr !important;
  }
}


/* ==========================================================================
   2. PHONE — one column, everywhere
   ========================================================================== */
@media (max-width: 640px) {

  [style*="grid-template-columns:repeat(5,1fr)"],
  [style*="grid-template-columns: repeat(5, 1fr)"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"],
  [style*="grid-template-columns:repeat(2,1fr)"],
  [style*="grid-template-columns: repeat(2, 1fr)"],
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1.55fr 1fr"],
  [style*="grid-template-columns: 1.55fr 1fr"],
  [style*="grid-template-columns:1.5fr 1fr"],
  [style*="grid-template-columns: 1.5fr 1fr"],
  [style*="grid-template-columns:1.3fr 1fr 1fr"],
  [style*="grid-template-columns: 1.3fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 40px 1.3fr"],
  [style*="grid-template-columns: 1fr 40px 1.3fr"],
  [style*="grid-template-columns:130px 1fr"],
  [style*="grid-template-columns: 130px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Flow diagrams: "box -> box -> box" with narrow arrow columns between.
     Stack the boxes; the arrows become short rows in between. */
  [style*="grid-template-columns:1fr 34px 1fr 34px 1fr 34px 1fr"],
  [style*="grid-template-columns: 1fr 34px 1fr 34px 1fr 34px 1fr"],
  [style*="grid-template-columns:1fr 28px 1fr 28px 1fr 28px 1fr"],
  [style*="grid-template-columns: 1fr 28px 1fr 28px 1fr 28px 1fr"],
  [style*="grid-template-columns:1fr 34px 1fr 34px 1fr"],
  [style*="grid-template-columns: 1fr 34px 1fr 34px 1fr"],
  [style*="grid-template-columns:1fr 44px 1fr"],
  [style*="grid-template-columns: 1fr 44px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Hero stat strip ("7 Modules | 23 Documents | 4 Entities") is a gapless
     flex row divided by hairlines — let it wrap rather than crush. */
  [style*="display:flex;gap:0"],
  [style*="display: flex; gap: 0px"] {
    flex-wrap: wrap;
    gap: 14px 0 !important;
  }

  /* Back-to-library bar on every document page */
  .lh-topbar { flex-wrap: wrap !important; }
}


/* ==========================================================================
   3. THE FILE INDEX TABLE (homepage "All anchors" list)
   Desktop is 4 columns: number | title | category | status. On a phone that
   squeezes the title to nothing, so we go to number | title and drop
   category + status underneath the title.
   NOTE: this value has no commas, so both spacing forms are identical apart
   from the colon — matched on the value alone.
   ========================================================================== */
@media (max-width: 640px) {

  /* `html` prefix is required: lh-glossary.js forces EVERY inline grid to
     1fr at <=900px. Without outranking it the container would collapse to
     one column while the rules below still placed cells in column 2 —
     a broken half-applied layout. Container and children must agree. */
  html [style*="44px 1fr 220px 96px"] {
    grid-template-columns: 32px 1fr !important;
    padding: 6px 0 !important;
  }

  /* Rows are <a class="idxrow"> — restack columns 3 and 4 under the title */
  html a[style*="44px 1fr 220px 96px"] > *:nth-child(3),
  html a[style*="44px 1fr 220px 96px"] > *:nth-child(4) {
    grid-column: 2 !important;
    padding-top: 0 !important;
    padding-bottom: 3px !important;
  }

  /* The header strip is a <div> — its "Category"/"Status" labels are
     meaningless once stacked, so hide them and keep "# / Document". */
  html div[style*="44px 1fr 220px 96px"] > *:nth-child(3),
  html div[style*="44px 1fr 220px 96px"] > *:nth-child(4) {
    display: none !important;
  }
}


/* ==========================================================================
   4. STICKY HEADER + NAVIGATION
   The library nav has 12 links in a wrapping row. On a phone that wraps to
   six stacked rows inside a sticky header and swallows the whole screen.
   Turn it into a single swipeable strip instead.
   ========================================================================== */
@media (max-width: 900px) {

  /* :has() scopes this to the two pages carrying the 12-link library nav —
     never the masthead on master-operational-plan.html, which has its own. */
  html header:has(nav[style*="margin-left:auto"]) > div,
  html header:has(nav[style*="margin-left: auto"]) > div {
    flex-wrap: wrap !important;
    gap: 10px !important;
    padding: 10px 16px !important;
  }

  html header nav[style*="margin-left:auto"],
  html header nav[style*="margin-left: auto"] {
    margin-left: 0 !important;
    width: 100%;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  html header nav[style*="margin-left:auto"]::-webkit-scrollbar,
  html header nav[style*="margin-left: auto"]::-webkit-scrollbar { display: none; }

  html header nav[style*="margin-left:auto"] > a,
  html header nav[style*="margin-left: auto"] > a {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 9px 13px !important;   /* comfortable 44px-tall tap target */
  }
}


/* ==========================================================================
   5. TYPE — headline sizes were fixed in pixels for a desktop canvas
   ========================================================================== */
@media (max-width: 640px) {

  [style*="font-size:64px"],
  [style*="font-size: 64px"] {
    font-size: clamp(30px, 9vw, 48px) !important;
  }
  [style*="font-size:52px"],
  [style*="font-size: 52px"] {
    font-size: clamp(28px, 8.5vw, 44px) !important;
  }
  [style*="font-size:48px"],
  [style*="font-size: 48px"] {
    font-size: clamp(27px, 8vw, 40px) !important;
  }
  [style*="font-size:46px"],
  [style*="font-size: 46px"] {
    font-size: clamp(26px, 7.6vw, 38px) !important;
  }

  [style*="font-size:34px"],
  [style*="font-size: 34px"],
  [style*="font-size:33px"],
  [style*="font-size: 33px"],
  [style*="font-size:32px"],
  [style*="font-size: 32px"] {
    font-size: clamp(22px, 6.2vw, 30px) !important;
  }

  [style*="font-size:31px"],
  [style*="font-size: 31px"],
  [style*="font-size:30px"],
  [style*="font-size: 30px"] {
    font-size: clamp(21px, 5.8vw, 28px) !important;
  }

  /* Tight desktop letter-spacing looks broken at small sizes */
  [style*="letter-spacing:-1px"],
  [style*="letter-spacing: -1px"] {
    letter-spacing: -.4px !important;
  }

  /* Headlines capped in inches for print — let them use the screen */
  [style*="max-width:12in"],
  [style*="max-width: 12in"],
  [style*="max-width:11in"],
  [style*="max-width: 11in"] {
    max-width: 100% !important;
  }
}


/* ==========================================================================
   6. SECTION PADDING — desktop breathing room is wasted space on a phone
   ========================================================================== */
@media (max-width: 640px) {

  /* The runtime drops redundant sides from the padding shorthand, so
     "88px 20px 76px 20px" as authored becomes "88px 20px 76px" in the DOM.
     Both spellings are listed.

     ORDER MATTERS: [style*=] is a substring match, so "padding: 64px 20px"
     also matches "padding: 64px 20px 56px". The two-value rules are listed
     FIRST so the longer, more specific ones below win on source order. */

  [style*="padding:64px 20px"],
  [style*="padding: 64px 20px"] {
    padding: 44px 18px !important;
  }
  [style*="padding:60px 20px"],
  [style*="padding: 60px 20px"] {
    padding: 42px 18px !important;
  }
  [style*="padding:44px 20px"],
  [style*="padding: 44px 20px"] {
    padding: 32px 18px !important;
  }
  [style*="padding:56px 46px"],
  [style*="padding: 56px 46px"] {
    padding: 40px 18px !important;
  }

  /* Longer forms — these must follow the two-value rules above. */

  [style*="padding:88px 20px 76px 20px"],
  [style*="padding: 88px 20px 76px"] {
    padding: 52px 18px 46px !important;
  }
  [style*="padding:64px 20px 56px 20px"],
  [style*="padding: 64px 20px 56px"] {
    padding: 44px 18px 38px !important;
  }
  [style*="padding:64px 20px 40px 20px"],
  [style*="padding: 64px 20px 40px"] {
    padding: 44px 18px 28px !important;
  }
  [style*="padding:64px 20px 24px 20px"],
  [style*="padding: 64px 20px 24px"] {
    padding: 44px 18px 20px !important;
  }
  [style*="padding:52px 54px 0 54px"],
  [style*="padding: 52px 54px 0px"] {
    padding: 36px 18px 0 !important;
  }
  [style*="padding:26px 20px 0 20px"],
  [style*="padding: 26px 20px 0px"] {
    padding: 22px 18px 0 !important;
  }

  /* Hero stat strip dividers */
  /* The runtime also expands ".18" to "0.18", so the normalized form
     is spelled out in full here rather than generated. */
  [style*="border-left:1px solid rgba(255,255,255,.18)"],
  [style*="border-left: 1px solid rgba(255, 255, 255, 0.18)"] {
    padding-left: 12px !important;
  }
}


/* ==========================================================================
   7. DOCUMENT PAGES (*.dc.html)
   These render as a printed 8.5in sheet with .65in margins. On a 390px
   phone those margins alone eat a third of the screen.
   ========================================================================== */
@media (max-width: 820px) {

  /* NO !important on purpose. lh-glossary.js ships its own .page sizing
     with !important and it is better tuned than this; where the script is
     present it wins. This is only the fallback for the pages without it,
     where it still outranks the base `.page` rule via the `html` prefix. */
  html .page {
    max-width: 100%;
    padding: 22px 16px;
    box-shadow: none;
  }
}

@media (max-width: 480px) {

  html .page { padding: 17px 13px; }
}


/* ==========================================================================
   8. TABLES — let wide tables scroll sideways instead of breaking the page
   ========================================================================== */
@media (max-width: 820px) {

  table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ==========================================================================
   9. MEDIA — nothing may be wider than the screen
   ========================================================================== */
@media (max-width: 900px) {

  img, video, svg { max-width: 100%; height: auto; }

  iframe { max-width: 100%; }

  /* Exception: explainer pages embed a 1500px-wide page inside a clipped,
     CSS-scaled frame to fake a screenshot. Capping it would shrink the fake
     screenshot instead of the phone. Leave it alone. */
  .sview iframe { max-width: none !important; }
}


/* ==========================================================================
   10. FORMS — iOS zooms the whole page in when a field is under 16px
   ========================================================================== */
@media (max-width: 820px) {

  input, select, textarea { font-size: 16px !important; }
}


/* ==========================================================================
   11. ANIMATED EXPLAINER PAGES (*-explainer.html)
   These are fixed 16:9 stages that already scale to any screen, so they need
   no layout surgery. Held sideways they fill the phone; held upright they
   letterbox into a thin band. Tell the reader to turn the phone.
   ========================================================================== */
@media (max-width: 820px) and (orientation: portrait) {

  #stage::after {
    content: "Turn your phone sideways for the full-screen explainer";
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    max-width: 88vw;
    text-align: center;
    background: rgba(46, 18, 72, .94);
    border: 1px solid rgba(244, 180, 26, .45);
    color: #F4B41A;
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    font-weight: 700;
    font-size: 13px;
    line-height: 1.35;
    padding: 10px 16px;
    border-radius: 999px;
    z-index: 99;
    pointer-events: none;
  }
}


/* ==========================================================================
   12. ACCESSIBILITY — respect "reduce motion" on phones too
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
