/* Job Board. Mobile first: the daily log and the clock are used on a job site, one thumb.
   WCAG 2.1 AA: 4.5:1 body text on both schemes, visible focus, reduced motion respected.
   One Google Font (Manrope, 500/700), design tokens on :root, dark by default (done-for-you).
   Pass two (2026-09-22): app shell (top bar desktop nav / bottom tab bar phone), job summary
   strip, stat tile grid, status pills everywhere a status renders, mobile card-row tables,
   toast/banner pattern replacing alert(), skeleton loading state, quiet destructive actions.
   Same tokens as pass one; nothing in the palette changed. */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;700;800&display=swap');

:root {
  /* dark (default): near-navy, not pure black */
  --bg: #12161d; --bg-alt: #181d26; --card: #1c222c; --card-raised: #242b37;
  --ink: #eef2f7; --muted: #a2adbc; --line: #2e3542; --line-soft: #232a34;
  --accent: #e8912b; --accent-ink: #1a1206; --accent-strong: #ffab4d;
  --ok: #4fce8b; --ok-ink: #06210f; --warn: #f2b84b; --warn-ink: #241800; --bad: #ff6b6b; --bad-ink: #2b0505;
  --focus: #7ec4ff;
  --radius: 14px; --radius-sm: 10px; --radius-lg: 18px; --tap: 44px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --font: 'Manrope', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.28), 0 8px 20px -12px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 8px 28px -8px rgba(0, 0, 0, 0.55);
  --content-max: 1360px;
  /* One gutter for every bar and the content, so all edges line up inside the GHL frame: the
     side padding grows from --sp-5 to whatever centres --content-max, and the bar backgrounds
     still run edge to edge. */
  --gutter: max(var(--sp-4), calc((100% - var(--content-max)) / 2));
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f5f2; --bg-alt: #ffffff; --card: #ffffff; --card-raised: #f0ede7;
    --ink: #1c1a17; --muted: #5b5850; --line: #ddd7cc; --line-soft: #e8e3da;
    --accent: #b56a0c; --accent-ink: #ffffff; --accent-strong: #96590a;
    --ok: #1c7a44; --ok-ink: #ffffff; --warn: #8a5900; --warn-ink: #ffffff; --bad: #b3261e; --bad-ink: #ffffff;
    --focus: #1a56db;
    --shadow-card: 0 1px 2px rgba(20, 18, 14, 0.06), 0 8px 20px -14px rgba(20, 18, 14, 0.18);
    --shadow-pop: 0 8px 28px -10px rgba(20, 18, 14, 0.28);
  }
}
:root[data-theme="light"] {
  --bg: #f7f5f2; --bg-alt: #ffffff; --card: #ffffff; --card-raised: #f0ede7;
  --ink: #1c1a17; --muted: #5b5850; --line: #ddd7cc; --line-soft: #e8e3da;
  --accent: #b56a0c; --accent-ink: #ffffff; --accent-strong: #96590a;
  --ok: #1c7a44; --ok-ink: #ffffff; --warn: #8a5900; --warn-ink: #ffffff; --bad: #b3261e; --bad-ink: #ffffff;
  --focus: #1a56db;
  --shadow-pop: 0 8px 28px -10px rgba(20, 18, 14, 0.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html { background: var(--bg); min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh;
  font: 16px/1.5 var(--font);
  padding-bottom: calc(var(--tap) + 28px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--font); font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.5rem; margin: var(--sp-5) 0 var(--sp-2); letter-spacing: -0.01em; }
h2 { font-size: 1.1875rem; margin: var(--sp-6) 0 var(--sp-3); color: var(--muted); font-weight: 700; }
a { color: var(--focus); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); color: var(--ink); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-card); z-index: 40; }
.skip:focus { left: 16px; z-index: 40; }

/* ---------------------------------------------------------------- header + job bar */
.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); background: var(--bg-alt);
}
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 800; font-size: 1.0625rem; }
.mark { width: 16px; height: 16px; border-radius: 5px; background: var(--accent); display: inline-block; }
.who { font-size: 0.875rem; color: var(--muted); }

