/* Worq Group Compliance — mobile-first PWA styles.
 *
 * Design tokens carried over from the prototype so the app looks like the thing
 * Andy signed off. Light and dark both supported because venue tablets are set
 * to whatever they were set to, and nobody is going to change it.
 *
 * Deliberate choices for the venue context:
 *  - tap targets are >=44px, because this is used one-handed with cold hands;
 *  - no hover-only affordances, because these are touch devices;
 *  - system fonts only, so nothing waits on a webfont over venue wifi;
 *  - safe-area insets respected, since it runs full-screen from the home screen.
 */

:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --surface-page:   #f9f9f7;
  --surface-card:   #ffffff;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --border:         rgba(11, 11, 11, 0.10);
  --accent:         #2a78d6;
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  /* An open issue is a fault to go and fix, not a date in the diary, so it gets
   * its own hue rather than sharing the amber of "due soon". Purple sits outside
   * the red-amber-green scale, which is the point: it reads as "flagged". */
  --status-issue:    #8b46c9;
  --status-good-bg:     #e8f7e8;
  --status-warning-bg:  #fef3da;
  --status-issue-bg:    #f1e7fb;
  --status-serious-bg:  #fbe6dd;
  --status-critical-bg: #f9dede;
  --warning-ink:  #7a5300;
  --issue-ink:    #5c2a87;
  --serious-ink:  #8a3d1f;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-page:   #0d0d0d;
    --surface-card:   #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --border:         rgba(255, 255, 255, 0.12);
    --accent:         #3987e5;
    --status-critical: #e66767;
    --status-issue:    #b07ce6;
    --status-good-bg:     #163016;
    --status-warning-bg:  #3a2f10;
    --status-issue-bg:    #2d1f3d;
    --status-serious-bg:  #3a2419;
    --status-critical-bg: #3a1a1a;
    --warning-ink:  #fab219;
    --issue-ink:    #c79cf0;
    --serious-ink:  #ec835a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The browser's own [hidden] rule is `display: none` at zero specificity, so any
 * class rule below that sets `display` beats it — which silently left the offline
 * banner and the full-screen evidence modal permanently on screen. Everything in
 * this file toggles visibility via the hidden attribute, so it has to win. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--surface-page);
  color: var(--text-primary);
  font-size: 16px;                 /* 16px minimum stops iOS zooming on focus */
}

button, input, textarea, select { font-family: inherit; font-size: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* The real WORQ mark rather than a "WQ" placeholder. Height-constrained with
 * auto width so the aspect ratio survives, and it sits on the card background
 * in both themes because the mark is a solid orange with no white in it. */
.brand-mark {
  height: 26px; width: auto; flex-shrink: 0; display: block;
}
.brand-text { line-height: 1.25; min-width: 0; }
.brand-text .name { font-weight: 700; font-size: 15px; }
.brand-text .sub {
  font-size: 12.5px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  min-width: 44px; min-height: 44px;
  border: none; background: transparent; color: var(--text-secondary);
  font-size: 19px; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-1); }
