/* JB Patch Tools — shared design system.
   External file so pages run under strict CSP (no inline styles). */

* { box-sizing: border-box; }

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2328;
  --ink-soft: #57606a;
  --line: #d0d7de;
  --accent: #1f2328;
  --accent-hover: #3a4048;
  --danger: #b42318;
  --ok: #1a7f37;
  --soft: #57606a;
  --flag: #b42318;
  --flagbg: #fff1f0;
  --chip: #eaeef2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(31, 35, 40, 0.08), 0 4px 14px rgba(31, 35, 40, 0.05);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

/* ---- Top navigation (shared) ---- */
.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topnav a,
.topnav button {
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.topnav a:hover,
.topnav button:hover { background: var(--bg); }
.topnav a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.topnav .spacer { flex: 1; }

/* ---- Cards & layout ---- */
.page {
  max-width: 640px;
  margin: 24px auto 48px;
  padding: 0 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.subtitle {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0 0 16px;
}
h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.small-text {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: normal;
}

/* ---- Buttons ---- */
button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
}
.btn-primary {
  width: 100%;
  padding: 11px;
  margin-top: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  padding: 9px 14px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-secondary:hover { background: var(--bg); }
.btn-copy {
  padding: 4px 12px;
  font-size: 12px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  display: none; /* shown by JS once there is content to copy */
}
.btn-copy:hover { background: var(--bg); }
.btn-copy.copied {
  color: var(--ok);
  border-color: var(--ok);
}

/* ---- Inputs & outputs ---- */
textarea,
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  color: var(--ink);
}
textarea {
  resize: vertical;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}
textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--card);
}

/* Status / error messaging */
.status {
  display: none;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.status.error {
  display: block;
  background: #fff1f0;
  border: 1px solid #ffa39e;
  color: var(--danger);
}
.status.info {
  display: block;
  background: #f0f6ff;
  border: 1px solid #b6d4fe;
  color: #1c4587;
}

.output-container { margin-top: 20px; }
.disclaimer {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 4px;
}

/* ---- Allergen Selector specifics ---- */
.search-wrap {
  position: relative;
  max-width: 340px;
}
#suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.suggestion-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
}
.suggestion-item:hover,
.suggestion-item.active {
  background: var(--bg);
}

#strengthSelection {
  margin-top: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
}
.strength-btn {
  min-width: 48px;
  min-height: 42px; /* comfortable touch target */
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.strength-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#selectedList { margin-top: 12px; }
#selectedList table {
  border-collapse: collapse;
  width: 100%;
}
#selectedList th,
#selectedList td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 14px;
}
#selectedList th {
  background: var(--bg);
  font-weight: 600;
}
.remove-btn {
  min-height: 30px;
  padding: 2px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--danger);
  font-size: 13px;
  line-height: 1;
}
.remove-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
#selectedList .remove-col { width: 1%; white-space: nowrap; }

#clinicalRelevanceSection {
  display: none;
  margin-top: 14px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
}
#clinicalRelevanceSection button {
  margin: 6px 6px 0 0;
  min-height: 38px;
  padding: 7px 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
#clinicalRelevanceSection button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.resultBox {
  display: none;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  padding: 12px;
  margin-top: 10px;
  overflow-y: auto;
  font-size: 14px;
}

/* ---- Sign-in ---- */
.login-page { max-width: 380px; margin-top: 9vh; }
.login-card h1 { margin-bottom: 2px; }
.login-card form { display: flex; flex-direction: column; margin-top: 6px; }
.login-label { font-size: 13px; color: var(--ink-soft); margin: 10px 0 4px; }
.login-card .btn-primary { margin-top: 16px; }

/* ---- Home page ---- */
.home-wrap p { color: var(--ink-soft); font-size: 14px; }
.home-wrap p strong { color: var(--ink); }

/* ---- Tray / QR ---- */
.qr-make-btn { margin-top: 12px; }
.qr-wrap { display: none; margin-top: 12px; text-align: center; }
.qr-wrap.show { display: block; }
.qr-wrap img { max-width: 100%; height: auto; image-rendering: pixelated; }
#qrOut { display: inline-block; background: #fff; padding: 8px; border-radius: 6px; }

