/* ── Flexo Africa — phone and tablet rescue ──────────────────────────────────
 *
 * ONE file, injected into every page, so a fix lands everywhere instead of
 * being copied into 77 separate pages and drifting apart.
 *
 * WHY IT EXISTS. Cam, 2026-09-04: "can we make the site easy to also see and
 * view on a mobile phone or iPad?" Measured all 29 linked pages at iPhone
 * width (390 px): 19 already fitted perfectly, and 9 ran off the side of the
 * screen so you had to pinch and drag to read them.
 *
 *     /                        needed 765px in a 384px screen   the admin nav
 *     /assets.html             540px    a row of buttons that would not wrap
 *     /admin-stats.html        465px    a 4-across row of stat cards
 *     /cylinder-repeat.html    461px    a reference table
 *     /pricing.html            458px    the plan comparison table
 *     /barcode-generator.html  449px    a card stretched by its own contents
 *     /trapping-advisor.html   433px    ink labels that would not wrap
 *     /anilox-calc.html        421px    a reference table
 *     /ink-mixing-calc.html    415px    a 4-across row of ink chips
 *
 * ⭐ THE HOME PAGE WAS ONLY BROKEN FOR CAM. Measured both ways: signed in as
 * admin it needed 765px because the four admin-only links (Admin, User
 * Approvals, Companies, Analytics) refuse to wrap; as an ordinary customer the
 * same page came to 384px and fitted fine.
 *
 * ⛔ NOTHING HERE HIDES CONTENT. `overflow-x:hidden` on the page would make
 * the numbers "fit" while quietly cutting off the right-hand columns of a
 * table. Anything genuinely too wide to fit, like a reference table, scrolls
 * INSIDE ITS OWN BOX so every column is still reachable.
 */

