/*!
 * Fluid Responsive Scale — Modern UI only
 * ---------------------------------------------------------------------------
 * Application wide responsive type + overflow handling.
 *
 * Two-stage scale:
 *
 *   Stage 1 (this file, CSS only) — the size this viewport "wants":
 *       clamp(0.75rem, 0.49rem + 0.125vw + 0.579vh, 1.25rem)
 *
 *   Stage 2 (public/js/fluid-fit.js) — `--ui-fit`, a multiplier in [0.8, 1]
 *       that the script lowers while the document is taller than the viewport.
 *       It resets to 1 on every resize, then re-descends, so the result is
 *       deterministic and never oscillates.
 *
 *   font-size: max(0.75rem, stage1 * var(--ui-fit))
 *
 * The 0.579vh coefficient is deliberately large: viewport height, not width,
 * is what decides whether a CRM page has to scroll vertically. Short laptop
 * screens (1280x720, 1366x768) get noticeably denser type than 1440p displays,
 * which is where the win against vertical scrolling comes from.
 *
 * Stage 1 base, before any auto-fit:
 *
 *   360 x  640 (small phone)    -> 12.00px
 *   414 x  896 (phone)          -> 13.55px
 *   768 x 1024 (tablet)         -> 14.73px
 *   1024 x 768 (landscape tab)  -> 13.57px
 *   1280 x 720 (short laptop)   -> 13.61px
 *   1366 x 768 (laptop)         -> 14.00px
 *   1440 x 900 (desktop)        -> 14.85px
 *   1920 x 1080 (desktop)       -> 16.49px
 *   2560 x 1440 (large desktop) -> 19.38px
 *   3840 x 2160 (4K, clamped)   -> 20.00px
 *
 * After auto-fit the effective size lands anywhere in 12px - 20px.
 *
 * The hard 0.75rem (12px) floor means text never renders smaller than 12px, no
 * matter how much content the page has. Bounds are in `rem` so the visitor's
 * browser font-size preference keeps working as an accessibility multiplier.
 *
 * Why scaling the root font size works here: Bootstrap 4, AdminLTE 3 and this
 * project's own stylesheets are authored in `rem`, so font sizes, padding,
 * margins, control heights and radii all scale together.
 *
 * Loaded last in every layout `<head>` so it wins over the theme stylesheets,
 * and only for users on the Modern UI.
 *
 * Width gate: the scale below applies only at 1440px viewport width or less.
 * On wider screens the root keeps the browser default (16px) and neither
 * stage shrinks anything - fluid-fit.js stands down there too.
 */

/* ── 1. Two-stage fluid root font size (1440px and below only) ──────────── */

html {
    /* Stop iOS Safari from inflating text in landscape, a common cause of
       unexpected horizontal scrolling. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

@media (max-width: 1440px) {
    html {
        /* Fallback for engines without clamp()/max()/vw/vh support. */
        font-size: 14px;

        /* Lowered by fluid-fit.js while the document overflows the viewport. */
        --ui-fit: 1;

        font-size: max(0.75rem,
            calc(clamp(0.75rem, calc(0.49rem + 0.125vw + 0.579vh), 1.25rem) * var(--ui-fit)));
    }
}

/* ── 2. Nothing may make the document wider than the viewport ───────────── */

html,
body {
    max-width: 100%;

    /* Final guard: the page itself never scrolls sideways.
       The guard has to sit on `html` *and* `body` - a value on `html` alone
       is propagated to the viewport while the root falls back to `visible`,
       which leaves the page scrollable. `clip` is declared after `hidden` on
       purpose: it is the only overflow value allowed to pair with
       `overflow-y: visible`, so neither element becomes a scroll container
       and AdminLTE's sticky/fixed header, sidebar and footer keep working
       (verified: `hidden` here breaks `position: sticky`, `clip` does not).
       Engines without `clip` fall back to `hidden`.
       Genuinely wide content stays reachable through its own scroll
       container (`.table-responsive`, DataTables `responsive`/`scrollX`,
       `pre`), never through the page. */
    overflow-x: hidden;
    overflow-x: clip;
}

body {
    /* Unbreakable strings (property IDs, long URLs, phone numbers, tokens)
       wrap onto the next line instead of extending the page width.
       `overflow-wrap` is inherited, so this covers every text node. */
    overflow-wrap: break-word;
    word-break: normal;
}

/* Replaced elements must never dictate page width. */
img,
svg,
video,
canvas,
iframe,
embed,
object {
    max-width: 100%;
}

/* ── 3. Table headers never split a word across lines ─────────────────────── */
/* `body { overflow-wrap: break-word }` above is inherited by every text node,
   including `<th>`. In wide matrix tables (dashboard "Inquiries by Agent" /
   "Inquiry Matrix — Agent × Status") that splits single words mid-word
   ("Attempted" → "Attempt ed", "Positive" → "Positiv e"), with a lone letter
   dangling on the next line. Headers may still wrap at spaces ("Visit" /
   "Planned"); when the columns no longer fit, the `.table-responsive`
   wrapper scrolls sideways instead of the page. Data cells keep break-word
   so long tokens, URLs and phone numbers still wrap. */
th {
    overflow-wrap: normal;
    word-break: normal;
}

/* ── 4. Wide content gets its own scroll container instead of the page ───── */

pre {
    max-width: 100%;
    overflow-x: auto;
}

.table-responsive,
.table-wrap,
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
