/*
 * Nothing on the site scrolls sideways (the owner's rule, December 2026).
 *
 * Skynet UI's answer to a wide table is `.sk-table-wrap { overflow-x: auto }`,
 * a box with its own sideways scrollbar, and the pages had copied that answer
 * into a dozen wrappers of their own. A scrollbar under a table hides the
 * columns past the edge and looks broken, so every page does this instead:
 *
 *   - a table that fits stays a table, with its headings allowed to wrap;
 *   - a table that does not fit becomes a list of cards, one per row, each
 *     cell labelled with its column's heading. public/js/fit-wide.js decides,
 *     by measuring, and adds `fit-stack` to the table.
 *
 * Without scripting the wrappers keep their old scroll (`html.fit-js` is set
 * by the script), which is the only state where they still can.
 *
 * Loaded by partials/header-v2.ejs, so every v2 page has it.
 * `npm run audit:mobile` fails on any box that scrolls sideways.
 */

/* ---- The wrappers no longer scroll; the table has to fit ---------------- */
html.fit-js body :is(
  .sk-table-wrap, .sv2-table-wrap, .aip-table-wrap, .kst-table-wrap,
  .overflow-x-auto, .table-responsive, .table-wrap, .table-container
):has(> table) {
  overflow-x: visible;
  max-width: 100%;
}
/* A sticky header needs its box to scroll up and down, never sideways. */
html.fit-js body .sk-table-wrap.sk-sticky-head { overflow-x: hidden; }

html.fit-js body table { max-width: 100%; }
html.fit-js body table th { white-space: normal; }
html.fit-js body table :is(th, td) { overflow-wrap: break-word; }

/* ---- A table that does not fit: one card per row ----------------------- */
html body table.fit-stack,
html body table.fit-stack > tbody,
html body table.fit-stack > tfoot,
html body table.fit-stack > * > tr,
html body table.fit-stack > tr {
  display: block;
  width: 100%;
  min-width: 0;
}
html body table.fit-stack { border-collapse: separate; }

/* The headings are still read by a screen reader; they are only not drawn,
   because every cell now carries its own. */
html body table.fit-stack > thead {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

html body table.fit-stack > * > tr,
html body table.fit-stack > tr {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--sk-border, rgba(255, 255, 255, 0.1));
}
html body table.fit-stack > * > tr:last-child,
html body table.fit-stack > tr:last-child { border-bottom: 0; }

html body table.fit-stack > * > tr > :is(td, th),
html body table.fit-stack > tr > :is(td, th) {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
  padding: 0.22rem 0;
  border: 0;
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
}
html body table.fit-stack > * > tr > :is(td, th) > *,
html body table.fit-stack > tr > :is(td, th) > * { min-width: 0; max-width: 100%; }
html body table.fit-stack > * > tr > :is(td, th)[data-fit-label]::before,
html body table.fit-stack > tr > :is(td, th)[data-fit-label]::before {
  content: attr(data-fit-label);
  flex: 0 0 auto;
  max-width: 45%;
  text-align: left;
  color: var(--sk-muted, #9ca3af);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  overflow-wrap: normal;
}
/* A cell with no heading (a "Loading…" row across every column, an untitled
   first column) reads as the row's own line. */
html body table.fit-stack > * > tr > :is(td, th):not([data-fit-label]),
html body table.fit-stack > tr > :is(td, th):not([data-fit-label]) {
  justify-content: flex-start;
  text-align: left;
}
/* A row of buttons stays together and wraps inside its cell. */
html body table.fit-stack :is(td, th) > :is(.flex, .sk-btn-group, .apv2-actions, div) {
  flex-wrap: wrap;
}
/* What the page hid stays hidden. */
html body table.fit-stack :is(td, th):is(.hidden, [hidden]) { display: none; }

/* ---- Everything else that used to scroll sideways --------------------- */
/* Tailwind's `overflow-x-auto` was the pages' own answer to "too wide". A box
   that only scrolls sideways stops scrolling; one that also scrolls up and
   down keeps that (the browser then still allows sideways, but what is
   inside now wraps, so there is nothing to scroll to). */
html.fit-js body .overflow-x-auto:not(.overflow-y-auto, .overflow-auto, [class*="max-h-"], [class*="h-"]) {
  overflow-x: visible;
}
/* A strip of chips or tabs wraps onto more rows. */
html.fit-js body :is(.overflow-x-auto, .scrollbar-hide):is(.flex, .inline-flex) { flex-wrap: wrap; }
html.fit-js body :is(.overflow-x-auto, .scrollbar-hide):is(.flex, .inline-flex) > * { min-width: 0; max-width: 100%; }
/* A path or a long line that was told never to wrap, wraps. */
html.fit-js body .overflow-x-auto.whitespace-nowrap { white-space: normal; overflow-wrap: anywhere; }
/* Tab strips wrap onto a second row rather than scroll. `clip`, not
   `visible`: once wrapped every tab is inside the strip, but Chromium still
   reports the unwrapped row as overflow and would carry it up to the card. */
html.fit-js body .sk-tabs { flex-wrap: wrap; overflow-x: clip; }
/* A tab row inside a box that used to scroll (`min-w-max` kept it on one
   line) wraps too. */
html.fit-js body .overflow-x-auto > :is(.flex, nav) { flex-wrap: wrap; min-width: 0; }
/* Code and log blocks wrap their lines. A code editor (CodeMirror) measures
   its own lines and keeps them. */
html body pre:not(:where(.CodeMirror, .cm-editor, .monaco-editor) *) {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: visible;
}
html body pre:not(:where(.CodeMirror, .cm-editor, .monaco-editor) *) code {
  white-space: inherit;
  overflow-wrap: inherit;
}

/* A chart canvas never draws wider than its box (Leaflet sizes its own). */
html body canvas:not(:where(.leaflet-container) *) { max-width: 100%; }
