/* Engineer app.
   System fonts only -- a webfont is a network dependency, and this app has to
   work in a property with no signal. Large tap targets throughout: this is used
   one-handed, often with gloves, often in poor light. */

:root {
  --ink:        #16212b;
  --ink-soft:   #4a5a68;
  --ink-faint:  #7d8b97;
  --ground:     #eaeef1;
  --surface:    #ffffff;
  --rule:       #d3dbe1;
  --rule-soft:  #e6ebef;

  --accent:     #0a5c7a;
  --accent-ink: #ffffff;
  --go:         #1a6e39;
  --stop:       #a3301f;
  --stop-bg:    #f7e9e6;
  --warn:       #8a6100;
  --warn-bg:    #faf0d6;
  --info-bg:    #e7f1f5;
  --paused:     #8a6100;

  --tap: 3rem;
  --pad: 1rem;
  --radius: 4px;

  /* We supply both palettes, so the browser must not force-darken the page --
     Chrome and Brave on Android will otherwise invert it themselves and the
     result is nobody's design. */
  color-scheme: light dark;
}

/* Handsets are used outdoors in daylight and in unlit roof spaces, so both
   themes have to hold up. Tokens only -- no component styles in here. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:        #e4eaef;
    --ink-soft:   #a8b6c1;
    --ink-faint:  #8494a0;
    --ground:     #0c1116;
    --surface:    #161e25;
    --rule:       #33414c;
    --rule-soft:  #232d36;

    --accent:     #2b90b5;
    --accent-ink: #06171f;
    --go:         #3f9e63;
    --stop:       #e07a63;
    --stop-bg:    #2e1c18;
    --warn:       #d9ad4a;
    --warn-bg:    #2b2416;
    --info-bg:    #12242c;
    --paused:     #d9ad4a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

/* ---------- app frame ---------- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 34rem;
  margin: 0 auto;
  background: var(--ground);
}

header.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: #ffffff;
  padding: 0.75rem var(--pad);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--tap);
}

header.bar h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header.bar .sub {
  font-size: 0.75rem;
  opacity: 0.85;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn {
  appearance: none;
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 1.1rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.iconbtn:disabled { opacity: 0.35; cursor: default; }

/* display:grid above outranks the user-agent [hidden] rule, so state it. */
.iconbtn[hidden] { display: none; }
.iconbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

main {
  flex: 1;
  padding: var(--pad);
  display: grid;
  gap: var(--pad);
  align-content: start;
}

/* ---------- connection + queue status ---------- */

#netbar {
  display: none;
  padding: 0.5rem var(--pad);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  background: var(--warn-bg);
  color: var(--warn);
  border-bottom: 1px solid var(--rule);
}

#netbar.show { display: block; }

/* ---------- generic surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--pad);
  display: grid;
  gap: 0.75rem;
}

.card > h2 {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

.rows { display: grid; gap: 0.85rem; }

.row { display: grid; gap: 0.15rem; }

.row dt {
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

.row dd { margin: 0; font-size: 1rem; }

.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
}

.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn.secondary {
  background: var(--surface);
  color: var(--accent);
}

.btn.go { background: var(--go); border-color: var(--go); }
.btn.stop { background: var(--stop); border-color: var(--stop); }

.btn.ghost {
  background: transparent;
  border-color: var(--rule);
  color: var(--ink);
}

.btnrow { display: grid; gap: 0.6rem; grid-auto-flow: row; }
.btnrow.two { grid-template-columns: 1fr 1fr; }

/* ---------- job list ---------- */

.joblist { display: grid; gap: 0.6rem; }

.job {
  appearance: none;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.85rem var(--pad);
  cursor: pointer;
  display: grid;
  gap: 0.3rem;
  width: 100%;
}

.job:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.job[data-status="in_progress"] { border-left-color: var(--go); }
.job[data-status="paused"]      { border-left-color: var(--paused); }
.job[data-status="travelling"],
.job[data-status="on_site"]     { border-left-color: var(--accent); }
.job[data-status="completed"]   { border-left-color: var(--rule); opacity: 0.6; }
.job[data-status="no_access"]   { border-left-color: var(--stop); }

.job .ref {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.job .addr { font-weight: 600; line-height: 1.3; }

.job .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.15rem;
}

.pill {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 2px;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.pill.go     { color: var(--go); }
.pill.paused { color: var(--paused); background: var(--warn-bg); }
.pill.stop   { color: var(--stop); }
.pill.plain  { color: var(--ink-faint); }
.pill.emerg  { color: var(--stop); background: var(--stop-bg); }

/* ---------- forms ---------- */

label.field { display: grid; gap: 0.35rem; }

label.field > span {
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.65rem 0.7rem;
  min-height: var(--tap);
  width: 100%;
}

textarea { min-height: 7rem; resize: vertical; line-height: 1.45; }

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

label.check {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  min-height: var(--tap);
  cursor: pointer;
}

label.check input { width: 1.35rem; height: 1.35rem; flex: none; accent-color: var(--accent); }

/* ---------- big yes/no ---------- */

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.choice button {
  appearance: none;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  min-height: 5rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid;
}

.choice .yes { border-color: var(--go); color: var(--go); background: var(--surface); }
.choice .no  { border-color: var(--stop); color: var(--stop); background: var(--surface); }
.choice button[aria-pressed="true"].yes { background: var(--go); color: #fff; }
.choice button[aria-pressed="true"].no  { background: var(--stop); color: #fff; }

/* ---------- photos ---------- */

.shots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  gap: 0.5rem;
}

.shot {
  position: relative;
  aspect-ratio: 1;
  background: var(--rule-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }

.shot .queued {
  position: absolute;
  inset: auto 0 0 0;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
  padding: 0.15rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.counter {
  font-size: 0.85rem;
  font-weight: 600;
}

.counter.short { color: var(--stop); }
.counter.met { color: var(--go); }

/* ---------- signature ---------- */

#sigpad {
  width: 100%;
  height: 11rem;
  background: var(--surface);
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  touch-action: none;
  display: block;
}

.stored { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 0.5rem; }

.stored button {
  background: var(--surface);
  border: 2px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.4rem;
  cursor: pointer;
  min-height: 4rem;
}

.stored button[aria-pressed="true"] { border-color: var(--accent); }
.stored img { width: 100%; height: 3rem; object-fit: contain; display: block; }

/* ---------- notices ---------- */

.notice {
  border: 1px solid;
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 0.75rem var(--pad);
  font-size: 0.9rem;
  display: grid;
  gap: 0.35rem;
}

.notice.warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.notice.stop { border-color: var(--stop); background: var(--stop-bg); color: var(--stop); }
.notice.info { border-color: var(--accent); background: var(--info-bg); color: var(--accent); }
.notice strong { font-weight: 700; }

/* ---------- steps ---------- */

.steps {
  display: flex;
  gap: 0.3rem;
  padding: 0 var(--pad);
  margin-top: 0.75rem;
}

.steps span {
  flex: 1;
  height: 3px;
  background: var(--rule);
  border-radius: 2px;
}

.steps span.done { background: var(--accent); }

footer.actions {
  position: sticky;
  bottom: 0;
  background: var(--ground);
  border-top: 1px solid var(--rule);
  padding: 0.75rem var(--pad);
  display: grid;
  gap: 0.6rem;
}

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
