/* SmartCertPro — phone-first. One design that stretches to desktop.
   Big touch targets, obvious labels, honest state colours (design law). */

:root {
  --brand: #12507a;
  --brand-dark: #0e3f61;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1a2733;
  --muted: #5c6b7a;
  --line: #d9e0e6;
  --ok: #1c7c3f;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fdf3e0;
  --err: #b3261e;
  --err-bg: #fce9e8;
  --queued: #1f5fa8;
  --queued-bg: #e7f0fb;
  --radius: 12px;
  --tap: 48px; /* minimum touch target */
  --maxw: 720px;
  font-size: 17px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over a class that sets display.
   (Without this, .topbar/.sidenav/.nudge { display: … } override [hidden] and
   an invisible overlay silently swallows taps.) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(env(safe-area-inset-top), 10px) 14px 10px;
  background: var(--brand);
  color: #fff;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; flex: 0 0 auto; }
.topbar .queue-pill { margin-left: auto; }
.topbar .linkbtn { color: #fff; }

/* ---- layout ---- */
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 14px calc(96px + env(safe-area-inset-bottom));
}
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.sidenav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 14px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sidenav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}
.sidenav a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- home tiles ---- */
.tiles { display: grid; gap: 12px; margin-bottom: 16px; }
.tile { transition: border-color 0.1s; }
.tile:active { border-color: var(--brand); }

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin: 0 0 16px;
}
h1 { font-size: 1.5rem; margin: 4px 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---- forms ---- */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="tel"], input[type="url"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid #bcd7ee; border-color: var(--brand); }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.linkbtn {
  background: none;
  border: none;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
  padding: 6px 8px;
}
.iconbtn {
  background: none; border: none; color: inherit; font-size: 1.3rem;
  min-width: 44px; min-height: 44px; cursor: pointer;
}

