:root {
  --navy: #003366;
  --navy-deep: #002e5c;
  --nhs-blue: #005eb8;
  --nhs-green: #00803b;
  --nhs-orange: #ed8c00;
  --nhs-purple: #330073;
  --nhs-red: #d9291c;
  --nhs-yellow: #ffb81c;
  --card: rgba(255, 255, 255, 0.10);
  --card-strong: rgba(255, 255, 255, 0.14);
  --stroke: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --text-2: rgba(255, 255, 255, 0.82);
  --text-3: rgba(255, 255, 255, 0.65);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--navy);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
svg.i { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  background: var(--navy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.topbar h1 { margin: 0; text-align: center; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: transparent; display: grid; place-items: center; font-size: 22px; color: #fff;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.12); }
.top-right { display: flex; justify-content: flex-end; }

main { outline: none; }
.page { max-width: 760px; margin: 0 auto; padding: 12px 20px calc(var(--safe-bottom) + 28px); }
.page-head { text-align: center; margin: 10px 0 18px; }
.page-head h2 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 15px; }

/* ---------- Splash ---------- */
.splash {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: calc(var(--safe-top) + 40px) 28px calc(var(--safe-bottom) + 18px);
  max-width: 520px; margin: 0 auto;
}
.splash .logo { width: min(300px, 76vw); height: auto; margin-bottom: 18px; }
.splash .tagline { font-weight: 600; font-size: 17px; color: rgba(255, 255, 255, 0.92); }
.splash .spacer { flex: 1; min-height: 24px; }
.btn-enter {
  width: 100%; padding: 18px; border-radius: 34px; border: 1px solid rgba(255, 255, 255, 0.35);
  background: #fff; color: var(--navy); font-weight: 700; font-size: 17px;
}
.splash .rga { height: 32px; width: auto; margin-top: 28px; }
.foot { font-size: 13px; color: rgba(255, 255, 255, 0.78); margin-top: 8px; }
.foot small { display: block; font-size: 12px; color: rgba(255, 255, 255, 0.7); margin-top: 2px; }
.install-hint {
  margin-top: 18px; padding: 12px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--stroke);
  font-size: 13px; color: var(--text-2); text-align: left;
}

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat {
  padding: 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--stroke); min-width: 0;
}
.stat .si { font-size: 14px; }
.stat .sv { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 700; font-size: 19px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sl { font-size: 11px; color: var(--text-3); }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.lozenge {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 16px; border-radius: 22px; background: var(--card); border: 1px solid var(--stroke);
  text-decoration: none; color: #fff;
}
.lozenge:active { background: var(--card-strong); }
.lozenge .bubble { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; color: #fff; flex: none; }
.lozenge .lt { flex: 1; min-width: 0; }
.lozenge .lt b { display: block; font-size: 17px; }
.lozenge .lt span { display: block; font-size: 13px; color: var(--text-3); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 12px; background: rgba(255, 255, 255, 0.18); white-space: nowrap; }
.chev { color: rgba(255, 255, 255, 0.5); font-size: 16px; }

/* ---------- Cards and forms ---------- */
.card { padding: 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--stroke); margin-bottom: 16px; }
.card > h3 { margin: 0 0 10px; font-size: 17px; }
.hint { font-size: 13px; color: var(--text-3); margin: 8px 0 0; }
.hint.warn { color: var(--nhs-yellow); }
.err { font-size: 14px; color: #ffb3ad; margin: 8px 0 0; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 6px 4px; }
.input {
  width: 100%; padding: 13px 16px; border-radius: 24px; border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.10); color: #fff; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: rgba(255, 255, 255, 0.45); }
.input:focus { border-color: rgba(255, 255, 255, 0.55); }
.input:disabled { opacity: 0.7; }
textarea.input { border-radius: 18px; min-height: 90px; resize: vertical; }
input[type="date"].input { min-height: 48px; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
.upper { text-transform: uppercase; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 2px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; border-radius: 31px; background: rgba(255, 255, 255, 0.22); transition: background 0.2s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); }
.switch input:checked + .track { background: #34c759; }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid #fff; outline-offset: 2px; }

.pill-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 14px; border-radius: 28px; border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12); color: #fff; font-weight: 600; font-size: 16px; margin-top: 10px;
}
.pill-btn:active { background: rgba(255, 255, 255, 0.2); }
.pill-btn:disabled { opacity: 0.5; cursor: default; }
.pill-btn.primary { background: #fff; color: var(--navy); }
.pill-btn.danger { color: #ffb3ad; }

.action-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 2px;
  border: 0; background: transparent; text-align: left; color: #fff;
}
.action-row .ai { font-size: 19px; width: 28px; display: grid; place-items: center; }
.action-row .at { flex: 1; min-width: 0; }
.action-row .at b { display: block; font-size: 16px; }
.action-row .at span { display: block; font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-row:disabled { opacity: 0.45; }
.action-row.danger .ai, .action-row.danger b { color: #ffb3ad; }
.divider { height: 1px; background: rgba(255, 255, 255, 0.14); margin: 6px 0; }

.segmented { display: flex; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.12); gap: 2px; }
.segmented button {
  flex: 1; padding: 8px 4px; border: 0; border-radius: 9px; background: transparent; color: #fff;
  font-size: 13px; font-weight: 600;
}
.segmented button.on { background: #fff; color: var(--navy); }

.result { font-size: 21px; font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.kv span:first-child { color: var(--text-2); }
.kv span:last-child { text-align: right; word-break: break-word; }

.summary3 { display: flex; justify-content: space-between; }
.summary3 div { text-align: center; }
.summary3 div:first-child { text-align: left; }
.summary3 div:last-child { text-align: right; }
.summary3 small { display: block; font-size: 13px; font-weight: 600; color: var(--text-3); }
.summary3 b { font-size: 22px; }

/* ---------- Totals ---------- */
.month { margin-bottom: 12px; }
.month-head {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--stroke); color: #fff; text-align: left;
}
.month.open .month-head { background: var(--card-strong); }
.month-head .mt { flex: 1; font-weight: 600; font-size: 17px; }
.month-head .ms { text-align: right; }
.month-head .ms b { display: block; }
.month-head .ms small { font-size: 12px; color: var(--text-3); }
.month-head .tw { transition: transform 0.2s; color: var(--text-3); }
.month.open .month-head .tw { transform: rotate(90deg); }
.entries { margin-top: 4px; border-radius: 18px; background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.10); overflow: hidden; }
.entry {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; text-decoration: none; color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.entry:last-child { border-bottom: 0; }
.entry:active { background: rgba(255, 255, 255, 0.08); }
.entry .el { flex: 1; min-width: 0; }
.entry .el b { display: block; font-size: 15px; }
.entry .el span { display: block; font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .er { text-align: right; }
.entry .er b { display: block; font-size: 15px; }
.entry .er span { font-size: 12px; color: var(--text-2); }

/* ---------- Map ---------- */
.map-box {
  height: 170px; border-radius: 14px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06); display: grid; place-items: center; color: rgba(255, 255, 255, 0.45); font-size: 13px;
  margin-top: 10px;
}
.map-box.live { display: block; }
.map-full {
  position: fixed; inset: 0; z-index: 200; background: var(--navy); display: flex; flex-direction: column;
}
.map-full header { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: calc(var(--safe-top) + 8px) 14px 8px; }
.map-full header b { font-size: 17px; }
.map-full .map-fill { flex: 1; }
.leaflet-container { font: inherit; background: #dfe7ee; }
.leaflet-control-attribution { font-size: 10px; }

/* ---------- Modal and toast ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 300; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px calc(16px) calc(var(--safe-bottom) + 16px);
}
.modal {
  width: 100%; max-width: 460px; border-radius: 20px; background: #0d3f70; border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.modal h4 { margin: 0 0 6px; font-size: 18px; text-align: center; }
.modal p { margin: 0 0 6px; color: var(--text-2); text-align: center; font-size: 15px; white-space: pre-line; }
.modal .pill-btn { margin-top: 10px; }
@media (min-width: 600px) { .modal-back { align-items: center; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translate(-50%, 30px);
  background: #fff; color: var(--navy); padding: 11px 18px; border-radius: 22px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 400; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.help h4 { margin: 18px 0 6px; font-size: 16px; }
.help h4:first-child { margin-top: 0; }
.help p, .help li { color: var(--text-2); font-size: 15px; }
.help ul, .help ol { padding-left: 20px; margin: 6px 0; }
.help code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: rgba(255, 255, 255, 0.1); padding: 1px 5px; border-radius: 6px; }
.help pre { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: rgba(0, 0, 0, 0.2); padding: 10px; border-radius: 10px; overflow-x: auto; }

.spinner { width: 18px; height: 18px; border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
.pill-btn.primary .spinner { border-color: rgba(0, 51, 102, 0.3); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

.postcode-big { font-family: ui-monospace, Menlo, monospace; font-size: 30px; font-weight: 700; letter-spacing: 1px; }

@media (max-width: 380px) {
  .page { padding-left: 16px; padding-right: 16px; }
  .stat .sv { font-size: 16px; }
  .menu-grid { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
.print-area { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff !important; color: #000 !important; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; color: #000; font-family: "Helvetica Neue", Arial, sans-serif; font-size: 10pt; }
  .pr-logo { display: block; margin: 0 auto 8pt; height: 50pt; }
  .pr-who b { font-size: 14pt; }
  .pr-who div { margin: 2pt 0; }
  .pr-rule { border-top: 0.75pt solid #000; margin: 6pt 0 14pt; }
  .pr-title { text-align: center; font-weight: 700; font-size: 16pt; margin-bottom: 10pt; }
  .pr-table { width: 100%; border-collapse: collapse; }
  .pr-table thead { display: table-header-group; }
  .pr-table th { background: #ebebeb; text-align: left; padding: 3pt 4pt; font-size: 10pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pr-table td { padding: 2pt 4pt; font-size: 10pt; }
  .pr-table .r { text-align: right; }
  .pr-table tr { break-inside: avoid; }
  .pr-table tfoot td { border-top: 0.75pt solid #000; font-weight: 700; font-size: 11pt; padding-top: 6pt; }
  .pr-sign { display: flex; justify-content: space-between; margin-top: 30pt; break-inside: avoid; }
  .pr-sign span { width: 45%; border-bottom: 0.5pt solid #000; padding-bottom: 18pt; }
  .pr-foot { margin-top: 18pt; font-size: 9pt; color: #444; }
}