.jobbar { display: flex; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); background: var(--bg); }
.jobbar select {
  flex: 1; min-height: var(--tap); font: inherit; font-size: 1rem; font-weight: 700; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 0 var(--sp-3);
  appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) center, calc(100% - 15px) center; background-size: 5px 5px; background-repeat: no-repeat;
}
.jobbar .ghost { min-width: var(--tap); flex: 0 0 auto; }
.jobbar .ghost .icon { width: 20px; height: 20px; }

/* Job summary strip: name, address, stage/status pill, dates, and (non-crew) contract + CO
   total. Present on every tab once a job is selected, built from data already in state. */
.jobstrip {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); background: var(--card); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.jobstrip-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.jobstrip-main strong { font-size: 1rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jobstrip-facts { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-5); align-items: center; }
.jobstrip-fact { display: flex; flex-direction: column; gap: 1px; font-size: 0.8125rem; }
.jobstrip-fact .k { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.jobstrip-fact .v { font-weight: 700; font-variant-numeric: tabular-nums; }

.view { padding: 0 var(--gutter); width: 100%; box-sizing: border-box; }

/* Page header: title + one-line description on the left, primary action on the right. Not
   every tab uses the description slot, but every h1 gets consistent top spacing this way. */
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.pagehead h1 { margin-bottom: 0; }
.pagehead .desc { margin: 2px 0 var(--sp-2); color: var(--muted); font-size: 0.9375rem; }
.pagehead .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; padding-top: var(--sp-1); }

/* ---------------------------------------------------------------- surfaces */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-4); box-shadow: var(--shadow-card);
}
.stack { display: grid; gap: var(--sp-3); min-width: 0; }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
label { display: grid; gap: var(--sp-1); font-size: 0.875rem; color: var(--muted); font-weight: 500; min-width: 0; }
label.row { display: flex; align-items: center; }
label.row input[type="checkbox"] { order: -1; }
.hint { font-size: 0.78rem; color: var(--muted); font-weight: 500; margin: 0; }

/* Native date/time inputs refuse to shrink below their locale's content width, which blows out
   a grid/flex track and causes horizontal scroll on a 375px screen. width:100% + min-width:0
   lets every field shrink to its container instead of forcing the page wider. */
input, textarea, select {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--card-raised);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; min-height: var(--tap);
  width: 100%; min-width: 0;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.85; }
textarea { min-height: 76px; resize: vertical; }
input[type="checkbox"] { min-height: auto; width: 22px; height: 22px; accent-color: var(--accent); }
input[type="color"] { padding: 2px; min-height: var(--tap); width: 64px; }
input:invalid:not(:placeholder-shown) { border-color: var(--bad); }

button, .ghost {
  font: inherit; font-weight: 700; font-size: 0.9375rem; min-height: var(--tap); padding: 0 var(--sp-4);
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--card-raised); color: var(--ink);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
}
button:hover, .ghost:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 800; }
button.primary:hover { background: var(--accent-strong); }
button.big { width: 100%; min-height: 76px; font-size: 1.25rem; }
button[disabled] { opacity: 0.55; cursor: default; }
/* Destructive actions: quiet by default (plain ghost, muted red text), not a loud filled red
   button sitting next to safe ones. They still confirm() before anything happens. */
button.danger, .ghost.danger { color: var(--bad); border-color: var(--line); background: transparent; }
button.danger:hover, .ghost.danger:hover { background: var(--bad); color: var(--bad-ink); border-color: transparent; }
.status { min-height: 1.3em; font-size: 0.9rem; color: var(--muted); margin: var(--sp-2) 0 0; font-weight: 500; }
.status.ok { color: var(--ok); } .status.bad { color: var(--bad); }

/* ---------------------------------------------------------------- lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-card); }
/* A list item that is itself a button (change-order rows): full-width, left-aligned, plain text
   flow so multi-line content (title + pill + meta) does not get squashed by the flex button base. */
