:root {
  --navy: #050a30; --sky: #47b9f5; --sky-soft: #e8f6fe; --bg: #f5f7fb; --card: #fff;
  --text: #0d1333; --muted: #5d6585; --line: #e3e7f0; --red: #d92d3a; --red-soft: #fdecee;
  --amber: #b86e00; --amber-soft: #fff4e0; --green: #13804a; --green-soft: #e6f6ed;
  --r: 14px; --shadow: 0 1px 2px rgba(5,10,48,.06), 0 4px 16px rgba(5,10,48,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.top { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 17px; margin: 0; font-weight: 600; flex: 1; letter-spacing: .2px; }
.top .back, .top .link { background: none; border: 0; color: #fff; padding: 6px 4px; font-size: 15px; opacity: .9; }
.brand { font-weight: 700; letter-spacing: -.3px; }
.brand b { color: var(--sky); font-weight: 700; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 110px); }
.wide { max-width: 1180px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border: 0; border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 14px;
  text-align: left; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; position: relative; }
.tile .ic { font-size: 26px; }
.tile strong { font-size: 16px; }
.tile.primary { background: var(--navy); color: #fff; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--sky-soft); color: #0a6aa0; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.tile .badge { position: absolute; top: 12px; right: 12px; }

.btn { border: 0; border-radius: 12px; padding: 14px 18px; font-weight: 600; background: var(--sky); color: var(--navy); }
.btn.navy { background: var(--navy); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--text); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.bar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); z-index: 20; }
.bar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 9px 14px; font-size: 15px; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }

