/* ===========================================================================
   Nothing a person types may push the page sideways.

   An author pasted an abstract with no spaces in it — a few hundred characters
   of one unbreakable "word" — and it ran straight out of its card and gave the
   whole admin page a horizontal scrollbar. The abstract was only the field they
   happened to fill: the paper title, the section headings, the code/type/status
   line and every fact in the summary grid all did the same thing, and a long
   title broke the layout twice as badly as the abstract did.

   The same bug had already been found and fixed once, on the submissions list
   (`#submissions-list td { overflow-wrap: anywhere }`), which is the tell: it is
   not one page's mistake, it is the default behaviour of text on the web. Long
   words do not wrap unless you say so, and every screen that shows something a
   user wrote is exposed until it does.

   So this file is a baseline rather than a patch. It is loaded for every page in
   the app, straight after frontend.css and before any page stylesheet, so a page
   that genuinely wants different behaviour can still override it.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   1. The catch-all.

   overflow-wrap is inherited, so this one declaration reaches every piece of
   text on the page. break-word rather than anywhere on purpose: it breaks a
   word that would otherwise overflow, without changing how boxes work out their
   minimum width. That distinction is what keeps buttons, labels, nav items and
   badges sizing exactly as they did — `anywhere` would let them wrap mid-word.
--------------------------------------------------------------------------- */
body {
    overflow-wrap: break-word;
}

/* ---------------------------------------------------------------------------
   2. Where the minimum width is the problem.

   A grid or flex child is `min-width: auto` by default, which means it refuses
   to shrink below its longest unbreakable word — so the word never gets the
   chance to wrap, and the track grows instead. This is the rule that stops one
   pasted DOI widening a whole summary grid.
--------------------------------------------------------------------------- */
.d-grid > *,
.d-flex > * {
    min-width: 0;
}

/* Deliberately NOT `overflow-wrap: anywhere` on table cells.
 *
 * It was here, and it did more harm than good. On a `th` it let a heading break
 * at any character: "Corresponding" collapsed to a 53px column reading one
 * letter per line, and "Actions" broke to "Action / s". On a `td` it let
 * ordinary words break in tight tables — "Cardiolog / y", "researcher@medica /
 * l.test" — because `anywhere` lowers a cell's minimum width, so the browser
 * squeezes columns instead of letting the table be as wide as it needs.
 *
 * A table that is too wide is not the bug this file is about. Every table here
 * already sits in an `overflow-x-auto` wrapper, so it scrolls inside its own
 * card and the page is untouched — which is what "stays within its designated
 * field" asks for. The pages that genuinely need cells to break say so
 * themselves: see `#submissions-list td` in admin-submissions.css. */

/* ---------------------------------------------------------------------------
   3. The paper itself.

   render_content_section() wraps everything it returns in .paper-content, so
   these rules reach all ten screens that show a submission — admin detail, the
   published paper, both reviewer rounds, all three researcher responses, the
   editor decisions and the author's own view — without any of them having to
   remember. Prose, video, poster, supporting document: one function, one class.

   `anywhere` and not `break-word` here, because this is precisely the text
   nobody controls: pasted sequence data, a URL with no spaces, a chemical name.
--------------------------------------------------------------------------- */
.paper-content {
    overflow-wrap: anywhere;
}

/* A figure inserted at 4000px wide, or a Sketchfab embed, must fit the column
   it is read in rather than setting the page width. */
.paper-content img,
.paper-content video,
.paper-content iframe,
.paper-content svg,
.paper-content canvas {
    max-width: 100%;
}

.paper-content img,
.paper-content video {
    height: auto;
}

/* Preformatted text is exempt from wrapping by definition, so it gets a scroll
   bar of its own instead of handing one to the page. */
.paper-content pre {
    max-width: 100%;
    overflow-x: auto;
}

/* An inserted table has a genuine minimum width — squeezing its columns to fit
   would make it unreadable. Let it scroll inside its own box instead. */
.paper-content table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
}

/* A bare URL is one long word by nature, and one is enough. */
.paper-content a {
    overflow-wrap: anywhere;
}
