:root {
  color-scheme: light;

  /* Fertilum design tokens */
  --bg: #f8faf9;
  --bg-soft: #f1f5f2;
  --surface: #ffffff;

  --ink: #1a2e2a;
  --ink-deep: #0f1a18;
  --ink-soft: #2d423d;
  --ink-muted: #5a6f69;
  --ink-faint: #8a9d97;

  --gold: #b08436;
  --gold-deep: #805e1f;
  --gold-soft: #ecd9b0;
  --gold-mist: #f4ead0;

  --peach: #f4d9c9;
  --cream: #f6ead9;

  --border: rgba(26, 46, 42, 0.08);

  --positive-bg: #e8f5e9;
  --positive-text: #2e7d32;
  --error-bg: #fce4ec;
  --error-text: #c62828;
  --info-bg: #f4ead9;
  --info-text: #805e1f;
  --neutral-bg: #f1f5f2;
  --neutral-text: #5a6f69;

  --shadow-sm: 0 1px 2px rgba(15, 26, 24, 0.04), 0 1px 3px rgba(15, 26, 24, 0.03);
  --shadow-md: 0 4px 12px rgba(15, 26, 24, 0.05), 0 1px 3px rgba(15, 26, 24, 0.03);
  --shadow-lg: 0 12px 40px rgba(15, 26, 24, 0.08), 0 2px 8px rgba(15, 26, 24, 0.04);

  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px;
  background: var(--ink);
  color: #ffffff;
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-decoration: none;
}

.brand-accent { color: var(--gold-soft); }

.device-info {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  opacity: 0.9;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.admin-link {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #ffffff;
  opacity: 0.7;
  text-decoration: none;
}

.admin-link:hover { opacity: 1; }

.page-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  margin: 0 0 24px;
  color: var(--ink);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 360px;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-field input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--ink);
}

.admin-form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.admin-form-actions .button {
  cursor: pointer;
}

.button-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}

.button-secondary:hover { background: var(--bg-soft); opacity: 1; }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 48px 40px;
}

.alert {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.alert-info {
  background: var(--info-bg);
  color: var(--info-text);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.kpi-card-dark {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.kpi-value {
  font-family: var(--font-serif);
  font-size: 2.3rem;
  line-height: 1;
  color: inherit;
}

.kpi-unit {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink-muted);
  margin-left: 2px;
}

.kpi-card-dark .kpi-unit { color: var(--gold-soft); }

.kpi-label {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.kpi-card-dark .kpi-label { color: var(--gold-soft); }

.kpi-sub {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--ink-faint);
}

.kpi-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--gold-soft);
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.toolbar input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--ink);
}

.toolbar input[type="text"]::placeholder { color: var(--ink-faint); }

.toolbar select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--ink);
}

.toolbar button {
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.toolbar button:hover { opacity: 0.88; transform: translateY(-1px); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table.samples th,
table.samples td {
  text-align: left;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

table.samples th {
  background: var(--bg-soft);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

table.samples td { font-size: 0.9rem; }

table.samples td.mono,
table.samples td .mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

table.samples tr:last-child td { border-bottom: none; }
table.samples tbody tr:hover td { background: var(--bg-soft); }

.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--gold-mist);
  color: var(--gold-deep);
}

.actions a {
  color: var(--gold-deep);
  text-decoration: none;
  margin-right: 16px;
  font-weight: 500;
  font-size: 0.85rem;
}

.actions a:hover { color: var(--gold); text-decoration: underline; }

.back-link {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.88rem;
}

.back-link:hover { color: var(--ink); }

.detail-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.detail-head h1 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0;
}

.muted { color: var(--ink-faint); font-family: var(--font-mono); font-size: 1.1rem; }

.button {
  display: inline-block;
  background: var(--ink);
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.button:hover { opacity: 0.88; transform: translateY(-1px); }

table.fields {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

table.fields th,
table.fields td {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.fields th {
  width: 40%;
  text-align: left;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

table.fields td {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
}

table.fields tr:last-child th,
table.fields tr:last-child td { border-bottom: none; }
table.fields tbody tr:hover td,
table.fields tbody tr:hover th { background: var(--bg-soft); }

.report {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 40px 48px 48px;
}

.report-download {
  position: absolute;
  top: 32px;
  right: 32px;
}

.report-title {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 400;
  text-align: center;
  margin: 0 0 28px;
  color: var(--ink);
}

.report-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 2px;
}

.report-value { font-size: 0.9rem; color: var(--ink); }

.report-meta-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.report-id-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

.report-id-right { text-align: right; }

.report-id-value {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  color: var(--ink);
}

.report-id-value.mono { font-family: var(--font-mono); font-size: 1.2rem; }

.report-section-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--ink);
  margin: 36px 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--ink);
}

.report-subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold-deep);
  margin: 0 0 8px;
}

