:root {
  --bg: #f4f7f8; --card: #ffffff; --ink: #1d2b30; --muted: #5d7078; --line: #d5dee2;
  --accent: #00897b; --accent-ink: #ffffff; --accent-soft: #e0f2f1;
  --pass: #1b7a35; --pass-bg: #dff3e4;
  --fail: #b3261e; --fail-bg: #fde4e1;
  --warn: #8a5a00; --warn-bg: #fff1cf;
  --idle: #55656c; --idle-bg: #e8edef;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101719; --card: #172125; --ink: #e6eef0; --muted: #93a6ad; --line: #2b3a40;
    --accent: #26a69a; --accent-ink: #00201d; --accent-soft: #123532;
    --pass: #7fd993; --pass-bg: #173b22;
    --fail: #ff9b92; --fail-bg: #471a17;
    --warn: #ffd37a; --warn-bg: #3f3010;
    --idle: #a7b6bc; --idle-bg: #243238;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
small { font-weight: 400; opacity: .85; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--accent); color: var(--accent-ink); padding: .7rem 1rem;
  padding-top: calc(.7rem + env(safe-area-inset-top));
}
.top a { color: inherit; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; }
.brand small { display: block; font-weight: 500; font-size: .8rem; }
.back { font-size: .9rem; text-decoration: underline !important; }

.warn-bar { background: var(--warn-bg); color: var(--warn); padding: .6rem 1rem; font-size: .9rem; }