.icon-btn-initials {
  font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
  background: var(--surface-1); border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 50%;
  min-width: 38px; width: 38px; height: 38px; min-height: 38px;
}
.icon-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Banners ---------- */
.banner {
  padding: 9px 16px;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.banner-offline { background: var(--status-warning-bg); color: var(--warning-ink); }
.banner-queue { background: var(--status-serious-bg); color: var(--serious-ink); }
/* The "moved" notice. Deliberately the loudest banner in the app: someone on the
 * old address is being told their browser may call this a scam, and the fix is a
 * two-minute reinstall they will otherwise never do. */
.banner-moved {
  background: var(--status-critical-bg); color: var(--status-critical);
  align-items: flex-start;
}
.banner-moved a.banner-btn { text-decoration: none; white-space: nowrap; align-self: center; }
.banner-btn {
  margin-left: auto; flex-shrink: 0;
  border: 1px solid currentColor; background: transparent; color: inherit;
  padding: 6px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
}
.loading-note, .empty-note {
  color: var(--text-muted); font-size: 14px; padding: 28px 0; text-align: center;
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 20px 0 8px;
}
.section-head h2 { font-size: 19px; margin: 0; }
.section-head .meta { font-size: 12.5px; color: var(--text-secondary); flex-shrink: 0; }

.back-link {
  background: none; border: none; color: var(--accent);
  font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 10px 0; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px;
}

/* ---------- Venue picker ---------- */
.venue-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px; margin-top: 12px;
}
.venue-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 8px; color: inherit;
}
.venue-card:active { border-color: var(--accent); }
.venue-card .vname { font-size: 16px; font-weight: 700; }
.venue-card .vloc { font-size: 12.5px; color: var(--text-secondary); }
.venue-card .vstats { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill-good     { background: var(--status-good-bg);     color: var(--status-good); }
.pill-warning  { background: var(--status-warning-bg);  color: var(--warning-ink); }
.pill-issue    { background: var(--status-issue-bg);    color: var(--issue-ink); }
.pill-serious  { background: var(--status-serious-bg);  color: var(--serious-ink); }
.pill-critical { background: var(--status-critical-bg); color: var(--status-critical); }
.pill-muted    { background: var(--surface-1); color: var(--text-secondary); }
/* Never recorded: grey, not red. We don't know anyone missed it - only that
 * there's no record. Red here would swamp the checks that really are late. */
.pill-unrecorded {
  background: var(--surface-1); color: var(--text-secondary);
  border: 1px dashed var(--baseline);
}

/* ---------- Venue score ---------- */
/* Staff see how their own site is doing — never a comparison against other
 * venues, which they can't see at all. */
.score {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-top: 14px;
}
.score-body { flex: 1; min-width: 0; }
.score-headline { font-size: 15px; line-height: 1.3; }
.score-legend { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }
.tone-good     { color: var(--status-good); }
.tone-warning  { color: var(--warning-ink); }
.tone-issue    { color: var(--issue-ink); }
.tone-critical { color: var(--status-critical); }
.tone-muted    { color: var(--text-secondary); }

/* Ring */
.ring { width: 74px; height: 74px; flex-shrink: 0; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--gridline); stroke-width: 8; }
.ring-value {
  fill: none; stroke-width: 8; stroke-linecap: round;
  transition: stroke-dasharray 0.5s ease;
}
.ring-text {
  transform: rotate(90deg); transform-origin: 40px 40px;
  font-size: 19px; font-weight: 700; fill: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.score-good     .ring-value { stroke: var(--status-good); }
.score-warning  .ring-value { stroke: var(--status-warning); }
.score-critical .ring-value { stroke: var(--status-critical); }

/* Proportional split — "62%" alone doesn't say whether that's 2 things or 20 */
.score-bar {
  display: flex; height: 8px; border-radius: 5px; overflow: hidden;
  background: var(--gridline); margin-top: 8px;
}
.seg { height: 100%; }
.seg + .seg { margin-left: 2px; }
.seg-good       { background: var(--status-good); }
.seg-warning    { background: var(--status-warning); }
.seg-issue      { background: var(--status-issue); }
.seg-critical   { background: var(--status-critical); }
.seg-unrecorded { background: var(--baseline); }

/* ---------- Per-check trend ---------- */
.check-trend { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-pass { background: var(--status-good); }
.dot-fail { background: var(--status-critical); }
.spark { display: inline-flex; align-items: center; line-height: 0; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.spark-head { fill: var(--accent); }
.spark-limit { stroke: var(--status-critical); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.55; }
.spark-breach .spark-line, .spark-breach .spark-head { stroke: var(--status-critical); fill: var(--status-critical); }

/* A colour rail down the card so the worst items are findable by scrolling,
 * not by reading every pill. */
.check-card.status-critical   { border-left: 4px solid var(--status-critical); }
.check-card.status-serious    { border-left: 4px solid var(--status-serious); }
.check-card.status-warning    { border-left: 4px solid var(--status-warning); }
.check-card.status-issue      { border-left: 4px solid var(--status-issue); }
.check-card.status-good       { border-left: 4px solid var(--status-good); }
.check-card.status-unrecorded { border-left: 4px solid var(--baseline); }

/* Reading entry: a dedicated sign button beside the field.
 * iOS renders inputmode="decimal" as a keypad with no minus key, so without this
 * a negative reading simply cannot be typed on a phone. */
.reading-input { display: flex; gap: 8px; align-items: stretch; }
.reading-input input { flex: 1; min-width: 0; }
.sign-btn {
  flex-shrink: 0; min-width: 52px; min-height: 44px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-1); color: var(--text-primary);
  font-size: 19px; font-weight: 700; cursor: pointer;
}
.sign-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* One-tap correction inside the warning. */
.fix-btn {
  margin-left: 6px; padding: 5px 10px; min-height: 34px;
  border: 1px solid currentColor; border-radius: 8px;
  background: transparent; color: inherit;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}

/* A suspect reading, flagged while it is still being typed. Amber not red: it
 * is very often a slip of the minus key rather than a broken freezer. */
.reading-warning {
  margin-top: 6px; padding: 7px 10px; border-radius: 8px;
  background: var(--status-warning-bg); color: var(--warning-ink);
  font-size: 12.5px; line-height: 1.35; font-weight: 600;
}

/* ---------- Filter chips ---------- */
.filter-row {
  display: flex; gap: 7px; margin: 14px -16px 4px; padding: 2px 16px 6px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--border); background: var(--surface-card);
  color: var(--text-secondary); border-radius: 999px;
  padding: 9px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.chip.active {
  background: var(--text-primary); color: var(--surface-card);
  border-color: var(--text-primary);
}

.group-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin: 20px 0 8px;
}

/* ---------- Check cards ---------- */
.check-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
}
.check-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.check-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.check-cat { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.check-last { font-size: 12.5px; color: var(--text-secondary); margin-top: 5px; }
.check-instructions {
  font-size: 13px; color: var(--text-secondary); margin-top: 9px; line-height: 1.5;
}
.check-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 11px; }
.log-btn {
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  padding: 11px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; min-height: 44px;
}
.log-btn:active { background: var(--accent); color: #fff; }
.text-btn {
  border: none; background: none; color: var(--text-secondary);
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 11px 4px; min-height: 44px;
}

/* ---------- Log form ---------- */
.log-form { margin-top: 13px; padding-top: 13px; border-top: 1px dashed var(--border); }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.form-row label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.form-row .hint { font-size: 11.5px; color: var(--text-muted); font-weight: 400; }
.form-row input, .form-row textarea, .form-row select {
  border: 1px solid var(--border); border-radius: 9px; padding: 12px;
  background: var(--surface-1); color: var(--text-primary);
  min-height: 44px; width: 100%;
}
.form-row textarea { resize: vertical; min-height: 68px; line-height: 1.45; }
.pass-fail { display: flex; gap: 8px; }
.pf-btn {
  flex: 1; padding: 13px 8px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-1);
  font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--text-secondary); min-height: 48px;
}
.pf-btn.sel-pass.selected {
  background: var(--status-good-bg); border-color: var(--status-good); color: var(--status-good);
}
.pf-btn.sel-fail.selected {
  background: var(--status-critical-bg); border-color: var(--status-critical); color: var(--status-critical);
}
.submit-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 14px 18px; border-radius: 10px;
  font-size: 15px; font-weight: 700; cursor: pointer; width: 100%; min-height: 50px;
}
.submit-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.form-error {
  background: var(--status-critical-bg); color: var(--status-critical);
  border-radius: 9px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}
