/* ============================================================
   LabTools — IVRT SAS Transport Formatter
   Brand: lab-bench palette (reagent teal, UV violet, fluorescein
   lime) on notebook paper. System fonts only — no web fonts, so
   the page stays fully self-contained and offline.
   ============================================================ */

:root {
  /* ink */
  --ink-900: #091320;
  --ink-800: #10203A;
  --ink:     #16233A;
  --ink-600: #4B5D75;
  --ink-400: #8798AC;

  /* surfaces */
  --paper:  #F4F6FA;
  --panel:  #FFFFFF;
  --sunk:   #F7F9FC;
  --line:   #DEE5EE;
  --line-2: #EDF1F6;

  /* reagents */
  --teal:     #0D9488;
  --teal-600: #0F766E;
  --teal-100: #D5F5EF;
  --teal-50:  #EFFCF9;
  --violet:   #7C3AED;
  --lime:     #84CC16;

  /* status */
  --ok:      #047857;  --ok-bg:   #ECFDF5;
  --warn:    #A45B08;  --warn-bg: #FFF8EC;
  --err:     #BE123C;  --err-bg:  #FFF1F4;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(11, 25, 45, .05), 0 1px 3px rgba(11, 25, 45, .04);
  --shadow-md: 0 2px 4px rgba(11, 25, 45, .04), 0 8px 20px rgba(11, 25, 45, .07);
  --shadow-lg: 0 4px 10px rgba(11, 25, 45, .06), 0 18px 44px rgba(11, 25, 45, .12);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;

  --gutter: 32px;
  --maxw: 1440px;
  /* Before a file is loaded there is only an invitation to load one, so the
     column is narrower and centred rather than pinned to the left edge. */
  --maxw-intro: 1160px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--ink-600); font-size: 13px; }
.tiny  { font-size: 12px; }

code {
  font: 12.5px/1.4 var(--mono);
  background: var(--teal-50);
  color: var(--teal-600);
  padding: 1.5px 5px;
  border-radius: 4px;
  border: 1px solid var(--teal-100);
  white-space: nowrap;
}

