:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f0f3f4;
  --text: #1c2629;
  --muted: #5d6b70;
  --border: #d8dfe2;
  --brand: #264653;
  --brand-text: #ffffff;
  --accent: #2a7f62;
  --accent-soft: #e3f2ec;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --focus: #3b82c4;
  --sick: #b7791f;
  --annual: #3b6fb6;
  --late: #8a4fb0;
  --late-soft: #f3eaf8;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121719;
    --surface: #1b2225;
    --surface-2: #232c30;
    --text: #e6ecee;
    --muted: #9aa8ad;
    --border: #334047;
    --brand: #1d3a45;
    --accent: #4cc39a;
    --accent-soft: #1d3a31;
    --danger: #f28b82;
    --danger-soft: #3d1f1d;
    --sick: #e0a84a;
    --annual: #7aa7e8;
    --late: #cfa3ec;
    --late-soft: #33263d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 96px;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

h1 { font-size: 1.6rem; margin: 28px 0 8px; line-height: 1.2; }
.lead { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.topbar { background: var(--brand); color: var(--brand-text); }
.topbar .wrap { display: flex; align-items: baseline; gap: 12px; padding-top: 14px; padding-bottom: 14px; }
.brand { font-weight: 700; font-size: 1.1rem; }
.topbar-sub { opacity: 0.75; }
.topbar .wrap { flex-wrap: wrap; }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav:first-child { margin-left: 0; }
.topnav a {
  color: var(--brand-text); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 6px 12px; border-radius: 99px; opacity: 0.8;
}
.topnav a:hover { opacity: 1; background: rgb(255 255 255 / 0.1); }
.topnav a[aria-current="page"] { opacity: 1; background: rgb(255 255 255 / 0.18); }

/* ---- Mileage ---- */

fieldset.card { min-width: 0; margin: 0 0 16px; }
fieldset legend { font-weight: 700; font-size: 1.05rem; padding: 0; float: left; width: 100%; margin-bottom: 12px; }
.vehicle-options { clear: both; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: 14px;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.choice strong { display: block; }
.choice small { display: block; color: var(--muted); font-size: 0.85rem; }
.vehicle .reg { margin-top: 14px; max-width: 260px; }
.vehicle .reg input { text-transform: uppercase; }
.vehicle .row-error { margin-top: 10px; }
.small-note { font-size: 0.85rem; margin: 12px 0 0; }

.days-head.journeys, .day.journey {
  grid-template-columns: 150px 72px minmax(160px, 1fr) minmax(160px, 1fr) 80px 116px 36px;
}
.day.journey { row-gap: 8px; padding-top: 10px; padding-bottom: 12px; }
.day.journey .notes { grid-column: 3 / 7; grid-row: 2; }
.day.journey .standard { grid-column: 1 / 3; grid-row: 2; }
.standard-in { font-size: 0.9rem; }
.day.journey { align-items: start; }
.day.journey .dayname, .day.journey .miles, .day.journey .passengers, .day.journey .remove { margin-top: 12px; }
.day.journey .date { margin-top: 12px; }
.day.journey .place { min-height: 38px; height: 62px; resize: none; padding: 6px 8px; line-height: 1.35; }
.day.journey textarea {
  font: inherit; color: inherit; background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; resize: vertical; min-height: 60px;
}
.car-fields { display: flex; gap: 16px; flex-wrap: wrap; }
.car-fields .reg { margin-top: 14px; }
.car-fields #car-field { min-width: 300px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stepper .step {
  width: 36px; height: 36px; border: 0; background: var(--surface-2); color: var(--text);
  font-size: 1.15rem; font-weight: 700; cursor: pointer;
}
.stepper .step:disabled { opacity: 0.35; cursor: default; }
.stepper output { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.passengers { justify-self: center; }
.totals-grid dd small { display: block; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.miles-in { text-align: right; }
.totals-grid.three { grid-template-columns: repeat(3, 1fr); }
.totals-grid dd.smaller { font-size: 1.05rem; padding-top: 4px; }

.needs { color: var(--late); font-weight: 700; white-space: nowrap; }
.notice ul { margin: 6px 0; padding-left: 20px; font-weight: 400; }
.notice a { color: inherit; }

/* ---- Payroll settings ---- */

.card > h2 { margin-bottom: 4px; }
.card > .muted { margin-top: 0; max-width: 80ch; }
.reopen-form { display: grid; grid-template-columns: 1.4fr 1.4fr 1fr auto; gap: 12px; align-items: end; margin: 12px 0; }
.settings-table { margin-top: 8px; }
.car-row { display: grid; grid-template-columns: 150px 1fr 1.2fr 36px; gap: 12px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--border); }
.car-row .remove { margin-bottom: 3px; }
.card-actions { margin-top: 14px; }
.rate-set { border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; margin-top: 10px; }
.rate-set > summary {
  cursor: pointer; font-weight: 700; padding: 12px 0; list-style-position: inside;
}
.rate-set > summary .muted { font-weight: 400; }
.rate-set[open] { padding-bottom: 14px; }
.rate-set[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.staff-field { margin: 12px 0; }
.staff-field textarea {
  font: 0.95rem/1.5 ui-monospace, Menlo, Consolas, monospace; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; width: 100%; max-width: 520px; resize: vertical;
}
.journey-row { display: grid; grid-template-columns: 1fr 1fr 100px 36px; gap: 12px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--border); }
.journey-row .remove { margin-bottom: 3px; }
.rate-set-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 12px; }
.rate-set-head .field { width: 200px; }
.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.rate-grid { align-items: end; }
.rate-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; }
.pence { display: flex; align-items: center; gap: 6px; }
.pence input { width: 80px; text-align: right; min-height: 38px; padding: 6px 8px; }
.pence small { color: var(--muted); }
.save-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap;
  padding: 4px 0 16px;
}
/* With unsaved changes the bar stays on screen, raised like the staff forms' bottom bar. */
.save-bar.dirty {
  position: sticky; bottom: 0; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.save-bar .errors { margin: 0; flex: 1 1 100%; }
.saved { color: var(--accent); font-weight: 600; }
.saved.unsaved { color: var(--late); }
.stat.warn { border-color: var(--late); background: var(--late-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ---- Form fields ---- */

.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.bot-check { margin-top: 16px; }
.bot-check:empty { display: none; }

.notice {
  background: var(--late-soft); color: var(--text);
  border-left: 4px solid var(--late); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 16px; font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
input, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 42px;
  width: 100%;
  font-weight: 400;
}
select:disabled { opacity: 0.45; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.details { display: grid; grid-template-columns: 1fr 1fr 290px; gap: 16px; }

/* ---- Buttons ---- */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 10px 18px;
  min-height: 44px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 4px 12px; min-height: 34px; font-size: 0.875rem; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1f18; } }

.actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }
.actions.center { justify-content: center; }

/* ---- Day rows ---- */

h2 { font-size: 1.1rem; margin: 0 0 12px; }
.center { text-align: center; }

.days-card { padding: 8px 0 0; }
.days-head, .day {
  display: grid;
  grid-template-columns: 150px 72px 96px 96px 96px 56px 44px 64px minmax(120px, 1fr) 36px;
  gap: 8px;
  align-items: center;
  padding: 6px 16px;
}
.days-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.day { border-bottom: 1px solid var(--border); border-left: 4px solid transparent; padding-left: 12px; }
.day[data-type="sick"] { border-left-color: var(--sick); }
.day[data-type="annual"] { border-left-color: var(--annual); }
.day.has-error { background: var(--danger-soft); }
.days-foot { padding: 14px 16px; }

.f-label { display: none; }
.dname { font-weight: 600; color: var(--muted); }
.late-tag {
  display: inline-block;
  font-size: 0.7rem; font-weight: 700; line-height: 1.3;
  color: var(--late); background: var(--late-soft);
  padding: 1px 6px; border-radius: 99px; white-space: nowrap;
}
.dayname { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.day-total .val { font-weight: 700; font-variant-numeric: tabular-nums; display: block; text-align: right; }
.f select, .f input { min-height: 38px; padding: 6px 8px; }
.f input[type="date"] { padding: 4px 8px; }

.typebox { display: flex; justify-content: center; align-items: center; cursor: pointer; min-height: 38px; }
.typebox input { width: 20px; height: 20px; min-height: 0; margin: 0; cursor: pointer; }
.typebox span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.typebox input[value="sick"] { accent-color: var(--sick); }
.typebox input[value="annual"] { accent-color: var(--annual); }

.remove {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: 8px;
  background: none; color: var(--muted);
  cursor: pointer;
}
.remove:hover { background: var(--surface-2); color: var(--danger); }
.row-error { grid-column: 1 / -1; color: var(--danger); font-size: 0.875rem; font-weight: 600; }
.row-error:empty { display: none; }

.totals-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0; }
.totals-grid > div { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; }
.totals-grid dt { font-size: 0.85rem; color: var(--muted); }
.totals-grid dd { margin: 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.totals-grid .grand { background: var(--accent-soft); }
.totals-grid .grand dd { color: var(--accent); }
#review-totals { margin-top: 16px; }

/* ---- Sticky totals bar ---- */

.sticky-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}
.sticky-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.totals { display: flex; gap: 18px; color: var(--muted); }
.totals strong { color: var(--text); font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* ---- Review / tables ---- */

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0 0 16px; }
.summary dt { font-size: 0.8rem; color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; word-break: break-word; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
tfoot th { border-bottom: 0; font-size: 1rem; }

.confirm { display: flex; gap: 10px; align-items: flex-start; margin-top: 18px; font-weight: 600; }
.confirm input { width: 22px; height: 22px; min-height: 0; margin: 1px 0 0; flex: none; }
.confirm.small { font-weight: 400; font-size: 0.9rem; color: var(--muted); }

.errors {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  white-space: pre-line;
  font-weight: 600;
}

/* ---- Done ---- */

.done { text-align: center; padding: 36px 20px; max-width: 620px; margin: 32px auto; }
.done h1 { margin-top: 12px; }
.tick {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.reference { font-size: 1.1rem; }
.reference strong { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.04em; }

/* ---- Admin ---- */

.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar .field { width: 300px; }
.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stats:empty { display: none; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.stat span { display: block; font-size: 0.85rem; color: var(--muted); }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.status { color: var(--muted); padding: 8px 0; }
.badge { font-size: 0.75rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); padding: 1px 7px; border-radius: 99px; }
.badge.muted { background: var(--surface-2); color: var(--muted); }
tr.old td { color: var(--muted); }
code { font-size: 0.85rem; }

/* ---- Small screens ---- */

@media (max-width: 900px) {
  .details { grid-template-columns: 1fr; }
  .days-head { display: none; }
  .day {
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    padding: 14px 16px 14px 12px;
  }
  .day .date { grid-column: 1 / 4; }
  .day .dayname { grid-column: 4 / 6; }
  .remove { grid-column: 6; grid-row: 1; justify-self: end; align-self: start; }
  .day > label:nth-of-type(2), .day > label:nth-of-type(3), .day > label:nth-of-type(4) { grid-column: span 2; }
  .day-total { grid-column: 1 / 3; }
  .typebox { grid-column: span 2; justify-content: flex-start; gap: 8px; align-self: end;
    border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; min-height: 44px; }
  .typebox span { position: static; width: auto; height: auto; clip: auto; font-size: 0.9rem; font-weight: 600; }
  .typebox:has(input:checked) { background: var(--surface-2); }
  .notes { grid-column: 1 / -1; }
  .f-label { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
  .dname { display: block; padding-top: 9px; color: var(--text); }
  .day-total .val { text-align: left; font-size: 1.05rem; padding-top: 6px; }
  .f select, .f input { min-height: 44px; }
  .days-foot .btn { width: 100%; }
  .totals-grid { grid-template-columns: 1fr 1fr; }
  .summary { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .day.journey { grid-template-columns: repeat(6, 1fr); }
  .day.journey .date { grid-column: 1 / 4; }
  .day.journey .from, .day.journey .to, .day.journey .notes, .day.journey .standard { grid-column: 1 / -1; grid-row: auto; }
  .day.journey .miles { grid-column: 1 / 4; }
  .day.journey .passengers { grid-column: 4 / -1; justify-self: start; }
  .day.journey .dayname, .day.journey .miles, .day.journey .passengers, .day.journey .remove, .day.journey .date { margin-top: 0; }
  .reopen-form { grid-template-columns: 1fr 1fr; }
  .car-row { grid-template-columns: 1fr 1fr 36px; }
  .car-row .field:nth-of-type(3) { grid-column: 1 / 3; }
  .car-row .remove { grid-column: 3; grid-row: 1; }
  .journey-row { grid-template-columns: 1fr 100px 36px; }
  .journey-row .field:nth-of-type(1), .journey-row .field:nth-of-type(2) { grid-column: 1 / 3; }
  .journey-row .remove { grid-column: 3; grid-row: 1; }
  .journey-row .field:nth-of-type(3) { grid-column: 1 / 2; }
}

@media (max-width: 640px) {
  .vehicle-options { grid-template-columns: 1fr; }
  .vehicle .reg, .car-fields #car-field { max-width: none; min-width: 0; width: 100%; }
  .reopen-form { grid-template-columns: 1fr; }
  .rate-set-head { flex-direction: column; align-items: stretch; }
  .rate-set-head .field { width: 100%; }
  .rate-grid { grid-template-columns: 1fr 1fr; }
  .topnav { margin-left: 0; width: 100%; }
  .topnav a { flex: 1; text-align: center; background: rgb(255 255 255 / 0.06); }
  .totals-grid.three { grid-template-columns: 1fr 1fr; }
  .totals-grid.three .grand { grid-column: 1 / -1; }
  h1 { font-size: 1.35rem; }
  .totals { flex-direction: column; gap: 0; font-size: 0.85rem; }
  .totals strong { font-size: 1rem; }
  .sticky-inner .btn { flex: none; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat:last-child { grid-column: 1 / -1; }
  .stat { padding: 10px 12px; }
  .stat strong { font-size: 1.25rem; }
  .toolbar .field, .toolbar-actions, .toolbar-actions .btn { width: 100%; }

  /* Admin table becomes stacked cards */
  .admin-table thead { display: none; }
  .admin-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .admin-table td { border: 0; padding: 2px 0; text-align: left; }
  .admin-table td::before { content: attr(data-label); display: block; font-size: 0.75rem; color: var(--muted); }
  .admin-table td:first-child { grid-column: 1 / -1; font-weight: 600; font-size: 1.05rem; }
  .admin-table td:first-child::before, .admin-table td:last-child::before { content: none; }
  .admin-table td[data-label="Email"] { grid-column: 1 / -1; word-break: break-all; }
}

@media print {
  .topbar, .sticky-bar, .actions { display: none; }
}

.admin-table code, .admin-table td[data-label="Submitted"] { white-space: nowrap; }
