:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --card: #fffdf8;
  --sunk: #ebe7dd;
  --rule: #c9c2b2;
  --soft: #e0dbcf;
  --ink: #1d1c19;
  --muted: #5c584f;
  --green: #2f5f3d;
  --button-ink: #fff;
  --bad: #b03a2e;
  --bad-soft: #f6e3e0;
  --serif: 'Iowan Old Style','Palatino Linotype',Palatino,Georgia,serif;
  --bg: var(--paper);
  --text: var(--ink);
  --text-3: var(--muted);
  --line: var(--rule);
  --line-soft: var(--soft);
}

:root[data-theme=dark] {
  color-scheme: dark;
  --paper: #191713;
  --card: #211e18;
  --sunk: #2c2820;
  --rule: #524b3a;
  --soft: #3b362b;
  --ink: #f2eee3;
  --muted: #c5bdab;
  --green: #6faa80;
  --button-ink: #0f1a12;
  --bad: #e08174;
  --bad-soft: #3a221e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  accent-color: var(--green);
}

::selection {
  background: #dcc48f;
  color: #1d1c19;
}

a {
  color: var(--green);
  text-underline-offset: 4px;
}

button,input,select,textarea {
  font: inherit;
  color: inherit;
  max-width: 100%;
  min-width: 0;
}

button,.button {
  cursor: pointer;
  min-height: 48px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 11px 16px;
  background: var(--card);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:active,.button:active {
  transform: translateY(1px);
}

.primary {
  background: var(--green);
  color: var(--button-ink);
  border-color: var(--green);
  font-weight: 600;
}

.danger {
  color: var(--bad);
  background: var(--bad-soft);
}

button:disabled {
  opacity: .55;
  cursor: wait;
}

input,select,textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-size: 16px;
  caret-color: var(--green);
}

textarea {
  min-height: 108px;
  resize: vertical;
}

input[type=checkbox] {
  width: 24px;
  height: 24px;
  min-height: 24px;
}

input[readonly] {
  background: var(--sunk);
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
}

fieldset {
  padding: 0;
  border: 0;
  margin: 0;
  min-width: 0;
}

fieldset:disabled {
  opacity: .8;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}

h1,h2,h3 {
  font-family: var(--serif);
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  font-size: 30px;
  margin: 12px 0;
}

h2 {
  font-size: 23px;
  margin: 0 0 20px;
}

h3 {
  font-size: 19px;
  margin: 12px 0;
}

p {
  overflow-wrap: anywhere;
}

.muted,small {
  color: var(--muted);
}

small {
  font-size: 12px;
}

.appbar {
  max-width: 760px;
  margin: auto;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  text-decoration: none;
}

.wordmark span {
  display: block;
  font: 12px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  color: var(--muted);
}

#saveState {
  font-size: 12px;
  text-align: right;
  max-width: 40%;
}

main {
  max-width: 720px;
  padding: 24px 20px 120px;
  margin: auto;
}

.heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.heading h1 {
  margin: 0;
}

.heading .primary {
  flex-shrink: 0;
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 3;
}

.tabs a {
  width: min(50%,360px);
  min-height: 58px;
  display: grid;
  place-items: center;
  text-decoration: none;
  font-weight: 600;
}

.tabs a[aria-current=page] {
  border-top: 3px solid var(--green);
}

section {
  margin: 32px 0;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 20px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 16px;
}

.grid .wide {
  grid-column: 1/-1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.row {
  padding: 18px 0;
  border-bottom: 1px solid var(--soft);
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
}

.jobrow {
  text-decoration: none;
  color: var(--ink);
}

.jobrow strong {
  display: block;
  font-family: var(--serif);
  font-size: 21px;
}

.jobrow p {
  margin: 5px 0;
}

.stamp {
  display: inline-block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  border: 1px solid currentColor;
  padding: 3px 7px;
  border-radius: 2px;
  white-space: nowrap;
  color: var(--green);
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #7a5710;
  border-radius: 50%;
  margin-right: 5px;
}

.jobmeta {
  min-width: 94px;
  text-align: right;
}

.empty {
  padding: 38px 0;
}

.banner,.checklist {
  padding: 16px;
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: 6px;
  margin: 20px 0;
}

.checklist {
  border-color: var(--bad);
}

.checklist a {
  display: block;
  padding: 12px 0;
  color: var(--bad);
}

.kitcard {
  padding: 18px 0;
  border-bottom: 1px solid var(--soft);
}

.kitcard .heading {
  margin: 0 0 16px;
}

.kitcard h3 {
  margin: 0;
}

details {
  border-bottom: 1px solid var(--soft);
}

summary {
  cursor: pointer;
  min-height: 56px;
  padding: 16px 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

summary span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  margin: 4px 0 0 18px;
}

details .grid {
  margin: 12px 0 20px;
}

.warning {
  color: var(--bad);
  padding: 12px;
  background: var(--bad-soft);
  border-radius: 4px;
}

.reading {
  font-variant-numeric: tabular-nums;
}

.inspection {
  display: grid;
  grid-template-columns: minmax(0,1fr) 90px;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--soft);
  font-size: 14px;
}