.report-info-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 24px;
  align-items: start;
}

.report-image {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  object-fit: cover;
  aspect-ratio: 4 / 3;
  background: var(--bg-soft);
  cursor: zoom-in;
  transition: opacity 0.15s ease;
}

.report-image:hover { opacity: 0.9; }

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 24, 0.92);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 48px;
  cursor: zoom-out;
}

.lightbox.is-open { display: flex; }

.lightbox-img {
  /* width/height + contain rather than max-width/max-height: the latter
     only ever shrinks, so a small image (the flagged-cell crops are
     276x137) opened at its natural size looked no bigger than it was in
     the grid -- as if clicking did nothing. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  filter: drop-shadow(0 12px 40px rgba(15, 26, 24, 0.5));
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: #ffffff;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font-body);
  padding: 8px;
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.lightbox-close:hover { opacity: 1; }

@media (max-width: 640px) {
  .lightbox { padding: 24px; }
  .lightbox-close { top: 10px; right: 12px; font-size: 2rem; }
}

.patient-sheet { max-width: 820px; }

.patient-provenance {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold-deep);
  margin: 0 0 6px;
}

.patient-sheet .report-title { text-align: left; }

.patient-value {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1.1;
}

.patient-lead {
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink-soft);
  margin: 20px 0 0;
}

.patient-body {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--ink-soft);
  margin: 0 0 14px;
}

.patient-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

table.patient-bands {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
}

table.patient-bands th,
table.patient-bands td {
  text-align: left;
  vertical-align: top;
  padding: 14px 16px;
  font-size: 0.92rem;
  line-height: 1.55;
  font-weight: 400;
}

table.patient-bands th {
  width: 26%;
  font-weight: 600;
  border-radius: 10px 0 0 10px;
  white-space: nowrap;
}

table.patient-bands td { border-radius: 0 10px 10px 0; }

/* The clinic's own published banding, reproduced with its own colour
   coding. Unlike the fragmentation heatmap -- which stays a single-hue
   magnitude ramp precisely so the portal isn't grading anything -- the
   judgement here is theirs, already made and published. */
.band-normal th, .band-normal td { background: #e8f5e9; color: #1f4d23; }
.band-elevated th, .band-elevated td { background: #fdece0; color: #7a4418; }
.band-high th, .band-high td { background: #fbdcdf; color: #8a2027; }

.band:not(.is-matched) th,
.band:not(.is-matched) td { opacity: 0.55; }

.band.is-matched th { box-shadow: inset 3px 0 0 currentColor; }

.band-marker {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.patient-link { color: var(--gold-deep); }

.slide-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.slide-bar-left,
.slide-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slide-bar .back-link { margin-bottom: 0; }

.slide-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--ink);
}

.slide-bar-right .button {
  padding: 8px 16px;
  cursor: pointer;
  font-family: var(--font-body);
}

.slide-viewport {
  position: relative;
  height: 74vh;
  min-height: 420px;
  overflow: hidden;
  background: var(--ink-deep);
  border-radius: 20px;
  border: 1px solid var(--border);
  cursor: grab;
  touch-action: none;
  /* Without this, dragging sweeps a text selection across the field
     labels and the browser drags that selection as a ghost layer over
     the stage instead of panning it. */
  user-select: none;
  -webkit-user-select: none;
}

.slide-viewport.is-dragging { cursor: grabbing; }

.slide-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: grid;
  grid-template-columns: repeat(5, 320px);
  grid-auto-rows: 240px;
  gap: 6px;
}

.slide-tile {
  position: relative;
  background-color: #000000;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.slide-tile-empty {
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.04) 6px,
    transparent 6px,
    transparent 12px
  );
  border: 1px dashed rgba(255, 255, 255, 0.18);
}

