/* RFD Truck Checks — Rowayton Hose Co. No. 1
   Brand: letterhead navy #141c4c, red accent from the badge, ivory paper.
   Light palette on :root; dark redefines tokens only (system + explicit). */

:root {
  --navy: #141c4c;            /* letterhead navy — headers, placards */
  --navy-ink: #f2f2ee;        /* text on navy */
  --navy-line: #2a3468;
  --paper: #f6f5f1;
  --card: #ffffff;
  --ink: #1a1d24;
  --muted: #5b626e;
  --line: #dcdad2;
  --accent: #b3261e;          /* engine red */
  --accent-ink: #ffffff;
  --sky: #70b0e0;             /* lighthouse sky, subtle accents only */
  --ok: #1a7f37;  --ok-bg: #e6f3ea;
  --warn: #8a5300; --warn-bg: #fbf0da;
  --bad: #b3261e;  --bad-bg: #fae8e6;
  --skip: #4a5568; --skip-bg: #e9edf2;
  --shadow: 0 1px 3px rgba(16, 20, 40, .10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #0e1334; --navy-ink: #e8e9ef; --navy-line: #262e5c;
    --paper: #13151b; --card: #1d2027; --ink: #e9e8e3; --muted: #9aa1ac;
    --line: #33373f; --accent: #e0574d; --accent-ink: #ffffff; --sky: #5d99c8;
    --ok: #57c07c; --ok-bg: #1c3124;
    --warn: #e3a44b; --warn-bg: #362b15;
    --bad: #ef6c61; --bad-bg: #3a201d;
    --skip: #9aa7b8; --skip-bg: #262c36;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --navy: #0e1334; --navy-ink: #e8e9ef; --navy-line: #262e5c;
  --paper: #13151b; --card: #1d2027; --ink: #e9e8e3; --muted: #9aa1ac;
  --line: #33373f; --accent: #e0574d; --accent-ink: #ffffff; --sky: #5d99c8;
  --ok: #57c07c; --ok-bg: #1c3124;
  --warn: #e3a44b; --warn-bg: #362b15;
  --bad: #ef6c61; --bad-bg: #3a201d;
  --skip: #9aa7b8; --skip-bg: #262c36;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
/* Generous clearance: the fixed bottom bar can reach ~200px when compartment
   names wrap to two lines — the last item row must always scroll clear of it. */
#app.has-bottombar { padding-bottom: calc(230px + env(safe-area-inset-bottom)); }

/* ---------- brand header (home) ---------- */
.brand-band {
  background: var(--card); border-bottom: 3px solid var(--navy);
  border-top: 6px solid var(--navy);
}
.brand-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.brand-inner img { width: 58px; height: 58px; object-fit: contain; }
.brand-name { color: var(--navy); font-weight: 800; font-size: 19px; letter-spacing: .04em; }
:root[data-theme="dark"] .brand-name { color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-name { color: var(--ink); } }
.brand-sub { color: var(--muted); font-size: 11.5px; letter-spacing: .18em; font-weight: 600; }

/* ---------- topbar (inner views) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: var(--navy-ink);
  border-bottom: 3px solid var(--accent);
  padding-top: env(safe-area-inset-top); /* installed-app: keep clear of the clock/notch */
}
.topbar-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; min-height: 56px;
}
.topbar h1 {
  margin: 0; font-size: 16.5px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .07em;
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .sub { font-size: 12px; letter-spacing: .03em; opacity: .75; font-weight: 500; text-transform: none; }
.backbtn, .topbtn {
  appearance: none; border: 0; background: rgba(255,255,255,.13);
  color: var(--navy-ink); border-radius: 9px;
  font: inherit; font-size: 14.5px; font-weight: 700; padding: 10px 13px; cursor: pointer;
  min-height: 44px;
}
.comp-switch {
  appearance: none; border: 0; background: rgba(255,255,255,.13); color: var(--navy-ink);
  border-radius: 9px; font: inherit; cursor: pointer;
  flex: 1; min-width: 0; text-align: left;
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; min-height: 46px;
}
.comp-switch .cname {
  flex: 1; min-width: 0;
  /* names like "Compartment #1 - Driver's Side - Top Drawer" must stay
     readable — allow two lines instead of cutting off the important tail */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-weight: 800; font-size: 14.5px; line-height: 1.2; text-transform: uppercase; letter-spacing: .03em;
}
.comp-switch .cpos { font-size: 12px; opacity: .8; font-weight: 600; white-space: nowrap; }
.comp-switch .caret { opacity: .7; font-size: 12px; }
.progress { height: 5px; background: rgba(255,255,255,.15); }
.progress > div { height: 100%; background: var(--accent); transition: width .2s; }

/* ---------- generic ---------- */
.wrap { padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.card .pad { padding: 16px; }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 16px;
  min-height: 52px; padding: 12px 18px;
}
.btn:focus-visible, .backbtn:focus-visible, .topbtn:focus-visible, .comp-switch:focus-visible,
input:focus-visible, textarea:focus-visible, .stepper button:focus-visible,
.item-main:focus-visible, .item-flag:focus-visible, .tab:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-navy { background: var(--navy); color: var(--navy-ink); }
.btn-ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.98); filter: brightness(.94); }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 3px 10px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.pill-ok   { background: var(--ok-bg);   color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad  { background: var(--bad-bg);  color: var(--bad); }
.pill-skip { background: var(--skip-bg); color: var(--skip); }
.pill-mut  { background: var(--paper);   color: var(--muted); border: 1px solid var(--line); }
.pill.pill-wrap { white-space: normal; text-align: right; max-width: 55%; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
input[type="text"], input[type="password"], input[type="tel"], textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--paper); border: 2px solid var(--line); border-radius: 10px;
  padding: 12px; min-height: 50px;
}
textarea { resize: vertical; }
.notice { border-left: 4px solid var(--warn); background: var(--warn-bg); color: var(--ink); border-radius: 8px; padding: 12px 14px; font-size: 14.5px; }
.notice.good { border-left-color: var(--ok); background: var(--ok-bg); }
.err { border-left: 4px solid var(--bad); background: var(--bad-bg); color: var(--ink); border-radius: 8px; padding: 12px 14px; font-size: 14.5px; }