.tray-import { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.dropzone {
  flex: 1; min-width: 240px; border: 2px dashed var(--line); border-radius: 8px;
  padding: 22px 14px; text-align: center; color: var(--ink-soft); cursor: pointer;
  background: var(--card);
}
.dropzone.dragover { border-color: var(--accent); background: var(--bg); }
#cameraWrap { display: none; margin: 10px 0; text-align: center; }
#cameraWrap.show { display: block; }
#cameraVideo { width: 100%; max-width: 420px; border-radius: 8px; background: #000; }
.tray-panel { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; overflow: hidden; }
.tray-panel h3 {
  font-size: 14px; margin: 0; padding: 8px 12px; background: var(--bg);
  border-bottom: 1px solid var(--line); font-weight: 600;
}
.tray-slot { display: flex; gap: 10px; padding: 6px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.tray-slot:first-child { border-top: none; }
.tray-slot .num { color: var(--soft); min-width: 26px; text-align: right; }
.tray-slot .cv { color: var(--soft); font-size: 12px; }
.tray-slot.empty { color: var(--soft); font-style: italic; }
.tray-slot.unmatched { background: var(--flagbg); }
.tray-slot.unmatched .name { color: var(--flag); }

/* ---- Grading ---- */
.grade-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin: 4px 0 10px;
}
.grade-status { font-size: 13px; color: var(--ink-soft); }
.grade-legend { font-size: 12px; color: var(--ink-soft); margin: 0 0 14px; }
.grade-legend b { color: var(--ink); font-weight: 600; }

.grade-panel { border: 1px solid var(--line); border-radius: 10px; margin: 12px 0; overflow: hidden; }
.grade-panel h3 {
  font-size: 12px; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-soft);
  margin: 0; padding: 8px 12px; background: var(--bg);
  border-bottom: 1px solid var(--line); font-weight: 600;
}

/* Two columns by column-flow: left column = slots 1..half top-to-bottom, right =
   the rest, mirroring the physical tray. Each grid row's two cells share a height
   (aligned). On a phone it collapses to a single column in natural 1..n order. */
.grade-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  grid-auto-flow: column; grid-template-rows: repeat(var(--rows, 6), auto);
}
@media (max-width: 560px) {
  .grade-grid { grid-template-columns: 1fr; grid-auto-flow: row; grid-template-rows: auto; }
}

