/* ============================================================
   National Welding — Calibration & Compliance
   Mobile-first design system (NWS maroon + charcoal)
   ============================================================ */

:root {
  /* Brand */
  --nws-maroon: #8a2432;
  --nws-maroon-dark: #6c1c27;
  --nws-maroon-tint: #f6e9eb;
  --charcoal: #232526;
  --charcoal-2: #34383a;

  /* Neutrals */
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #dfe4ea;
  --line-strong: #c6cdd6;
  --ink: #1c2126;
  --ink-2: #55606c;
  --ink-3: #8a95a1;

  /* Status */
  --pass: #1f8a4c;
  --pass-bg: #e6f4ec;
  --fail: #c62b32;
  --fail-bg: #fbe8e9;
  --warn: #b9791b;
  --warn-bg: #fcf1de;
  --info: #2b6cb0;
  --info-bg: #e7f0f8;
  --na: #6b7683;
  --na-bg: #eef1f4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(20,25,30,.08), 0 6px 18px rgba(20,25,30,.06);
  --shadow-lg: 0 8px 30px rgba(20,25,30,.16);
  --nav-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.app { overflow-x: hidden; }
.list-item { overflow: hidden; }
.list-item .li-end .badge { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; }
a { color: var(--nws-maroon); text-decoration: none; }
button { font-family: inherit; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  background: var(--charcoal);
  color: #fff;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.topbar .logo-wrap {
  background: #fff; border-radius: 8px; padding: 5px 8px; display: flex; align-items: center;
}
.topbar .logo-wrap img { height: 22px; display: block; }
.topbar .title { font-size: .82rem; letter-spacing: .02em; opacity: .85; }
.topbar .title strong { display: block; font-size: .98rem; letter-spacing: 0; opacity: 1; }
.topbar .spacer { flex: 1; }
.topbar .whoami {
  display: flex; align-items: center; gap: 8px; font-size: .8rem;
  background: rgba(255,255,255,.1); padding: 5px 10px; border-radius: 20px; cursor: pointer;
}
/* ---------- Support inbox ---------- */
.tabbar a { position: relative; }
.tab-badge {
  position: absolute; top: 4px; left: 50%; margin-left: 6px;
  background: var(--nws-maroon); color: #fff; font-size: .62rem; font-weight: 800;
  min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 4px;
}
.list-item.unread .li-title { font-weight: 800; }
.list-item.unread { background: var(--info-bg); }
.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.thread .msg {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 15px; max-width: 82%;
}
.thread .msg.mine { align-self: flex-end; background: var(--nws-maroon-tint); border-color: #e6cdd2; }
.thread .msg.theirs { align-self: flex-start; }
.thread .msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.thread .msg-head strong { font-size: .84rem; }
.thread .msg-body { font-size: .92rem; line-height: 1.55; white-space: pre-wrap; }
.tiny-badge { font-size: .62rem; padding: 1px 6px; }

.topbar-icon {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.1); color: #fff; font-size: .95rem; text-decoration: none;
}
.topbar-icon:hover { background: rgba(255,255,255,.2); }
.topbar .whoami .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--nws-maroon);
  display: grid; place-items: center; font-weight: 700; font-size: .72rem;
}

.page { max-width: 1080px; margin: 0 auto; padding: 16px 14px 32px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; margin: 0; }
.page-head .sub { color: var(--ink-2); font-size: .9rem; margin: 2px 0 0; }
.page-head .grow { flex: 1; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: .9rem; margin-bottom: 6px; cursor: pointer; }

