/* ============================================================================
   Field Log — shared stylesheet
   Dark, high-contrast, thumb-sized targets. Works on a phone in the cab and on
   a wall-mounted TV in the office.
   ========================================================================== */

:root {
  --bg: #0b1220;
  --bg-soft: #101a2d;
  --card: #151f34;
  --card-2: #1b2740;
  --line: #26344f;
  --line-soft: #1e2a42;
  --text: #e9eefb;
  --muted: #97a6c4;
  --accent: #3d7dff;
  --accent-ink: #ffffff;
  --ok: #2fbf71;
  --warn: #f0a828;
  --bad: #ef5d5d;
  --permit: #8b5cf6;
  --start: #3d7dff;
  --lunch: #f0a828;
  --end: #ef5d5d;
  --break: #17a2b8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f9;
    --bg-soft: #e4eaf4;
    --card: #ffffff;
    --card-2: #f4f7fc;
    --line: #d3dced;
    --line-soft: #e2e8f3;
    --text: #101a2d;
    --muted: #5a6a86;
    --shadow: 0 10px 26px rgba(16, 26, 45, 0.12);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg-soft), var(--bg) 60%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 8px;
  top: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  z-index: 50;
}

/* ---------- app bar ---------- */

.appbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), #7b5cff);
  color: #fff;
  font-size: 20px;
}
.brand strong { display: block; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { display: block; font-size: 12px; color: var(--muted); }

.appnav { display: flex; gap: 6px; margin-left: auto; }
/* Both nav links are the same button. The selected one is filled with the accent
   colour; before this the inactive one lost its border entirely, so the pair looked
   like a button next to a bare word. */
.navlink {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card-2);
}
.navlink:hover { color: var(--text); border-color: var(--muted); }
.navlink.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.appbar-right { display: flex; align-items: center; gap: 8px; }

/* ---------- layout ---------- */

main {
  width: min(1180px, 100% - 24px);
  margin: 18px auto 40px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 17px; margin: 0; letter-spacing: 0.2px; }
.card-head-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

h3 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.hint.warn {
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
.dot { color: var(--line); }

/* ---------- hero / live clock ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 1.2fr);
  gap: 20px;
  align-items: center;
}
.hero-time {
  font-family: var(--mono);
  font-size: clamp(46px, 11vw, 74px);
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hero-meta { color: var(--muted); font-size: 14px; margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.hero-side { display: grid; gap: 12px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.2px; }
.field.grow { flex: 1; }

input[type="text"], input[type="date"], input[type="time"], input[type="password"], input[type="search"], select {
  width: 100%;
  /* A date input's intrinsic width comes from the browser's picker UI, and it will
     happily overflow a narrow grid column. Allowing it to shrink is what keeps the
     From/To boxes side by side on a phone instead of on top of each other. */
  min-width: 0;
  max-width: 100%;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  min-height: 44px;
}
input[type="date"] { padding-inline: 8px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.check.slim { font-size: 13px; }

/* ---------- buttons ---------- */

button { font: inherit; cursor: pointer; }

.btn, .ghost {
  border-radius: 999px;
  padding: 11px 18px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  font-weight: 600;
  min-height: 44px;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn:hover, .ghost:hover { filter: brightness(1.12); }
.btn:active, .ghost:active { transform: scale(0.985); }
.ghost.small, .btn.small { padding: 7px 12px; min-height: 34px; font-size: 13px; }
.btn.danger { background: var(--bad); }
.linkish { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 4px; }

/* ---------- punch list ---------- */

.punch-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: 640px;
}

.punch {
  position: relative;
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 18px 18px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card-2);
  border-left: 5px solid var(--tone, var(--accent));
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.2s ease;
}
button.punch:hover { background: color-mix(in srgb, var(--card-2) 80%, var(--tone, var(--accent))); }
button.punch:active { transform: scale(0.99); }

/* A recorded punch is a readout, not a control: it must not look pressable. */
.punch.is-locked {
  cursor: default;
  background: color-mix(in srgb, var(--card-2) 88%, var(--tone, var(--accent)));
  opacity: 0.92;
}

.punch .punch-label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 700; }
.punch .punch-time { font-family: var(--mono); font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.punch .punch-sub { font-size: 12.5px; color: var(--muted); min-height: 18px; }
.punch[data-set="1"] .punch-time { color: var(--text); }
.punch[data-open="1"] .punch-time { color: var(--ok); }
.punch .punch-fix {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 8px;
  font-size: 11.5px;
  padding: 5px 9px;
  cursor: pointer;
  opacity: 0.9;
}
.punch .punch-fix:hover { color: var(--text); }
.punch .punch-flag {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--warn);
}
.punch[data-tone="permit"] { --tone: var(--permit); }
.punch[data-tone="start"] { --tone: var(--start); }
.punch[data-tone="lunch"] { --tone: var(--lunch); }
.punch[data-tone="end"] { --tone: var(--end); }

/* ---------- submit ---------- */

.submit-card { border-left: 5px solid var(--ok); }
.submit-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn-submit { min-width: 180px; }
.btn-submit.is-done { background: var(--ok); }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.submit-banner {
  color: var(--ok);
  border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--line));
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 12px;
}
.punch-grid.is-submitted { opacity: 0.6; }
.punch-grid.is-submitted .punch-fix { pointer-events: none; opacity: 0.4; }

/* ---------- breaks ---------- */