/* ── brand bar ──────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 13px var(--gutter);
  background: var(--ink-900);
  color: #fff;
  /* faint graph-paper ruling, drawn in CSS so nothing loads */
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 26px 26px, 26px 26px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: inherit;
}
.brand .mark { width: 34px; height: 34px; flex: none; overflow: visible; }
.mark .glass { fill: none; stroke: rgba(255,255,255,.82); stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.mark .fluid { fill: url(#fluid); }
.mark .trace { fill: none; stroke: rgba(9,19,32,.55); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.mark .bub   { fill: rgba(255,255,255,.75); }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 18px; font-weight: 400; letter-spacing: -.2px; }
.brand-name b { font-weight: 700; color: #35E0BC; }
.brand-tag {
  font-size: 11px; letter-spacing: .32px;
  color: rgba(255,255,255,.5);
  text-transform: lowercase;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.toplink {
  color: rgba(255,255,255,.72); text-decoration: none;
  font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: var(--radius-sm);
}
.toplink:hover { color: #fff; background: rgba(255,255,255,.09); }

/* The offline-guarantee trigger opens a dialog, so it is built to read as a
   button rather than as another link in the bar: pill, border, tinted fill. */
button.toplink {
  font-family: var(--sans); line-height: 1;
  background: transparent; border: 0; cursor: pointer;
}
/* `button.toplink` above zeroes the border and background, so the pill has to
   out-specify it — hence button.toplink.toplink-dot rather than .toplink-dot. */
button.toplink.toplink-dot {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px 9px 13px;
  border: 1px solid rgba(53, 224, 188, .42);
  border-radius: 30px;
  background: rgba(16, 185, 129, .16);
  color: rgba(255, 255, 255, .94);
  transition: background .13s, border-color .13s, color .13s;
}
button.toplink.toplink-dot:hover {
  background: rgba(16, 185, 129, .28);
  border-color: rgba(53, 224, 188, .75);
  color: #fff;
}
.toplink-dot .dot { box-shadow: 0 0 0 3px rgba(16, 185, 129, .28); }

/* A link rendered as running text — used where a <button> has to sit inside a
   sentence, so it must not look like a control. */
.linkish {
  font: inherit; font-weight: 600;
  background: none; border: 0; padding: 0;
  color: var(--teal-600);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.linkish:hover { color: var(--teal); }

/* bubbles drift up and fade; disabled for reduced-motion */
@keyframes rise {
  0%   { transform: translateY(0)     scale(.65); opacity: 0; }
  22%  {                              opacity: .85; }
  100% { transform: translateY(-8px)  scale(1.05); opacity: 0; }
}
.mark .bub { animation: rise 3.4s ease-in-out infinite; transform-origin: center; }
.mark .b2  { animation-duration: 4.1s; animation-delay: .8s; }
.mark .b3  { animation-duration: 3.7s; animation-delay: 1.7s; }

@media (prefers-reduced-motion: reduce) {
  .mark .bub { animation: none; opacity: .7; }
}

/* ── hero ───────────────────────────────────────────────── */

.hero {
  padding: 30px var(--gutter) 4px;
  max-width: var(--maxw-intro);
  margin: 0 auto;
}
.kicker {
  margin: 0 0 8px;
  font: 600 11.5px/1 var(--mono);
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--teal-600);
}
.hero h1 {
  margin: 0;
  font-size: 27px; font-weight: 680; letter-spacing: -.55px;
  color: var(--ink-800);
}
.hero .sub {
  margin: 9px 0 0;
  font-size: 14.5px; color: var(--ink-600);
  max-width: 82ch;
}
.hero .sub em { color: var(--ink); font-style: normal; font-weight: 600; }

.hero-badge { margin: 16px 0 0; }
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px 6px 10px;
  background: var(--ok-bg);
  border: 1px solid #B9E9D3;
  border-radius: 30px;
  font-size: 12.5px; font-weight: 650; letter-spacing: .1px;
  color: var(--ok);
}
/* The hero badge is the second door into the offline dialog. */
button.badge { font-family: var(--sans); cursor: pointer; transition: background .13s, border-color .13s; }
button.badge:hover { background: #E1FAEE; border-color: #93DDC0; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10B981; flex: none;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .2);
}

/* ── study type ─────────────────────────────────────────── */

/* Pivotal vs. validation changes which TRT codes and PRODUCT STRENGTH values
   are legitimate, so it sits above the steps rather than inside one. */
.studybar {
  padding: 4px var(--gutter) 0;
  max-width: var(--maxw-intro);
  margin: 0 auto;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.seg {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 4px 4px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow-sm);
  flex: none;
}
.seg-label {
  font: 650 10.5px/1 var(--sans);
  letter-spacing: .8px; text-transform: uppercase;
  color: var(--ink-400);
  margin-right: 7px;
}
.seg-btn {
  font: 600 13px/1 var(--sans);
  padding: 7px 15px;
  border: 1px solid transparent;
  border-radius: 30px;
  background: transparent;
  color: var(--ink-600);
  cursor: pointer;
  transition: background .13s, color .13s, box-shadow .13s;
}
.seg-btn:hover:not(.is-on) { background: var(--sunk); color: var(--ink); }
.seg-btn.is-on {
  background: var(--teal);
  border-color: var(--teal-600);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.studybar-note {
  margin: 0;
  flex: 1 1 420px;
  font-size: 13px;
  color: var(--ink-600);
  max-width: 96ch;
}
.studybar-note b { color: var(--ink); font-weight: 650; }

/* ── workspace: setup tray + result ─────────────────────────
   Before a workbook is open there is nothing but the drop zone, so the
   workspace is one column and the intro keeps its full size. Once one is open,
   `is-loaded` lands on #shell: steps 1–3 fold into a tray down the left and the
   formatted table — the thing the operator came for — takes the rest of the
   page. The tray carries its own scrollbar so the result keeps the page scroll.
   ---------------------------------------------------------- */

.workspace { padding: 22px var(--gutter) 8px; max-width: var(--maxw-intro); margin: 0 auto; }
.result { min-width: 0; }

/* Loaded, the cap comes off: a 26-column table wants every pixel there is, so
   the tray and the result run the full width of the window. */
#shell.is-loaded :is(.hero, .studybar, .workspace) { max-width: none; }
#shell.is-loaded .workspace {
  display: grid;
  grid-template-columns: clamp(460px, 31vw, 660px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* the intro has done its job by now — give the space to the table */
#shell.is-loaded .hero { padding: 20px var(--gutter) 0; }
#shell.is-loaded .hero h1 { font-size: 21px; letter-spacing: -.4px; }
#shell.is-loaded .hero .sub { display: none; }
#shell.is-loaded .hero-badge { display: none; }   /* the brand bar carries it */

#shell.is-loaded .tray {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 5px;               /* clear of its own scrollbar */
  scrollbar-width: thin;
}
#shell.is-loaded .tray .step { padding: 15px 16px 17px; margin-bottom: 14px; }
#shell.is-loaded .tray .step:last-child { margin-bottom: 2px; }
#shell.is-loaded .tray .step h2 { font-size: 14.5px; margin-bottom: 11px; gap: 9px; }
#shell.is-loaded .tray .step .num {
  width: 22px; height: 22px; font-size: 12px;
  box-shadow: 0 0 0 3px var(--teal-50);
}
#shell.is-loaded .tray .step > p.muted { font-size: 12px; margin: -3px 0 11px; }
#shell.is-loaded .tray .row { gap: 12px; margin-bottom: 12px; }
#shell.is-loaded .tray .row label { flex: 1 1 140px; min-width: 0; }
#shell.is-loaded .tray .row select { width: 100%; }
#shell.is-loaded .tray .ro { font-size: 12.5px; line-height: 1.3; overflow-wrap: anywhere; }
#shell.is-loaded .tray .preview-wrap { max-height: 200px; overflow: auto; }

/* The result column supplies its own gutter through .workspace. */
#shell.is-loaded .output-wrap { padding: 0 0 44px; max-width: none; }

/* Copy / CSV / Print stay reachable however far down the table you scroll. */
#shell.is-loaded .resultbar {
  position: sticky; top: 14px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px 18px;
  padding: 13px 16px 14px;
  margin-bottom: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}
#shell.is-loaded .resultbar h2 { margin: 0; font-size: 14.5px; }
#shell.is-loaded .resultbar .toolbar { margin: 0; flex: 1 1 auto; }
#issues { margin-bottom: 14px; }

/* ── steps ──────────────────────────────────────────────── */

.step {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px 22px;
  margin-bottom: 18px;
}
.step h2 {
  margin: 0 0 14px;
  font-size: 16.5px; font-weight: 670; letter-spacing: -.2px;
  display: flex; align-items: center; gap: 11px;
  color: var(--ink-800);
}
.step .num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--teal); color: #fff;
  font: 700 13px/1 var(--sans);
  box-shadow: 0 0 0 4px var(--teal-50);
  flex: none;
}
.step > p.muted { margin: -6px 0 14px; max-width: 88ch; }

/* ── controls ───────────────────────────────────────────── */

.btn, .ghost {
  font: 600 13.5px/1 var(--sans);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  text-transform: none;          /* the global `label` rule would uppercase label.btn */
  letter-spacing: normal;
  transition: background .13s, box-shadow .13s, border-color .13s, color .13s;
}
.btn {
  background: var(--teal); color: #fff;
  border-color: var(--teal-600);
  box-shadow: var(--shadow-sm);
}
.btn:hover:not(:disabled) { background: var(--teal-600); }
.btn:disabled { background: #C9D3DE; border-color: #C9D3DE; color: #F4F6FA; cursor: not-allowed; box-shadow: none; }

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-600);
}
.ghost:hover { border-color: var(--ink-400); color: var(--ink); }
.topbar .ghost { border-color: rgba(255,255,255,.22); color: rgba(255,255,255,.78); }
.topbar .ghost:hover { border-color: rgba(255,255,255,.5); color: #fff; background: rgba(255,255,255,.07); }

:is(.btn, .ghost, button, select, input, a):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
/* on the dark bar the teal ring disappears — outline in white instead */
.topbar button:focus-visible, .topbar a:focus-visible { outline-color: #35E0BC; }

select, input[type=text], input[type=number] {
  font: 13.5px/1.3 var(--sans);
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  max-width: 100%;
  transition: border-color .13s, box-shadow .13s;
}
select:hover, input:hover { border-color: var(--ink-400); }
select:focus, input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-50); outline: none; }
input[type=number] { width: 68px; font-family: var(--mono); }
input[type=text] { font-family: var(--mono); font-size: 13px; }
select:disabled, input:disabled { background: var(--sunk); color: var(--ink-400); cursor: not-allowed; }

label {
  display: block;
  font: 600 11px/1 var(--sans);
  letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-600);
}
label > select, label > input, label > .ro { display: block; margin-top: 6px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.ro { font: 600 14px/1.4 var(--sans); padding: 6px 0; }

.row { display: flex; gap: 26px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 16px; }

/* ── drop zone ──────────────────────────────────────────── */

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px 24px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, var(--teal-50), transparent 62%),
    var(--sunk);
  transition: border-color .15s, background .15s;
}
.drop p { margin: 7px 0; }
.drop p:first-child { font-size: 16px; }
.drop.over {
  border-color: var(--teal);
  background: var(--teal-50);
}
.drop p.muted:not(.tiny) { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--ink-400); }
label.btn { display: inline-block; }
.drop a { color: var(--teal-600); font-weight: 600; }