/* ---------- Bottom nav (mobile) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(20,25,30,.06);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-3); font-size: .66rem; font-weight: 600; letter-spacing: .01em;
  padding: 6px 2px;
}
.tabbar a .ic { font-size: 1.2rem; line-height: 1; }
.tabbar a.active { color: var(--nws-maroon); }
.tabbar a.active .ic { transform: translateY(-1px); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card.tight { padding: 12px; }
.card h3 { font-size: 1rem; }
.card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-title h3 { margin: 0; }
.card-title .grow { flex: 1; }
.muted { color: var(--ink-2); }
.tiny { font-size: .78rem; }
.section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; margin: 18px 0 8px; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.stat .num { font-size: 1.9rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.stat .lbl { color: var(--ink-2); font-size: .78rem; margin-top: 6px; }
.stat.accent { background: linear-gradient(140deg, var(--nws-maroon), var(--nws-maroon-dark)); color: #fff; border: none; }
.stat.accent .lbl { color: rgba(255,255,255,.85); }
.stat.warn .num { color: var(--warn); }
.stat.fail .num { color: var(--fail); }
.stat.pass .num { color: var(--pass); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 11px 16px; border-radius: var(--radius-sm); font-size: .92rem; font-weight: 600;
  cursor: pointer; transition: .12s; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--nws-maroon); border-color: var(--nws-maroon); color: #fff; }
.btn.primary:hover { background: var(--nws-maroon-dark); }
.btn.dark { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--nws-maroon); }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: .84rem; }
.btn.block { width: 100%; }
.btn.pass { background: var(--pass); border-color: var(--pass); color: #fff; }
.btn.fail { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  z-index: 45; background: var(--nws-maroon); color: #fff; border: none;
  border-radius: 28px; height: 52px; padding: 0 20px; font-weight: 700; font-size: .95rem;
  box-shadow: var(--shadow-lg); cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 700;
  padding: 3px 9px; border-radius: 20px; letter-spacing: .01em; white-space: nowrap;
}
.badge.pass { background: var(--pass-bg); color: var(--pass); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.na   { background: var(--na-bg); color: var(--na); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 600;
  padding: 4px 10px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-2);
}
.type-tag { font-weight: 700; font-size: .7rem; padding: 2px 7px; border-radius: 5px; letter-spacing: .03em; }
.type-MCT { background: #e9f6ee; color: var(--pass); }
.type-CALIBRATION { background: #fff6d6; color: #8a6d00; }
.type-VALIDATION { background: #e3f3fb; color: var(--info); }
.type-WIRESPEED { background: #fdeede; color: var(--warn); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item .li-icon {
  width: 40px; height: 40px; border-radius: 10px; background: var(--nws-maroon-tint);
  color: var(--nws-maroon); display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0;
}
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-sub { color: var(--ink-2); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-end { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list-item .chev { color: var(--ink-3); font-size: 1.1rem; flex-shrink: 0; }

/* ---------- Search ---------- */
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 9px 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.search input { border: none; outline: none; flex: 1; font-size: .95rem; background: transparent; color: var(--ink); }
.search .ic { color: var(--ink-3); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: .74rem; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=tel],
input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 16px; font-family: inherit; background: var(--surface); color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--nws-maroon); box-shadow: 0 0 0 3px var(--nws-maroon-tint); }
textarea { resize: vertical; min-height: 74px; }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: transparent; padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: .86rem; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--nws-maroon); color: #fff; }

