:root {
  color-scheme: light;
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --text: #2C2C2A;
  --text-2: #5F5E5A;
  --border: #E4E2DA;
  --accent: #185FA5;
  --on-accent: #FFFFFF;
  --danger: #A32D2D;
  --danger-bg: #FCEBEB;
  --ok-bg: #EAF3DE;
  --ok-text: #27500A;
  --warn-bg: #FAEEDA;
  --warn-text: #633806;
  --coral: #FAECE7;
  --coral-text: #712B13;
  --holiday: var(--coral);
  --holiday-text: var(--coral-text);
  --weekend: #F1EFE8;
  --leave: #F1EFE8;
  --leave-text: #444441;
  --muted: #76756F;

  --amber: #FAEEDA;  --amber-text: #633806;
  --teal: #E1F5EE;   --teal-text: #085041;
  --purple: #EEEDFE; --purple-text: #3C3489;
  --pink: #FBEAF0;   --pink-text: #72243E;
  --blue: #E6F1FB;   --blue-text: #0C447C;
  --red: #FCEBEB;    --red-text: #791F1F;
  --green: #EAF3DE;  --green-text: #27500A;
}

/* The chosen public holiday colour. Everything holiday-coloured reads these two tokens. */
.holiday-green { --holiday: var(--green); --holiday-text: var(--green-text); }
.holiday-red { --holiday: var(--red); --holiday-text: var(--red-text); }
.holiday-pink { --holiday: var(--pink); --holiday-text: var(--pink-text); }
.holiday-blue { --holiday: var(--blue); --holiday-text: var(--blue-text); }
.holiday-amber { --holiday: var(--amber); --holiday-text: var(--amber-text); }
.holiday-teal { --holiday: var(--teal); --holiday-text: var(--teal-text); }
.holiday-purple { --holiday: var(--purple); --holiday-text: var(--purple-text); }
.holiday-grey { --holiday: var(--leave); --holiday-text: var(--leave-text); }

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { font-weight: 500; line-height: 1.25; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
strong { font-weight: 500; }
p { margin: 0; }
a { color: var(--accent); }
ul { list-style: none; margin: 0; padding: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* Layout */

.topbar {
  display: flex; align-items: center; gap: 24px;
  max-width: 1248px; margin: 0 auto; padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 500; font-size: 15px; color: var(--text); text-decoration: none; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; white-space: nowrap; }
.topnav a:hover { background: var(--weekend); }
.topnav a[aria-current] { color: var(--text); background: var(--weekend); font-weight: 500; }

.page { max-width: 1248px; margin: 0 auto; padding: 24px; }
.section { margin-top: 24px; }
.section > h2, .section-head { margin-bottom: 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.tabs { display: none; }

.subtabs { display: flex; gap: 4px; margin: 12px 0 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.subtabs a { padding: 8px 12px; color: var(--text-2); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtabs a[aria-current] { color: var(--text); font-weight: 500; border-bottom-color: var(--accent); }

.year-links { display: flex; gap: 12px; }
.year-links a[aria-current] { color: var(--text); font-weight: 500; text-decoration: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.list { overflow: hidden; }
.list > * + * { border-top: 1px solid var(--border); }
.list-row { display: block; padding: 12px 16px; color: var(--text); text-decoration: none; }

.sub { color: var(--text-2); }
.meta { color: var(--text-2); font-size: 13px; }
.optional { color: var(--text-2); font-weight: 400; }
.tag { display: inline-block; padding: 0 6px; border-radius: 6px; font-size: 13px; background: var(--weekend); color: var(--text-2); }

.notice, .alert { padding: 8px 12px; border-radius: 8px; margin-bottom: 16px; }
.notice { background: var(--ok-bg); color: var(--ok-text); }
.alert { background: var(--danger-bg); color: var(--danger); }
.alert a { color: inherit; }

/* Controls */

button, .btn, .btn-primary, input, select {
  font: inherit; color: inherit; border-radius: 8px;
}
button, .btn, .btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border);
  text-decoration: none; cursor: pointer;
}
button:hover, .btn:hover { background: var(--weekend); }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.btn-primary:hover, button.btn-primary:hover { background: var(--accent); filter: brightness(0.92); }
.btn-danger { color: var(--danger); }
.btn-link, button.btn-link { background: none; border: none; padding: 4px 0; min-height: 0; color: var(--accent); text-decoration: underline; }
.btn-link:hover, button.btn-link:hover { background: none; }
.btn-link-danger, button.btn-link-danger { color: var(--danger); }
.logout { flex: none; }
.logout .btn-link { color: var(--text-2); }

.theme-switch { display: inline-flex; flex: none; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.theme-switch button { min-height: 28px; padding: 2px 8px; font-size: 13px; color: var(--text-2); background: none; border: none; border-radius: 0; }
.theme-switch button + button { border-left: 1px solid var(--border); }
.theme-switch button:hover { background: var(--weekend); }
.theme-switch button:focus-visible { outline-offset: -2px; }
.theme-switch button[aria-pressed='true'] { background: var(--weekend); color: var(--text); font-weight: 500; }
.theme-switch + .meta { margin-top: 8px; }

input, select { width: 100%; min-height: 36px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); }
input[type='radio'], input[type='checkbox'] { width: auto; min-height: 0; }
input.short { display: block; max-width: 90px; }

label { display: block; font-size: 13px; color: var(--text-2); }
label input, label select { margin-top: 4px; color: var(--text); font-size: 15px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
label.check input { margin: 0; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.fields .wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: center; max-width: 480px; }
.inline-form select { flex: 1; min-width: 0; }
.inline-form button { flex: none; white-space: nowrap; }

.form-card { padding: 12px 16px; margin-top: 8px; }
.form-card > summary, .off-list > summary { cursor: pointer; font-weight: 500; }
.form-card[open] > summary { margin-bottom: 12px; }
.form-card form + form { margin-top: 12px; }
.form-card > summary .chip { margin-right: 4px; }
.off-list { padding: 12px 16px; margin-top: 8px; }
.off-list .sub { margin-top: 8px; }

.pager { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font-size: 20px; line-height: 1;
}
.pager-today { margin-left: 4px; }

/* Chips and swatches */

.chip {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 22px; padding: 0 5px; border-radius: 6px;
  font-size: 12px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums;
  background: transparent; color: var(--muted);
}
.sw-amber { background: var(--amber); color: var(--amber-text); }
.sw-teal { background: var(--teal); color: var(--teal-text); }
.sw-purple { background: var(--purple); color: var(--purple-text); }
.sw-pink { background: var(--pink); color: var(--pink-text); }
.sw-blue { background: var(--blue); color: var(--blue-text); }
.sw-red { background: var(--red); color: var(--red-text); }
.sw-green { background: var(--green); color: var(--green-text); }
.sw-coral { background: var(--coral); color: var(--coral-text); }
.sw-grey { background: var(--leave); color: var(--leave-text); }
.chip-ph { background: var(--holiday); color: var(--holiday-text); }
.chip-nw { box-shadow: inset 0 0 0 1px var(--text-2); color: var(--text-2); }
.chip-off { color: var(--muted); font-weight: 400; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 0; border: none; }
.swatches legend { font-size: 13px; color: var(--text-2); padding: 0; margin-bottom: 4px; }
.swatch { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.swatch input { margin: 0; }
.swatch.sw-amber { color: var(--amber-text); }
.swatch.sw-teal { color: var(--teal-text); }
.swatch.sw-purple { color: var(--purple-text); }
.swatch.sw-pink { color: var(--pink-text); }
.swatch.sw-blue { color: var(--blue-text); }

/* Today */

.holiday-banner { background: var(--holiday); color: var(--holiday-text); padding: 8px 12px; border-radius: 8px; margin-top: 12px; }
.holiday-banner .tag { background: transparent; color: inherit; padding: 0; }
.day-group { padding: 12px 16px; margin-top: 12px; }
.day-group h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.count { margin-left: auto; color: var(--text-2); font-weight: 400; }
.person { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; min-height: 34px; }
.list > .person { padding: 10px 16px; }
.person strong { display: block; }
.person .meta { display: block; }
.day-group .person .meta { text-align: right; }
.nobody { color: var(--danger); padding: 4px 0; }
.empty { padding: 24px; margin-top: 12px; }
.empty h2 { font-size: 18px; margin-bottom: 4px; }
.empty .btn-primary { margin-top: 12px; }

/* Month */

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0; font-size: 13px; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

.roster-wrap { overflow: auto; max-height: calc(100vh - 220px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.roster { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.roster th, .roster td { padding: 0; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); background: var(--surface); }
.roster tbody tr:last-child > * { border-bottom: none; }
.roster tr > *:last-child { border-right: none; }

.roster thead th { position: sticky; top: 0; z-index: 2; font-weight: 400; color: var(--text-2); }
.roster thead th a { display: block; min-width: 33px; padding: 4px 0; color: inherit; text-decoration: none; text-align: center; line-height: 1.25; }
.roster thead th span { display: block; font-size: 12px; }

.roster .name-col { position: sticky; left: 0; z-index: 1; width: 140px; min-width: 140px; max-width: 140px; padding: 0 10px; text-align: left; font-weight: 400; color: var(--text); }
.roster .name-col span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster thead .name-col { z-index: 3; color: var(--text-2); }

.roster .is-weekend { background: var(--weekend); }
.roster thead .is-holiday { background: var(--holiday); color: var(--holiday-text); }
.roster td.is-holiday .cell-off { background: var(--holiday); color: var(--holiday-text); }
.roster thead .is-today { color: var(--accent); font-weight: 500; }
.roster thead .is-today a { font-weight: 500; }
.roster .is-today { box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent); }

.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 100%; min-width: 33px; height: 34px; min-height: 0; padding: 0; border: none; border-radius: 0;
  font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.cell:hover { outline: 2px solid var(--text-2); outline-offset: -2px; }
.cell:focus-visible { outline-offset: -2px; }
button.cell { background: transparent; }
button.cell.sw-amber { background: var(--amber); }
button.cell.sw-teal { background: var(--teal); }
button.cell.sw-purple { background: var(--purple); }
button.cell.sw-pink { background: var(--pink); }
button.cell.sw-blue { background: var(--blue); }
button.cell.sw-red { background: var(--red); }
button.cell.sw-green { background: var(--green); }
button.cell.sw-coral { background: var(--coral); }
button.cell.sw-grey { background: var(--leave); }
button.cell.cell-ph { background: var(--holiday); color: var(--holiday-text); }
.cell-nw { color: var(--text-2); box-shadow: inset 0 0 0 1px var(--text-2); }
.cell-off { color: var(--muted); font-weight: 400; }
.is-changed::after { content: ''; position: absolute; top: 3px; right: 3px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.tail { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: color-mix(in srgb, var(--tail) 45%, transparent); }
.tail.is-now { width: 4px; background: var(--tail); animation: tail-pulse 2s ease-in-out infinite; }
@keyframes tail-pulse { 50% { opacity: 0.3; } }
.tail-amber { --tail: var(--amber-text); }
.tail-teal { --tail: var(--teal-text); }
.tail-purple { --tail: var(--purple-text); }
.tail-pink { --tail: var(--pink-text); }
.tail-blue { --tail: var(--blue-text); }
.stripe { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--tail); }
.tail-key { position: relative; display: inline-block; width: 30px; height: 22px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.still-on { margin: 0 0 12px; font-size: 13px; color: var(--text-2); }
.still-on strong { color: var(--text); }

.holiday-list li { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 4px 0; }
.holiday-date { min-width: 56px; color: var(--text-2); font-variant-numeric: tabular-nums; }

dialog {
  width: min(460px, calc(100vw - 32px)); padding: 20px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
}
dialog[open] { animation: fade 120ms ease-out; }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; margin-top: 12px; }
.options button { justify-content: flex-start; min-height: 44px; text-align: left; }
.dialog-foot { display: flex; justify-content: space-between; margin-top: 12px; }

/* Staff */

.staff-row { padding: 12px 16px; }
.staff-main { display: flex; justify-content: space-between; gap: 12px; }
.staff-main strong { display: block; }
.staff-pager { margin: 24px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chips li { text-align: center; }
.chip-day { display: block; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chips .is-today .chip-day { color: var(--accent); font-weight: 500; }

/* Settings */

.colour-row { margin: 0 0 12px; padding: 0; border: none; }
.colour-row legend { padding: 0; margin-bottom: 6px; }
.dots { display: flex; flex-wrap: wrap; gap: 8px; }
.dot { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 1px solid currentColor; border-radius: 50%; cursor: pointer; }
.dot input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.dot:has(input:checked)::after { content: '\2713'; font-size: 15px; font-weight: 500; line-height: 1; }
.dot:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.slots { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.slots select { width: 76px; }
.slot-buttons { display: flex; gap: 8px; margin-bottom: 12px; }

.holiday-row { padding: 10px 16px; }
div.holiday-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.holiday-summary { display: flex; gap: 12px; }
summary.holiday-summary { cursor: pointer; list-style: none; }
summary.holiday-summary::-webkit-details-marker { display: none; }
.holiday-name .meta { margin-left: 4px; }
details.holiday-row form { margin-top: 12px; }

/* Requests */

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: var(--surface); font-size: 12px; font-weight: 500; line-height: 1;
}
.tab-icon { position: relative; display: inline-flex; }
.tab-icon .badge { position: absolute; top: -6px; left: 14px; }

.status { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.status-waiting { background: var(--warn-bg); color: var(--warn-text); }
.status-ok { background: var(--ok-bg); color: var(--ok-text); }
.status-no { background: var(--danger-bg); color: var(--danger); }
.status-neutral { background: var(--weekend); color: var(--text-2); }

.gap-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: var(--text); text-decoration: none; }
.gap-row:hover { background: var(--weekend); }
.gap-main { flex: 1; min-width: 0; }
.gap-main strong, .gap-main .meta { display: block; }
.gap-action { color: var(--accent); white-space: nowrap; }

.suggestion { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.suggestion-main { flex: 1; min-width: 0; }
.suggestion-main strong, .suggestion-main .meta { display: block; }
.suggestion-actions { display: flex; gap: 8px; }
.meta.warn { color: var(--warn-text); font-weight: 500; }
.rank {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%; background: var(--weekend); color: var(--text-2); font-size: 13px; font-weight: 500;
}
.left-out { color: var(--text-2); }
.left-out li { padding: 2px 0; }

.timeline { list-style: none; margin: 0; padding: 12px 16px; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--border); }
.timeline strong, .timeline .meta { display: block; }

.needs-cover {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-top: 4px; padding: 8px 10px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn-text); text-decoration: none; font-weight: 500;
}
.needs-cover .meta { color: inherit; font-weight: 400; }

.needs-cover-cell { position: relative; }
.needs-cover-cell::before {
  content: ''; position: absolute; z-index: 1; left: 0; bottom: 0;
  border-left: 9px solid var(--danger); border-top: 9px solid transparent;
}

.dialog-link { margin-top: 12px; }
a.dialog-link:not(.btn-primary) { display: inline-block; }
a.dialog-link[hidden] { display: none; }

.btn-wide { width: 100%; margin-top: 8px; min-height: 44px; }

/* Login */

.login { max-width: 400px; margin: 10vh auto 0; padding: 24px; }
.login .brand { margin-bottom: 16px; }
.login .sub { margin-top: 4px; }
.login form { margin-top: 16px; }
.login .btn-primary { width: 100%; margin-top: 12px; min-height: 44px; }
.login p:last-child { margin-top: 12px; }

/* Tablets: tighter, so everything in the top bar still fits on one line */

@media (max-width: 899px) {
  .topbar { gap: 12px; padding: 12px 16px; }
  .topnav a { padding: 6px 8px; }
}

/* Phones */

@media (max-width: 767px) {
  input, select, button { font-size: 16px; }
  label input, label select { font-size: 16px; }

  .topbar { padding: 12px 16px; }
  .topnav { display: none; }
  .logout { display: none; }
  .topbar .theme-switch { display: none; }

  .page { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(4, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabs a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; color: var(--text-2); text-decoration: none; font-size: 12px;
  }
  .tabs a[aria-current] { color: var(--accent); font-weight: 500; }
  .tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

  button, .btn, .btn-primary { min-height: 44px; }
  button.btn-link { min-height: 0; padding: 8px 0; }
  .theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); }
  .theme-switch button { min-height: 44px; font-size: 15px; }
  .icon-btn { width: 44px; height: 44px; }
  input, select { min-height: 44px; }

  .roster-wrap { max-height: calc(100vh - 280px); }
  .roster .name-col { width: 88px; min-width: 88px; max-width: 88px; padding: 0 8px; }
  .roster thead th a { min-width: 36px; }
  .cell { min-width: 36px; height: 40px; min-height: 40px; }

  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 12px 12px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

  .inline-form { flex-direction: column; align-items: stretch; }
  .legend { font-size: 12px; }
  .subtabs a { padding: 8px 6px; font-size: 14px; }
  .dots { gap: 5px; }
  .dot { width: 29px; height: 29px; }
  .suggestion { flex-wrap: wrap; }
  .suggestion-main { flex-basis: calc(100% - 36px); }
  .suggestion-actions { flex-basis: 100%; }
  .suggestion-actions form { flex: 1; }
  .suggestion-actions button { width: 100%; }
  .gap-row .gap-action { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  dialog[open], .tail.is-now { animation: none; }
}