.list li:has(> button.co-row) { padding: 0; }
.list button.co-row {
  display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4); min-height: auto; font-weight: 400; color: var(--ink);
}
.list button.co-row strong { font-weight: 700; }
.list button.co-row .pill { margin-left: var(--sp-2); }
.list button.co-row .meta { display: block; margin-top: 4px; }
.list .meta { font-size: 0.85rem; color: var(--muted); }
.pill {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em;
}
.pill.ok { color: var(--ok-ink); background: var(--ok); border-color: transparent; }
.pill.warn { color: var(--warn-ink); background: var(--warn); border-color: transparent; }
.pill.bad { color: var(--bad-ink); background: var(--bad); border-color: transparent; }
.photos { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.photos img { width: 76px; height: 76px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); }

/* ---------------------------------------------------------------- empty states */
.empty {
  display: grid; gap: var(--sp-2); justify-items: start; padding: var(--sp-5) var(--sp-4);
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}
.empty p { margin: 0; font-size: 0.9375rem; }
.empty button, .empty a.ghost { margin-top: var(--sp-1); }

/* ---------------------------------------------------------------- skeleton loading state */
.skel { display: grid; gap: var(--sp-2); }
.skel-row { height: 46px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--card-raised) 25%, var(--line-soft) 37%, var(--card-raised) 63%); background-size: 400% 100%; }
@media (prefers-reduced-motion: no-preference) { .skel-row { animation: skel-shimmer 1.4s ease infinite; } }
@keyframes skel-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------------------------------------------------------------- toast / banner
   Replaces alert() for errors and confirmations. Fixed above the tab bar on phone, top-right
   on desktop. role=status + aria-live so screen readers announce it without stealing focus. */
.toast {
  position: fixed; left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--tap) + 40px + env(safe-area-inset-bottom));
  z-index: 30; margin: 0 auto; max-width: 480px; display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  background: var(--card-raised); border: 1px solid var(--line); color: var(--ink); font-size: 0.9rem; font-weight: 600;
}
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }
.toast .toast-close { margin-left: auto; min-height: 28px; min-width: 28px; padding: 0; border: 0; background: transparent; color: var(--muted); font-weight: 700; }
@media (min-width: 900px) {
  .toast { left: auto; right: var(--sp-5); bottom: auto; top: 72px; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 160ms ease; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---------------------------------------------------------------- tables */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); }
table.grid { border-collapse: collapse; width: 100%; font-size: 0.875rem; background: var(--card); }
.grid th, .grid td { border-bottom: 1px solid var(--line-soft); padding: 10px 12px; text-align: left; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: var(--bg-alt); color: var(--muted); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--line); }
.grid tbody tr:nth-child(even) { background: var(--line-soft); }
.grid td.on { background: var(--accent); color: var(--accent-ink); text-align: center; font-weight: 700; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.neg { color: var(--bad); font-weight: 700; }
.grid tfoot th, .grid tr:last-child th { font-weight: 700; }
/* Weekly schedule grid: the column for the week containing today, same reference point as the Gantt today-line. */
.grid th.today-col, .grid td.today-col { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.grid th.today-col { color: var(--ink); }

/* Mobile card rows: opt-in per table with .grid-cards. Each td carries data-label (from the
   header text) so a media query can turn the table into a stack of labelled key/value cards
   under 640px without duplicating markup or touching how the JS builds it. The weekly schedule
   grid and the Gantt table are day-by-day matrices, not row records, so they keep scrolling
   horizontally instead (documented in the redesign brief). */
@media (max-width: 640px) {
  .grid-cards, .grid-cards thead, .grid-cards tbody, .grid-cards tr, .grid-cards td { display: block; width: 100%; }
  .grid-cards thead { position: absolute; left: -9999px; }
  .grid-cards tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--card); }
  .grid-cards tbody tr:nth-child(even) { background: var(--card); }
  .grid-cards td { border-bottom: 1px solid var(--line-soft); padding: 8px 0; white-space: normal; display: flex; justify-content: space-between; gap: var(--sp-3); align-items: center; }
  .grid-cards td:last-child { border-bottom: 0; }
  .grid-cards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; flex: 0 0 auto; }
  .grid-cards td.num { text-align: right; }
  .grid-cards .scroll-x { border: 0; overflow: visible; }
}

