:root {
  --green: #1f4d3f;
  --green-2: #2e6b58;
  --green-tint: #e6efeb;
  --paper: #f6f8f7;
  --surface: #ffffff;
  --ink: #17221e;
  --muted: #5e6b66;
  --line: #d9e1dd;
  --red: #b42318;
  --red-tint: #fdecea;
  --amber: #9a5a06;
  --amber-tint: #fdf3e2;
  --blue: #1d5a8c;
  --blue-tint: #e8f0f8;
  --grey-tint: #eef1f0;
  --radius: 6px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--paper); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
a { color: var(--green-2); }
p { margin: 0 0 .8em; }
.num, time, td.n { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid #7fb8a4; outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--green); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.05rem; padding: 0 10px 16px; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 10px; }
.brand small { display: block; font-weight: 400; opacity: .75; font-size: .8rem; }
.side a { color: #e3eee9; text-decoration: none; padding: 8px 10px; border-radius: var(--radius); display: flex; justify-content: space-between; align-items: center; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.active { background: #fff; color: var(--green); font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { font-size: .85rem; padding: 10px; border-top: 1px solid rgba(255,255,255,.15); opacity: .9; }
.side .who button { margin-top: 8px; }
.main { padding: 28px 32px 60px; max-width: 1280px; width: 100%; }
.topbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 30; transform: translateX(-105%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 12px; background: var(--green); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; }
  .main { padding: 18px 14px 60px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.toolbar label { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.section > h2:first-child { margin-top: 0; }

/* Stat strip: one row of figures, not a card per number */
.stats { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.stat { flex: 1 1 150px; padding: 14px 18px; border-right: 1px solid var(--line); text-decoration: none; color: inherit; }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert b { color: var(--red); }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 12px; color: var(--ink); }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #b9c5c0; border-radius: var(--radius); background: #fff; color: var(--ink); }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; margin-right: 6px; }
label.check { display: flex; align-items: center; font-weight: 500; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }

button, .btn { font: inherit; font-weight: 600; border-radius: var(--radius); border: 1px solid var(--green); background: var(--green); color: #fff; padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--green-2); }
button:disabled { opacity: .55; cursor: wait; }
button.secondary, .btn.secondary { background: #fff; color: var(--green); }
button.secondary:hover, .btn.secondary:hover { background: var(--green-tint); }
button.danger { background: var(--red); border-color: var(--red); }
button.small, .btn.small { padding: 4px 10px; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--green-2); padding: 0; text-decoration: underline; font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; font-weight: 650; color: var(--muted); background: #fafbfb; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fbfa; }
td.n, th.n { text-align: right; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Priority is shown as a coloured rule on the left edge of each request */
tr.p1 td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.p2 td:first-child { box-shadow: inset 4px 0 0 #d98a1a; }
tr.p3 td:first-child { box-shadow: inset 4px 0 0 var(--blue); }
tr.p4 td:first-child { box-shadow: inset 4px 0 0 #a9b4af; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--grey-tint); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--red-tint); color: var(--red); }
.badge.amber { background: var(--amber-tint); color: var(--amber); }
.badge.blue { background: var(--blue-tint); color: var(--blue); }
.badge.green { background: var(--green-tint); color: var(--green); }

/* ---------- Rota ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(140px, 1fr)); gap: 8px; overflow-x: auto; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 140px; display: flex; flex-direction: column; }
.day > header { padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: .9rem; display: flex; justify-content: space-between; }
.day.today > header { background: var(--green-tint); }
.day .shifts { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.shift { border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; font-size: .84rem; background: #fff; text-align: left; color: var(--ink); font-weight: 400; display: block; width: 100%; }
button.shift:hover { background: #f5f9f7; }
.shift b { font-weight: 650; }
.shift.gap { border-color: #e7b1ab; background: var(--red-tint); }
.shift.gap.rp { border: 2px solid var(--red); }
.shift .who { display: block; }
@media (max-width: 860px) { .week { grid-template-columns: 1fr; } .day { min-height: 0; } }

/* ---------- Clock ---------- */
.clock-panel { text-align: center; padding: 36px 20px; }
.clock-now { font-size: 3.2rem; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.clock-btn { font-size: 1.3rem; padding: 18px 42px; border-radius: 999px; margin-top: 18px; }
.clock-btn.out { background: var(--red); border-color: var(--red); }

/* ---------- KPI grid ---------- */
.kpi-grid input { width: 72px; text-align: right; padding: 6px; }
.kpi-grid th { white-space: normal; min-width: 90px; vertical-align: bottom; }
.meter { height: 6px; background: var(--grey-tint); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--green-2); }
.meter i.low { background: #d98a1a; }

/* ---------- Dialog, toast, auth ---------- */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 25, 20, .45); }
dialog .dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
dialog .dlg-head h2 { margin: 0; }
dialog .dlg-body { padding: 18px 20px; max-height: 75vh; overflow-y: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius); z-index: 100; max-width: 90vw; }
.toast.err { background: var(--red); }
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--amber-tint); color: #5c3a05; margin-bottom: 14px; }
.notice.info { background: var(--blue-tint); color: #123a5a; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--green); }
.auth-box { background: #fff; border-radius: 10px; padding: 30px; width: min(420px, 100%); }
.auth-box h1 { color: var(--green); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--green); border-color: var(--green); }
.comment { border-left: 3px solid var(--line); padding: 4px 12px; margin-bottom: 10px; }
.loading { color: var(--muted); padding: 20px 0; }

/* ---------- Kiosk ---------- */
.kiosk { min-height: 100vh; display: grid; place-items: center; background: var(--green); color: #fff; padding: 20px; }
.kiosk-box { width: min(420px, 100%); text-align: center; }
.kiosk-box .clock-now { color: #fff; }
.kiosk-box input { font-size: 1.4rem; text-align: center; padding: 12px; letter-spacing: .2em; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.pad button { font-size: 1.6rem; padding: 16px 0; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); justify-content: center; }
.pad button:hover { background: rgba(255,255,255,.2); }
.kiosk-result { font-size: 1.5rem; padding: 30px 10px; }
.kiosk-box .go { width: 100%; justify-content: center; font-size: 1.2rem; padding: 14px; background: #fff; color: var(--green); }

/* ---------- Print (invoices) ---------- */
.invoice-doc { background: #fff; border: 1px solid var(--line); padding: 36px; max-width: 800px; }
.invoice-doc .head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.invoice-doc pre { font: inherit; white-space: pre-wrap; margin: 0; }
@media print {
  .side, .topbar, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .invoice-doc { border: 0; padding: 0; }
}

/* ---------- Compliance matrix ---------- */
.matrix-wrap { overflow: auto; max-height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.matrix { border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid #edf1ef; padding: 0; text-align: center; }
.matrix thead th { position: sticky; top: 0; z-index: 2; background: #fafbfb; vertical-align: bottom; }
.matrix thead th.col { height: 170px; width: 38px; min-width: 38px; }
.matrix thead th.col span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; padding: 8px 0; max-height: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink); }
.matrix .name { position: sticky; left: 0; z-index: 1; background: #fff; text-align: left; padding: 6px 12px; min-width: 190px; white-space: nowrap; }
.matrix thead .name { z-index: 3; background: #fafbfb; }
.matrix .pct { padding: 6px 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.matrix tfoot td { background: #fafbfb; font-size: .78rem; color: var(--muted); padding: 6px 2px; position: sticky; bottom: 0; }
.cell { display: block; width: 38px; height: 34px; line-height: 34px; font-size: .78rem; font-weight: 700; border: 0; border-radius: 0; padding: 0; background: transparent; color: var(--muted); justify-content: center; }
button.cell { cursor: pointer; }
button.cell:hover { outline: 2px solid var(--green-2); outline-offset: -2px; background: inherit; }
.cell.s-done { background: #d7ebe1; color: var(--green); }
.cell.s-strong { background: var(--green-2); color: #fff; }
.cell.s-warn { background: var(--amber-tint); color: var(--amber); }
.cell.s-bad { background: var(--red-tint); color: var(--red); }
.cell.s-info { background: var(--blue-tint); color: var(--blue); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 16px; font-size: .85rem; color: var(--muted); align-items: center; }
.legend .cell { display: inline-block; width: 28px; height: 22px; line-height: 22px; text-align: center; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.bar { display: inline-block; width: 70px; height: 6px; background: var(--grey-tint); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-left: 6px; }
.bar i { display: block; height: 100%; background: var(--green-2); }
.bar i.low { background: var(--red); }
.bar i.mid { background: #d98a1a; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 4px 0 12px; }
.checks label { font-weight: 500; display: flex; align-items: center; margin: 0; }
.person-head { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline; }
