/*
 * Built for a phone held in one hand, in sun, possibly with a glove on.
 * Big targets, high contrast, nothing that needs precision.
 */

:root {
  --bg: #151c24;
  --panel: #1e2732;
  --line: #2d3947;
  --ink: #f2f5f8;
  --dim: #9fb0c0;
  --accent: #f08a24;
  --ok: #3fa96a;
  --danger: #cc3b3b;
  --tap: 52px; /* minimum touch target */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Never let the page bounce past the fixed bars. */
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ─── Bars ─────────────────────────────────────────────────────────────── */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.job {
  background: none;
  border: none;
  color: var(--ink);
  font-size: 18px;
  font-weight: 650;
  padding: 6px 0;
}

.date { color: var(--dim); font-size: 14px; margin-left: auto; }

.offline {
  background: #45321a;
  color: #ffcf8a;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  min-height: var(--tap);
  background: none;
  border: none;
  color: var(--dim);
  font-size: 15px;
}

.tab.active { color: var(--accent); font-weight: 650; }

/* ─── Layout ───────────────────────────────────────────────────────────── */

main { padding: 14px; }
.screen { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.grow { flex: 1; min-width: 140px; }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0 4px; width: 100%; }

.lbl {
  color: var(--dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
}

.head { font-weight: 650; margin: 4px 0; }
.hint { color: var(--dim); font-size: 14px; margin: 4px 0; }
.warn { background: #45321a; color: #ffcf8a; padding: 10px; border-radius: 10px; font-size: 14px; }

/* ─── Controls ─────────────────────────────────────────────────────────── */

input, textarea, select {
  width: 100%;
  min-height: var(--tap);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  padding: 12px;
  font: inherit;
  /* 16px+ stops iOS zooming the page when a field is focused. */
  font-size: 17px;
}

textarea { min-height: 120px; resize: vertical; }

.note-wrap { position: relative; }
.mic {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 20px;
}
.mic.on { background: var(--accent); }

.qty { display: flex; align-items: center; gap: 8px; }
.qty input { flex: 1; }
.unit { color: var(--dim); min-width: 34px; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: center;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1200; }
.btn.secondary { background: var(--panel); }
.btn.ghost { background: none; color: var(--dim); }
.btn.danger { background: none; border-color: var(--danger); color: #ff8b8b; }
.btn.big { min-height: 60px; font-size: 19px; width: 100%; }
.btn:active { filter: brightness(0.88); }
.small { min-height: 40px; padding: 8px 12px; border-radius: 10px; }

/* ─── Chips ────────────────────────────────────────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.chip.on { background: var(--accent); border-color: var(--accent); color: #1b1200; font-weight: 650; }
.chip small { display: block; color: inherit; opacity: 0.75; font-size: 12px; }

/* ─── GPS ──────────────────────────────────────────────────────────────── */

.gps {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: none;
  color: var(--dim);
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.gps.ok { color: var(--ok); border-style: solid; }
.gps.bad { color: #ffb4b4; }

/* ─── Photos ───────────────────────────────────────────────────────────── */

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; }
.thumb img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.thumb button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

/* ─── Lists ────────────────────────────────────────────────────────────── */

.list { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--ink);
  font: inherit;
}

.item .top { display: flex; gap: 10px; align-items: baseline; }
.item .time { font-variant-numeric: tabular-nums; font-weight: 650; }
.item .code { color: var(--accent); font-weight: 650; }
.item .qty-badge { margin-left: auto; color: var(--dim); font-size: 14px; }
.item .note { color: var(--ink); margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--dim); font-size: 13px; margin-top: 4px; }
.item .nogps { color: #ffb4b4; }

.preview {
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
  max-height: 46vh;
}

/* ─── Banner and toast ─────────────────────────────────────────────────── */

.banner {
  margin: 10px 14px 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
}
.banner p { margin: 0 0 8px; font-size: 15px; }
.banner-actions { display: flex; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #0c1016;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 16px;
  border-radius: 999px;
  font-size: 15px;
  z-index: 10;
  max-width: 92vw;
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 160ms ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* ─── SOPs and task runs ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: auto;
}
.badge.draft { background: #45321a; color: #ffcf8a; }
.badge.review { background: #1d3a4a; color: #9fdcff; }
.badge.approved { background: #1d3d2a; color: #9fe0b5; }
.badge.retired { background: #333; color: #aaa; }

.group { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; margin: 10px 0 2px; }
.group.sub { text-transform: none; letter-spacing: 0; margin-top: 4px; }

.item.run { border-left: 4px solid var(--accent); }
.item.run.done { border-left-color: var(--ok); opacity: 0.85; }
.item .action { margin-left: auto; color: var(--accent); font-weight: 650; font-size: 14px; }
.item .delay { color: #ffcf8a; }

.timer { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 15px; }
.pos { font-weight: 650; }
.steptitle { font-size: 21px; font-weight: 700; margin: 6px 0 0; line-height: 1.3; }
.mistake { background: #2a1d1d; border-left: 4px solid var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 15px; margin: 0; }
.mistake::before { content: "Common mistake: "; font-weight: 650; color: #ff8b8b; }

.illustration { width: 100%; max-height: 42vh; object-fit: contain; background: #fff; border-radius: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

details { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
details summary { min-height: 46px; display: flex; align-items: center; font-weight: 650; color: var(--dim); cursor: pointer; }
details[open] summary { color: var(--ink); }
details .md { padding-bottom: 12px; }

.checklist { display: flex; flex-direction: column; gap: 6px; }
.checklist label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
}
.checklist input[type="checkbox"] { width: 26px; height: 26px; min-height: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.checklist label.on { border-color: var(--ok); }

/* Rendered markdown from the SOP files. Everything is textContent. */
.md { font-size: 16px; line-height: 1.5; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin-bottom: 4px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 6px; line-height: 1.25; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 17px; } .md h4 { font-size: 16px; color: var(--dim); }
.md blockquote { margin: 0 0 10px; padding: 8px 12px; border-left: 3px solid var(--line); color: var(--dim); }
.md table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel); }
.md .stepcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 0 0 10px; }
.md .stepcard h3 { margin-top: 0; }
.md .tag { color: var(--dim); font-size: 14px; margin: 6px 0 0; }
.md .tag b { color: var(--ink); }
.md .why { border-left: 3px solid var(--accent); padding-left: 10px; }

/* The hidden attribute must win over every display rule above. Without this,
   .screen { display: flex } and .btn { display: inline-flex } quietly show
   hidden screens and buttons stacked below the live one. */
[hidden] { display: none !important; }

/* ─── Punch lists, SWMP walks, header identity ─────────────────────────── */

.bar .who { color: var(--dim); font-size: 13px; }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; margin-left: auto; }
.status.open { background: #45321a; color: #ffcf8a; }
.status.claimed { background: #1d3a4a; color: #9fdcff; }
.status.passed { background: #1d3d2a; color: #9fe0b5; }
.status.returned { background: #4a1d1d; color: #ffb4b4; }
.steer { font-size: 22px; font-weight: 700; text-align: center; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.steer small { display: block; font-size: 13px; color: var(--dim); font-weight: 400; margin-top: 4px; }
.bigphoto { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 12px; background: #000; }
.linkbox { font: 14px ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: #0f1319; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

/* The SOP reader's fold for reviewer material: quiet, at the bottom. */
details.reviewer { margin-top: 18px; border-style: dashed; }
details.reviewer summary { color: var(--dim); }

/* ─── CDOT pay-item picker ─────────────────────────────────────────────── */

.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips.scroll .chip { flex: none; white-space: nowrap; }
.chip.more { color: var(--dim); border-style: dashed; }

.results { max-height: 46vh; overflow-y: auto; }
.results .item { min-height: 52px; padding: 10px 12px; }
.results .item .top { align-items: center; }
.results .item .short { color: var(--ink); }
.results .group { margin: 2px 0; }
.results .hint { padding: 4px 2px; }

.codecard { border-color: var(--accent); }
.codecard .note { white-space: normal; }
.codecard .clear {
  margin-left: 8px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

/* ─── SWMP quick picks: measures the worker records ────────────────────── */

.measures { display: flex; flex-direction: column; gap: 8px; }
.measure { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.measure input { flex: 0 0 120px; }
.measure .mlabel { flex: 1; font-size: 15px; }
.measure .mlabel small { display: block; color: var(--dim); font-size: 13px; }
.measure .unit { min-width: 48px; }
.paid .change { background: none; border: none; color: var(--accent); font: inherit; font-size: 14px; padding: 0 4px; min-height: 32px; text-decoration: underline; }
.warnpanel { border-color: var(--danger); }
.warnpanel p { margin: 0; }
