:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --text: #171a1f;
  --muted: #5d6673;
  --line: #dde1e7;
  --accent: #2f6fd6;
  --accent-text: #ffffff;
  --warn: #c8443b;
  --warn-bg: #fdeceb;
  --radius: 14px;
  --gutter: 16px;
  --tabs-h: 76px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --surface: #1d2128; --surface-2: #272c35; --text: #eef0f3; --muted: #9aa3b0;
    --line: #333945; --accent: #6aa0ff; --accent-text: #0b1220; --warn: #ff8a80; --warn-bg: #3a2220;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --surface: #1d2128; --surface-2: #272c35; --text: #eef0f3; --muted: #9aa3b0;
  --line: #333945; --accent: #6aa0ff; --accent-text: #0b1220; --warn: #ff8a80; --warn-bg: #3a2220;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) var(--gutter) 24px; }
h1 { font-size: 1.35rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .9rem; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.block { display: flex; width: 100%; }
.btn.danger { color: var(--warn); }
.btn[disabled] { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field select, .field input {
  width: 100%; min-height: 46px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
input[type="color"] { padding: 4px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--muted); font-size: .75rem; font-weight: 600;
}
.tabs button[aria-current="page"] { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cal-head h1 { margin: 0; flex: 1; text-align: center; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 1.2rem; }
.people { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.person { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.person[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow span { text-align: center; font-size: .72rem; color: var(--muted); padding: 4px 0; }
.day {
  position: relative; aspect-ratio: 1 / 1.08; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 2px 5px; min-width: 0;
}
.day.blank { border: 0; background: none; }
.day .n { font-size: .72rem; color: var(--muted); }
.day.today .n { color: var(--accent); font-weight: 800; }
.day.today { border-color: var(--accent); }
.chip {
  min-width: 70%; max-width: 100%; padding: 3px 4px; border-radius: 8px; text-align: center; font-weight: 800; font-size: .85rem;
  color: #fff; background: var(--c, #8a929c); overflow: hidden; text-overflow: clip; white-space: nowrap;
}
.chip.off { background: var(--surface-2); color: var(--muted); }
.chip.empty { background: none; color: var(--muted); font-weight: 400; }
.day.flag { border: 2px solid var(--warn); background: var(--warn-bg); }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stat { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.stat b { display: block; font-size: 1.2rem; }
.stat .muted { font-size: .78rem; }
.empty-state { text-align: center; padding: 36px 12px; }

/* scan */
.strip { display: block; width: 100%; height: 30px; object-fit: cover; object-position: left center; border-radius: 6px; background: var(--surface-2); }
.rowcard { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; }
.rowcard .minis { display: flex; gap: 2px; margin-top: 6px; flex-wrap: nowrap; overflow: hidden; }
.mini { flex: 1 1 0; height: 10px; border-radius: 2px; background: var(--c, #8a929c); min-width: 0; }
.mini.q { background: var(--warn); }
.scroller { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 10px; }
.scroller img { display: block; height: 44px; width: auto; max-width: none; }
.notice { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden], .toast[hidden] { display: none; }
.sheet-body {
  width: 100%; max-width: 640px; max-height: 80vh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom));
}
.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 10px; }
.pick button { min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pick .chip { min-width: 40px; }
.pick small { color: var(--muted); font-size: .7rem; line-height: 1.1; text-align: center; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 20; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; }

/* settings */
.shift-edit { display: grid; grid-template-columns: 56px 1fr; gap: 8px; align-items: center; margin-bottom: 10px; }
.shift-edit .times { grid-column: 2; display: flex; gap: 8px; align-items: center; }
.shift-edit input[type="time"] { flex: 1; width: 0; min-width: 0; min-height: 40px; padding: 0 8px; }
.shift-edit input[type="color"] { width: 48px; min-height: 40px; }
.shift-edit input[type="text"] { min-height: 40px; }

/* table corner editor */
.crop-scroll { overflow: auto; padding: 20px; margin: 0 -8px 12px; border-radius: 8px; background: var(--surface-2); max-height: 62vh; touch-action: pan-x pan-y; }
.cropper { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.cropper img { display: block; width: 100%; height: auto; pointer-events: none; }
.cropper svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cropper polygon { fill: rgba(47, 111, 214, .12); stroke: #2f6fd6; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.handle { position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%; background: #2f6fd6; border: 4px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.5); touch-action: none; cursor: grab; }

/* calendar fills the screen: the month grid takes all the height the header and summary leave */
main { max-width: 760px; }
body:has(main.fill) { padding-bottom: 0; }
main.fill { display: flex; flex-direction: column; min-height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom)); padding-bottom: 12px; }
main.fill .cal-head, main.fill .people, main.fill .dow, main.fill .summary { flex: none; }
main.fill .fill-grid { flex: 1; min-height: 0; grid-template-rows: repeat(var(--weeks), minmax(48px, 1fr)); }
main.fill .fill-grid .day { aspect-ratio: auto; min-height: 0; padding: 6px 3px 8px; }
main.fill .fill-grid .day .n { font-size: clamp(.72rem, 1.9vh, .95rem); }
main.fill .fill-grid .chip { font-size: clamp(.85rem, 2.6vh, 1.2rem); padding: clamp(3px, .9vh, 9px) 4px; min-width: 76%; }
main.fill .summary { margin-top: 12px; }

/* bottom scan bar replaces the tab bar */
.tabs { display: none; }
.scanbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--line); padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom)); }
.scanbar .btn { max-width: 728px; margin: 0 auto; }
.scanbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* top of the calendar: person dropdown and settings */
.top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.top select { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 1.05rem; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* pop-up window */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 8; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100dvh - 24px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.35); outline: none; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h1 { flex: 1; margin: 0; font-size: 1.1rem; }
.modal-body { overflow: auto; padding: 14px 16px; flex: 1; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.modal-foot[hidden] { display: none; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); margin-bottom: 12px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }
.suggest { font-size: .85rem; margin: -6px 0 12px; color: var(--muted); }
.suggest.good { color: #2a9d6f; }
.suggest.warn { color: var(--warn); }
.sumrow { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; min-height: 52px; }
.sumrow.skipped { opacity: .55; }
.tag { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.ok { background: #dff3ea; color: #1d7a55; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.person-edit { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.person-edit input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag.ok { background: #1c3a2e; color: #7bd3ab; } }

/* day numbers above the photo strip */
.scroller img { height: 52px; }
.stripwrap { position: relative; display: inline-block; padding-top: 20px; }
.ruler { position: absolute; top: 0; left: 0; right: 0; height: 20px; }
.ruler span { position: absolute; top: 2px; transform: translateX(-50%); font-size: .7rem; line-height: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ruler span.bad { color: #fff; background: var(--warn); border-radius: 8px; padding: 0 5px; font-weight: 800; }

/* every field gets the theme's own colours: unstyled inputs kept the browser's white background while their
   text took the dark theme's light colour (white on white) */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
input:not([type="color"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]), select {
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
}
input::placeholder { color: var(--muted); opacity: 1; }
.shift-edit input[type="time"] { font-size: .85rem; padding: 0 4px 0 8px; }
.shift-edit .times { gap: 6px; }

/* "All" view: one small chip per shift with the number of people on it */
.day.multi { justify-content: flex-start; gap: 3px; overflow: hidden; }
.day.multi .stack { display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; min-height: 0; }
main.fill .fill-grid .day.multi { padding: 4px 2px 4px; }
main.fill .fill-grid .day.multi .chip.tiny { font-size: clamp(.62rem, 1.7vh, .8rem); padding: 1px 2px; min-width: 0; width: 100%; line-height: 1.25; border-radius: 6px; }
.chip small { font-weight: 600; font-size: .85em; opacity: .95; }
.grp { margin-top: 14px; }
.grp-head { display: flex; align-items: center; gap: 10px; }
.grp-head .chip { min-width: 44px; }
.names { list-style: none; margin: 6px 0 0; padding: 0; }
.names li { padding: 8px 2px; border-top: 1px solid var(--line); }

/* the All view: chips keep their size and each week grows to fit them, so the page scrolls on a short screen
   instead of squashing the text into lines */
.day.multi .stack .chip.tiny { flex: none; }
main.fill .fill-grid.fit { grid-template-rows: repeat(var(--weeks), minmax(max-content, 1fr)); }
main.fill .fill-grid.fit .day.multi { min-height: auto; overflow: visible; }
@media (max-width: 380px) { main.fill .fill-grid .day.multi .chip.tiny { font-size: .56rem; letter-spacing: -.2px; } }

.modal-body .grp:first-child { margin-top: 0; }

.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

/* first-visit setup */
.progress.big { height: 12px; border-radius: 6px; margin: 18px 0 10px; }
.progress.big i { transition: width .2s ease; }
.ok-box { background: #dff3ea; color: #14573d; border: 1px solid #2a9d6f; border-radius: 12px; padding: 12px 14px; margin-bottom: 4px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ok-box { background: #1c3a2e; color: #bfeed7; } }
.benefits { padding-left: 20px; margin: 0 0 14px; }
.benefits li { margin-bottom: 8px; }

/* circular progress */
.ring { position: relative; width: 150px; height: 150px; margin: 18px auto 12px; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .25s ease; }
.ring-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .ring-fill { transition: none; } }

/* two long buttons stacked, main action first */
.stack-foot { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* Scan lives in the top row next to the name dropdown, so there is no bottom bar */
:root { --tabs-h: 0px; }
.scan-top { flex: none; width: 44px; min-height: 44px; padding: 0; border-radius: 12px; }
.scan-top svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.scanbar { display: none; }
/* a touch smaller so long names fit beside the two icon buttons */
.top select { font-size: .95rem; padding: 0 8px 0 12px; }

/* today: a tinted background as well as the outline */
:root { --today-bg: #dce8fb; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --today-bg: #263a58; } }
:root[data-theme="dark"] { --today-bg: #263a58; }
.day.today { background: var(--today-bg); border-color: var(--accent); border-width: 2px; }
.day.today .n { font-weight: 800; }
/* the date number on the tint: darker blue in light mode, lighter in dark, so it stays easy to read */
:root { --today-text: #174a9c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --today-text: #b9d3ff; } }
:root[data-theme="dark"] { --today-text: #b9d3ff; }
.day.today .n { color: var(--today-text); }

/* Shift types on narrow phones: the right-hand column may shrink below its contents' natural width
   (a grid column of 1fr cannot), otherwise the rows spill out of the card and the window scrolls sideways. */
.shift-edit { grid-template-columns: 56px minmax(0, 1fr); }
.shift-edit > * { min-width: 0; }
.card { min-width: 0; }
.modal-body { overflow-x: hidden; }
/* the colour picker follows the theme instead of the browser's grey frame */
input[type="color"] { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; width: 48px; height: 40px; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 7px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 7px; }
