/* X12 denial analytics — layout and theme.
 *
 * The sidebar rule below is the important part. See the block comment on
 * `.app` for why it is written this way.
 */

:root {
  /* Palette taken from the reference platform's tokens.css so the two
     applications read as one product. Names differ (--ink for --text,
     --panel for --surface); the values are theirs. */
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --ink: #1c2530;
  --muted: #5b6672;
  --line: #d9dee5;
  --accent: #1f5fb2;
  --accent-hover: #1a4f96;
  --accent-soft: #e6f0fa;
  --good: #157038;
  --bad: #c0392b;
  --warn: #8f5c0a;
  --good-bg: #e3f3e9;
  --bad-bg: #fbe9e7;
  --warn-bg: #fbf1e0;
  --sidebar-width: 232px;
  --sidebar-rail: 64px;
}

/* "System" follows the OS; an explicit choice overrides it via [data-theme].
 * Both blocks set the same variables so the two paths cannot drift apart. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a;
    --panel: #161d26;
    --panel-2: #1e2732;
    --ink: #e6ebf1;
    --muted: #9aa7b4;
    --line: #2c3743;
    --accent: #5aa0e6;
    --accent-hover: #7cb4ee;
    --accent-soft: #16283b;
    --good: #4cc27f;
    --bad: #e06c5c;
    --warn: #e0a34a;
    --good-bg: #16301f;
    --bad-bg: #341c19;
    --warn-bg: #322613;
  }
}

:root[data-theme="dark"] {
  --bg: #0f141a;
  --panel: #161d26;
  --panel-2: #1e2732;
  --ink: #e6ebf1;
  --muted: #9aa7b4;
  --line: #2c3743;
  --accent: #5aa0e6;
  --accent-hover: #7cb4ee;
  --accent-soft: #16283b;
  --good: #4cc27f;
  --bad: #e06c5c;
  --warn: #e0a34a;
  --good-bg: #16301f;
  --bad-bg: #341c19;
  --warn-bg: #322613;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ---------------------------------------------------------------------------
 * Independent scroll containers.
 *
 * Without this the sidebar shares the window's scroll position with the main
 * content, so clicking an item near the bottom reloads the page with the
 * sidebar back at the top — and the user has to scroll down again to carry on
 * in the same section. Fixing it in JavaScript alone is not possible: the
 * sidebar has to *own* a scroll position before one can be restored.
 * ------------------------------------------------------------------------ */
.app {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app__body {
  flex: 1;
  min-height: 0;          /* lets the children actually shrink and scroll */
  display: flex;
  overflow: hidden;
}

.sidebar {
  position: relative;                 /* the collapse control anchors to this */
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  overflow-x: hidden;
  overflow-y: auto;       /* its own scrollbar, its own position */
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 34px 0 24px;               /* room for the toggle at the top */
  transition: width .16s ease, flex-basis .16s ease;
}

main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;       /* scrolls independently of the sidebar */
  padding: 20px 26px 60px;
}

/* Collapsed sidebar. Persisted in localStorage — a layout preference belongs
 * to the user, unlike a scroll position, which belongs to the tab.
 *
 * A narrow rail, not nothing: collapsing to zero width took the expand control
 * with it, so the only way back was the keyboard or a reload. The rail keeps
 * the control reachable, which is how the reference platform does it. */
.app.is-collapsed .sidebar {
  width: var(--sidebar-rail);
  flex-basis: var(--sidebar-rail);
}
.app.is-collapsed .nav-group__label { display: none; }
.app.is-collapsed .nav__label { display: none; }
.app.is-collapsed .nav a {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
  border-left-width: 0;
}
.app.is-collapsed .nav a[aria-current="page"] {
  border-left-width: 0;
  box-shadow: inset 2px 0 0 var(--accent);
}

/* The round control at the sidebar's top-right, fully inside the rail it
 * controls. As a hamburger in the topbar it sat next to the title with nothing
 * associating it with the sidebar, and nobody found it. */