.slide-tile-label {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #ffffff;
  background: rgba(15, 26, 24, 0.6);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.slide-note { margin-top: 12px; }

/* Sequential ramp for the per-field fragmentation heatmap: one hue
   (the brand gold), light to dark, validated for monotone lightness and
   step separation. Deliberately not a diverging good/bad scale -- that
   would be reading a threshold into the number, which is the reader's
   call, not the portal's. */
.heat-1 { background: #d4ae5e; color: var(--ink); }
.heat-2 { background: #b98c3d; color: var(--ink); }
.heat-3 { background: #9c7029; color: #ffffff; }
.heat-4 { background: #7d561b; color: #ffffff; }
.heat-5 { background: #5c3d10; color: #ffffff; }

.heat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;  /* surface gap -- white separates the cells, not borders */
  margin-top: 4px;
}

.heat-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.heat-cell:hover { transform: scale(1.04); }
.heat-cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.heat-empty {
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  color: var(--ink-faint);
  cursor: default;
}

/* A field whose image hasn't been read yet must not look like a field that
   genuinely has no image -- one is temporary, the other is real. */
.heat-pending {
  background: repeating-linear-gradient(
    45deg,
    var(--bg-soft),
    var(--bg-soft) 4px,
    var(--surface) 4px,
    var(--surface) 8px
  );
  border: 1px solid var(--border);
  color: var(--ink-faint);
  cursor: default;
}

.heat-empty:hover,
.heat-pending:hover { transform: none; }

.heat-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  opacity: 0.75;
  letter-spacing: 0.04em;
}

.heat-value {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 1;
}

.heat-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-top: 16px;
}

.heat-legend-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.heat-legend-scale {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--ink-faint);
}

.heat-swatch {
  display: inline-block;
  width: 26px;
  height: 12px;
  border-radius: 3px;
}

.heat-legend-empty-key {
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: normal;
}

.heat-legend-empty-key .heat-swatch { width: 14px; }

.subtitle-link {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--gold-deep);
  text-decoration: none;
  margin-left: 8px;
}

.subtitle-link:hover { text-decoration: underline; }

.subtitle-note {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink-faint);
  margin-left: 6px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-top: 4px;
}

.field-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  border: none;
  padding: 0;
  background: var(--bg-soft);
  cursor: pointer;
}

.field-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.field-cell.is-excluded img { opacity: 0.4; }

.field-cell.is-excluded::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--gold);
  border-radius: 6px;
}

.field-cell-empty {
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.field-cell-empty .field-num { position: static; background: none; color: var(--ink-faint); }

.field-num {
  position: absolute;
  left: 2px;
  bottom: 2px;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  color: #ffffff;
  background: rgba(15, 26, 24, 0.55);
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1.4;
}

.field-cell:hover img { opacity: 0.82; }
.field-cell:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.field-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 24, 0.94);
  z-index: 1100;
  align-items: stretch;
  justify-content: center;
  padding: 40px;
  gap: 24px;
}

.field-viewer.is-open { display: flex; }

.field-viewer-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.field-viewer-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.field-viewer-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  align-self: center;
  max-height: 90vh;
  overflow-y: auto;
}

.field-viewer-position {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  color: var(--ink);
  margin: 2px 0 10px;
}

.field-viewer-status {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 18px;
}

.field-viewer-status.is-included { background: var(--positive-bg); color: var(--positive-text); }
.field-viewer-status.is-excluded-label { background: var(--gold-mist); color: var(--gold-deep); }

.field-viewer-well-label { margin-top: 16px; }

.field-viewer-note {
  margin-top: 14px;
  font-size: 0.76rem;
  color: var(--ink-faint);
  line-height: 1.5;
}