/* ── preview ────────────────────────────────────────────── */

.preview-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
table.preview { border-collapse: collapse; font: 12px/1.5 var(--mono); white-space: nowrap; }
table.preview td {
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  padding: 5px 10px;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink-600);
}
table.preview tr.is-header td {
  background: var(--teal-50);
  color: var(--teal-600);
  font-weight: 700;
  border-bottom: 2px solid var(--teal-100);
}
/* Above the header, or past the end of its block — shown for context, not read. */
table.preview tr.outside-block td { color: var(--ink-400); opacity: .55; font-style: italic; }
table.preview td.rowlab {
  background: var(--sunk); color: var(--ink-400);
  font-weight: 600; text-align: right;
  position: sticky; left: 0;
  border-right: 1px solid var(--line);
}

/* ── mapping tables ─────────────────────────────────────── */

.map-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.map-table th {
  text-align: left;
  font: 600 10.5px/1 var(--sans);
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--ink-400);
  border-bottom: 1px solid var(--line);
  padding: 0 12px 9px;
}
.map-table td {
  border-bottom: 1px solid var(--line-2);
  padding: 9px 12px;
  vertical-align: middle;
}
.map-table tbody tr:hover td { background: var(--sunk); }
/* Unticked in step 3 — kept legible, but visibly not part of the output. */
.map-table tbody tr.excluded td { opacity: .48; }
.map-table tbody tr.excluded td:nth-child(2) { text-decoration: line-through; }
.map-table tbody tr:last-child td { border-bottom: 0; }
.map-table td:first-child {
  font: 650 12.5px/1.3 var(--mono);
  color: var(--ink-800);
  white-space: nowrap;
}
.map-table tr.req td:first-child::after { content: "*"; color: var(--err); font-weight: 700; margin-left: 3px; }