.sidebar__toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.sidebar__toggle:hover { color: var(--accent); border-color: var(--accent); }
.app.is-collapsed .sidebar__toggle { right: 50%; transform: translateX(50%); }

header.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 18px;
  background: var(--panel);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

header.topbar h1 { font-size: 15px; margin: 0; font-weight: 700; }
header.topbar .spacer { flex: 1; }
header.topbar .meta { font-size: 12px; color: var(--muted); }

.toggle {
  border: 1px solid rgba(255, 255, 255, .35);
  background: transparent;
  color: inherit;
  border-radius: 4px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 13px;
}
.toggle:hover { background: rgba(255, 255, 255, .12); }

/* Segmented control — theme and number scale. Ported from the reference
 * platform's `.segmented`, which the user already knows how to read. */
/* Themed variables, not white-on-accent: the topbar is a surface panel now, so
   translucent white borders were invisible against it. */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}
.segmented button {
  padding: 3px 11px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.segmented button:first-child { border-left: 0; }
.segmented button:hover { background: var(--panel-2); color: var(--ink); }
.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.segmented__label {
  font-size: 11px;
  color: var(--muted);
  align-self: center;
  margin-right: 2px;
}

/* Sidebar collapsed before first paint, so it does not flash open then shut. */
html.sidebar-precollapsed .sidebar { width: 0; flex-basis: 0; padding: 0; overflow: hidden; }

/* --- navigation ---------------------------------------------------------- */
.nav-group { padding: 10px 0 4px; }
.nav-group__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 0 16px 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  color: var(--ink);
  text-decoration: none;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.nav a:hover { background: var(--accent-soft); }
.nav a[aria-current="page"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
  color: var(--accent);
}

/* Two-letter badge, as the reference platform uses. It is what the collapsed
   rail shows: truncating the label instead gave "Denial su..." and
   "By depart...", a rail that is narrower but no easier to read. */
.nav__icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  color: inherit;
  background: color-mix(in srgb, currentColor 13%, transparent);
}
.nav__label { overflow: hidden; text-overflow: ellipsis; }

/* --- panels and tables --------------------------------------------------- */
h2 { font-size: 17px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }

.cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  min-width: 170px;
}
.card .label { font-size: 12px; color: var(--muted); }
.card .value { font-size: 21px; font-weight: 600; margin-top: 3px; }
.card .note { font-size: 11px; color: var(--muted); margin-top: 3px; }
.card.good .value { color: var(--good); }
.card.bad .value { color: var(--bad); }

/* A long table scrolls inside itself rather than the page, with its header
 * pinned. Ported from the reference platform: without the wrapper the header
 * scrolls away after twenty rows and every column becomes a guess. */
.table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
}
/* Opt-out for short summary tables that should just flow with the page. */
.table-wrap--auto { max-height: none; overflow: visible; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  margin: 0;
}
/* A bare table outside a wrapper keeps the border it used to have. */
.table-wrap > table { border: 0; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); }
thead th {
  background: var(--panel-2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  z-index: 2;
  /* An inset shadow, not border-bottom: a sticky cell paints over its own
     border as the body scrolls under it, so the rule disappears exactly when
     it is most needed. */
  box-shadow: inset 0 -1px 0 var(--line);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--accent-soft); }
tr.total td { font-weight: 700; border-top: 2px solid var(--muted); background: var(--accent-soft); }

/* A cell that leads somewhere: the drill-down affordance. */
td a, .drill { color: var(--accent); text-decoration: none; border-bottom: 1px dotted; }
td a:hover { border-bottom-style: solid; }

/* --- breadcrumb: where this view came from ------------------------------- */
.trail {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.trail a { color: var(--accent); text-decoration: none; }
.trail a:hover { text-decoration: underline; }
.trail .sep { opacity: .5; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 12px;
}
.chip a { color: var(--muted); text-decoration: none; font-weight: 700; }
.chip a:hover { color: var(--bad); }

.empty { color: var(--muted); padding: 18px; text-align: center; }
.bar { height: 8px; background: var(--accent); border-radius: 3px; display: inline-block; }

@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 5; height: 100%; box-shadow: 0 0 18px rgba(0,0,0,.2); }
  main { padding: 14px; }
}