.required-note { color: var(--status-critical); font-weight: 600; }

/* ---------- Evidence ---------- */
.evidence-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.capture-btn {
  border: 1px dashed var(--border); background: var(--surface-1);
  color: var(--text-secondary); border-radius: 10px;
  padding: 12px 14px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; min-height: 48px;
}
.thumb-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb {
  position: relative; width: 74px; height: 74px; border-radius: 9px;
  overflow: hidden; border: 1px solid var(--border); background: var(--surface-1);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-muted); text-align: center; cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .thumb-kind { font-size: 22px; }
.thumb-remove {
  position: absolute; top: 2px; right: 2px;
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer;
}
.thumb-note {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 10px; line-height: 1.5; text-align: center;
}
.thumb-progress {
  position: absolute; bottom: 0; left: 0; height: 3px;
  background: var(--accent); transition: width 0.2s ease;
}
.thumb.failed { border-color: var(--status-critical); }

/* ---------- History ---------- */
.history-item {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: 11px; padding: 12px 14px; margin-bottom: 9px;
}
.history-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.history-when { font-size: 13.5px; font-weight: 600; }
.history-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; }
.history-notes {
  font-size: 13px; margin-top: 7px; padding-left: 10px;
  border-left: 2px solid var(--gridline); color: var(--text-secondary);
}
.history-item.superseded { opacity: 0.62; }
.tag {
  display: inline-block; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 5px; margin-right: 5px;
  background: var(--surface-1); color: var(--text-muted);
}
.tag-correction { background: var(--status-warning-bg); color: var(--warning-ink); }
.tag-superseded { background: var(--surface-1); color: var(--text-muted); }
.tag-demo { background: var(--status-critical-bg); color: var(--status-critical); }

/* ---------- Admin ---------- */
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; margin: 4px -16px 12px; padding: 0 16px 6px; }
.admin-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
}
.admin-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--gridline);
}
.admin-row:last-child { border-bottom: none; }
.admin-row-editing { background: var(--surface-1); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.admin-card-editing { border-color: var(--accent); }
.admin-row .label { font-size: 14px; font-weight: 600; }
.admin-row .sub { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.switch {
  flex-shrink: 0; min-width: 62px; min-height: 40px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-1); color: var(--text-secondary);
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.switch.on { background: var(--status-good-bg); border-color: var(--status-good); color: var(--status-good); }
.inline-input {
  width: 78px; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); text-align: center;
}
.link-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.link-btn {
  border: 1px solid var(--border); background: var(--surface-card);
  color: var(--text-secondary); border-radius: 9px;
  padding: 11px 14px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 44px;
  display: inline-flex; align-items: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  background: var(--text-primary); color: var(--surface-card);
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600; max-width: 90vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 60;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--status-critical); color: #fff; }

/* ---------- Account sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-inner {
  background: var(--surface-card); width: 100%; max-width: 480px;
  border-radius: 16px 16px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
}
.sheet-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
}
.sheet-name { font-size: 20px; font-weight: 700; margin-top: 6px; }
.sheet-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; word-break: break-all; }
.sheet-note { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin: 14px 0 18px; }
.sheet-cancel { display: block; width: 100%; text-align: center; margin-top: 6px; }

/* ---------- Evidence modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.85);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-inner { position: relative; max-width: 100%; max-height: 100%; }
.modal-inner img, .modal-inner video { max-width: 100%; max-height: 84vh; border-radius: 10px; display: block; }
.modal-close {
  position: absolute; top: -46px; right: 0;
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, 0.2); color: #fff;
  font-size: 17px; cursor: pointer;
}
.modal-note { color: #fff; font-size: 14px; text-align: center; padding: 20px; }