@media (max-width: 768px) {

  /* ── 1. Nothing may be wider than the screen ─────────────────────────── */
  img, svg, video, canvas { max-width: 100%; height: auto; }

  /* ⭐⭐ THE SINGLE MOST USEFUL RULE HERE. A grid or flex child defaults to
   * min-width:auto, which means it refuses to shrink below its own content
   * and shoves the whole page wider. That is what made the Barcode Generator
   * card 425px wide inside a 342px column.
   *
   * ⚠️ IT HAS TO BE EVERY GRID, NOT A NAMED LIST. The first attempt named
   * five (.grid, .cards, .cols, .setup-grid, .bases-grid) and Cylinder Repeat
   * STILL ran over, because its boxes sit in a .input-grid nobody had listed.
   * Naming them one at a time is chasing the last page you happened to open.
   * `min-width: 0` only ever ALLOWS something to shrink, so it cannot break a
   * layout that already fits — which is what makes the broad selector safe. */
  [class*="grid"] > *, [class*="row"] > *, .cards > *, .cols > * { min-width: 0; }

  /* ── 2. Rows of links and buttons wrap instead of running off the edge ── */
  /* ⚠️ EVERY BAR OF TABS AND LINKS, NOT JUST THE ONE CALLED nav-tabs. The
   * Assets Admin page runs its own `.page-tabs` bar, 584px of tabs in a 390px
   * screen, and the FMCG brief pages run their own `.nav-links`. Neither is
   * called nav-tabs, so neither was wrapping. flex-wrap does nothing at all
   * to something that is not a flex row, which is what makes this safe.    */
  nav.nav-tabs, [class*="nav"], [class*="tabs"] { flex-wrap: wrap !important; row-gap: 6px; }

  /* Same story at the bottom of the page: the FMCG brief pages lay their
   * footer out as one non-wrapping row (brand, links, copyright) and it hung
   * 11px off the edge. A footer that wraps costs nothing on a desktop.     */
  footer, [class*="footer"] { flex-wrap: wrap; row-gap: 10px; }
  .co-header-right  { flex-wrap: wrap !important; row-gap: 8px; margin-left: 0 !important; }
  .ink-labels       { flex-wrap: wrap !important; row-gap: 6px; }

  /* ── 3. Multi-column blocks stack instead of squeezing ───────────────── */
  .cards      { grid-template-columns: repeat(2, 1fr) !important; }
  .cols       { grid-template-columns: 1fr !important; }
  .bases-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .stats-row, .stats-bar { grid-template-columns: repeat(2, 1fr) !important; }

  /* ── 4. A table too wide for a phone scrolls inside its own box, so every
   *      column is still reachable, and the PAGE stays put.
   *
   * ⚠️ THIS HAS TO BE EVERY TABLE, NOT A NAMED LIST. The first attempt named
   * the three tables the measurement had caught (#table1, .compare-table,
   * .ref-table) and the Analytics page STILL ran over, because its Top cities
   * and Top networks panels hold a second, unnamed table 403px wide. A named
   * list only ever fixes the tables somebody has already tripped over.
   * On a table that already fits, this rule does nothing you can see.        */
  .scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── 4b. A file picker refuses to shrink below its own natural width and
   *       shoves the row off the screen. Nearly every tool has one, so this
   *       is worth doing site-wide rather than page by page. It is what made
   *       the Barcode Generator's "Fit to existing artwork" row overflow.   */
  /* ⚠️ `width:100%` IS NOT COSMETIC, IT IS A REGRESSION FIX. A file picker
   * sizes itself from its own text, so the moment the 16px rule below made
   * that text bigger the picker grew from about 250px to 303px, and on Visual
   * Compare that pushed the two drop zones side by side out to 426px in a
   * 390px screen — a page that had been fitting perfectly. MEASURED before and
   * after: 0px over, then 36px over, then 0px again with this line. */
  input[type="file"] { width: 100%; min-width: 0; max-width: 100%; }
  .row { flex-wrap: wrap; }

  /* ── 4c. Trapping Advisor's ink labels are a grid with two hard 148px
   *       columns, which cannot fit a phone. Let those two shrink; the order
   *       and alignment of the labels is unchanged.                          */
  .ink-labels { grid-template-columns: 1fr minmax(0, 148px) minmax(0, 148px) 28px !important; }

  /* ═══ POLISH ═══════════════════════════════════════════════════════════
   * Everything above makes a page FIT. Everything below makes it pleasant to
   * actually use with a thumb. Measured on 2026-09-04 across the seven busiest
   * pages before writing any of it.
   */

  /* ── 6. Things you tap are big enough to hit.
   * MEASURED: 44px is the accepted comfortable minimum, and the site was well
   * under it — the home page had 15 of its 38 tappable things below 44px, the
   * smallest at 15px, and AI Quality Control had 7 of 8. It is the shared
   * header on every page: "Help", "Sign out", "All tools", "Dashboard" were
   * all 16 to 31px tall. Padding grows them; nothing moves on desktop.
   *
   * ⚠️ `[class*="header"]` as well as `header`. Company Admin builds its top
   * bar out of `<div class="header">` rather than a real `<header>` tag, so
   * its logo (34px) and its two Back links (32px) slipped straight past the
   * plain `header a` above. Same lesson as the tables and the grids.
   *
   * `a[class*="link"]` is there for the 437 tiny "Result" and "Input" download
   * pills in the super-admin job log, which were 22px. MEASURED THE COST
   * HONESTLY: each job row grows from 90px to 112px and the whole log gets
   * 21% longer (46,357px to 55,971px). Worth it — those pills are how you
   * fetch a customer's finished file, and at 22px you miss them.            */
  /* ⛔⛔ THIS RULE MUST NEVER SET `display`, AND HERE IS WHY.
   * It did, for one round, and it broke every tool that has a Download
   * button. mobile.css loads AFTER each page's own <style>, so
   * `display: inline-flex` here beat the page's own `.dl-btn { display:none }`
   * and the green Download button sat there on a phone BEFORE you had run
   * anything. Caught live on Separation Report. Height only, from here on. */
  nav.nav-tabs a, nav.nav-tabs .nav-tab, header a, header button, footer a,
  [class*="header"] a, [class*="footer"] a, .links a, a[class*="link"],
  [class*="nav"] a, a[class*="nav"], a[class*="logo"],
  .btn, .toggle-btn, .browse-btn, .gen-btn, .calc-btn, .dl-btn, .order-btn {
    min-height: 44px;
  }

  /* A link laid out as plain inline text ignores a height, so the bars of
   * links DO need a display of their own. Kept to bars only — a top bar, a
   * footer, a row of tabs, the pills in the job log — because those are
   * always on screen, so changing their display cannot reveal something the
   * page meant to keep hidden. Buttons need none of this: a button already
   * honours a height and centres its own label.                             */
  nav.nav-tabs a, nav.nav-tabs .nav-tab, header a, footer a,
  [class*="header"] a, [class*="footer"] a, .links a, a[class*="link"],
  [class*="nav"] a, a[class*="nav"], a[class*="logo"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ⛔ WHAT IS DELIBERATELY LEFT ALONE. A link sitting inside a sentence stays
   * the size of the sentence: "Terms of Service" mid-paragraph on the sign-up
   * page, and the email addresses and web addresses written into the Privacy
   * and Terms text. Those measure 16 to 17px and that is CORRECT — blowing a
   * word in a paragraph up to 44px tall would tear the paragraph apart. The
   * rule above is for links that behave like buttons, not for prose.
   * Also left: one "Submit a Brief" button on the FMCG dashboard at 43px. It
   * carries its sizing in a style="" attribute with no class to hook, and 1px
   * is not worth an !important.                                             */

  /* The one action you came to the page for is worth a bit more thumb.      */
  .btn-primary, .gen-btn, .calc-btn { min-height: 48px; }

  /* ⚠️ AND EVERY BUTTON, NOT A NAMED LIST. Same lesson as the tables and the
   * grids above: the named list above missed the "x" remove buttons on Ink
   * Cost (28px), "Add ink" on Anilox (33px), "Add Colour" on Ink Calculator
   * (35px) and the four tab buttons on Colour Swatch (42px), because each
   * page names its buttons differently. A plain button centres its own text,
   * so it needs the height and nothing else. min-height never makes anything
   * wider, so this cannot push a page off the screen.
   * A drop-down is a tap target too, and must stay a drop-down, so it takes
   * the height without the inline-flex above.                               */
  button, input[type="button"], input[type="submit"], [role="button"],
  select { min-height: 44px; }

  /* ── 7. ⭐ TAPPING A BOX NO LONGER ZOOMS THE WHOLE PAGE.
   * iPhone and iPad zoom in automatically whenever you tap a field whose text
   * is under 16px, and then you are left scrolled sideways trying to find your
   * place again. MEASURED: AI Quality Control had 2 such fields. 16px is the
   * exact threshold, so this is the whole fix.                              */
  input, select, textarea { font-size: 16px !important; }

  /* ── 8. The recent-jobs list on the home page is readable.
   * MEASURED: 150 of the smallest pieces of text on the home page are this one
   * list — the job number at 11px and the file name and time at 12px, three
   * to a row. On a phone that is a squint. Bigger text, and the row wraps
   * instead of crushing three columns into 390px.                           */
  .projects-row { flex-wrap: wrap; row-gap: 4px; padding: 14px 16px; }
  .projects-row-num, .projects-row-file, .projects-row-time,
  .projects-row-tool, .projects-row-user { font-size: 13px !important; }
  .projects-row .projects-row-tool,
  .projects-row .projects-row-user { flex: 0 0 auto; }

  /* ── 9. The "Order plates" banner stops squeezing its own text.
   * It is a flex row that will not wrap, so on a phone the wording was
   * crushed into a column about 127px wide beside the button. Stack it.     */
  .order-banner-inner { flex-direction: column; align-items: flex-start; gap: 14px; }
  .order-btn { width: 100%; justify-content: center; white-space: normal; }

  /* ── 5. The worksmap tools: sidebar above the preview, not beside it.
   *      (Moved here from the inline style that used to live in main.py, so
   *      every mobile rule is in one place. Unchanged otherwise.)          */
  .layout        { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr; overflow: auto !important; }
  .sidebar       { max-height: none !important; width: 100% !important; }
  .preview-panel { min-height: 60vh; }
  body           { height: auto !important; overflow: auto !important; }
  header         { flex-wrap: wrap; height: auto !important; padding: 8px 12px !important; gap: 8px !important; }
  header h1      { font-size: 14px !important; }
}

/* ── iPad and small laptops ──────────────────────────────────────────────
 * Between a phone and a desktop the nav still needs to wrap on a busy admin
 * account, and a four-across row of stat cards is tight. Nothing else here. */
@media (min-width: 769px) and (max-width: 1024px) {
  nav.nav-tabs { flex-wrap: wrap; row-gap: 6px; }
  .grid > *, .cards > *, .cols > * { min-width: 0; }
}