/* ---------- top tab strip ---------- */
.toptabs {
  position: sticky; top: 0; z-index: 25;
  background: var(--navy); border-bottom: 3px solid var(--accent);
  padding-top: env(safe-area-inset-top);
}
.toptabs .inner { max-width: 640px; margin: 0 auto; display: flex; }
.toptab {
  appearance: none; background: none; border: 0; cursor: pointer; font: inherit;
  flex: 1; min-height: 52px; padding: 8px 4px; position: relative;
  color: var(--navy-ink); opacity: .6;
  font-weight: 800; font-size: 14px; letter-spacing: .07em; text-transform: uppercase;
}
.toptab.active { opacity: 1; background: rgba(255,255,255,.13); }
.toptab .tbadge {
  display: inline-block; margin-left: 6px; vertical-align: 2px;
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 800; padding: 1px 7px;
}
.toptab:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- home ---------- */
.rig-head {
  background: var(--navy); color: var(--navy-ink);
  padding: 12px 16px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.rig-head .name { font-size: 19px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.motto { text-align: center; color: var(--muted); font-size: 12.5px; font-style: italic; padding: 4px 0 8px; }
.footer-tools { display: flex; gap: 18px; justify-content: center; padding: 0 0 10px; }
.footer-tools button { appearance: none; background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; min-height: 44px; }

/* ---------- check flow ---------- */
.itemlist { display: flex; flex-direction: column; }
.item-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); background: var(--card); }
.item-row:last-child { border-bottom: 0; }
.item-row.is-missing { background: var(--bad-bg); }
.item-row.is-damaged { background: var(--warn-bg); }
.item-row.is-skipped { background: var(--skip-bg); }
.item-main {
  appearance: none; border: 0; background: none; cursor: pointer;
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 6px 10px 14px;
  text-align: left; font: inherit; color: var(--ink);
}
.item-main:active { background: rgba(20,28,76,.06); }
.tick {
  flex: 0 0 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 800; color: transparent;
}
.is-ok .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.is-missing .tick { background: var(--bad); border-color: var(--bad); color: #fff; }
.is-damaged .tick { background: var(--warn); border-color: var(--warn); color: #fff; }
.is-skipped .tick { background: var(--skip); border-color: var(--skip); color: #fff; }
.item-meta { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 16px; }
.qty-chip {
  flex: 0 0 auto; align-self: center;
  background: var(--paper); border: 2px solid var(--line); border-radius: 9px;
  padding: 5px 10px; white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px; font-weight: 800; color: var(--muted);
}
.qty-chip.multi { color: var(--ink); border-color: var(--muted); font-size: 16.5px; }
.qty-chip.long { font-size: 12px; white-space: normal; max-width: 92px; text-align: center; line-height: 1.25; color: var(--ink); }
.qty-chip.mini { padding: 1px 7px; font-size: 12px; border-width: 1px; }
.qty-chip.mini.multi { font-size: 13px; }
.add-item-row {
  appearance: none; cursor: pointer; font: inherit;
  background: none; border: 0; border-top: 2px dashed var(--line);
  width: 100%; min-height: 56px; padding: 12px;
  color: var(--muted); font-weight: 700; font-size: 14.5px;
}
.add-item-row:active { background: var(--paper); }
.flagnote { font-size: 13px; font-weight: 700; margin-top: 2px; }
.is-missing .flagnote { color: var(--bad); }
.is-damaged .flagnote { color: var(--warn); }
.is-skipped .flagnote { color: var(--skip); }
.issue-badge {
  display: inline-block; margin-top: 3px;
  font-size: 12.5px; font-weight: 700; color: var(--warn);
  background: var(--warn-bg); border-radius: 6px; padding: 2px 7px;
}
.item-flag {
  appearance: none; cursor: pointer; font: inherit;
  flex: 0 0 82px; margin: 8px 10px 8px 4px;
  background: var(--warn-bg); color: var(--warn);
  border: 2px solid var(--warn); border-radius: 10px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center;
}
.item-flag:active { background: var(--paper); }
.is-missing .item-flag, .is-damaged .item-flag, .is-skipped .item-flag { color: var(--ink); border-color: currentColor; }

.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
}
.bottombar .inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.bottombar .nav-row { display: flex; gap: 10px; }
.bottombar .nav-row .btn { flex: 1; }
.bottombar .nav-row .btn.narrow { flex: 0 0 26%; }
.bulk-btn { min-height: 46px !important; }

/* ---------- sheets / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 24, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 640px;
  border-radius: 16px 16px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  max-height: 86dvh; overflow-y: auto;
}
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.seg .btn { min-height: 58px; font-size: 14.5px; padding: 8px 6px; flex-direction: column; gap: 2px; }
.seg .btn .seg-ic { font-size: 19px; }
.btn.sel-navy { background: var(--navy); color: var(--navy-ink); border-color: var(--navy); }
.seg .btn.sel-missing { background: var(--bad); color: #fff; border-color: var(--bad); }
.seg .btn.sel-damaged { background: var(--warn); color: #fff; border-color: var(--warn); }
.seg .btn.sel-skipped { background: var(--skip); color: #fff; border-color: var(--skip); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 16px; }
.stepper button {
  appearance: none; cursor: pointer; font: inherit;
  width: 58px; height: 58px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--paper); color: var(--ink);
  font-size: 28px; font-weight: 800; line-height: 1;
}
.stepper .count { font-size: 30px; font-weight: 800; min-width: 96px; text-align: center; }
.chip-row { display: flex; gap: 8px; justify-content: center; }
.chip {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 700;
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--line); border-radius: 999px; padding: 9px 16px; min-height: 44px;
}
.chip.on { border-color: var(--accent); color: var(--accent); }

/* compartment picker */
.comp-list { display: flex; flex-direction: column; max-height: 60dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.comp-item {
  appearance: none; background: var(--card); border: 0; border-bottom: 1px solid var(--line);
  font: inherit; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; gap: 10px; padding: 13px 14px; min-height: 52px; text-align: left;
}
.comp-item:last-child { border-bottom: 0; }
.comp-item.current { background: var(--skip-bg); }
.comp-item .cn { flex: 1; min-width: 0; font-weight: 600; }
.comp-item .cs { font-size: 12.5px; }

/* ---------- sign-off ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-tiles .card { text-align: center; padding: 12px 4px; }
.stat-tiles .num { font-size: 26px; font-weight: 800; }
.stat-tiles .lbl { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- lists (reports / issues) ---------- */
.filter-tabs { display: flex; gap: 8px; }
.filter-tabs .chip { flex: 1; text-align: center; justify-content: center; display: inline-flex; }
.list-row {
  appearance: none; background: var(--card); border: 0; border-bottom: 1px solid var(--line);
  width: 100%; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 10px; padding: 13px 14px; min-height: 62px;
}
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .chev { color: var(--muted); font-size: 18px; }
.month-head { padding: 6px 2px 0; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14.5px; }
.kv:last-child { border-bottom: 0; }

details.compsec { border-bottom: 1px solid var(--line); }
details.compsec:last-child { border-bottom: 0; }
details.compsec summary {
  cursor: pointer; padding: 13px 14px; list-style: none;
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
details.compsec summary::-webkit-details-marker { display: none; }
details.compsec summary .grow { flex: 1; min-width: 0; font-weight: 700; }
details.compsec summary .chev { transition: transform .15s; }
details.compsec[open] summary .chev { transform: rotate(180deg); }
details.compsec .body { padding: 0 14px 12px; }
.result-line {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14.5px;
}
.result-line:last-child { border-bottom: 0; }
button.result-line {
  appearance: none; background: none; border: 0; border-bottom: 1px dashed var(--line);
  width: 100%; font: inherit; color: var(--ink); cursor: pointer; text-align: left; min-height: 46px;
}

/* ---------- toast ---------- */
/* Toasts stack BELOW sheets/overlays (z 50) so they can never block a sheet's buttons. */
#toast-root { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 0; right: 0; z-index: 40; display: flex; justify-content: center; pointer-events: none; }
#app.has-bottombar ~ #toast-root { bottom: calc(210px + env(safe-area-inset-bottom)); }
.toast {
  pointer-events: auto;
  background: var(--navy); color: var(--navy-ink);
  border-radius: 12px; padding: 12px 16px; margin: 0 14px;
  display: flex; align-items: center; gap: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  font-size: 14.5px; font-weight: 600; max-width: 600px;
}
.toast button { appearance: none; background: none; border: 0; color: var(--sky); font: inherit; font-weight: 800; cursor: pointer; padding: 4px 8px; }

/* ---------- misc ---------- */
.center { text-align: center; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