.break-panel { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.break-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.break-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.btn-break { background: var(--break); color: #04222a; }
.btn-break[data-active="1"] { background: var(--ok); color: #04220f; }

.break-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.break-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  flex-wrap: wrap;
}
.break-list .mono { font-family: var(--mono); }
.break-list .span { color: var(--muted); font-size: 13px; }
.break-list .grow { flex: 1; }
.break-list .empty { color: var(--muted); font-size: 13px; background: none; border-style: dashed; }

.notes-row { margin-top: 14px; }

/* ---------- dashboard password gate ---------- */

.gate { max-width: 460px; margin: 8vh auto 0; }
.gate h2 { margin: 0 0 8px; }
.gate .field { margin-top: 12px; }
.gate #gateError { color: var(--warn); }
.gate #gateError[hidden] { display: none; }

/* ---------- dialogs ---------- */

dialog.sheet {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 20px;
  width: min(560px, 92vw);
  box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(4, 8, 18, 0.62); backdrop-filter: blur(2px); }
dialog.sheet h2 { margin: 0 0 6px; font-size: 18px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.edit-fields { display: grid; gap: 10px; margin: 14px 0; max-height: 52vh; overflow: auto; }
.edit-row { display: grid; grid-template-columns: 1fr 130px; gap: 10px; align-items: center; }
.edit-row .edit-note { grid-column: 1 / -1; }
.qr-wrap {
  width: min(320px, 80vw);
  aspect-ratio: 1;
  margin: 12px auto;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
}

/* ---------- dashboard ---------- */

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}
/* Grid children default to min-width:auto, which refuses to shrink below the
   intrinsic width of a date input — so on a phone the From/To boxes pushed past
   their column and overlapped. min-width:0 lets them shrink into the grid. */
.filters > * { min-width: 0; }
.filters .presets { display: flex; gap: 6px; flex-wrap: wrap; grid-column: 1 / -1; }
.preset {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
}
.preset[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.export-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.export-bar .sep { width: 1px; height: 24px; background: var(--line); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
table.sheet-table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 900px; }
table.sheet-table th, table.sheet-table td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.sheet-table thead th {
  background: var(--card-2);
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
table.sheet-table tbody tr:hover { background: var(--card-2); }
table.sheet-table td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.sheet-table tr.is-mine { background: color-mix(in srgb, var(--accent) 12%, transparent); }
table.sheet-table tr.is-open td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.sheet-table tr.is-empty td { color: var(--muted); }
table.sheet-table tfoot td { background: var(--card-2); font-weight: 700; }
.cell-time { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cell-sub { display: block; font-size: 12px; color: var(--muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
.cell-flags { display: flex; gap: 5px; }
.flag {
  font-size: 10.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.flag.fixed { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.flag.submitted { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); font-weight: 700; }
.flag.auto { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.flag.open { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.flag.miss { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }

.row-actions { display: flex; gap: 6px; }

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
}
.empty-state strong { color: var(--text); display: block; margin-bottom: 4px; font-size: 16px; }

/* ---------- sync pill, footer, toasts ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--card-2);
}
.pill::before { content: "●"; font-size: 13px; line-height: 1; }
.pill[data-state="idle"] { color: var(--ok); }
.pill[data-state="syncing"] { color: var(--accent); }
.pill[data-state="offline"] { color: var(--warn); }
.pill[data-state="auth"], .pill[data-state="error"] { color: var(--bad); }

.appfoot {
  width: min(1180px, 100% - 24px);
  margin: 0 auto 30px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12.5px;
}

.toast-stack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  z-index: 60;
  width: min(380px, calc(100vw - 28px));
}
.toast {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  cursor: pointer;
}
.toast.is-in { opacity: 1; transform: none; }
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--bad); }
.toast-icon { font-size: 15px; line-height: 1.3; }

/* Wall-mounted TV / office screen: readable from across the room. */
body.is-big { font-size: 19px; }
body.is-big main { width: min(1600px, 100% - 24px); }
body.is-big .hero-time { font-size: clamp(64px, 12vw, 120px); }
body.is-big table.sheet-table { font-size: 17px; }
body.is-big table.sheet-table th, body.is-big table.sheet-table td { padding: 13px 14px; }
body.is-big .appfoot, body.is-big .hint { font-size: 14px; }

/* ---------- responsive + print ---------- */

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .appbar { gap: 10px; padding: 10px 12px; }
  .appnav { order: 3; width: 100%; }
  .navlink { flex: 1; text-align: center; }
  .card { padding: 14px; }
  .edit-row { grid-template-columns: 1fr; }
  .toast-stack { left: 14px; right: 14px; width: auto; }

  /* From and To share one row and size to their content, so they stay small and
     clear of each other. Worker and Show keep a full-width row each. */
  .filters { grid-template-columns: auto auto; justify-content: start; gap: 8px; }
  .filters .field.date-field { justify-items: start; }
  .filters .field.date-field > span { font-size: 11.5px; }
  .filters > .field:not(.date-field) { grid-column: 1 / -1; }
  .filters .field.date-field input[type="date"] {
    /* width:auto rather than 100%: the box shrinks to the date it shows instead of
       filling its column. min-height on the shared rule keeps the tap target. */
    width: auto;
    padding: 8px 6px;
    font-size: 15px;
  }
}

@media print {
  :root { --card: #fff; --bg: #fff; --text: #000; --muted: #444; --line: #bbb; }
  body { background: #fff; }
  .appbar, .appfoot, .filters, .export-bar, .toast-stack, .row-actions, .btn, .ghost, .preset { display: none !important; }
  .card { box-shadow: none; border: none; padding: 0; }
  table.sheet-table { min-width: 0; font-size: 11px; }
  table.sheet-table th, table.sheet-table td { padding: 4px 6px; }
  main { width: 100%; margin: 0; }
}
