:root {
  color-scheme: light;
  --surface-0: #f3f3f1;
  --surface-1: #fcfcfb;
  --border: #dcdbd6;
  --grid: #e8e7e3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-dark: #1c5cab;
  --series-1: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --captured: #9ec5f4;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--surface-0); color: var(--text-primary); }
a { color: var(--accent-dark); }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

#topbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: #1f2a36; color: #fff; position: sticky; top: 0; z-index: 10; }
#topbar .brand { color: #fff; font-weight: 700; text-decoration: none; }
#crumb { color: #cfd8e3; }
.spacer { flex: 1; }
#hw { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: #2c3a48; color: #e6edf3; white-space: nowrap; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); }
.chip.ok .dot { background: var(--good); }
.chip.bad .dot { background: var(--critical); }
.chip.warn .dot { background: var(--warning); }
.chip.sim { background: var(--warning); color: #000; font-weight: 700; }

main { padding: 16px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

button, .btn { font: inherit; padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; color: var(--text-primary); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.big { font-size: 18px; padding: 12px 22px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.danger { color: #8f1f1f; border-color: #e7b7b7; }
button.danger:hover:not(:disabled) { border-color: var(--critical); background: #fbeeee; }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * { margin-left: 6px; }
button.link { border: none; background: none; color: var(--accent-dark); padding: 0; text-decoration: underline; }
kbd { font-family: inherit; font-size: 12px; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; opacity: .8; }

input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0 0 14px; }
legend { font-weight: 600; padding: 0 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); }
th { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
td.num, th.num { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover { background: #f0f5fc; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: #fff; color: var(--text-secondary); }
.badge.uncal { border-color: var(--serious); color: #8a3a12; background: #fdf0ea; }
.badge.cal { border-color: var(--good); color: var(--good-text); background: #eef8ee; }
.badge.fail { border-color: var(--critical); color: #8f1f1f; background: #fbeeee; }

/* run screen */
.run { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr); gap: 14px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text-primary); }
.viewchecks { display: flex; gap: 18px; align-items: center; margin-bottom: 8px; }
.viewchecks label { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--text-primary); cursor: pointer; }
.viewchecks input { width: 16px; height: 16px; margin: 0; cursor: pointer; }
.viewchecks input:disabled, .viewchecks input:disabled + * { cursor: not-allowed; }
.viewchecks label:has(input:disabled) { color: var(--text-muted); }
.viewchecks #detNote { margin-left: 2px; }
.viewchecks #detNote.warnnote { color: #8a3a12; font-weight: 600; }
.camtop { width: 100%; aspect-ratio: 4 / 3; background: #222; border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.camtop img, .camside img { width: 100%; height: 100%; object-fit: contain; display: block; }
.camsides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.camside { aspect-ratio: 4 / 3; background: #222; border-radius: var(--radius); overflow: hidden; position: relative; }
.camlabel { position: absolute; left: 6px; bottom: 4px; color: #fff; font-size: 12px; text-shadow: 0 0 3px #000; }

.panhead { display: flex; align-items: baseline; gap: 12px; }
.panno { font-size: 44px; font-weight: 800; line-height: 1; }
.step { border-top: 1px solid var(--grid); padding-top: 12px; margin-top: 12px; }
.step-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.step-title .n { width: 22px; height: 22px; border-radius: 50%; background: #1f2a36; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.step-title .tick { color: var(--good-text); }
.scale-read { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stable { font-weight: 700; font-size: 13px; padding: 2px 8px; border-radius: 4px; }
.stable.yes { background: #eef8ee; color: var(--good-text); border: 1px solid var(--good); }
.stable.no { background: #f3f3f1; color: var(--text-muted); border: 1px solid var(--border); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.err { color: #8f1f1f; }

/* layout map */
.map { overflow: auto; }
.map-grid { display: grid; gap: 3px; width: max-content; }
.cell { width: 38px; height: 30px; border-radius: 4px; border: 1px solid var(--border); background: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cell.captured { background: var(--captured); color: #0d366b; }
.cell.weighed { background: #fde8b8; color: #6b4a00; }
.cell.done { background: var(--good); color: #fff; font-weight: 600; }
.cell.review { background: #bfe6bf; color: #0b4d0b; }
.unit-switch { display: inline-flex; gap: 2px; }
.unit-switch button { padding: 2px 8px; font-size: 12px; }
#topbar .unit-switch button:not(.primary) { background: #2c3a48; color: #e6edf3; border-color: #3b4b5b; }
.cell.skipped { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #e8e7e3 4px, #e8e7e3 8px); color: var(--text-muted); text-decoration: line-through; }
.cell.empty { visibility: hidden; }
.cell.current { outline: 3px solid #1f2a36; outline-offset: 1px; z-index: 1; }
.cell.flag::after { content: ""; position: absolute; right: 2px; top: 2px; width: 7px; height: 7px; border-radius: 50%; background: var(--critical); box-shadow: 0 0 0 1.5px #fff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.flagdot, .legend .flagdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--critical); margin-right: 5px; vertical-align: 1px; }
.legend .sw { display: inline-block; width: 14px; height: 12px; border-radius: 3px; border: 1px solid var(--border); vertical-align: -2px; margin-right: 4px; }

/* drawer */
#drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; justify-content: flex-end; }
#drawer[hidden] { display: none; }
#drawer .panel { width: min(980px, 96vw); height: 100%; overflow: auto; background: var(--surface-0); padding: 16px 20px; }
.imgs { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.imgs img { width: 100%; border-radius: var(--radius); background: #222; display: block; }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { font-size: 11px; fill: var(--text-muted); }
.chart .axis line, .chart .gridline { stroke: var(--grid); }
.chart .bar { fill: var(--series-1); }
.chart .bar:hover, .chart .hit:hover + .bar { fill: var(--accent-dark); }
.tip { position: absolute; pointer-events: none; background: #1f2a36; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 4px; white-space: nowrap; transform: translate(-50%, calc(-100% - 8px)); }

/* simulation bar */
body.has-sim main { padding-bottom: 96px; }
#sim { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: #fff8e6; border-top: 2px solid var(--warning); padding: 6px 16px; font-size: 13px; box-shadow: 0 -2px 10px rgba(0,0,0,.12); }
#sim[hidden] { display: none; }
#sim .bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
#sim .grp { display: inline-flex; align-items: center; gap: 4px; }
#sim button { padding: 3px 8px; font-size: 12px; }
#sim select { padding: 2px 4px; font-size: 12px; }
#sim .chk { display: inline-flex; flex-direction: row; align-items: center; gap: 4px; color: var(--text-primary); font-size: 13px; }
#sim.min .grp, #sim.min .chk, #sim.min #simScene { display: none; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30; }
#toast .t { background: #1f2a36; color: #fff; padding: 10px 16px; border-radius: var(--radius); margin-top: 6px; max-width: 70vw; }
#toast .t.err { background: var(--critical); }

/* on the dashboard (/collect/r/<rig>/) */
#topbar .rigname { color: #cfd8e3; font-size: 13px; white-space: nowrap; }
#topbar a.nav { color: #fff; font-size: 13px; white-space: nowrap; }

/* empty test list: the ways to start, centred */
.start { min-height: calc(100vh - 180px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.start h1 { font-size: 24px; margin: 0 0 4px; }
.start .choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-top: 20px; }
.start .choice { display: flex; flex-direction: column; gap: 6px; width: 300px; padding: 20px 22px; text-align: left; font: inherit;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); text-decoration: none; cursor: pointer; }
.start .choice b { font-size: 18px; }
.start .choice span { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.start .choice:hover { border-color: var(--accent); }
.start .choice.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.start .choice.primary span { color: #e3eefb; }
.start .choice.primary:hover { background: var(--accent-dark); }
/* narrow screens (phone, tablet on the dashboard): the status chips wrap instead of running off the edge */
@media (max-width: 900px) {
  #topbar { flex-wrap: wrap; row-gap: 6px; padding: 8px 12px; }
  #topbar .brand { white-space: nowrap; }
  #hw { flex-wrap: wrap; }
  .unit-switch button { white-space: nowrap; }
}