.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .name { flex: 1; min-width: 0; }
.item .name small { display: block; color: var(--muted); font-size: 12.5px; }
.step { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.step button { width: 42px; height: 42px; border: 0; background: #fff; font-size: 20px; color: var(--navy); }
.step input { width: 48px; height: 42px; border: 0; text-align: center; font-weight: 600; -moz-appearance: textfield; }
.step input::-webkit-outer-spin-button, .step input::-webkit-inner-spin-button { -webkit-appearance: none; }
.num { width: 76px; height: 44px; border: 1.5px solid var(--line); border-radius: 12px; text-align: center; font-weight: 600; font-size: 17px; }
.num.empty { border-color: var(--sky); background: var(--sky-soft); }
.field { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; }
textarea.field { min-height: 70px; resize: vertical; }
label.lbl { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.cat { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin: 16px 0 2px; }
.qty { font-weight: 700; min-width: 34px; text-align: right; }
.low { color: var(--red); }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 440px; margin: 0 auto; }
.login .logo { font-size: 34px; text-align: center; margin-bottom: 4px; color: var(--navy); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 22px 0; }
.names button { padding: 18px 10px; border-radius: var(--r); border: 0; background: #fff; box-shadow: var(--shadow); font-weight: 600; }
.dots { display: flex; justify-content: center; gap: 14px; margin: 22px 0; }
.dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--navy); }
.dots span.f { background: var(--navy); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pad button { height: 64px; border-radius: 16px; border: 0; background: #fff; box-shadow: var(--shadow); font-size: 24px; font-weight: 600; }
.pad button.k { background: transparent; box-shadow: none; font-size: 15px; color: var(--muted); }

/* admin */
.tabs { display: flex; gap: 4px; background: #e9edf5; padding: 4px; border-radius: 12px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 12px; border-radius: 9px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: #fff; color: var(--navy); box-shadow: var(--shadow); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; color: var(--navy); }
.kpi .l { font-size: 13px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8fafd; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
td input.field { padding: 7px 9px; border-radius: 8px; }
td input.tiny { width: 70px; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }
.empty-state { text-align: center; color: var(--muted); padding: 22px 8px; }
.sheet { position: fixed; inset: 0; background: rgba(5,10,48,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet .panel { background: #fff; width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet .panel { border-radius: 20px; } .tiles { grid-template-columns: repeat(4, 1fr); } }
/* address lookup */
.suggest-wrap { position: relative; }
.suggest { position: absolute; left: 0; right: 0; z-index: 30; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(5,10,48,.15); overflow: hidden; margin-top: 4px; }
.suggest:empty { display: none; }
.suggest .opt { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: #fff; padding: 11px 14px; font-size: 15px; color: var(--text); }
.suggest .opt:first-child { border-top: 0; }
.suggest .opt:active { background: var(--sky-soft); }
.suggest .opt small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.small.verified { color: var(--green); font-weight: 600; }
.small.warn { color: var(--amber); }
/* inline text buttons (payroll) */
.wrap .link { background: none; border: 0; padding: 0; color: #0a6aa0; font: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.wrap td .link strong { color: var(--navy); }
/* protocol reader */
.md { font-size: 15.5px; line-height: 1.55; }
.md h3 { font-size: 18px; margin: 20px 0 6px; color: var(--navy); }
.md h4 { font-size: 16px; margin: 16px 0 4px; }
.md h5, .md h6 { font-size: 15px; margin: 12px 0 4px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li.check { list-style: none; margin-left: -22px; display: flex; gap: 8px; align-items: flex-start; }
.md li.check input { width: 20px; height: 20px; flex: none; margin-top: 2px; accent-color: var(--navy); }
.md blockquote { margin: 10px 0; padding: 10px 12px; background: var(--sky-soft); border-left: 4px solid var(--sky); border-radius: 8px; }
.md table { margin: 8px 0; font-size: 14px; }
/* colour-coded protocol sections */
.md .sec { border-left: 5px solid var(--c); background: var(--bgc); border-radius: 10px; padding: 2px 14px 6px; margin: 12px 0; }
.md .sec > h3:first-child, .md .sec > h4:first-child { margin-top: 10px; color: var(--c); }
.md .sec h5, .md .sec h6 { color: var(--c); }
.md .sec table th { color: var(--c); }
.sec-info { --c: #4a5578; --bgc: #f4f6fa; }
.sec-indic { --c: #13804a; --bgc: #eaf7ef; }
.sec-contra { --c: #c4252f; --bgc: #fdeeef; }
.sec-admin { --c: #0a6aa0; --bgc: #e9f5fd; }
.sec-effects { --c: #a35f00; --bgc: #fff5e3; }
.sec-docs { --c: #6a4bb8; --bgc: #f3effc; }
.md blockquote.urgent { background: var(--red-soft); border-left-color: var(--red); }
.md-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.md-legend span { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 99px; color: var(--c); background: var(--bgc); border: 1px solid var(--c); }
/* full manual */
.pm-toc { margin: 8px 0 0; padding-left: 24px; }
.pm-toc li { margin: 7px 0; line-height: 1.35; }
.pm-toc .link { text-align: left; font-weight: 600; color: var(--navy) !important; text-decoration: none !important; }
.pm-part { scroll-margin-top: 70px; }
.pm-part .pm-title { font-size: 19px !important; text-transform: none !important; letter-spacing: 0 !important; color: var(--navy) !important; margin: 4px 0 2px !important; }
.pm-critical { border: 2px solid var(--red); }
.md blockquote.pm-notes, blockquote.pm-notes { margin: 8px 0; padding: 10px 12px; background: var(--sky-soft); border-left: 4px solid var(--sky); border-radius: 8px; white-space: pre-wrap; font-size: 14.5px; }
.pm-top { position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px); width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; font-size: 20px; box-shadow: var(--shadow); z-index: 25; }
/* signatures */
.sigpad { width: 100%; height: 150px; border: 1.5px dashed var(--navy); border-radius: 12px; background: #fff; touch-action: none; display: block; margin-top: 6px; }
.sig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin-top: 6px; }
.sig-line { border-bottom: 1px solid var(--text); padding-bottom: 2px; }
.sig-v { min-height: 24px; font-weight: 600; }
.sig-l { font-size: 11.5px; color: var(--muted); border-top: 0; margin-top: 2px; }
@media print {
  body > *:not(.sheet) { display: none !important; }
  .sheet { position: static !important; background: none !important; display: block !important; }
  .sheet .panel { max-height: none !important; overflow: visible !important; box-shadow: none !important; max-width: none !important; border-radius: 0 !important; }
  .no-print, .pm-top, #toast { display: none !important; }
  .md .sec { break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Staff assistant chat */
.chat-log { max-height: 56vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--sky-soft); border-bottom-left-radius: 4px; white-space: normal; }
.msg.bot.urgent { background: var(--red-soft); border: 1.5px solid var(--red); }
.msg.bot .md p { margin: 0 0 6px; }
.msg.bot .md .sec { padding: 0; border: 0; background: none; margin: 0; }