.adjust-section-label { margin-top: 16px; }

.adjust-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.adjust-label {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
}

.adjust-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.adjust-btn:hover { background: var(--gold-mist); }
.adjust-btn:active { background: var(--gold-soft); }

.adjust-value {
  min-width: 28px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}

.adjust-reset {
  display: block;
  margin-top: 10px;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  cursor: pointer;
}

.adjust-reset:hover { background: var(--bg-soft); color: var(--ink); }

.adjusted-header td {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gold-deep);
  background: var(--gold-mist);
  border-bottom: 2px solid var(--gold-soft);
  padding: 8px 12px;
}

.adjusted-row td { background: var(--cream); }

.adjusted-well-row th,
.adjusted-well-row td {
  background: var(--cream);
  color: var(--gold-deep);
  font-style: italic;
}

.field-viewer-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: #ffffff;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  opacity: 0.85;
}

.field-viewer-close:hover { opacity: 1; }

.field-viewer-nav {
  align-self: center;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  font-size: 2.4rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}

.field-viewer-nav:hover { background: rgba(255, 255, 255, 0.2); }
.field-viewer-nav:disabled { opacity: 0.25; cursor: default; }
.field-viewer-nav:disabled:hover { background: rgba(255, 255, 255, 0.1); }

@media (max-width: 720px) {
  .field-viewer { flex-direction: column; padding: 16px; gap: 10px; }
  .field-viewer-panel { width: auto; max-height: 28vh; }
  .field-viewer-nav { width: 40px; height: 40px; font-size: 1.8rem; }
  .field-viewer-close { top: 10px; right: 14px; }
}

.report-image-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

table.report-kv {
  width: 100%;
  border-collapse: collapse;
}

table.report-kv th,
table.report-kv td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.85rem;
}

table.report-kv th {
  color: var(--ink-muted);
  font-weight: 500;
  width: 55%;
}

table.report-kv td { color: var(--ink); font-weight: 500; }

/* The 55% label width above is for the two-column variant; in this
   four-column one it asks for 110% of the row, which squeezed the value
   columns until "48 %" broke across two lines. Give the four columns
   widths that actually add up. */
table.report-kv-pairs th { width: 30%; }
table.report-kv-pairs td { width: 20%; }
table.report-kv-pairs th:nth-child(3) { padding-left: 20px; }

/* Values that carry a unit ("48 %", "8.657 M/mL") must not break between
   the number and its unit. */
table.report-kv-units td { white-space: nowrap; }

table.report-kv tr:last-child th,
table.report-kv tr:last-child td { border-bottom: none; }

table.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

table.report-table thead th {
  background: var(--ink);
  color: #ffffff;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  text-align: left;
}

table.report-table tbody td,
table.report-table tbody td.report-category {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

table.report-table tbody tr:nth-child(even) { background: var(--bg-soft); }

.report-category { font-weight: 600; color: var(--ink); white-space: nowrap; }

.report-result { font-weight: 600; }
.report-result.is-red { color: var(--error-text); }
.report-result.is-underline { text-decoration: underline; }

.report-caption {
  margin: 10px 2px 0;
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.report-caption .is-red { color: var(--error-text); font-weight: 600; }
.report-caption .is-underline { text-decoration: underline; }

.report-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 40px;
  margin-bottom: 8px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 8px 0 4px;
}

.video-card {
  margin: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.video-card video {
  display: block;
  width: 100%;
  background: var(--ink-deep);
}

.video-card {
  cursor: zoom-in;
}

.video-card figcaption {
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.video-hint {
  color: var(--ink-faint);
  text-transform: none;
  letter-spacing: normal;
}

.wipe {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #000000;
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  line-height: 0;
}

.wipe-video {
  display: block;
  width: 100%;
}

.wipe-overlay {
  position: absolute;
  inset: 0;
  /* clip-path set from JS: inset(0 0 0 X%) reveals the tracked video to
     the right of the divider, leaving the raw frame visible to its left. */
}

.wipe-overlay .wipe-video {
  height: 100%;
  object-fit: cover;
}

.wipe-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(-1px);
  pointer-events: none;
}

.wipe-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(15, 26, 24, 0.4);
}

.wipe-tag {
  position: absolute;
  bottom: 10px;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
  background: rgba(15, 26, 24, 0.6);
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  line-height: 1.5;
}

.wipe-tag-left { left: 10px; }
.wipe-tag-right { right: 10px; }

.wipe-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.wipe-hint {
  font-size: 0.66rem;
  color: var(--ink-faint);
}

.cell-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 4px;
}