/* ---- account controls in the topbar ------------------------------------ */
.account { display: flex; align-items: center; gap: .5rem; margin-left: .25rem; }
.account__name {
  font-size: .78rem; font-weight: 600; color: var(--fg);
  text-decoration: none; padding: .2rem .5rem; border-radius: 5px;
  border: 1px solid var(--line);
}
.account__name:hover { background: var(--accent-soft); }
.account__out {
  font-size: .78rem; color: var(--muted); text-decoration: none;
  padding: .2rem .45rem; border-radius: 5px;
}
.account__out:hover { color: var(--fg); background: var(--accent-soft); }
/* Deliberately loud. A seeded password that is mentioned quietly is the one
   that survives to production. */
.account__warn {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; color: #8a1c13; background: #fdecea;
  border: 1px solid #f2c2bd; border-radius: 5px; padding: .18rem .45rem;
  text-decoration: none;
}
.account__warn:hover { filter: brightness(.97); }

/* --- two-column layout for side-by-side panels --------------------------- */
/* auto-fit with a minimum keeps this honest at every width: two columns when
   there is room, one when there is not, with no breakpoint to maintain. The
   min() guard stops the minimum from exceeding the container on a narrow
   screen, which would otherwise force a horizontal scroll. */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 18px;
  align-items: start;
}
/* The heading inside a column loses the top margin it would carry when
   stacked: the grid gap already provides the separation. */
.columns > section > h3:first-child { margin-top: 0; }

/* --- landing page --------------------------------------------------------
 * Deliberately sparse. The management report carries the analytical weight;
 * this page answers "what is this, and can I trust the data yet" and then gets
 * out of the way. Repeating the report's figures here made it read as a weaker
 * version of the same screen.
 */
/* One card, centred, rather than content pinned to the left edge of a wide
   window. On a 1440px screen the copy occupied the first third and left two
   thirds of empty panel beside it, which read as unfinished rather than
   spacious. */
.landing {
  max-width: 900px;
  margin: 10px auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 34px 38px 32px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
}
:root[data-theme="dark"] .landing,
.landing { text-align: left; }

.hero { margin: 0 0 26px; text-align: center; }
.hero h1 { font-size: 24px; margin: 0 0 10px; letter-spacing: -0.01em; color: var(--ink); }
.hero p {
  color: var(--muted); font-size: 14.5px; line-height: 1.65;
  margin: 0 auto 18px; max-width: 60ch;
}

