/* Crewbook — one visual language for the cab and the office.
   Built dark-first: the driver opens this at 4am in a dark yard, and a white
   screen at that hour is genuinely unpleasant to look at. */
:root {
  --ink: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --hi: #ff6b35;          /* safety orange: the one thing that shouts */
  --hi-ink: #1a0d06;
  --pass: #2ea043;
  --fail: #e5484d;
  --warn: #d9a441;
  --radius: 14px;
  --tap: 56px;            /* nothing tappable is smaller than this */
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ink: #f4f6f8; --surface: #fff; --surface-2: #f0f3f6; --line: #d8dee6;
    --text: #12181f; --muted: #5c6b7a; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ink); color: var(--text); min-height: 100vh;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 15px; }
a { color: var(--hi); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 560px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.spread { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }

/* --- brand bar --- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px calc(10px); display: flex; gap: 12px; align-items: center;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { font-weight: 700; letter-spacing: -0.03em; font-size: 18px; }
.brand span { color: var(--hi); }

/* --- surfaces --- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.tight { padding: 12px; }
.card.flag { border-color: var(--hi); }

/* --- buttons --- */
button, .btn {
  font: inherit; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-hi { background: var(--hi); border-color: var(--hi); color: var(--hi-ink); }
.btn-big { min-height: var(--tap); font-size: 18px; width: 100%; border-radius: var(--radius); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--fail); border-color: var(--fail); color: #fff; }

/* --- form --- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  width: 100%; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--hi); outline-offset: -1px; }
/* Tick boxes are not text fields: the generic rule above would blow them up
   into 48px grey slabs. */
input[type="checkbox"], input[type="radio"] {
  width: 20px; height: 20px; min-height: 0; padding: 0; flex: none;
  accent-color: var(--hi);
}
textarea { min-height: 84px; resize: vertical; }

/* --- chips --- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip-pass { background: rgba(46,160,67,.16); border-color: rgba(46,160,67,.5); color: #7ee294; }
.chip-fail { background: rgba(229,72,77,.16); border-color: rgba(229,72,77,.5); color: #ff9ea0; }
.chip-warn { background: rgba(217,164,65,.16); border-color: rgba(217,164,65,.5); color: #f0cd8a; }
.chip-hi   { background: rgba(255,107,53,.16); border-color: rgba(255,107,53,.5); color: #ffab85; }

/* --- prestart checklist: three big targets, thumb-reachable --- */
.check-item { border-bottom: 1px solid var(--line); padding: 14px 0; }
.check-item:last-child { border-bottom: 0; }
.check-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 10px; }
.check-label { font-weight: 600; flex: 1; }
.choices { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.choices button { min-height: var(--tap); border-radius: 12px; font-size: 16px; }
.choices button[aria-pressed="true"][data-v="pass"] { background: var(--pass); border-color: var(--pass); color: #04210b; }
.choices button[aria-pressed="true"][data-v="fail"] { background: var(--fail); border-color: var(--fail); color: #fff; }
.choices button[aria-pressed="true"][data-v="na"]   { background: var(--muted); border-color: var(--muted); color: var(--ink); }
.section-head {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 22px 0 4px;
}

/* --- sticky action bar on the driver screens --- */
.sticky-foot {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--ink) 28%);
  padding: 20px 0 calc(12px + env(safe-area-inset-bottom));
}

/* --- tables (office) --- */
.scroll-x { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- tabs --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; color: var(--muted); padding: 12px 14px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--hi); }

/* --- toast --- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 99;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 14px 18px; border-radius: 12px; max-width: min(520px, 92vw);
  box-shadow: 0 10px 40px rgba(0,0,0,.5); font-weight: 600;
}
#toast.bad { border-color: var(--fail); }
#toast.good { border-color: var(--pass); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.big-num { font-size: 34px; font-weight: 700; letter-spacing: -.03em; }

/* --- signature pad --- */
.sig-wrap { position: relative; }
.sig-pad {
  width: 100%; height: 190px; touch-action: none; display: block;
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: 12px;
}
.sig-pad.signed { border-style: solid; border-color: var(--pass); }
.sig-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none; font-size: 14px;
}

/* --- contract text --- */
.doc { font-size: 14px; line-height: 1.65; }
.doc h2 { font-size: 19px; margin: 0 0 12px; }
.doc h3 { font-size: 15px; margin: 18px 0 6px; }
.doc h4 { font-size: 14px; margin: 14px 0 4px; }
.doc p { margin: 0 0 10px; white-space: pre-wrap; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.doc strong { font-weight: 700; }

/* ======================================================================
   Phone
   The driver screens were built for a phone from the start. The office
   console was not — it is tables and tabs, and a boss checking something
   from a truck stop is still on a 375px screen.
   ====================================================================== */

/* A row of tabs wider than the screen scrolls, and snaps, rather than
   squeezing six labels into 375px until none of them are readable. */
.tabs {
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button { scroll-snap-align: start; }

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    padding-left: 12px; padding-right: 12px;
    row-gap: 2px;
  }
  /* Brand and sign-out share the first line; the tabs take the second and
     scroll, so no control is ever half off the edge. */
  .topbar .brand { flex: 1 1 auto; }
  .topbar .tabs {
    order: 3; flex: 1 0 100%;
    margin: 0 -12px; padding: 0 12px;
    border-bottom: 0;
  }
  .wrap { padding: 12px; }

  /* Tables become one block per row: the column heading moves inline next
     to its value, so nothing depends on a header that has scrolled away. */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 10px; background: var(--surface-2);
  }
  table.stack tr:hover { background: var(--surface-2); }
  table.stack td {
    border: 0; padding: 5px 0;
    display: flex; gap: 12px; align-items: baseline; justify-content: space-between;
    text-align: right;
  }
  table.stack td::before {
    content: attr(data-l);
    color: var(--muted); font-size: 11.5px; text-transform: uppercase;
    letter-spacing: .05em; text-align: left; flex: 0 0 auto;
  }
  /* A cell with nothing to label, and the first cell, read as a heading. */
  table.stack td:first-child {
    font-weight: 700; font-size: 16px; padding-bottom: 8px;
    border-bottom: 1px solid var(--line); margin-bottom: 4px;
  }
  table.stack td:first-child::before { content: ''; }
  /* The first cell is a heading, so it reads from the left like one. */
  table.stack td:first-child { justify-content: flex-start; text-align: left; }
  table.stack td.num { text-align: right; }
  table.stack td:empty { display: none; }

  /* Header rows stop being a left/right pair and become a stack. */
  .spread { flex-wrap: wrap; }
  .spread > .row { flex-wrap: wrap; }

  /* Anything tappable gets a thumb-sized target, including the small
     inline buttons that are comfortable with a mouse and not with a hand. */
  button, .btn { min-height: 44px; }
  .tabs button { min-height: 44px; }
  .chip { padding: 5px 11px; }

  /* Stat tiles two-up rather than one enormous column. */
  .card.grow { min-width: 0 !important; flex: 1 1 calc(50% - 6px); }
  .big-num { font-size: 27px; }

  h1 { font-size: 23px; } h2 { font-size: 17px; }

  /* A modal on a phone is a sheet: full width, anchored to the bottom, and
     clear of the home indicator. */
  .sheet {
    align-items: flex-end !important; padding: 0 !important;
  }
  .sheet > .card {
    max-width: 100% !important; width: 100%;
    max-height: 92vh !important;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Side-by-side form fields stack. Cards are excluded: this rule is for
     inputs sitting two-up in a row, not for the stat tiles, which want to
     stay two-up on a phone. */
  .row > .grow:not(.card) { flex: 1 1 100%; }
}

/* The roster's day columns: swipe through the week one day at a time. */
.week { scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.week > * { scroll-snap-align: start; }
@media (max-width: 760px) {
  .week > * { flex: 0 0 78% !important; min-width: 0 !important; }
}

/* Room to scroll something into view under a sticky bar. */
.sig-wrap, .check-item { scroll-margin: 90px; }