.gslot {
  position: relative; display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 14px; cursor: pointer; background: var(--card); transition: background .12s;
}
.gslot.gcol-l { border-right: 1px solid var(--line); }
@media (max-width: 560px) { .gslot.gcol-l { border-right: none; } }
.gslot:hover { background: var(--bg); }
.gslot .gnum {
  flex: none; width: 20px; text-align: right; color: var(--ink-soft);
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.gslot .gtext {
  flex: 1; min-width: 0; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.gslot .gname.um { color: var(--flag); }
.gslot .gcv { color: var(--ink-soft); font-size: 11px; margin-left: 5px; white-space: nowrap; }
.gslot .gbadge {
  flex: none; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 6px;
  display: none; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.gslot.graded .gbadge { display: inline-flex; }
.gslot.empty, .gslot.filler { color: var(--ink-soft); font-style: italic; cursor: default; }
.gslot.empty:hover, .gslot.filler:hover { background: var(--card); }

/* graded row tint + badge colours, by severity */
.gslot.gr-strong { background: #fdecea; }
.gslot.gr-strong .gbadge { background: var(--flag); color: #fff; }
.gslot.gr-pos { background: #fdf1e3; }
.gslot.gr-pos .gbadge { background: #d98324; color: #fff; }
.gslot.gr-doubt .gbadge { background: #fde8a6; color: #7a5b00; }
.gslot.gr-ir .gbadge { background: #e3efd9; color: #3f6b28; }
.gslot.gr-neg .gbadge, .gslot.gr-nt .gbadge { background: var(--chip); color: var(--ink-soft); }
/* No prefers-color-scheme overrides: the app is a fixed light theme so it renders
   identically in every browser regardless of the OS dark-mode setting. */

/* tap-to-grade picker — fixed-positioned by JS so it is never clipped by the
   panel box; flips above the slot when there is no room below. */
.gpicker {
  position: fixed; z-index: 300;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; width: 224px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; box-shadow: 0 4px 18px rgba(31,35,40,.18);
}
.gpicker .gp {
  min-height: 40px; padding: 6px 4px; font-size: 15px; font-weight: 700;
  border: 1px solid var(--line); border-radius: 7px; background: var(--card);
  color: var(--ink); cursor: pointer;
}
.gpicker .gp:hover { border-color: var(--accent); }
.gpicker .gp.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
.gpicker .gp-strong { color: var(--flag); }
.gpicker .gp-pos { color: #c26a12; }
.gpicker .gp-clear {
  grid-column: 1 / -1; font-size: 13px; font-weight: 600; color: var(--ink-soft);
}

/* ---- Sticky output bar: stays at the top while the RN scrolls a long tray ---- */
.grade-sticky {
  position: sticky; top: 0; z-index: 40;
  background: var(--card);
  margin: 0 -20px 12px;          /* bleed to the card edges so nothing peeks past */
  padding: 8px 20px 10px;
  border-bottom: 1px solid var(--line);
}
.grade-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rel-label {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-soft);
}
.rel-label select {
  padding: 6px 8px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fafbfc; color: var(--ink);
}

/* ---- Copy preview modal: shows exactly what was copied ---- */
.copy-modal-backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(31, 35, 40, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.copy-modal {
  background: var(--card); border-radius: 12px; box-shadow: 0 12px 40px rgba(31,35,40,.3);
  width: 100%; max-width: 640px; max-height: 82vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.copy-modal-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.copy-modal-title { font-weight: 600; font-size: 15px; }
.copied-chip {
  font-size: 12px; font-weight: 600; color: var(--ok);
  background: #e6f4ea; border: 1px solid #b7dfc2; border-radius: 999px;
  padding: 3px 10px;
}
.copied-chip.fail { color: var(--danger); background: #fff1f0; border-color: #ffa39e; }
.copy-modal-close {
  margin-left: auto; padding: 6px 14px; font-size: 13px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
}
.copy-modal-close:hover { background: var(--bg); }
.copy-modal-body {
  padding: 14px 18px 18px; overflow-y: auto; font-size: 14px; line-height: 1.5;
}
.copy-modal-body p { margin: 0 0 12px; }
.copy-modal-body p:last-child { margin-bottom: 0; }

/* ---- Print: QR facesheet copy (parser page) and patient report (tray page) ----
   The print containers are hidden on screen; window.print() after tagging <body>
   with a mode class prints ONLY that container, in plain black on white. */
#qrPrint, #reportPrint { display: none; }
@media print {
  body.print-qr .topnav, body.print-qr .page,
  body.print-report .topnav, body.print-report .page { display: none !important; }
  body.print-qr #qrPrint { display: block; }
  body.print-report #reportPrint { display: block; }

  #qrPrint { text-align: left; padding: 0.25in; }
  #qrPrint img { width: 2in; height: 2in; image-rendering: pixelated; }
  #qrPrint .qr-print-caption { font-size: 10pt; margin: 6pt 0 0; color: #000; }

  #reportPrint { color: #000; font-size: 11pt; line-height: 1.45; padding: 0.2in; }
  #reportPrint h1 { font-size: 16pt; margin: 0 0 2pt; }
  #reportPrint .rpt-sub { font-size: 10pt; margin: 0 0 10pt; }
  #reportPrint .rpt-intro { margin: 0 0 12pt; }
  #reportPrint .rpt-item { border-top: 1pt solid #000; padding: 8pt 0; page-break-inside: avoid; }
  #reportPrint .rpt-name { font-size: 12pt; font-weight: 700; margin: 0 0 3pt; }
  #reportPrint .rpt-grade { font-weight: 700; }
  #reportPrint .rpt-desc { margin: 0; }
  #reportPrint .rpt-foot { border-top: 1pt solid #000; margin-top: 10pt; padding-top: 6pt; font-size: 9pt; }
}
