/* Mobile-first styling for driverchecks.ajanderson.co.uk */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --bar: #1e293b;
  --brand: #1d4ed8;
  --green: #16a34a;
  --green-soft: #bbf7d0;
  --green-ink: #166534;
  --red: #dc2626;
  --red-soft: #fecaca;
  --red-ink: #991b1b;
  --amber-bg: #fef3c7;
  --amber-ink: #92400e;
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body.driver-body {
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ---------- top bar ---------- */
.d-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bar);
  color: #fff;
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
.d-bar-back {
  background: none;
  border: 0;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px 4px 2px;
  cursor: pointer;
}
.d-bar-title { flex: 1; min-width: 0; }
.d-bar-title strong { display: block; font-size: 1.05rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-bar-title small { display: block; font-size: .78rem; color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-bar-logout { margin: 0; }
.d-bar-btn {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 7px;
  padding: 6px 11px;
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- layout ---------- */
.d-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 12px 36px;
}
.d-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
  margin-bottom: 14px;
}
.d-card-flush { padding: 0; overflow: hidden; }
.d-card h1 { font-size: 1.35rem; margin: 0 0 6px; }
.d-muted { color: var(--muted); margin: 0 0 14px; font-size: .92rem; }
.d-small { font-size: .84rem; }

/* ---------- alerts ---------- */
.d-alert {
  padding: 11px 13px;
  border-radius: 9px;
  margin-bottom: 14px;
  font-size: .92rem;
  font-weight: 500;
}
.d-alert-red { background: #fee2e2; color: var(--red-ink); border: 1px solid #fecaca; }

/* ---------- forms ---------- */
.d-form { display: flex; flex-direction: column; gap: 14px; }
.d-field { display: flex; flex-direction: column; gap: 6px; }
.d-field > span { font-size: .88rem; font-weight: 700; color: var(--ink-2); }
.d-field > small { font-size: .8rem; color: var(--muted); }
.d-field input,
.d-field select,
.d-field textarea {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #f8fafc;
  border: 1.5px solid var(--line-2);
  border-radius: 9px;
  padding: 12px 12px;
  width: 100%;
  appearance: auto;
}
.d-field input:focus,
.d-field select:focus,
.d-field textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .15);
}
.d-reg-input { text-transform: uppercase; font-weight: 700; letter-spacing: .06em; font-size: 1.15rem !important; }
.d-pin-input { font-size: 1.3rem !important; letter-spacing: .28em; text-align: center; font-weight: 700; }

/* ---------- buttons ---------- */
.d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  border: 0;
  border-radius: 10px;
  padding: 13px 18px;
  cursor: pointer;
  width: 100%;
}
.d-btn:disabled { opacity: .6; cursor: wait; }
.d-btn-lg { padding: 15px 18px; font-size: 1.05rem; }
.d-btn-primary { background: var(--brand); color: #fff; }
.d-btn-green { background: var(--green); color: #fff; }
.d-btn-camera { background: #cbd5e1; color: #1e293b; }
.d-link-btn {
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--brand);
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.d-link-muted { color: var(--muted); }

/* ---------- summary strip ---------- */
.d-summary-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 12px;
  font-size: .88rem;
  color: var(--ink-2);
}

/* ---------- checklist rows (Truckcom-inspired) ---------- */
.d-check-row {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}
.d-check-row:last-child { border-bottom: 0; }
.d-check-row.missing { background: #fff7ed; box-shadow: inset 4px 0 0 #ea580c; }
.d-check-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.d-check-label {
  font-size: .98rem;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
  min-width: 0;
}
.d-check-btns {
  display: flex;
  gap: 8px;
  flex: none;
}
.d-choice {
  min-width: 78px;
  padding: 11px 12px;
  border-radius: 8px;
  border: 2px solid transparent;
  font: inherit;
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.d-choice-defect {
  background: #fde2e2;
  color: #7f1d1d;
}
.d-choice-defect.selected {
  background: var(--red);
  color: #fff;
  border-color: #991b1b;
}
.d-choice-ok {
  background: #dcfce7;
  color: #14532d;
}
.d-choice-ok.selected {
  background: var(--green);
  color: #fff;
  border-color: #166534;
}

/* recorded defect pills under a checklist row */
.d-row-defects {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.d-def-pill {
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: .86rem;
}
.d-def-pill-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  color: var(--red-ink);
  margin-bottom: 3px;
}
.d-def-pill-notes { color: var(--ink-2); margin-bottom: 6px; white-space: pre-wrap; }
.d-def-pill-actions { display: flex; gap: 14px; font-size: .82rem; }
.d-add-another {
  align-self: flex-start;
  background: none;
  border: 1px dashed var(--red);
  color: var(--red-ink);
  border-radius: 7px;
  padding: 6px 10px;
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
}

/* declarations */
.d-decl-row { background: #fafafa; }
.d-decl-text { margin: 0 0 10px; font-size: .95rem; font-weight: 500; color: var(--ink); }
.d-decl-btns { justify-content: flex-end; }

/* signature */
.d-sig-section { padding: 14px; background: #fff; }
.d-sig-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.d-sig-name {
  font: inherit;
  font-size: 1rem;
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--line-2);
  padding: 8px 4px;
  margin-bottom: 12px;
  background: transparent;
}
.d-sig-name:focus { outline: none; border-bottom-color: var(--brand); }
.d-sig-pad-wrap {
  position: relative;
  height: 170px;
  background: #dbeafe;
  border: 1.5px solid #93c5fd;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
}
.d-sig-pad-wrap canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.d-sig-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #475569;
  font-weight: 600;
  pointer-events: none;
}

/* ---------- defect entry screen ---------- */
.d-defect-cat-tag {
  display: inline-block;
  background: #fee2e2;
  color: var(--red-ink);
  font-weight: 700;
  font-size: .88rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.d-defect-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
  margin-top: 4px;
}
.d-defect-sub-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 2px;
}
.d-photo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.d-photo-item {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line-2);
}
.d-photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-photo-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 0;
  background: rgba(15, 23, 42, .8);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  line-height: 1;
  cursor: pointer;
}

/* ---------- confirmation screen ---------- */
.d-done-card { text-align: center; padding: 28px 18px; }
.d-done-icon {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
}
.d-done-icon.ok { background: #dcfce7; color: var(--green); }
.d-done-icon.warn { background: var(--amber-bg); color: var(--amber-ink); }
.d-done-icon.bad { background: #fee2e2; color: var(--red); }
.d-done-extra {
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 14px 0 20px;
  font-size: .9rem;
}
.d-done-extra p { margin: 4px 0; }
.d-done-actions { display: flex; flex-direction: column; gap: 10px; }