/* Study-level values no sheet can supply — RANDCODE, ALIQUOT. Auto-detection
   will never fill them and a blank one looks exactly like a deliberate blank,
   so the row is marked until it carries a value. Amber, not red: nothing is
   wrong yet, it is simply waiting on the operator. */
.map-table tr.needs-input td { background: var(--warn-bg); }
.map-table tbody tr.needs-input:hover td { background: #FCEFDB; }
.map-table tr.needs-input td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.map-table tr.needs-input input[type=text] {
  border-color: #E0A85C;
  background: #FFFDF8;
}
.map-table tr.needs-input input[type=text]::placeholder { color: #B07A2E; }
/* Step 2 says where RANDCODE comes from; this goes there. It spans the value and
   decimals cells and is filled in the brand's action colour, because it is the
   only thing in the row worth clicking. */
.map-table .jump {
  display: block; width: 100%;
  font: 700 12px/1.2 var(--sans);
  letter-spacing: .2px;
  padding: 10px 10px;
  color: #fff;
  background: var(--teal);
  border: 1px solid var(--teal-600);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background .13s, box-shadow .13s;
}
.map-table .jump:hover { background: var(--teal-600); box-shadow: var(--shadow-md); }

/* The box being jumped to, so the caret landing in it is not the only signal. */
@keyframes pop {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(224, 168, 92, .6); }
  35%  { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(224, 168, 92, 0); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(224, 168, 92, 0); }
}
.map-table input.pop {
  animation: pop .48s ease-out 2;
  position: relative; z-index: 1;   /* the scaled box sits over its neighbours */
}
@media (prefers-reduced-motion: reduce) {
  /* no scaling, but still say which box — the class is stripped afterwards */
  .map-table input.pop { animation: none; outline: 2px solid var(--warn); outline-offset: 1px; }
}

/* Same idea one cell at a time: a step 3 box still waiting for a value. The row
   is not washed amber — several arms each missing a code would drown the table. */
.map-table input.needs-val {
  border-color: #E0A85C;
  background: #FFFDF8;
}
.map-table input.needs-val::placeholder { color: #B07A2E; }

.needs {
  display: block;
  margin-top: 3px;
  font: 650 9.5px/1.3 var(--sans);
  letter-spacing: .55px;
  text-transform: uppercase;
  color: var(--warn);
  white-space: nowrap;
}
.map-table select { min-width: 210px; }
.map-table .unmapped select { border-color: var(--err); background: var(--err-bg); color: var(--err); }
.map-table .derived {
  color: var(--violet); font-style: normal;
  font: 600 11px/1 var(--sans); letter-spacing: .4px; text-transform: uppercase;
}

#trtTable td:first-child { font-family: var(--mono); color: var(--teal-600); }

/* ── mapping tables, in the tray ────────────────────────────
   Still tables, still one row per variable, with the column heads in place —
   only tightened: fixed column widths so the controls line up down the tray,
   and everything a size or two smaller.
   ---------------------------------------------------------- */

#shell.is-loaded .tray .map-table { font-size: 12.5px; table-layout: fixed; }
#shell.is-loaded .tray .map-table th { padding: 0 8px 7px; font-size: 10px; letter-spacing: .5px; }
#shell.is-loaded .tray .map-table td { padding: 7px 8px; }
#shell.is-loaded .tray .map-table td:first-child { font-size: 12px; white-space: normal; overflow-wrap: anywhere; }
#shell.is-loaded .tray .map-table select,
#shell.is-loaded .tray .map-table input[type=text],
#shell.is-loaded .tray .map-table input[type=number] {
  min-width: 0; width: 100%;
  font-size: 12.5px; padding: 6px 7px;
}
#shell.is-loaded .tray .map-table .derived { font-size: 10px; letter-spacing: .3px; display: inline-block; }
#shell.is-loaded .tray .map-table .muted.tiny { font-size: 11px; }

/* variable · label · source · column/value · dp */
#shell.is-loaded .tray #step2 .map-table th:nth-child(1) { width: 16%; }
#shell.is-loaded .tray #step2 .map-table th:nth-child(2) { width: 22%; }
#shell.is-loaded .tray #step2 .map-table th:nth-child(3) { width: 24%; }
#shell.is-loaded .tray #step2 .map-table th:nth-child(4) { width: 25%; }
#shell.is-loaded .tray #step2 .map-table th:nth-child(5) { width: 13%; }

/* the dp box is a two-character field in a narrow column, so the spinner is the
   first thing that has to go */
#shell.is-loaded .tray .map-table input[type=number] { appearance: textfield; }
#shell.is-loaded .tray .map-table input[type=number]::-webkit-inner-spin-button,
#shell.is-loaded .tray .map-table input[type=number]::-webkit-outer-spin-button {
  appearance: none; margin: 0;
}