/* ---------- Stepper ---------- */
.stepper { display: flex; align-items: center; gap: 6px; margin-bottom: 16px; }
.stepper .step { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: .8rem; font-weight: 600; }
.stepper .step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line-strong); font-size: .78rem; }
.stepper .step.on { color: var(--nws-maroon); }
.stepper .step.on .n { background: var(--nws-maroon); color: #fff; border-color: var(--nws-maroon); }
.stepper .step.done .n { background: var(--pass); color: #fff; border-color: var(--pass); }
.stepper .bar { flex: 1; height: 2px; background: var(--line); min-width: 10px; }

/* ---------- Measurement table ---------- */
.mtable-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table.mtable { width: 100%; border-collapse: collapse; font-size: .86rem; min-width: 520px; }
table.mtable th, table.mtable td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: center; }
table.mtable thead th { background: var(--surface-2); color: var(--ink-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
table.mtable th.grp { background: var(--charcoal); color: #fff; font-size: .74rem; }
table.mtable input { padding: 7px 6px; text-align: center; font-size: .9rem; }
table.mtable td.res { font-weight: 800; }
table.mtable td.res.pass { color: var(--pass); }
table.mtable td.res.fail { color: var(--fail); }
table.mtable td.res.pending { color: var(--ink-3, #9aa3ad); font-weight: 600; }
/* a measured cell awaiting a reading */
table.mtable input::placeholder { color: var(--ink-3, #b3bac2); }

/* Machine-limits reminder above the measurement table */
.minfo { background: var(--nws-maroon-tint, #f6ebef); border: 1px solid var(--line-strong); border-left: 3px solid var(--nws-maroon, #7a1f2b); border-radius: var(--radius-sm); padding: 9px 12px; font-size: .82rem; color: var(--ink-2); margin-bottom: 12px; }
.minfo b { color: var(--ink); }
/* second line inside a segmented-control button */
.seg-sub { display: block; font-size: .66rem; opacity: .72; font-weight: 500; margin-top: 1px; }

/* Standards editor (Setup) */
.std-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 8px; }
.std-group-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.std-opt { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--line); }
.std-opt:first-of-type { border-top: none; }
.std-opt .std-name { flex: 1; font-size: .86rem; }
.std-opt .star { background: none; border: none; cursor: pointer; font-size: 1.1rem; line-height: 1; color: var(--ink-3, #9aa3ad); padding: 2px 4px; }
.std-opt .star.on { color: var(--nws-maroon, #7a1f2b); }

/* Hard-stop sheet (reading out of tolerance) */
.stop-title { color: var(--fail); margin-bottom: 6px; }
.stopbox { background: var(--fail-tint, #fdecea); border: 1px solid var(--fail); color: var(--fail); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .92rem; margin: 8px 0 12px; }
.formula-box { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 12px 14px; font-size: .8rem; color: var(--ink-2); }
.formula-box b { color: var(--ink); }

/* ---------- Guided next-step banner ---------- */
.nextstep {
  display: flex; align-items: center; gap: 14px; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.nextstep.ok { background: linear-gradient(135deg,#eaf6ee,#f5fbf7); border: 1px solid #bfe3cc; }
.nextstep.due { background: linear-gradient(135deg,#fcf3df,#fdf9ef); border: 1px solid #ecd6a0; }
.nextstep.overdue, .nextstep.fail { background: linear-gradient(135deg,#fbe9ea,#fdf4f4); border: 1px solid #ecbfc2; }
.nextstep .ns-ic { font-size: 1.7rem; }
.nextstep .ns-main { flex: 1; }
.nextstep .ns-main .t { font-weight: 800; font-size: .98rem; }
.nextstep .ns-main .d { color: var(--ink-2); font-size: .84rem; }

/* ---------- Timeline ---------- */
.timeline { position: relative; margin-left: 8px; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 10px 0 10px 4px; cursor: pointer; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 16px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--line-strong); }
.tl-item.pass::before { border-color: var(--pass); background: var(--pass); }
.tl-item.fail::before { border-color: var(--fail); background: var(--fail); }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-head .ttl { font-weight: 700; font-size: .92rem; }
.tl-sub { color: var(--ink-2); font-size: .8rem; }

/* ---------- Key/val ---------- */
.kv { display: grid; grid-template-columns: 1fr; gap: 2px; }
.kv .row2 { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.kv .row2 .k { color: var(--ink-2); }
.kv .row2 .v { font-weight: 600; text-align: right; }

/* ---------- Certificate ---------- */
.cert-toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.cert {
  background: #fff; color: #111; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); max-width: 820px; margin: 0 auto; padding: 26px;
}
.cert .cert-head { display: flex; align-items: flex-start; gap: 16px; border-bottom: 3px solid var(--nws-maroon); padding-bottom: 14px; margin-bottom: 14px; }
.cert .cert-head img { height: 40px; }
.cert .cert-head .ch-main { flex: 1; }
.cert .cert-head h2 { color: var(--nws-maroon); font-size: 1.25rem; margin: 0; letter-spacing: .01em; }
.cert .cert-head .std { font-size: .78rem; color: #555; }
.cert .cert-head .rno { text-align: right; font-size: .8rem; }
.cert .cert-head .rno b { display: block; font-size: 1rem; }
.cert-sec-title { background: var(--charcoal); color: #fff; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; padding: 5px 10px; border-radius: 4px; margin: 16px 0 8px; font-weight: 700; }
.cert-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 22px; font-size: .82rem; }
.cert-grid .c { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dotted #ddd; }
.cert-grid .c .k { color: #666; }
.cert-grid .c .v { font-weight: 600; text-align: right; }
table.cert-table { width: 100%; border-collapse: collapse; font-size: .78rem; margin-top: 4px; }
table.cert-table th, table.cert-table td { border: 1px solid #ccc; padding: 5px 6px; text-align: center; }
table.cert-table th { background: var(--surface-2); }
table.cert-table td.p { color: var(--pass); font-weight: 700; }
table.cert-table td.f { color: var(--fail); font-weight: 700; }
.cert-result { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding: 12px 16px; border-radius: 6px; }
.cert-result.pass { background: var(--pass-bg); border: 1px solid #bfe3cc; }
.cert-result.fail { background: var(--fail-bg); border: 1px solid #ecbfc2; }
.cert-result .big { font-size: 1.4rem; font-weight: 800; }
.cert-result.pass .big { color: var(--pass); }
.cert-result.fail .big { color: var(--fail); }
.cert-sign { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 14px; gap: 28px; }
.cert-sign .sig { font-family: "Segoe Script", "Brush Script MT", cursive; font-size: 1.6rem; color: #14213d; padding: 0 4px 2px; min-height: 1.7rem; }
.cert-sign .sig-block { flex: 1; }
.cert-sign .sig-space { min-height: 1.7rem; }
.cert-sign .sig-line { border-bottom: 1px solid #555; margin: 2px 0 4px; }
.cert-compliance { margin-top: 14px; padding: 10px 12px; border: 1px solid #cbd5e1; border-left: 3px solid #14213d; background: #f8fafc; border-radius: 6px; font-size: .8rem; color: #334155; }
.cert-compliance b { color: #14213d; }
.cert-foot { margin-top: 20px; padding-top: 10px; border-top: 1px solid #ddd; font-size: .68rem; color: #888; text-align: center; }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,20,25,.5); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.sheet .grabber { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 0 auto 14px; }
.sheet h3 { font-size: 1.1rem; }
.choice { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; cursor: pointer; }
.choice:hover { border-color: var(--nws-maroon); background: var(--nws-maroon-tint); }
.choice .ci { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0; }
.choice .cm { flex: 1; }
.choice .cm .t { font-weight: 700; }
.choice .cm .d { font-size: .82rem; color: var(--ink-2); }
.choice.rec { border-color: var(--nws-maroon); box-shadow: 0 0 0 2px var(--nws-maroon-tint); }
.choice .rec-tag { font-size: .66rem; font-weight: 700; background: var(--nws-maroon); color: #fff; padding: 2px 7px; border-radius: 10px; }

/* ---------- Big action buttons (home) ---------- */
.action-grid { display: grid; gap: 12px; margin-bottom: 18px; }
.action {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 16px; cursor: pointer; box-shadow: var(--shadow); transition: .12s;
}
.action:hover { border-color: var(--nws-maroon); }
.action:active { transform: translateY(1px); }
.action .a-ic { width: 48px; height: 48px; border-radius: 12px; background: var(--nws-maroon-tint); color: var(--nws-maroon); display: grid; place-items: center; font-size: 1.5rem; flex-shrink: 0; }
.action .a-body { flex: 1; display: flex; flex-direction: column; }
.action .a-t { font-weight: 800; font-size: 1.05rem; }
.action .a-d { color: var(--ink-2); font-size: .84rem; }
.action .chev { color: var(--ink-3); font-size: 1.3rem; }
.action.primary { background: linear-gradient(140deg, var(--nws-maroon), var(--nws-maroon-dark)); border: none; color: #fff; }
.action.primary .a-ic { background: rgba(255,255,255,.16); color: #fff; }
.action.primary .a-d { color: rgba(255,255,255,.85); }
.action.primary .chev { color: rgba(255,255,255,.7); }

/* ---------- Test option list (home) ---------- */
.test-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.test-opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); transition: .12s;
}
.test-opt:hover { border-color: var(--nws-maroon); background: var(--nws-maroon-tint); }
.test-opt:active { transform: translateY(1px); }
.test-opt .to-ic { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.test-opt .to-main { flex: 1; min-width: 0; }
.test-opt .to-t { font-weight: 800; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.test-opt .to-tag { font-size: .64rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; background: var(--nws-maroon); color: #fff; padding: 3px 8px; border-radius: 10px; }
.test-opt .to-d { color: var(--ink-2); font-size: .84rem; }
.test-opt .chev { color: var(--ink-3); font-size: 1.3rem; }

.home-add { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 2px 0 18px; }

/* reports filter row + table */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.seg.scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.seg.scroll button { white-space: nowrap; }
table.rtable { min-width: 720px; font-size: .82rem; }
table.rtable th, table.rtable td { text-align: left; white-space: nowrap; padding: 9px 10px; }
table.rtable thead th { position: sticky; top: 0; background: var(--surface-2); }
table.rtable tbody tr { cursor: pointer; }
table.rtable tbody tr:hover { background: var(--surface-2); }
table.rtable td.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .78rem; }
table.rtable td.res { font-weight: 800; }
table.rtable td.res.pass { color: var(--pass); }
table.rtable td.res.fail { color: var(--fail); }

/* small icon (delete) button in list rows */
.icon-btn { border: none; background: transparent; cursor: pointer; font-size: 1.05rem; padding: 6px 8px; border-radius: 8px; color: var(--ink-3); flex-shrink: 0; line-height: 1; }
.icon-btn:hover { background: var(--fail-bg); color: var(--fail); }

/* ---------- Chain "next step" banner (not printed) ---------- */
.chain-next { margin-top: 4px; }
@media print { .chain-next { display: none !important; } }

/* ---------- Guidance banner ---------- */
.guide { display: flex; align-items: flex-start; gap: 12px; background: var(--info-bg); border: 1px solid #cfe0f0; color: #1f3f5c; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: .9rem; }
.guide .g-ic { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--info); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .85rem; }

/* ---------- Help chip / button ---------- */
.help-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--nws-maroon); border-radius: 20px; padding: 6px 12px; font-size: .8rem; font-weight: 700; cursor: pointer; flex-shrink: 0; }
.help-chip:hover { background: var(--nws-maroon-tint); }
.help-chip .q { display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--nws-maroon); color: #fff; font-size: .7rem; }
.help-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.help-badge { width: 30px; height: 30px; border-radius: 50%; background: var(--nws-maroon); color: #fff; display: grid; place-items: center; font-weight: 800; }
.help-body { color: var(--ink); font-size: .92rem; }
.help-body p { margin: 0 0 10px; }
.help-body ul, .help-body ol { margin: 0 0 10px; padding-left: 20px; }
.help-body li { margin-bottom: 6px; }

/* ---------- Tooltip (?) ---------- */
.qmark { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--ink-3); color: #fff; font-size: .68rem; font-weight: 800; cursor: pointer; vertical-align: middle; margin-left: 4px; }
.qmark.light { background: rgba(255,255,255,.35); }
.tippop { position: fixed; z-index: 90; max-width: 240px; background: var(--charcoal); color: #fff; font-size: .8rem; line-height: 1.4; padding: 9px 12px; border-radius: 10px; box-shadow: var(--shadow-lg); }

/* ---------- MCT screen 2 (protocol layout) ---------- */
.btn.proto { border-color: var(--info); color: var(--info); background: var(--info-bg); font-weight: 700; }
.btn.proto:hover { background: #dbe9f6; }
.mct-test-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.mct-test-head h4 { margin: 0; font-size: 1rem; }
.mct-test { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.mct-test:first-of-type { border-top: none; }
.mct-test-name { font-weight: 700; font-size: .88rem; margin-bottom: 8px; }
.mct-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px 14px; align-items: center; }
.mct-grid .mc { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mct-grid .mc-l { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; }
.mct-grid .mc-v { font-weight: 700; font-variant-numeric: tabular-nums; }
.mct-grid .mc-in { display: flex; align-items: center; gap: 6px; }
.mct-grid input.mct-meas { width: 90px; padding: 8px 10px; text-align: center; }
.mct-grid .unit { font-size: .78rem; color: var(--ink-2); }
.mct-q { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mct-q-text { font-weight: 700; font-size: .92rem; flex: 1; min-width: 180px; }
.mct-q select { width: auto; }
.proto-body p { margin: 0 0 10px; }
.proto-body ul { margin: 0 0 10px; padding-left: 20px; }
.proto-body li { margin-bottom: 4px; }
@media (max-width: 520px) {
  .mct-grid { grid-template-columns: 1fr 1fr; }
  .mct-grid .mc:last-child { grid-column: 1 / -1; }
}

/* ---------- How-to (details) ---------- */
.howto { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); overflow: hidden; }
.howto summary { cursor: pointer; padding: 13px 16px; font-weight: 700; color: var(--nws-maroon); list-style: none; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: "▸ "; }
.howto[open] summary::before { content: "▾ "; }
.howto-body { padding: 0 16px 14px; font-size: .9rem; color: var(--ink); }
.howto-body ol { margin: 0; padding-left: 20px; }
.howto-body li { margin-bottom: 8px; }

.choice.locked { opacity: .7; border-style: dashed; }
.choice.locked:hover { border-color: var(--line-strong); background: var(--surface); }

/* ---------- Empty ---------- */
.empty { text-align: center; color: var(--ink-3); padding: 40px 20px; }
.empty .e-ic { font-size: 2.4rem; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); background: var(--charcoal); color: #fff; padding: 12px 18px; border-radius: 24px; font-size: .88rem; font-weight: 600; z-index: 80; box-shadow: var(--shadow-lg); }

/* ---------- Desktop ---------- */
@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; }
}
@media (min-width: 980px) {
  .app { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .tabbar {
    position: sticky; top: 0; height: calc(100vh - 46px); flex-direction: column; width: 232px;
    border-top: none; border-right: 1px solid var(--line); box-shadow: none; padding: 14px 10px; gap: 4px;
    align-self: start;
  }
  .tabbar a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: .92rem; padding: 11px 14px; border-radius: 10px; }
  .tabbar a .ic { font-size: 1.15rem; }
  .tabbar a.active { background: var(--nws-maroon-tint); }
  .fab { display: none; }
  .page { padding: 22px 26px 40px; }
}

/* ---------- Print ---------- */
@page { size: A4; margin: 14mm; }
@media print {
  .topbar, .tabbar, .fab, .cert-toolbar, .back-link, .nextstep, .chain-next { display: none !important; }
  body, .app, .page { background: #fff; padding: 0; margin: 0; }
  .cert { box-shadow: none; border: none; max-width: 100%; padding: 0; }
  .app { display: block; }
  /* Keep each certificate together and start a new one on its own page (bulk print). */
  .cert { page-break-after: always; break-after: page; }
  .cert:last-child { page-break-after: auto; break-after: auto; }
  .cert-sign, .cert-result, .cert-table, tr { break-inside: avoid; }
  .cert-table thead { display: table-header-group; }
}

/* ---------- Sign-in ---------- */
.loggedout .tabbar, .loggedout .whoami { display: none !important; }
.loggedout.app-grid .app { display: block; }
.login-wrap { min-height: calc(100vh - var(--nav-h)); display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 28px 26px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { background: var(--charcoal); border-radius: 10px; padding: 12px; display: inline-flex; margin-bottom: 14px; }
.login-logo img { height: 30px; display: block; }
.login-card h1 { font-size: 1.25rem; margin: 0 0 2px; }
.login-card .sub { color: var(--ink-2); margin: 0 0 16px; font-size: .92rem; }
.login-card .field { text-align: left; }
.login-card form { margin-top: 6px; }
.login-msg { background: var(--info-bg); color: var(--info); border-radius: var(--radius-sm); padding: 8px 12px; font-size: .85rem; margin-bottom: 12px; }
.login-err { color: var(--fail); font-size: .85rem; min-height: 18px; margin: 2px 0 8px; text-align: left; }
.login-hint { color: var(--ink-3); font-size: .78rem; margin: 14px 0 0; }

/* Bulk print/PDF route: hide the app shell, stack the certificates. */
.printmode .topbar, .printmode .tabbar { display: none !important; }
.printmode .app { display: block !important; }
.printset .cert { margin: 0 auto 22px; }
