:root {
  color-scheme: dark; /* native date pickers, scrollbars and form controls render dark */
  --bg: #0b0b0d; --card: #16161a; --raised: #202026; --bar: #000; --ink: #ececf0; --muted: #9a9aa3; --line: #2c2c33;
  --accent-ink: #ff4d47; --ok-bg: #12301c; --bad-bg: #3a1414; --warn-bg: #3a2c0a;
  --red: #e10600; --ok: #3fb950; --bad: #ff6b6b; --warn: #e3b341;
  --radius: 10px; --tap: 44px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent-ink); }
main { padding: 12px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); max-width: 820px; margin: 0 auto; }
h1 { font-size: 1.05rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 1rem; margin: 0 0 10px; }
h3 { font-size: .9rem; margin: 12px 0 6px; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bar); color: #fff; border-bottom: 2px solid var(--red);
}
.topbar .back, .topbar .icon-link { color: #fff; text-decoration: none; font-size: 1.8rem; line-height: 1; min-width: 28px; }
.logo { background: var(--red); color: #fff; font-weight: 800; border-radius: 6px; padding: 2px 8px; }
.save-state { font-size: .75rem; color: #bbb; }
.save-state.ok { color: #7ee2a0; } .save-state.warn { color: #ffcc66; } .save-state.bad { color: #ff8a80; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; font-size: .85rem; text-align: center; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; border: 1px solid var(--line); display: block; color: inherit; text-decoration: none; }
.card.error { background: var(--bad-bg); color: var(--bad); }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; } .grow { flex: 1; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* "hidden" must win over display rules below (e.g. label { display: block }), or boxes the
   app hides, like "Describe the damage", stay on screen. */
[hidden] { display: none !important; }
label { display: block; font-size: .85rem; color: var(--muted); }
/* Phone browsers (iOS Safari especially) give date boxes a native minimum width that ignores
   width: 100% and pushes them off the card; drop the native box styling so they fit. */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea, button, .button {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  min-height: var(--tap); border-radius: 8px; border: 1px solid var(--line); padding: 8px 10px; width: 100%;
  background: var(--raised); color: inherit;
}
textarea { resize: vertical; }
button, .button { cursor: pointer; background: var(--raised); border-color: var(--line); text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; width: auto; color: var(--ink); }
button.primary, .button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.block { display: flex; width: 100%; margin-bottom: 12px; }
.small-btn { min-height: 36px; padding: 4px 10px; font-size: .85rem; }
.error-text { color: var(--bad); margin: 0; min-height: 1em; }
.warn-text { color: var(--bad); font-weight: 700; font-size: .8rem; }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; }
.chip { min-height: 36px; border-radius: 999px; padding: 4px 14px; white-space: nowrap; font-size: .9rem; }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.badge { background: var(--raised); color: var(--ink); border: 1px solid var(--red); border-radius: 6px; padding: 2px 8px; font-size: .8rem; font-weight: 700; }
.engine-card strong { font-size: 1.05rem; }

.code-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.code { min-height: 56px; font-weight: 800; font-size: 1.1rem; width: 100%; }
.code.on { background: var(--red); border-color: var(--red); color: #fff; }
.code.healthy.on { background: #238636; border-color: #238636; }
.status-tag { font-size: .75rem; font-weight: 700; border-radius: 6px; padding: 2px 8px; margin-right: 6px; }
.status-tag.healthy { color: var(--ok); background: var(--ok-bg); }
.status-tag.damaged { color: var(--bad); background: var(--bad-bg); }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: -12px -12px 12px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 4; }
.tab { padding: 8px 12px; border-radius: 8px; white-space: nowrap; text-decoration: none; color: var(--ink); font-size: .9rem; }
.tab.on { background: var(--red); color: #fff; }

.stage-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.progress-row { display: grid; grid-template-columns: 110px 1fr 56px; gap: 8px; align-items: center; color: inherit; text-decoration: none; padding: 6px 0; }
progress { width: 100%; height: 10px; accent-color: var(--red); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.thumb { padding: 0; border: 0; aspect-ratio: 1; overflow: hidden; border-radius: 8px; min-height: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 12px; }
.viewer { background: var(--card); border-radius: var(--radius); padding: 10px; max-width: 100%; max-height: 100%; overflow: auto; }
.viewer img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }

.part-group h3 { color: var(--muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .04em; }
.part-row { display: flex; gap: 6px; align-items: center; border-top: 1px solid var(--line); padding: 6px 0; }
.part-main { flex: 1; flex-direction: column; align-items: flex-start; background: none; border: 0; text-align: left; padding: 4px 0; }
.lib-row { border-top: 1px solid var(--line); padding: 8px 0; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 8px; }
.row-label { font-weight: 600; }
.cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.cell { display: flex; flex-direction: column; gap: 2px; }
.cell.inline { flex-direction: row; align-items: center; max-width: 160px; }
.cell-label { font-size: .75rem; color: var(--muted); }
.cell input { text-align: center; padding: 8px 4px; font-variant-numeric: tabular-nums; }
input.ok { border-color: var(--ok); background: var(--ok-bg); }
input.out { border-color: var(--bad); background: var(--bad-bg); }
.hint { font-size: .7rem; color: var(--muted); min-height: .9em; text-align: center; }

.item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; border-top: 1px solid var(--line); padding: 8px 0; }
.check { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--ink); flex: 1; min-height: var(--tap); }
.check input { width: 26px; height: 26px; min-height: 0; accent-color: var(--ok); flex: none; }
.item-date { width: auto; display: inline-block; min-height: 36px; padding: 4px 8px; font-size: 14px; }
.segmented { display: flex; }
.segmented button { border-radius: 0; min-height: 38px; }
.segmented button:first-child { border-radius: 8px 0 0 8px; } .segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button.on { background: var(--red); color: #fff; border-color: var(--red); }

.pattern { margin: 14px 0 0; padding: 10px; background: var(--raised); border: 1px dashed var(--line); border-radius: 8px; }
.pattern figcaption { font-weight: 600; font-size: .85rem; margin-bottom: 8px; text-align: center; }
.pattern-row { display: grid; gap: 6px; margin-bottom: 6px; }
.bolt { text-align: center; border: 2px solid var(--muted); border-radius: 999px; padding: 4px 0; font-weight: 700; font-size: .85rem; }

.locked-banner { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); font-size: .9rem; }
.post-note { border-top: 1px solid var(--line); padding: 8px 0; }
.post-note p { margin: 2px 0 0; white-space: pre-wrap; }
.damage-box textarea { border-color: var(--bad); }
input:disabled, textarea:disabled, select:disabled, button:disabled { opacity: .55; cursor: not-allowed; }
.thumb:disabled { opacity: 1; }

.ok-text { color: var(--ok); font-weight: 700; font-size: .8rem; }
.unfinished { border-color: var(--warn); }
.unfinished-group { border-top: 1px solid var(--line); padding-top: 8px; }
.unfinished-group h3 { margin: 4px 0; }
.same-reason { display: flex; gap: 6px; margin-bottom: 6px; }
.reason-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 8px; align-items: center; margin-top: 6px; color: var(--ink); }
.reason-row input { margin-top: 0; min-height: 38px; }

/* Complete: the lock button is wide, so it gets its own full-width line under the date. */
.complete-row { grid-template-columns: 90px minmax(0, 1fr); }
.complete-row button { grid-column: 1 / -1; width: 100%; min-height: var(--tap); }
