/* Theme: <html data-theme="light|dark"> forces one; no attribute follows the phone's setting. */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #121826;
  --muted: #586174;
  --line: #dbe1ea;
  --header: #1d4ed8;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --focus: #2563eb;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn-bg: #fff4d6;
  --ok: #157347;
  --radius: 12px;
  /* Sized for a phone used in a truck: big text, big targets. */
  --tap: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161c26;
    --text: #e6ebf2;
    --muted: #97a2b4;
    --line: #283244;
    --header: #172554;
    --brand: #2563eb;
    --focus: #60a5fa;
    --danger: #ff8a80;
    --danger-bg: #3a1c1a;
    --warn-bg: #3a3218;
    --ok: #5cc98b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161c26;
  --text: #e6ebf2;
  --muted: #97a2b4;
  --line: #283244;
  --header: #172554;
  --brand: #2563eb;
  --focus: #60a5fa;
  --danger: #ff8a80;
  --danger-bg: #3a1c1a;
  --warn-bg: #3a3218;
  --ok: #5cc98b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 19px; line-height: 1.45; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  min-height: calc(env(safe-area-inset-top) + 60px);
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px 16px;
  background: var(--header); color: var(--brand-ink);
}
.top:has(#back:not([hidden])) { padding-left: 4px; }
.theme-btn { font-size: 24px; }
.top h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); padding: 0; border: 0; background: transparent; color: inherit; font-size: 28px; }
.net { font-size: 15px; padding: 3px 10px; border-radius: 99px; background: #0003; }

main { padding: 14px; padding-bottom: calc(env(safe-area-inset-bottom) + 32px); max-width: 720px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 6px; font-size: 21px; line-height: 1.25; }
.muted { color: var(--muted); font-size: 17px; }
.closed { border-color: var(--danger); background: var(--danger-bg); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-bg); margin: 10px 0; }
.error { padding: 12px 14px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); margin: 10px 0; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
/* Buttons in an action row share the full width (e.g. Directions | Enter load). */
.actions { margin-top: 12px; flex-wrap: nowrap; }
.actions > .btn, .actions > button { flex: 1 1 0; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 8px 18px; border-radius: 12px; line-height: 1.25;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-align: center; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:active, .btn:active { filter: brightness(.92); }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
.block { width: 100%; margin-top: 10px; }
.block + .muted { margin-top: 6px; }

label { display: block; font-weight: 600; margin: 14px 0 6px; }
/* 20px also keeps iPhones from zooming in when a field is tapped (they zoom below 16px). */
input, textarea, select {
  width: 100%; min-height: var(--tap); padding: 10px 14px; font: inherit; font-size: 20px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
}
input[type=checkbox] { width: 30px; min-height: 30px; height: 30px; accent-color: var(--brand); }
.check { display: flex; gap: 12px; align-items: center; font-weight: 600; margin: 14px 0; min-height: var(--tap); }
.invalid { border-color: var(--danger); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
a { color: var(--focus); }

/* Cassette tables: up to 3 cassette columns plus labels on a ~360px phone, so tighter than the rest. */
.card:has(> table.cst) { overflow-x: auto; padding-left: 10px; padding-right: 10px; }
table.cst { width: 100%; border-collapse: collapse; font-size: 17px; }
table.cst th, table.cst td { border-bottom: 1px solid var(--line); padding: 8px 2px; text-align: right; }
table.cst th { font-size: 15px; color: var(--muted); font-weight: 600; }
table.cst th:first-child, table.cst td:first-child { text-align: left; }
table.cst td:first-child { padding-right: 6px; }
table.cst input { min-height: 50px; min-width: 68px; padding: 6px 6px; font-size: 19px; text-align: right; }
table.cst input[type=checkbox] { min-width: 30px; min-height: 30px; }

.toast {
  position: fixed; left: 14px; right: 14px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 560px; margin: 0 auto; padding: 14px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); z-index: 20;
}
.sig { width: 100%; height: 240px; border: 2px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; }
#scanner { width: 100%; }

/* /install */
.install-hero { display: flex; gap: 14px; align-items: center; margin: 4px 0 16px; }
.install-hero img { border-radius: 16px; flex: none; }
.install-hero h2 { margin: 0 0 2px; font-size: 23px; }
.install-hero p { margin: 0; }
.steps { padding-left: 22px; margin: 8px 0; }
.steps li { margin-bottom: 10px; }
.inline-icon { width: 22px; height: 22px; vertical-align: -5px; color: var(--focus); }
.qr { display: block; width: 220px; max-width: 100%; margin: 12px auto; border-radius: 8px; }
.center { text-align: center; }