/* include · value · rows · randcode · TRT · product · strength */
#shell.is-loaded .tray #trtTable th:nth-child(1) { width: 12%; }
#shell.is-loaded .tray #trtTable th:nth-child(2) { width: 14%; }
#shell.is-loaded .tray #trtTable th:nth-child(3) { width: 11%; }
#shell.is-loaded .tray #trtTable th:nth-child(4) { width: 14%; }
#shell.is-loaded .tray #trtTable th:nth-child(5) { width: 19%; }
#shell.is-loaded .tray #trtTable th:nth-child(6) { width: 12%; }
#shell.is-loaded .tray #trtTable th:nth-child(7) { width: 18%; }
#shell.is-loaded .tray #trtTable td:nth-child(3) { white-space: nowrap; }
/* PRODUCT — derived from TRT, so it reads as a value rather than a control */
#shell.is-loaded .tray #trtTable td:nth-child(6) { font: 650 11px/1.3 var(--mono); color: var(--ink-600); }

/* ── toolbar & issues ───────────────────────────────────── */

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 15px; }
#stats { font-family: var(--mono); font-size: 11.5px; color: var(--ink-400); }

#issues:empty { display: none; }
/* The marker hangs in the left pad rather than being a flex item, so a message
   that wraps — and they do, in the result column — flows as one paragraph
   instead of breaking at every <code> and <b>. */