.photos {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 4px;
}

.photos button {
  padding: 0;
  border: 0;
  border-radius: 0;
  aspect-ratio: 1;
  overflow: hidden;
}

.photos img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

dialog {
  max-width: min(700px,94vw);
  max-height: 90dvh;
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px;
}

dialog::backdrop {
  background: #0009;
}

dialog img {
  display: block;
  max-width: 100%;
  max-height: 65dvh;
  margin: 12px auto;
}

canvas.signature {
  display: block;
  width: 100%;
  height: 160px;
  background: white;
  border: 1px solid var(--rule);
  border-radius: 4px;
  touch-action: none;
}

.signature-preview {
  max-height: 80px;
  max-width: 100%;
  background: white;
}

#notice {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%,660px);
  padding: 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 4px;
  z-index: 10;
}

.back {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
}

.settings-group {
  background: var(--card);
  padding: 16px;
  border: 1px solid var(--soft);
  border-radius: 6px;
}

.template-choice {
  display: block;
  width: 100%;
  margin: 8px 0;
}

.btn--block {
  width: 100%;
  margin: 5px 0;
}

.scan {
  position: fixed;
  inset: 0;
  background: var(--card);
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.scan__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.scan__stage {
  position: relative;
  flex: 1;
  min-height: 160px;
  background: #000;
  overflow: hidden;
}

.scan__stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan__reticle {
  position: absolute;
  inset: 25% 12%;
  border: 2px solid white;
  border-radius: 4px;
}

.scan__hint,.scan__sub {
  padding: 0 16px;
}

.scan__foot {
  padding: 12px 16px;
  overflow: auto;
  max-height: 45dvh;
}

.scan__thumbs {
  display: flex;
  overflow: auto;
  gap: 8px;
}

.scan__thumbs img {
  width: 80px;
  height: 70px;
  object-fit: cover;
}

.scan-open {
  overflow: hidden;
}

.scan__x {
  font-size: 24px;
}

.scan__stage.is-off {
  flex: 0 0 160px;
}

.scan__busy {
  color: white;
}

.save-error {
  color: var(--bad);
}

[hidden] {
  display: none!important;
}

@media(hover:hover) {
  button:hover,.button:hover {
    filter: brightness(.95);
  }
  .jobrow:hover {
    background: var(--sunk);
  }
}

@media(max-width:420px) {
  main {
    padding-inline: 16px;
  }
  .appbar {
    padding-inline: 16px;
  }
  .grid {
    gap: 12px;
  }
  .heading {
    gap: 10px;
  }
  .heading h1 {
    font-size: 27px;
  }
  .jobrow {
    align-items: flex-start;
    gap: 10px;
  }
  .jobrow strong {
    font-size: 20px;
  }
  .jobmeta {
    min-width: 88px;
  }
  .actions button {
    flex-grow: 1;
  }
}

@media(prefers-reduced-motion:no-preference) {
  main {
    animation: enter 180ms cubic-bezier(.16,1,.3,1);
  }
  @keyframes enter {
    from {
      transform: translateY(5px);
    }
    to {
      transform: translateY(0);
    }
  }
}

main {
  padding-bottom: calc(160px + env(safe-area-inset-bottom));
}

.job-primary {
  position: fixed;
  bottom: calc(58px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--rule);
  padding: 12px 16px;
  z-index: 2;
}

.job-primary button {
  display: block;
  width: 100%;
  max-width: 680px;
  margin: auto;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.chips button {
  border-radius: 24px;
  padding: 8px 14px;
}

.chips button[aria-pressed=true] {
  border-color: var(--green);
  background: var(--sunk);
}

.signin {
  max-width: 400px;
  margin: 40px auto;
  border: 0;
}

.signin form, #inviteFields {
  display: grid;
  gap: 20px;
}

.invite-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
}

.signin button {
  width: 100%;
}

.readings-row {
  margin: 16px 0;
}

.circuit-row {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 12px;
}

.circuit-row details {
  border: 0;
}

#saveState {
  cursor: pointer;
}

#saveState {
  min-height: 48px;
  padding: 4px 8px;
  border: 0;
  background: transparent;
}

.ro {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}

.ro strong {
  color: var(--ink, inherit);
  font-size: 15px;
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#saveState[hidden] {
  display: none;
}
.tabs[hidden] { display: none; }

.photo-checklist { list-style: none; padding: 0; margin: 12px 0 20px; }
.photo-checklist li + li { border-top: 1px solid var(--rule); }
.evidence-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 0;
  cursor: pointer;
}
.evidence-row > span:nth-child(2) { flex: 1; min-width: 0; }
.evidence-row img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.camera-label { color: var(--green); font-weight: 600; }
.evidence-row:focus-within { outline: 2px solid var(--green); outline-offset: 3px; }
.evidence-row input[type=file] {
  display: block;
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.photo-item { min-width: 0; }
.photo-item > button { width: 100%; }
.photo-item p { overflow-wrap: anywhere; }
#customerSignoff { margin: 24px 0; }
.photos { gap: 12px; }
@media (max-width: 600px) {
  .photos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