.cell-card {
  margin: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.cell-card img {
  display: block;
  width: 100%;
  cursor: zoom-in;
  transition: opacity 0.15s ease;
}

.cell-card img:hover { opacity: 0.88; }

.cell-card figcaption {
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--ink-muted);
}

.video-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 24, 0.94);
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.video-viewer.is-open { display: flex; }

.video-viewer-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 100%;
  max-height: 100%;
}

.video-viewer video {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 8px;
  background: #000000;
  box-shadow: var(--shadow-lg);
  cursor: ns-resize;  /* scroll here to scrub */
}

.video-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 18px;
}

.video-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink);
  cursor: pointer;
}

.video-btn:hover { background: var(--gold-mist); }
.video-btn.is-active { background: var(--ink); color: #ffffff; border-color: var(--ink); }

.video-btn-icon {
  padding: 6px 12px;
  font-size: 1rem;
  line-height: 1;
}

#video-scrub {
  flex: 1;
  min-width: 140px;
  accent-color: var(--gold);
}

.video-time {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  min-width: 56px;
  text-align: right;
}

.video-speeds {
  display: flex;
  gap: 4px;
}

.video-viewer-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  text-align: center;
}

.video-viewer-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: #ffffff;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  opacity: 0.85;
}

.video-viewer-close:hover { opacity: 1; }

@media (max-width: 720px) {
  .video-viewer { padding: 16px; }
  .video-controls { border-radius: 16px; }
}

.histogram-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px 40px;
  margin: 24px 0 8px;
}

.histo-title {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-align: center;
  margin-bottom: 10px;
}

.histo-unit {
  font-weight: 400;
  text-transform: none;
  color: var(--ink-faint);
  letter-spacing: normal;
}

.histo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 22px;
}

.histo-bucket {
  width: 48px;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--ink-muted);
  text-align: right;
}

.histo-bucket-wide { width: 90px; }
.histo-axis-wide { margin-left: 98px; }

.histo-track {
  flex: 1;
  height: 12px;
  background: var(--bg-soft);
  border-radius: 4px;
  overflow: hidden;
}

.histo-fill {
  display: block;
  height: 100%;
  background: var(--gold);
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}

.histo-value {
  /* Wide enough for the longest value the device reports here
     ("100.00 %"), and never wrapping: the row is a fixed 22px, so a
     value breaking onto a second line overlapped the bar below it. */
  width: 58px;
  flex-shrink: 0;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.histo-axis {
  display: flex;
  justify-content: space-between;
  /* Must match the row's own geometry or the 0-100 ticks sit off the bar
     track: bucket label (48px) + gap (8) on the left, value (58px) +
     gap (8) on the right. */
  margin-left: 56px;
  margin-right: 66px;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-faint);
}

.remark-box {
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
}

.report-footer { margin-top: 32px; }

.report-footer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--ink);
}

.report-footer-meta {
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  text-align: center;
}

@media (max-width: 720px) {
  .report { padding: 28px 20px 32px; }
  .report-download { position: static; display: block; margin: 0 auto 20px; width: fit-content; }
  .report-info-grid,
  .report-details-grid,
  .histogram-grid { grid-template-columns: 1fr; }
  .report-image { aspect-ratio: 16 / 10; }
}

@media (max-width: 640px) {
  .topbar { padding: 16px 20px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .container { padding: 32px 20px; }
  .toolbar { flex-direction: column; }
  .detail-head h1 { font-size: 1.8rem; }
  table.samples, table.samples thead { display: block; }
  table.samples { overflow-x: auto; }
}