.issue {
  position: relative;
  border-radius: var(--radius-sm);
  padding: 10px 42px 10px 30px;
  margin-bottom: 8px;
  font-size: 13px;
  border: 1px solid;
}
.issue::before {
  position: absolute; left: 13px; top: 10px;
  font-weight: 700; font-family: var(--mono);
}

/* The eye that opens the rows behind a check. It inherits the panel's colour,
   so it reads as part of the message rather than as a stray control. */
.issue-eye {
  position: absolute; top: 7px; right: 8px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  padding: 0;
  color: inherit;
  background: rgba(255, 255, 255, .55);
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  opacity: .62;
  cursor: pointer;
  transition: opacity .13s, background .13s;
}
.issue-eye:hover { opacity: 1; background: #fff; }
.issue-eye svg { width: 16px; height: 16px; display: block; }
.issue-eye svg path { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.issue-eye svg circle { fill: currentColor; stroke: none; }
.issue.warn { background: var(--warn-bg); border-color: #F5DDB4; color: var(--warn); }
.issue.warn::before { content: "!"; }
.issue.err  { background: var(--err-bg);  border-color: #F7C9D4; color: var(--err); }
.issue.err::before { content: "\00d7"; }
.issue.ok   { background: var(--ok-bg);   border-color: #B9E9D3; color: var(--ok); }
.issue.ok::before { content: "\2713"; }
.issue code { background: rgba(255,255,255,.6); border-color: currentColor; color: inherit; opacity: .95; }

/* ── the deliverable ────────────────────────────────────── */

.output-wrap { padding: 6px var(--gutter) 44px; max-width: var(--maxw); }
.output-page {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 34px 36px 38px;
  font-family: "Times New Roman", Times, serif;
  position: relative;
  overflow: hidden;
}
/* a reagent stripe down the edge of the "paper" */
.output-page::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 4px;
  background: linear-gradient(180deg, var(--teal), var(--lime));
}

.doc-title { font-size: 18px; font-weight: 700; margin: 0 0 12px; color: #000; }
.doc-sub   { font-size: 16px; margin: 0 0 24px; color: #1a1a1a; }

.table-scroll { overflow-x: auto; }

table.fda {
  border-collapse: collapse;
  font-family: "Times New Roman", Times, serif;
  font-size: 11px;
  color: #000;               /* the deliverable is black on white, not brand ink */
}
table.fda th, table.fda td {
  border: 1px solid #000;
  padding: 4px 6px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
table.fda th { font-weight: 700; background: #fff; }
table.fda th.banner { font-size: 13px; padding: 6px; }
table.fda tbody td { font-weight: 400; }
table.fda tbody tr:hover td { background: #FBFDFE; }

/* ── offline guarantee, as a dialog ─────────────────────────
   It used to sit at the foot of the page, where it was only ever read by
   someone who scrolled past the table. As a dialog off the brand bar it can be
   opened at any point in a run — including before a file is chosen, which is
   when the question actually gets asked.
   ---------------------------------------------------------- */

.modal {
  width: min(880px, calc(100vw - 40px));
  max-height: min(86vh, 920px);
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(9, 19, 32, .55); }

.modal-head {
  display: flex; align-items: center; gap: 14px;
  flex: none;
  padding: 17px 20px 15px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--sunk), var(--panel));
}
.modal-head h2 {
  display: flex; align-items: center; gap: 11px;
  margin: 0; font-size: 17px; font-weight: 680;
  letter-spacing: -.2px; color: var(--ink-800);
}
.modal-head .dot { box-shadow: 0 0 0 4px rgba(16,185,129,.18); }
.modal-x {
  margin-left: auto; flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font: 400 21px/1 var(--sans);
  color: var(--ink-400);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .13s, border-color .13s, background .13s;
}
.modal-x:hover { color: var(--ink); border-color: var(--ink-400); background: var(--sunk); }

.modal-body {
  flex: 1 1 auto; min-height: 0;
  padding: 20px 24px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── the rows behind a check ────────────────────────────────
   Twenty-six columns of evidence needs the room, so this dialog is wider than
   the offline one and its table scrolls in both directions inside a frame
   rather than stretching the page.
   ---------------------------------------------------------- */

.modal-wide { width: min(1480px, calc(100vw - 40px)); }

/* the check, repeated verbatim: the claim the rows below are answering */
.ev-claim { margin: 0 0 12px; }
/* stays position:relative — the marker is absolute, and would otherwise anchor
   itself to the dialog and land in the top-left corner */
.ev-claim.issue { padding: 11px 14px 11px 30px; margin-bottom: 12px; }
.ev-claim.issue::before { top: 11px; }

.ev-scroll {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  overscroll-behavior: contain;
}

.ev-table { border-collapse: separate; border-spacing: 0; font: 12px/1.45 var(--mono); }
.ev-table th, .ev-table td {
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  padding: 5px 9px;
  text-align: right;
  white-space: nowrap;
}
.ev-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--sunk);
  border-bottom: 1px solid var(--line);
  font: 650 10.5px/1.4 var(--sans);
  letter-spacing: .6px; text-transform: uppercase;
  color: var(--ink-600);
  text-align: right;
}
.ev-table tbody tr:hover td { background: var(--sunk); }
.ev-table tbody tr:last-child td { border-bottom: 0; }

/* the row's own identity — which sheet line, or which output row */
.ev-table :is(th, td).ev-rowhead {
  position: sticky; left: 0; z-index: 1;
  background: var(--sunk);
  border-right: 1px solid var(--line);
  text-align: left;
  font-weight: 650;
  color: var(--ink-800);
}
.ev-table thead th.ev-rowhead { z-index: 3; }
.ev-table tbody tr:hover td.ev-rowhead { background: var(--line-2); }
.ev-sub { display: block; font-size: 11px; color: var(--ink-400); font-weight: 400; }

/* the column the check is actually about */
.ev-table .ev-hi { background: var(--warn-bg); color: var(--warn); font-weight: 650; }
.ev-table thead th.ev-hi { background: #FBEFD8; color: var(--warn); }
.ev-table tbody tr:hover td.ev-hi { background: #FBEFD8; }
/* an empty cell is usually the whole point, so it is drawn rather than blank */
.ev-table .ev-empty { color: var(--ink-400); }

.offline h3 { margin: 22px 0 9px; font-size: 14px; font-weight: 680; color: var(--ink-800); }
.offline p { margin: 0 0 12px; font-size: 14px; max-width: 94ch; color: var(--ink-600); }
.offline p.lead { font-size: 15px; color: var(--ink); }
.offline ul { margin: 0 0 12px; padding-left: 20px; max-width: 94ch; }
.offline li { font-size: 14px; margin-bottom: 8px; color: var(--ink-600); }
.offline strong { font-weight: 660; color: var(--ink); }
.offline a { color: var(--teal-600); font-weight: 600; }
.offline kbd {
  font: 11.5px/1 var(--mono);
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 2px 6px; background: var(--sunk);
  color: var(--ink);
}

.repo {
  margin: 20px 0 16px;
  padding: 17px 20px;
  background: linear-gradient(135deg, var(--teal-50), var(--sunk));
  border: 1px solid var(--teal-100);
  border-radius: var(--radius-sm);
}
.repo p { margin: 0; }
.repo-lead {
  font: 700 10.5px/1 var(--sans);
  text-transform: uppercase; letter-spacing: .9px;
  color: var(--teal-600); margin-bottom: 7px !important;
}
/* An <a> styled as a button — .btn sets padding and colour, this adds the bits
   an anchor doesn't get for free. */
.repo-btn, .offline a.repo-btn {
  display: inline-block;
  text-decoration: none;
  color: #fff;
  margin: 11px 0 2px;
}
.offline a.repo-btn:hover { color: #fff; }
.repo p + p { margin-top: 7px !important; }
.repo .tiny { margin-top: 8px !important; color: var(--ink-400); }
.repo .tiny code { font-size: 11.5px; }

/* ── toast ──────────────────────────────────────────────── */

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 22px);
  background: var(--ink-900); color: #fff;
  padding: 11px 20px; border-radius: 30px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── narrow screens ─────────────────────────────────────── */

/* The bar runs out of room for the long form of the claim well before the
   layout does, so it has a short form to fall back on. */
.tl-short { display: none; }
@media (max-width: 1180px) {
  .tl-long  { display: none; }
  .tl-short { display: inline; }
}

/* Below this the tray has no column to sit in: it goes back above the result,
   still stacked, and nothing is pinned. */
@media (max-width: 1100px) {
  #shell.is-loaded .workspace { display: block; }
  #shell.is-loaded .tray {
    position: static;
    max-height: none; overflow: visible;
    padding-right: 0; margin-bottom: 16px;
  }
  #shell.is-loaded .resultbar { position: static; max-height: none; overflow: visible; }
  #shell.is-loaded .hero .sub { display: block; }
}

@media (max-width: 720px) {
  :root { --gutter: 18px; }
  .topbar { flex-wrap: wrap; gap: 12px; }
  .brand-tag { display: none; }
  .hero h1 { font-size: 22px; }
  .map-table select { min-width: 0; width: 100%; }
  .output-page { padding: 22px 18px 26px; }
  .modal { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; border-left-width: 4px; }
  .modal-head { padding: 14px 14px 12px 16px; }
  .modal-body { padding: 16px 16px 22px; }
}

/* ── print: the deliverable alone, landscape, as in the PDF ── */

@media print {
  @page { size: landscape; margin: 0.5in; }

  html, body { background: #fff; }
  .no-print, .toast { display: none !important; }
  /* Neither the offline dialog nor the checks are marked .no-print — they are
     hidden here instead, so the .no-print inventory stays exactly the five
     chrome blocks. The printed page is the deliverable and nothing else. */
  dialog, dialog::backdrop { display: none !important; }
  #issues { display: none !important; }

  /* the tray is gone, so the result column is the whole page */
  .workspace, #shell.is-loaded .workspace { display: block; padding: 0; max-width: none; }
  .result { min-width: 0; }
  .output-wrap, #shell.is-loaded .output-wrap { padding: 0; max-width: none; }
  .output-page {
    border: 0; border-radius: 0; padding: 0;
    box-shadow: none; overflow: visible;
  }
  .output-page::before { display: none; }

  .doc-title { font-size: 14px; margin-bottom: 10px; }
  .doc-sub   { font-size: 13px; margin-bottom: 18px; }

  .table-scroll { overflow: visible; }
  table.fda { font-size: 8pt; width: 100%; }
  table.fda th, table.fda td { padding: 2px 3px; }
  table.fda th.banner { font-size: 10pt; }
  table.fda thead { display: table-header-group; }
  table.fda tr { break-inside: avoid; }
  table.fda tbody tr:hover td { background: #fff; }
}