/* One line of live state, not a card. Muted until something is wrong. */
.status {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
}
.status b { color: var(--fg); font-weight: 650; }
.status .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #22a06b;
  flex: 0 0 auto;
}
.status.warn { border-color: #b4884a; color: #b4884a; }
.status.warn .dot { background: #d9a441; }
.status.warn b { color: inherit; }

/* The flow: seven words, no sentences. The words carry the meaning; explaining
   each one is what turns a landing page into a document. */
.flow {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; margin: 0 0 30px; font-size: 13px;
}
.flow span {
  padding: 7px 13px; border-radius: 6px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 600;
}
.flow i { color: var(--muted); font-style: normal; font-size: 13px; }
.flow span:last-of-type { border-color: var(--accent); color: var(--accent); }

/* Exactly two columns on a wide window, one when narrow.
   `auto-fit` was wrong twice here: unconstrained it made four thin strips, and
   capped with a max-width it collapsed to a single column. Two columns is the
   intent, so state it, and switch at a width where two no longer fit. */
.points {
  display: grid; gap: 20px 40px; margin: 0 0 30px;
  grid-template-columns: 1fr 1fr;
  padding-top: 26px; border-top: 1px solid var(--line);
}
@media (max-width: 900px) { .points { grid-template-columns: 1fr; } }
.point { border-left: 2px solid var(--accent); padding: 2px 0 2px 14px; }
.point b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.point span { color: var(--muted); font-size: 12.5px; line-height: 1.6; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.actions a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 7px; font-size: 13.5px; font-weight: 650;
  text-decoration: none; border: 1px solid var(--line); color: var(--fg);
}
.actions a.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.actions a.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.actions a:hover { border-color: var(--accent); }
.actions a.primary:hover { filter: brightness(1.08); }

/* --- X12 Reader ----------------------------------------------------------
 * Ported from the reference platform. Everything here is client-side: the file
 * never leaves the browser, which is the only reason the page can honestly
 * say "not imported, not saved".
 */
.reader-notice {
  background: var(--warn-bg); border: 1px solid var(--warn); color: var(--warn);
  border-radius: 7px; padding: 11px 14px; font-size: 13px; line-height: 1.6;
  margin: 0 0 18px;
}
.reader-notice strong { color: inherit; }
.reader-notice a { color: inherit; font-weight: 600; }

.reader-grid {
  display: grid; gap: 16px; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
.reader-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px 16px; min-width: 0;
}
.reader-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.reader-head h2 { font-size: 14px; margin: 0; }
.reader-head .spacer { flex: 1; }

.reader-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  border-radius: 6px; padding: 4px 11px; font: inherit; font-size: 12px; cursor: pointer;
}
.reader-btn:hover { border-color: var(--accent); color: var(--accent); }

.reader-drop {
  border: 1px dashed var(--line); border-radius: 8px; padding: 16px;
  text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 10px;
}
.reader-drop.is-drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.reader-input {
  width: 100%; min-height: 220px; resize: vertical;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px;
}
.reader-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.reader-hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.reader-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.reader-tab {
  border: 0; border-left: 1px solid var(--line); background: transparent;
  color: var(--muted); font: inherit; font-size: 12px; padding: 4px 11px; cursor: pointer;
}
.reader-tab:first-child { border-left: 0; }
.reader-tab:hover { background: var(--panel-2); color: var(--ink); }
.reader-tab.is-active { background: var(--accent); color: #fff; font-weight: 600; }

.reader-status {
  border-left: 3px solid var(--line); background: var(--panel-2);
  border-radius: 0 7px 7px 0; padding: 10px 13px; font-size: 13px; line-height: 1.6;
}
.reader-status ul { margin: 6px 0 0; padding-left: 18px; }
.reader-status li { margin: 3px 0; }
.reader-status.is-ok { border-left-color: var(--good); background: var(--good-bg); color: var(--good); }
.reader-status.is-warning { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.reader-status.is-error { border-left-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.reader-status.is-ok strong,
.reader-status.is-warning strong,
.reader-status.is-error strong { color: inherit; }

.reader-delims { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.reader-delims strong {
  color: var(--ink); font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px;
}

.reader-filter { display: flex; align-items: center; gap: 10px; margin: 12px 0 10px; }
.reader-filter input {
  flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink);
}
.reader-filter input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.reader-count { color: var(--muted); font-size: 12px; white-space: nowrap; }

.reader-view { display: none; max-height: 520px; overflow: auto; }
.reader-view.is-active { display: block; }
.reader-placeholder { color: var(--muted); font-size: 13px; padding: 20px 4px; }
.reader-capped {
  color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn);
  border-radius: 6px; padding: 7px 10px; font-size: 12px; margin: 0 0 10px;
}

.reader-tree, .reader-tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.reader-tree > li { padding-left: 0; }
.reader-tree summary { cursor: pointer; padding: 4px 2px; font-size: 13px; }
.reader-node { font-weight: 600; }
.reader-meta { color: var(--muted); font-size: 11.5px; margin-left: 8px; }
.reader-leaf {
  display: flex; gap: 9px; padding: 3px 6px; border-radius: 4px;
  font-size: 12.5px; cursor: pointer; align-items: baseline;
}
.reader-leaf code {
  font-size: 11px; font-weight: 700; color: var(--accent);
  min-width: 34px; display: inline-block;
}
.reader-leaf .v { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-leaf:hover { background: var(--accent-soft); }
.reader-leaf.is-selected, .reader-seg.is-selected { background: var(--accent-soft); outline: 1px solid var(--accent); }

.reader-seg { padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.reader-seg:hover { background: var(--accent-soft); }
.reader-seg-raw {
  font: 12px/1.7 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}
.reader-seq { color: var(--muted); font-size: 10.5px; min-width: 42px; display: inline-block; }
.reader-tag { font-weight: 700; color: var(--accent); }
.reader-sep { color: var(--muted); opacity: .65; }
.reader-seg-desc { font-size: 11.5px; color: var(--muted); }

.reader-detail h3 { font-size: 14px; margin: 0 0 2px; }
.reader-detail table { margin-top: 10px; }
.reader-decode {
  display: inline-block; margin-left: 8px; font-size: 11.5px; color: var(--accent);
  background: var(--accent-soft); border-radius: 4px; padding: 0 6px;
}
.reader-comp {
  margin-top: 4px; font-size: 11.5px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.reader-foot { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* --- reader: business tables ---------------------------------------------
 * The segment filter above the views searches tags, descriptions and raw
 * segments — it drives Tree and Segments and has no meaning for a table, which
 * carries its own filter. Left visible above the Tables view it would look
 * like a control that silently does nothing, so it is hidden there.
 *
 * Toggled by showTab() rather than written as :has(#rdTable.is-active). The
 * app opens in whatever browser the user has set as default, so the engine is
 * not ours to pin; a class the script sets behaves the same everywhere, and
 * this rule is not worth being the file's only bet on selector support. */
.reader-card.is-tables .reader-filter { display: none; }

/* Once a file is parsed, reading it is the whole job and the input box has had
 * its turn — so the structure card takes the full grid width and the input card
 * steps aside. This is not a table-only need: a deep HL tree and a long raw
 * segment both run off the side of a half-width card just as a wide table does.
 * The input is one tab away, and Clear brings it straight back.
 *
 * Marked by the script for the same reason the filter rule above is: the engine
 * is whatever browser the user has set as default, and this is not worth being
 * the file's only bet on selector support. */
.reader-grid.is-wide { grid-template-columns: 1fr; }
.reader-grid.is-wide .reader-card.is-input { display: none; }

/* Only the inner scroller scrolls. The view was a second scroller wrapped
 * around the first: content overflowed the inner box, the inner box overflowed
 * the view, and the outer one carried it sideways until the leading columns
 * were off-screen with no scrollbar in reach to bring them back. */
.reader-grid.is-wide .reader-view.is-active {
  max-height: none;
  overflow: visible;
}
/* The height the content actually gets, now that the view is not capping it.
 * Tree and Segments scroll themselves; the table scrolls inside .table-wrap. */
.reader-grid.is-wide .reader-view.is-active#rdTree,
.reader-grid.is-wide .reader-view.is-active#rdSegs,
.reader-grid.is-wide .reader-view.is-active#rdDetail {
  max-height: calc(100vh - 300px);
  overflow: auto;
}
.reader-grid.is-wide .table-wrap { max-height: calc(100vh - 340px); }

.reader-metrics {
  display: grid; gap: 8px; margin-bottom: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
}
.reader-metric {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 7px; padding: 9px 11px;
}
.reader-metric .n { font-size: 19px; font-weight: 650; line-height: 1.2; }
.reader-metric .l { font-size: 11px; color: var(--muted); margin-top: 2px; }

.reader-table-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}
.reader-table-bar select, .reader-table-bar input {
  font: inherit; font-size: 12.5px; padding: 5px 9px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink);
}
.reader-table-bar select { max-width: 100%; }
.reader-table-bar input { flex: 1; min-width: 160px; }
.reader-table-bar select:focus, .reader-table-bar input:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* The wrapper, sticky header and row styling all come from .table-wrap and the
   base table rules; only the differences belong here. Columns stay on one line
   so a wide business table scrolls sideways rather than growing tall cells —
   except the few that hold prose or a raw segment. */
table.reader-data { min-width: 100%; width: max-content; font-size: 12.5px; }
table.reader-data th, table.reader-data td { white-space: nowrap; }
table.reader-data td.reader-wrapcell { white-space: normal; min-width: 220px; }
.reader-wrapcell {
  font: 11.5px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}
/* The way back to the segment that produced the row. */
.reader-jump {
  border: 0; background: none; padding: 0; font: inherit;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}


/* --- pagination ---------------------------------------------------------- */
.pager {
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
  margin: 0 0 22px; font-size: 12.5px; color: var(--muted);
}
.pager__count { font-weight: 600; color: var(--ink); }
.pager__controls, .pager__size { display: flex; align-items: center; gap: 8px; }
.pager__page { color: var(--muted); }
.pager a {
  color: var(--accent); text-decoration: none;
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 9px;
}
.pager a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pager strong {
  color: #fff; background: var(--accent); border: 1px solid var(--accent);
  border-radius: 5px; padding: 2px 9px; font-weight: 600;
}
/* Disabled prev/next keeps its space so the bar does not shift on the first
   and last page. */
.pager .off { border: 1px solid transparent; padding: 2px 9px; opacity: .45; }

/* --- notices and forms on the Data page ---------------------------------- */
.note {
  border-left: 3px solid var(--line); background: var(--panel-2);
  border-radius: 0 7px 7px 0; padding: 10px 14px;
  font-size: 13px; line-height: 1.6; margin: 0 0 18px;
}
.note--ok { border-left-color: var(--good); background: var(--good-bg); color: var(--good); }
.note--bad { border-left-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.note--warn { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.note strong { color: inherit; }
.note code {
  background: rgba(127,127,127,.16); border-radius: 4px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px;
}

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  border-radius: 6px; padding: 7px 15px; font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
/* Restore replaces the database, so its button does not look like the others. */
.btn--danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn--danger:hover { filter: brightness(1.08); color: #fff; border-color: var(--bad); }

.restore-form { max-width: 640px; margin-bottom: 24px; }
.restore-form label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin: 12px 0 4px;
}
.restore-form input {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 13px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); margin-bottom: 4px;
}
.restore-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.restore-form .btn { margin-top: 12px; }

/* --- export buttons beside the page heading ------------------------------ */
.page-head {
  display: flex; align-items: baseline; gap: 16px;
  flex-wrap: wrap; margin: 0 0 4px;
}
.page-head h2 { margin: 0; }
.downloads { display: flex; gap: 8px; margin-left: auto; }
.btn--sm { padding: 4px 11px; font-size: 12px; text-decoration: none; }
a.btn { display: inline-flex; align-items: center; }
a.btn:hover { text-decoration: none; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.button-row form { margin: 0; }

/* --- per-table export links (a page with several unrelated tables) -------- */
.section-head {
  display: flex; align-items: baseline; gap: 14px;
  flex-wrap: wrap; margin: 24px 0 8px;
}
.section-head h3 { margin: 0; }
.section__export { margin-left: auto; display: flex; gap: 6px; }
.section__export a {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-decoration: none; border: 1px solid var(--line);
  border-radius: 5px; padding: 2px 9px;
}
.section__export a:hover { color: var(--accent); border-color: var(--accent); }

/* --- import page ---------------------------------------------------------- */
.import-grid {
  display: grid; gap: 16px; margin-bottom: 26px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}
.import-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px 18px;
}
.import-card h3 { margin: 0 0 4px; font-size: 14px; }
.import-card .sub { font-size: 12px; line-height: 1.6; margin: 0 0 14px; }
.import-card input[type="file"] {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 12.5px;
  border: 1px dashed var(--line); border-radius: 7px;
  padding: 10px; background: var(--bg); color: var(--ink); margin-bottom: 12px;
}
.import-card input[type="text"] {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 13px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink);
}
/* The path field and its Browse button. The button keeps its own width and the
   field takes the rest, so a long path does not squeeze the button away. */
.path-row { display: flex; gap: 8px; align-items: stretch; }
.path-row input[type="text"] { flex: 1 1 auto; min-width: 0; }
.path-row .btn { flex: 0 0 auto; white-space: nowrap; }
/* Quieter than the primary actions: browsing only fills the field, and the
   operator still chooses Preview or Import afterwards. */
.btn-quiet { background: var(--panel-alt); color: var(--ink); }
.import-card label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin: 0 0 4px;
}
.import-card label.check {
  font-weight: 500; margin: 10px 0; display: flex; align-items: center; gap: 7px;
}
.import-card label.check input { margin: 0; }

/* --- import job progress -------------------------------------------------- */
.job-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  border-left: 3px solid var(--line); background: var(--panel-2);
  border-radius: 0 8px 8px 0; padding: 13px 16px; margin-bottom: 14px;
}
.job-head--run { border-left-color: var(--accent); }
.job-head--ok { border-left-color: var(--good); }
.job-head--bad { border-left-color: var(--bad); }
.job-status { font-weight: 700; font-size: 15px; margin-right: 10px; }
.job-source { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.job-counts { font-size: 13px; color: var(--muted); white-space: nowrap; }
.job-counts b { color: var(--ink); }

.job-now {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px; margin-bottom: 12px;
}
.job-now code {
  background: var(--panel-2); border-radius: 4px; padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px;
}
.job-note { color: var(--muted); font-size: 12px; }
.job-cancel { margin-bottom: 18px; }

/* A moving indicator, because the file counter legitimately does not move
   while a file holding a thousand transaction sets is read. Without it the
   page looks stalled at exactly the moment most work is happening. */
.spinner {
  width: 13px; height: 13px; flex: 0 0 auto; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* --- reader help popup ---------------------------------------------------
   Ported from the reference reader's v13 popup. Its own colours were named for
   that stylesheet's tokens (--surface2, --border, --primary); these are the
   equivalents here, so the dialog follows light and dark with everything else
   rather than carrying a second palette. */
.reader-help-bar { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.helpbtn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-alt, var(--panel));
  color: var(--accent); font-weight: 800; font-size: 15px;
  display: inline-grid; place-items: center; padding: 0; line-height: 1;
  cursor: pointer;
}
.helpbtn:hover { border-color: var(--accent); }
.help-dialog {
  width: min(620px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.help-dialog::backdrop { background: rgba(0, 0, 0, .62); }
.help-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-alt, var(--panel));
}
.help-head h2 { font-size: 16px; margin: 0; }
.help-close {
  margin-left: auto; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 6px; width: 30px; height: 30px;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.help-body {
  padding: 16px 18px 18px; color: var(--muted);
  font-size: 13.5px; line-height: 1.6;
}
.help-body p { margin: 0 0 12px; }
.help-body ul { margin: 8px 0 14px; padding-left: 20px; }
.help-body li { margin: 5px 0; }
.help-body strong { color: var(--ink); }
.help-callout {
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel-alt, var(--panel));
  color: var(--ink);
}

/* The persona lens on a denial (§14.3). Chips are links, not filters, so they
   carry their own rule rather than reusing .chip, whose anchor is nested. */
.chipbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.chipbar .chip {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  padding: 5px 12px;
}
.chipbar .chip:hover { color: var(--accent); border-color: var(--accent); }
.chipbar .chip--on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chipbar .chip--on:hover { color: #fff; }

.lens {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 18px;
}
.lens-q {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}
.lens h4 { margin: 0 0 8px; font-size: 17px; }
.lens p { margin: 0 0 10px; }
/* Basis and limit are the point of the panel, not footnotes: the limit says
   what the reading cannot support, which is the half a reader most needs. */
.lens-basis, .lens-limit {
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 9px;
  margin: 0;
}
.lens-limit { color: var(--bad); }
.lens-link { margin: 10px 0 0; font-size: 13px; }
.lens-link a { color: var(--accent); text-decoration: none; font-weight: 700; }
.lens-link a:hover { text-decoration: underline; }