/* ---------------------------------------------------------------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.tile { grid-column: span 12; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-4); box-shadow: var(--shadow-card); }
.tile .k { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.tile .v { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .v.neg { color: var(--bad); }
@media (min-width: 560px) { .tile { grid-column: span 6; } }
@media (min-width: 900px) { .tile { grid-column: span 3; } }

/* ---------------------------------------------------------------- segmented control */
.seg { display: flex; gap: var(--sp-1); background: var(--card-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px; }
.seg [role="tab"] { border: 0; background: transparent; border-radius: calc(var(--radius) - 3px); min-height: 38px; padding: 0 var(--sp-3); color: var(--muted); font-weight: 700; }
.seg [aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- primary nav / app shell
   Phone: fixed bottom tab bar, icon over label, the current tab picked out with the accent.
   Desktop (>=900px): the same buttons become a top bar row, icon beside label, content capped
   at --content-max and centered below it. Same markup, same data-go handlers, only the layout
   changes -- this is the "app shell" decision documented in the redesign brief. */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--bg-alt);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs button {
  flex: 1; min-width: 0; padding: 6px 2px; border: 0; border-radius: 0; background: transparent;
  font-size: 0.68rem; font-weight: 700; color: var(--muted); min-height: calc(var(--tap) + 14px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-direction: column; gap: 3px;
}
.tabs button .icon { width: 22px; height: 22px; flex: 0 0 auto; }
.tabs button[aria-selected="true"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); background: var(--card-raised); }
.tabs button[hidden] { display: none; }
/* The clock-in tab is where crew lands first; give it slightly more visual weight on phone by
   making its icon a hair larger, matching "clock button dominant" without a special-case layout. */
.tabs button[data-go="clock"] .icon { width: 24px; height: 24px; }

@media (min-width: 900px) {
  .tabs {
    position: sticky; top: 0; bottom: auto; order: -1; border-top: 0; border-bottom: 1px solid var(--line);
    justify-content: flex-start; gap: var(--sp-1); padding: 0 var(--gutter); width: 100%; box-sizing: border-box;
  }
  .tabs button { flex: 0 0 auto; flex-direction: row; padding: 0 var(--sp-3); font-size: 0.875rem; min-height: 52px; gap: var(--sp-2); }
  .tabs button[aria-selected="true"] { box-shadow: inset 0 -3px 0 var(--accent); background: transparent; }
  body { padding-bottom: var(--sp-6); display: flex; flex-direction: column; }
  .top { order: -3; }
  .top, .jobbar, .jobstrip { padding-left: var(--gutter); padding-right: var(--gutter); box-sizing: border-box; }
  .jobbar { width: 100%; }
  .jobbar select { max-width: 360px; flex: 0 1 360px; }
  .jobstrip { order: -1; }
  .jobstrip { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) { button, .tabs button, .seg [role="tab"] { transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease; } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------- Gantt view */
.gantt svg { display: block; background: var(--card); }
.gantt svg text { font-family: inherit; fill: var(--ink); }
.gantt svg .bar { cursor: pointer; }
.gantt svg .bar:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
table.grid tbody tr[role="button"] { cursor: pointer; }
table.grid tbody tr[role="button"]:hover { background: var(--card-raised); }
table.grid tbody tr[role="button"]:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

/* Schedule edit panel */
#sched-edit input[type="color"] { padding: 2px; min-height: var(--tap); width: 64px; }
details.card { padding: var(--sp-3) var(--sp-4); }
details.card summary { cursor: pointer; font-weight: 700; padding: var(--sp-2) 0; min-height: var(--tap); display: flex; align-items: center; }
details.card[open] summary { margin-bottom: var(--sp-3); border-bottom: 1px solid var(--line-soft); padding-bottom: var(--sp-3); }

/* Icons: inline SVG only, stroke-based, inherit color, never an icon font. */
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