.tabs {
  display: flex; gap: .25rem; padding: .5rem 1rem 0; max-width: 980px; margin: 0 auto;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.tabs button {
  flex: 1; border: 1px solid var(--line); border-bottom: none; background: var(--card); color: var(--muted);
  padding: .7rem .5rem; font: inherit; font-weight: 600; border-radius: var(--radius) var(--radius) 0 0; cursor: pointer;
}
.tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

main { max-width: 980px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
}
details.card > summary { cursor: pointer; font-weight: 700; font-size: 1.05rem; }
details.card[open] > summary { margin-bottom: .75rem; }

.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
label.f { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: .65rem .7rem; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 1px;
}

button.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); padding: .7rem 1.1rem; min-height: 46px; cursor: pointer;
}
button.btn.secondary { background: transparent; color: var(--accent); }
button.btn.danger { background: transparent; color: var(--fail); border-color: var(--fail); }
button.btn.small { min-height: 36px; padding: .35rem .7rem; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Key numbers */
.kv { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kv > div { background: var(--accent-soft); border-radius: 10px; padding: .6rem .8rem; }
.kv b { display: block; font-size: 1.3rem; line-height: 1.15; }
.kv span { font-size: .8rem; color: var(--muted); }

/* Messages */
.note { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: .6rem .8rem; border-radius: 6px; font-size: .92rem; }
.note.warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.note.bad { border-color: var(--fail); background: var(--fail-bg); color: var(--fail); }
.note.ok { border-color: var(--pass); background: var(--pass-bg); color: var(--pass); }
.note + .note { margin-top: .5rem; }

/* Verdict chips */
.chip {
  display: inline-block; border-radius: 999px; padding: .2rem .65rem; font-size: .8rem; font-weight: 700;
  background: var(--idle-bg); color: var(--idle); white-space: nowrap; border: 1px solid transparent;
}
.chip.PASS { background: var(--pass-bg); color: var(--pass); }
.chip.FAIL { background: var(--fail-bg); color: var(--fail); }
.chip.IN_PROGRESS { background: var(--warn-bg); color: var(--warn); }
.chip.NOT_REQUIRED { background: transparent; border: 1px dashed var(--idle); }

.banner { border-radius: var(--radius); padding: .9rem 1rem; font-weight: 700; font-size: 1.1rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.banner small { font-weight: 500; font-size: .9rem; }
.banner.PASS { background: var(--pass-bg); color: var(--pass); }
.banner.FAIL { background: var(--fail-bg); color: var(--fail); }
.banner.IN_PROGRESS { background: var(--warn-bg); color: var(--warn); }
.banner.NOT_STARTED, .banner.NOT_REQUIRED { background: var(--idle-bg); color: var(--idle); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex-basis: 100%; }
.progress > i { display: block; height: 100%; background: currentColor; }

/* Pair / direction pickers */
.pairs { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.pairs button, .seg button {
  border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px;
  font: inherit; font-weight: 700; padding: .5rem .2rem; min-height: 56px; cursor: pointer;
}
.pairs button small { display: block; font-size: .7rem; font-weight: 600; margin-top: .15rem; }
.pairs button.PASS small { color: var(--pass); } .pairs button.FAIL small { color: var(--fail); }
.pairs button.IN_PROGRESS small { color: var(--warn); }
.pairs button[aria-pressed="true"], .seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }

/* Checklist */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.steps h3 { margin: .8rem 0 .2rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.steps label { display: grid; grid-template-columns: 28px 1fr; gap: .6rem; align-items: start; padding: .45rem .3rem; border-radius: 8px; cursor: pointer; }
.steps label:has(input:checked) { color: var(--muted); }
.steps label:has(input:checked) span { text-decoration: line-through; }
.steps input[type=checkbox] { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--accent); }
.steps b { font-variant-numeric: tabular-nums; }

/* Toggle buttons for leak / washout */
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.toggles label {
  display: flex; align-items: center; gap: .6rem; border: 2px solid var(--line); border-radius: 10px;
  padding: .7rem .8rem; font-weight: 600; cursor: pointer; min-height: 52px;
}
.toggles input { width: 22px; height: 22px; accent-color: var(--fail); }
.toggles label:has(input:checked) { border-color: var(--fail); background: var(--fail-bg); color: var(--fail); }

/* Tables */
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.invalid td { background: var(--warn-bg); }
tr.failed td { background: var(--fail-bg); }
td button { margin-right: .25rem; }

.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.matrix button.chip { cursor: pointer; font: inherit; font-size: .8rem; font-weight: 700; border: 1px solid transparent; }

#toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; max-width: 92vw;
  transition: transform .2s, opacity .2s; z-index: 20; font-weight: 600; opacity: 0; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.bad { background: var(--fail); color: #fff; }

.print-only { display: none; }

@media (max-width: 520px) {
  main { padding: .75rem; }
  .card { padding: .85rem; }
  .brand small { display: none; }
}

@media print {
  body { background: #fff; color: #000; }
  body > :not(#printArea) { display: none !important; }
  #printArea { display: block !important; font-size: 11pt; }
  #printArea h1 { font-size: 16pt; } #printArea h2 { font-size: 13pt; margin-top: 1rem; }
  #printArea table { font-size: 9.5pt; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 3px 5px; }
  #printArea .run { break-inside: avoid; margin-bottom: 1rem; }
  #printArea .chip { border: 1px solid #000; background: none; color: #000; }
}

/* Measurement point tables (9.1.4 logger) */
table.pts input[type=text] { min-height: 40px; padding: .4rem .5rem; text-align: right; min-width: 4.2rem; }
table.pts td { vertical-align: middle; }
table.pts td.calc { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.pts tr.flag-warn td.calc, table.pts tr.flag-warn td:first-child { background: var(--warn-bg); }
table.pts tr.flag-bad td.calc, table.pts tr.flag-bad td:first-child { background: var(--fail-bg); }
.fitbox { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-top: .75rem; }
.fitbox > div { background: var(--accent-soft); border-radius: 10px; padding: .5rem .7rem; }
.fitbox b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.fitbox span { font-size: .78rem; color: var(--muted); }
.fitbox .bad { background: var(--fail-bg); color: var(--fail); }
.fitbox .ok { background: var(--pass-bg); color: var(--pass); }
svg.chart { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 8px; }
svg.chart text { fill: var(--muted); font-size: 11px; }
main { grid-template-columns: minmax(0, 1fr); }
label.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--accent); color: var(--accent);
  padding: .7rem 1.1rem; min-height: 46px; cursor: pointer;
}

/* Photos */
.phslot { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; margin-bottom: .6rem; }
.phhead { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; }
.ph { position: relative; display: inline-block; }
.ph img { height: 56px; width: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.ph button { position: absolute; top: -8px; right: -8px; min-height: 24px !important; padding: 0 .35rem !important; line-height: 1; border-radius: 99px; background: var(--card) !important; }
.chip.NOT_STARTED { background: var(--idle-bg); color: var(--idle); }