/* ---- honest state pills ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}
.pill.ok     { background: var(--ok-bg);     color: var(--ok); }
.pill.saving { background: var(--queued-bg); color: var(--queued); }
.pill.queued { background: var(--queued-bg); color: var(--queued); }
.pill.failed { background: var(--err-bg);    color: var(--err); }
.pill.refused{ background: var(--err-bg);    color: var(--err); }
.pill.held   { background: var(--warn-bg);   color: var(--warn); }
.pill.sending{ background: var(--queued-bg); color: var(--queued); }
.pill.warn   { background: var(--warn-bg);   color: var(--warn); }

/* The queue pill is a real touch target (Build 3.1): tapping it opens the queue. */
.queue-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 0.85rem; background: rgba(255,255,255,0.18); color: #fff; cursor: pointer; border: none; }
.queue-pill:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Queue screen (Build 3.1) — every unlanded item, its state, reason and way out. */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.queue-list { list-style: none; margin: 8px 0 0; padding: 0; }
.queue-row { border: 1px solid var(--line, #e2e2e2); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.queue-label { font-weight: 700; }
.queue-reason { margin-top: 6px; color: var(--muted, #666); }
.queue-row.state-held .queue-reason,
.queue-row.state-refused .queue-reason { color: var(--err, #b00); font-weight: 600; }
.queue-ways { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 10px; }
.queue-content { margin-top: 10px; padding: 10px; background: #f7f7f7; border-radius: 8px; font-size: 0.9rem; }
.queue-content > div { margin: 2px 0; }
.queue-servmsg { margin-bottom: 8px; font-weight: 600; }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.linkbtn.danger { color: var(--err, #b00); }

.savebar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.savebar .status { min-height: 32px; display: inline-flex; align-items: center; }

/* ---- logo preview ---- */
.logo-preview {
  display: block;
  max-width: 180px;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
  margin: 8px 0;
}

/* ---- messages ---- */
.msg { padding: 12px 14px; border-radius: 10px; margin: 12px 0; font-weight: 600; }
.msg.ok  { background: var(--ok-bg);  color: var(--ok); }
.msg.err { background: var(--err-bg); color: var(--err); }

/* ---- diagnostics tables / logs ---- */
.logrow { border-bottom: 1px solid var(--line); padding: 10px 0; font-size: 0.9rem; }
.logrow .ts { color: var(--muted); font-size: 0.8rem; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #eef2f5; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.tag.err { background: var(--err-bg); color: var(--err); }
.tag.ok  { background: var(--ok-bg);  color: var(--ok); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }
.scroll { overflow-x: auto; }

/* ---- build badge ---- */
.build-badge {
  position: fixed;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 30;
  background: rgba(26, 39, 51, 0.82);
  color: #fff;
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}

/* ---- install nudge ---- */
.nudge {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 12px;
}
.nudge-body {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  padding: 16px;
  max-width: var(--maxw);
  width: 100%;
}
.nudge-body strong { display: block; margin-bottom: 4px; }
.nudge-body p { margin: 4px 0 12px; color: var(--muted); }
.nudge-actions { display: flex; align-items: center; gap: 10px; }

/* ---- update bar (loud, app-wide; app.js sets the wording + tappability) ---- */
.updatebar {
  position: fixed;
  left: 0; right: 0;
  top: 0;
  z-index: 60;
  background: var(--brand, #12507a);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.28);
}
.updatebar.tappable { cursor: pointer; }
.updatebar.tappable::after { content: ' ›'; }

/* ---- broken-store banner (loud, app-wide) ---- */
.bootbanner {
  position: sticky;
  top: 0;
  z-index: 25;
  background: var(--err);
  color: #fff;
  font-weight: 700;
  padding: 12px 14px;
  text-align: center;
}
.bootbanner .muted { color: #ffe3e1; }

/* ---- record lists (people, instruments, presets) ---- */
.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
  text-align: left;
}
.rec-row .grow { flex: 1 1 auto; min-width: 0; }
.rec-row .title { font-weight: 700; }
.rec-row .sub { color: var(--muted); font-size: 0.9rem; }
.rec-row.retired { opacity: 0.6; }
.rowbtn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer;
}
.rowbtn:active { border-color: var(--brand); }

/* ---- calibration badge ---- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-weight: 700; font-size: 0.78rem; white-space: nowrap;
}
.badge.in-date  { background: var(--ok-bg);   color: var(--ok); }
.badge.due-soon { background: var(--warn-bg); color: var(--warn); }
.badge.overdue  { background: var(--err-bg);  color: var(--err); }
.badge.unknown  { background: #eef2f5;        color: var(--muted); }

/* ---- overdue-warning component (informs, never blocks) ---- */
.warn-box {
  background: var(--warn-bg); border: 1px solid #e6c98a; color: var(--warn);
  border-radius: 10px; padding: 12px 14px; margin: 10px 0; font-weight: 600;
}
.warn-box.overdue { background: var(--err-bg); border-color: #e6a9a4; color: var(--err); }

/* ---- usual-kit slots ---- */
.kit-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.kit-row label { flex: 0 0 42%; margin: 0; }
.kit-row select { flex: 1 1 auto; min-height: var(--tap); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; }

/* ---- select boxes generally ---- */
select { font-size: 1rem; color: var(--ink); }
.field-select { width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; }

/* ---- system-preset flag + move buttons ---- */
.sysflag { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 6px; background: #eef2f5; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.move-btns { display: inline-flex; gap: 4px; }

/* ---- temp password, shown once ---- */
.temp-pass {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.15rem; font-weight: 700;
  background: var(--ok-bg); color: var(--ok);
  padding: 10px 14px; border-radius: 10px; display: inline-block; margin: 6px 0;
  user-select: all;
}

/* ---- signature preview ---- */
/* Reserve the preview's height so choosing a signature never shifts the form
   (no layout jump under the thumb — and the Save button never moves mid-tap). */
#sigWrap { min-height: 96px; display: flex; align-items: center; }
.sig-preview { display: block; max-width: 260px; max-height: 120px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; margin: 8px 0; }

/* ---- desktop stretch: the same design, wider and calmer ---- */
@media (min-width: 900px) {
  :root { --maxw: 860px; }
  .view { padding-top: 28px; }
  .form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .form-2col .full { grid-column: 1 / -1; }
}

/* --- Build 3: clients, properties, the certificate shell ------------------ */
.listhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.listhead h1 { margin: 0; }
.stale-line { margin: 4px 0 10px; font-style: italic; }

/* filter chips + picker search */
.filterbar { display: flex; gap: 8px; margin: 10px 0; }
.chip {
  display: inline-block; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-weight: 700; cursor: pointer; min-height: 40px;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.picker-search {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); font-size: 1rem; margin: 6px 0 12px; box-sizing: border-box;
}
.picker-results { display: flex; flex-direction: column; gap: 8px; }
.picker-row {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; min-height: 48px;
}
.picker-row:active { border-color: var(--brand); }
.picker-main { display: block; font-weight: 700; }
.picker-sub { display: block; color: var(--muted); font-size: 0.9rem; }
.picker-empty { padding: 8px 0; }
.picker-add {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px;
  border: 1px dashed var(--brand); background: var(--card); color: var(--brand); font-weight: 700;
  cursor: pointer; min-height: 48px;
}

/* certificate flow + rows */
.flow-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.cert-row { margin-bottom: 10px; }
.cert-row-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.cert-row-date { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.cert-row h2 { margin: 2px 0; }

/* draft field rows + conflict */
.draft-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.draft-row:last-child { border-bottom: none; }
.draft-label { color: var(--muted); font-size: 0.85rem; }
.draft-value { font-weight: 700; }
.conflict { border: 1px solid var(--warn, #b8860b); }
.conflict p { margin: 6px 0; }
.dup-nudge { margin-top: 8px; }

/* ---- Build 4: boards, the board screen, toggles, photo ---- */
.save-sticky { position: sticky; top: 0; z-index: 5; padding: 6px 0; background: var(--bg); min-height: 30px; }
.board-section h2 { margin-top: 0; }
.bfield { padding: 10px 0; border-bottom: 1px solid var(--line); }
.bfield:last-child { border-bottom: none; }
.bfield-label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.binput, .bselect {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-size: 1rem; min-height: 48px;
}
.binput.greyed, .binput:disabled { opacity: 0.55; background: var(--bg); }
.bfree { margin-top: 8px; }
.bfixed { font-weight: 700; }

/* PASS/FAIL/LIM/N/A — big one-tap targets; tap the selected one again to clear */
.verdict-group { display: flex; gap: 8px; flex-wrap: wrap; }
.verdict {
  flex: 1 1 60px; min-height: 48px; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer;
}
.verdict.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* numeric with first-class LIM / N/A chips */
.numrow { display: flex; gap: 8px; align-items: center; }
.numrow .bnum { flex: 1 1 auto; }
.numflag {
  min-height: 48px; min-width: 56px; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer;
}
.numflag.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.numflag:disabled { opacity: 0.45; }

/* ---- Build 6: readings (chips, keypad, three-way, list line, section nav) ---- */
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip:disabled { opacity: 0.45; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chiprow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.rchip { min-width: 56px; padding: 8px 14px; }
.rinput, .cont-input { font-variant-numeric: tabular-nums; }
.cont-seg { margin-bottom: 8px; }
.cont-input { margin-top: 8px; }
.rfield-err { display: block; color: var(--err); font-size: 0.85rem; margin-top: 4px; }
.rfield-err:empty { display: none; }
.rcd-at-line { margin: 8px 0; }
.section-nav { margin-top: 12px; display: flex; gap: 8px; }
.circuit-row-readings {
  display: block; color: var(--muted); font-size: 0.8rem; margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* fold-away sub-board device */
.fold-head {
  display: flex; width: 100%; justify-content: space-between; align-items: center;
  background: none; border: none; padding: 4px 0; font-size: 1.1rem; font-weight: 700; cursor: pointer;
}
.fold-note { margin: 2px 0 8px; }

/* photo */
.board-photo { margin: 4px 0 10px; }
.board-photo-thumb { max-width: 100%; max-height: 240px; border-radius: 10px; border: 1px solid var(--line); display: block; }
.board-photo.placeholder {
  display: flex; align-items: center; justify-content: center; height: 120px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 10px; background: var(--bg);
}
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.photo-btn { cursor: pointer; }
.checkline { display: flex; align-items: center; gap: 8px; min-height: 44px; }

/* the draft's Boards list */
.board-list { list-style: none; margin: 8px 0 0; padding: 0; }
.board-list li { margin-bottom: 8px; }
.board-row {
  display: flex; width: 100%; align-items: center; gap: 12px; text-align: left;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; min-height: 56px;
}
.board-row-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.board-row-thumb.none {
  display: flex; align-items: center; justify-content: center; font-size: 0.62rem; color: var(--muted);
  border: 1px dashed var(--line); background: var(--bg); text-align: center;
}
.board-row-main { flex: 1 1 auto; display: flex; flex-direction: column; }
.board-row-name { font-weight: 700; }
.board-row-sub { color: var(--muted); font-size: 0.9rem; }
.board-row-caret { color: var(--muted); font-size: 1.4rem; }
.tag.board-scope { background: var(--queued-bg); color: var(--queued); }

/* Build 4.3 — the local-store degraded banner (B2) and the reset escape. */
.storage-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 60;
  background: var(--err-bg); color: var(--err);
  padding: 8px 12px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.storage-banner .btn.small { white-space: nowrap; }
.reset-escape { margin-top: 8px; }
.reset-escape .btn { margin-right: 8px; }
