/* ─────────────────────────────────────────────────────────────
   Mobile overflow fixes (site-wide).
   On phones nothing may be wider than the viewport — otherwise the whole
   page shifts left/right. Wide things scroll inside their own box instead.
   Loaded after main.css and each page's extra CSS.
   ───────────────────────────────────────────────────────────── */

/* Media never wider than its container */
img, video, iframe, embed, object { max-width: 100%; }
img, video { height: auto; }

/* Long URLs / unbroken strings wrap instead of widening the page */
p, li, dd, td, th, blockquote, figcaption, .card-body, .text-muted { overflow-wrap: break-word; }
a[href^="http"], .break-anywhere { overflow-wrap: anywhere; word-break: break-word; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }

/* Flex/grid children may shrink below their content width */
.card, .card-body, .flex-between > *, .container > * { min-width: 0; }

/* Rich content (blog posts, regulation text, events): wide tables scroll
   inside themselves */
.post-content table, .blog-content table, .reg-content table, .rich-content table,
.event-description table {
    display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
}

/* Generic wrapper for any wide table */
.table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Tool page headers (cabinet, index): buttons wrap instead of overflowing */
.tool-header { flex-wrap: wrap; gap: 0.6rem; }
.tool-header > h1 { min-width: 0; }
.tool-header-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; min-width: 0; }

/* ROI calculator layout */
.roi-layout { display: grid; grid-template-columns: 350px minmax(0, 1fr); gap: 1.5rem; }
.roi-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }

@media (max-width: 900px) {
    .roi-layout { grid-template-columns: minmax(0, 1fr); }
    .roi-layout .card[style*="sticky"] { position: static !important; }
}

@media (max-width: 768px) {
    .container { padding-left: 1rem; padding-right: 1rem; }
    .flex-between { flex-wrap: wrap; gap: 0.6rem; }

    .tool-header { padding: 0.9rem 1rem !important; align-items: flex-start !important; }
    .tool-header > h1 { font-size: 1.15rem !important; }
    .tool-header-actions .btn { padding: 0.35rem 0.7rem; font-size: 0.82rem; }

    .roi-summary { grid-template-columns: minmax(0, 1fr); }

    /* Cabinet tool */
    .stats-bar { padding: 1rem; gap: 0.6rem; }
    .stat-card { padding: 0.8rem 0.5rem; }
    .stat-card .number { font-size: 1.5rem; }
    .nav-tabs { padding: 0 0.5rem; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tab { padding: 0.7rem 0.9rem; white-space: nowrap; flex-shrink: 0; }
    .table-toolbar { flex-wrap: wrap; gap: 0.6rem; padding: 0.8rem 1rem; }
    .search-box { width: 100%; }
    .cab-cards { grid-template-columns: minmax(0, 1fr); padding: 0.6rem; }
    .add-form-grid { grid-template-columns: minmax(0, 1fr); }
    .modal { width: calc(100vw - 1rem); max-width: calc(100vw - 1rem); min-width: 0; }
    .modal-overlay { padding: 0.5rem; }
}

/* Last-resort safety net (see PR): anything we missed is clipped
   rather than shifting the whole page sideways. `clip` (unlike `hidden`)
   does not create a scroll container, so position:sticky keeps working. */
@media (max-width: 768px) {
    body { overflow-x: clip; }
}
