:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --text: #171a26;
  --muted: #646a7e;
  --border: #e1e3ea;
  --brand: #14182b;
  --brand-text: #ffffff;
  --accent: #c98a0b;
  --accent-soft: #fdf3dc;
  --good: #16794a;
  --good-soft: #e3f4ea;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --mine: #1f5fd1;
  --mine-soft: #e6eefc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 43, .06), 0 2px 8px rgba(20, 24, 43, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --surface: #181c2e;
    --surface-2: #20253a;
    --text: #e8eaf2;
    --muted: #9aa0b5;
    --border: #2b3149;
    --brand: #0a0d18;
    --accent: #f2b63c;
    --accent-soft: #3a2f14;
    --good: #4cc98a;
    --good-soft: #15301f;
    --bad: #ff7a6b;
    --bad-soft: #3a1a18;
    --mine: #7ea8ff;
    --mine-soft: #1c2a4a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- top bar ---------- */
.topbar {
  background: var(--brand);
  color: var(--brand-text);
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; letter-spacing: .2px; }
.logo svg { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  text-decoration: none; padding: 7px 11px; border-radius: 8px; white-space: nowrap;
  color: rgba(255,255,255,.75); font-size: .92rem;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.14); }
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 6px; }
  .nav { margin-left: 0; width: 100%; order: 3; }
}

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 500;
  min-height: 38px; white-space: nowrap;
}
a.btn { text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1405; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 9px 0 0 9px; }
.btn-group .btn:last-child { border-radius: 0 9px 9px 0; }
.btn-group .btn + .btn { margin-left: -1px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=tel], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); min-height: 40px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.money-input { position: relative; }
.money-input::before { content: "£"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 24px; }

/* ---------- cards & tables ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin-right: auto; }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
@media (max-width: 760px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }

/* ---------- rota ---------- */
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.week-label { font-weight: 700; min-width: 170px; text-align: center; }
.day { margin-bottom: 14px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.day-head h2 { margin-right: auto; }
.day.today .day-head h2::after { content: "Today"; margin-left: 8px; font-size: .7rem; vertical-align: middle; background: var(--accent); color: #1a1405; padding: 2px 7px; border-radius: 99px; }
.day-empty { color: var(--muted); font-size: .9rem; padding: 4px 0 6px; }
.venue-blocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.venue-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.venue-block h3 { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 1rem; }
.venue-block h3 .muted { font-weight: 500; font-size: .85rem; }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.person {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 9px; border-radius: 8px; background: var(--surface-2); font-size: .92rem;
}
.person.mine { background: var(--mine-soft); color: var(--mine); font-weight: 600; }
.person.unfilled { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
button.person { width: 100%; border: 0; cursor: pointer; text-align: left; }
button.person:hover { outline: 1px solid var(--border); }
.person .t { font-size: .8rem; opacity: .85; white-space: nowrap; font-weight: 500; }
.person .note { display: block; font-size: .78rem; font-weight: 400; opacity: .85; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 10, 20, .55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .spacer { margin-right: auto; }
.staff-picks { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; }
.staff-picks .check { padding: 5px 0; }
.staff-picks .clash { font-size: .78rem; color: var(--accent); }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 8px 11px; border-radius: 8px; margin-bottom: 12px; font-size: .9rem; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .logo { justify-content: center; font-size: 1.3rem; margin-bottom: 18px; color: var(--text); }
.login .logo svg { width: 36px; height: 36px; }
.login .btn { width: 100%; }

/* ---------- rota picker grids ---------- */
:root {
  --cov-none-bg: #eceef3; --cov-none-fg: #7a8093;
  --cov-gap-bg: #fbd9d5; --cov-gap-fg: #9b1c12; --cov-gap-bd: #e8857a;
  --cov-ok-bg: #d3efdf; --cov-ok-fg: #11633b; --cov-ok-bd: #6fc597;
}
@media (prefers-color-scheme: dark) {
  :root {
    --cov-none-bg: #232840; --cov-none-fg: #7f86a0;
    --cov-gap-bg: #4a1f1c; --cov-gap-fg: #ffb3aa; --cov-gap-bd: #a8463c;
    --cov-ok-bg: #173826; --cov-ok-fg: #8fe0b4; --cov-ok-bd: #2f7d52;
  }
}
.btn-group .btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .btn-group .btn.on { background: var(--accent); color: #1a1405; border-color: var(--accent); } }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: -4px 0 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid transparent; }

.cell {
  border: 1px solid transparent; border-radius: 9px; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  padding: 6px 4px; min-height: 50px; line-height: 1.15;
}
.cell:hover { filter: brightness(.96); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cell.none, .sw.none { background: var(--cov-none-bg); color: var(--cov-none-fg); }
.cell.gap, .sw.gap { background: var(--cov-gap-bg); color: var(--cov-gap-fg); border-color: var(--cov-gap-bd); }
.cell.ok, .sw.ok { background: var(--cov-ok-bg); color: var(--cov-ok-fg); border-color: var(--cov-ok-bd); }
.cell.current { box-shadow: 0 0 0 2px var(--accent); }
.cell.blank { background: none; cursor: default; }
.cell-main { font-weight: 700; font-size: .9rem; white-space: nowrap; }
.cell-sub { font-size: .72rem; font-variant-numeric: tabular-nums; opacity: .9; min-height: .9em; }

.pick-grid { display: flex; flex-direction: column; gap: 8px; }
.pick-month { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; }
.pick-month-name { font-weight: 700; color: var(--muted); font-size: .85rem; }
.pick-weeks { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.pick-days { min-width: 0; }
.cell { min-width: 0; overflow: hidden; }
@media (max-width: 480px) { .pick-weeks .cell-main { font-size: .78rem; } }

.pick-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.pick-days .dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.pick-days .cell { aspect-ratio: 1 / .85; min-height: 44px; }
.pick-days .cell-main { font-size: 1rem; }

.day.picked .day-head h2 { color: var(--accent); }
.day { scroll-margin-top: 120px; } /* clear the sticky top bar when jumping to a day */

.range-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 14px; }
.range-bar label.field { margin: 0; }
.range-bar input[type=date] { width: 160px; }
