/* On-call scheduling — one stylesheet, no inline styles (the CSP forbids them). */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../vendor/fonts/atkinson-hyperlegible-next-latin-wght-normal.825fabef695f.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --ink: #13262f;
  --ink-soft: #4a626c;
  --page: #edf1f1;
  --surface: #ffffff;
  --line: #cdd8da;
  --line-soft: #e3eaeb;
  --tide: #1c6e80;
  --tide-dark: #124f5d;
  --beacon: #f0a81c;
  --beacon-soft: #fdf1d3;
  --ok: #2c7a4b;
  --ok-soft: #e2f2e8;
  --danger: #b3261e;
  --danger-soft: #fbe6e4;
  --info-soft: #e3edf7;
  --radius: 4px;
  --step: 0.5rem;
  --c: var(--tide);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 1rem/1.5 "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--tide-dark); text-underline-offset: 0.15em; }
a:hover { color: var(--ink); }

:focus-visible { outline: 3px solid var(--beacon); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--step); max-width: 72ch; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* --- Shell ----------------------------------------------------------------- */

/* The top bar is a simulated B-mode ultrasound image: a zoomed long-axis view of a
   common carotid artery under a linear transducer. The title sits in the lumen.
   Layers, front to back: orientation marker, focal-zone caret, depth scale,
   one calcified plaque with its acoustic shadow, and the seamless vessel tile.
   The two images are generated by scripts/make-topbar-art.py. */
.topbar {
  --echo: rgba(214, 232, 238, 0.8);
  color: #fff;
  background-color: #040c10;
  background-image:
    radial-gradient(circle, var(--echo) 0 2px, transparent 2.7px),
    conic-gradient(from 60deg at 0 50%, var(--echo) 60deg, transparent 0),
    linear-gradient(to bottom,
      transparent calc(12.5% - 0.5px), var(--echo) calc(12.5% - 0.5px) calc(12.5% + 0.5px),
      transparent calc(12.5% + 0.5px) calc(37.5% - 0.5px), var(--echo) calc(37.5% - 0.5px) calc(37.5% + 0.5px),
      transparent calc(37.5% + 0.5px) calc(62.5% - 0.5px), var(--echo) calc(62.5% - 0.5px) calc(62.5% + 0.5px),
      transparent calc(62.5% + 0.5px) calc(87.5% - 0.5px), var(--echo) calc(87.5% - 0.5px) calc(87.5% + 0.5px),
      transparent calc(87.5% + 0.5px)),
    url("../img/scan-plaque.818ae28db74e.png"),
    url("../img/scan-vessel.6df001d3e90b.webp");
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, repeat-x;
  background-position: left 6px top 5px, right 7px top 72%, right top, 50% 0, left top;
  background-size: 7px 7px, 5px 7px, 4px 100%, auto 100%, auto 100%;
}
.topbar-inner { display: flex; align-items: center; gap: 1rem; padding: 0.7rem 1rem; max-width: 1280px; margin: 0 auto; }
@media (min-width: 44rem) {
  /* Wider screens: move the plaque off-centre, clear of the account links. */
  .topbar { background-position: left 6px top 5px, right 7px top 72%, right top, 64% 0, left top; }
}
/* Keeps the text readable wherever it crosses a bright vessel wall (large fonts, zoom). */
.topbar .brand, .topbar a.account, .topbar .linklike { text-shadow: 0 0 5px #040c10, 0 0 2px #040c10; }
.brand { font-weight: 700; color: #fff; text-decoration: none; margin-right: auto; }
.brand span { color: var(--beacon); }
.topbar a.account, .topbar .linklike { color: #d6e2e5; font-size: 0.875rem; }
.topbar form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; color: var(--tide-dark); }

.nav { background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.nav ul { display: flex; gap: 0.25rem; list-style: none; margin: 0 auto; padding: 0 0.5rem; max-width: 1280px; }
.nav a { display: block; padding: 0.7rem 0.75rem; color: var(--ink-soft); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a.is-current { color: var(--ink); border-bottom-color: var(--beacon); font-weight: 700; }
.nav .divider { border-left: 1px solid var(--line); margin: 0.5rem 0.4rem; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
main.narrow { max-width: 46rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin-right: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel > h2 { margin-bottom: 0.75rem; }
.panel.flush { padding: 0; overflow-x: auto; }
.stack > * + * { margin-top: 1rem; }
.split { display: grid; gap: 1rem; }
@media (min-width: 60rem) { .split { grid-template-columns: 2fr 1fr; align-items: start; } .split.even { grid-template-columns: 1fr 1fr; } }

/* --- Flash messages -------------------------------------------------------- */

.flash { list-style: none; margin: 0 0 1rem; padding: 0; }
.flash li { padding: 0.6rem 0.8rem; border-left: 4px solid var(--tide); background: var(--info-soft); margin-bottom: 0.4rem; border-radius: 0 var(--radius) var(--radius) 0; }
.flash li.success { border-color: var(--ok); background: var(--ok-soft); }
.flash li.error { border-color: var(--danger); background: var(--danger-soft); }
.flash li.warning { border-color: var(--beacon); background: var(--beacon-soft); }

/* --- Buttons and forms ----------------------------------------------------- */

.btn { display: inline-block; font: inherit; font-weight: 700; line-height: 1.2; padding: 0.55rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--tide-dark); background: var(--tide); color: #fff; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--tide-dark); color: #fff; }
.btn.quiet { background: var(--surface); color: var(--tide-dark); border-color: var(--line); }
.btn.quiet:hover { border-color: var(--tide-dark); background: var(--surface); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.go { background: var(--beacon); border-color: #b97c06; color: var(--ink); }
.btn.go:hover { background: #dc970f; color: var(--ink); }
.btn.big { font-size: 1.1rem; padding: 0.8rem 1.2rem; }
.btn.small { font-size: 0.875rem; padding: 0.3rem 0.6rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="time"],
input[type="datetime-local"], input[type="search"], input[type="url"], input[type="tel"], select, textarea {
  width: 100%; max-width: 32rem; padding: 0.5rem 0.6rem; border: 1px solid #9fb1b5; border-radius: var(--radius); background: #fff;
}
select[multiple] { min-height: 8rem; }
textarea { max-width: 44rem; }
label { font-weight: 700; display: block; margin-bottom: 0.2rem; }
input[type="checkbox"], input[type="radio"] { width: 1.1rem; height: 1.1rem; accent-color: var(--tide); vertical-align: -0.15em; margin-right: 0.35rem; }

.form > div, .form > fieldset { margin: 0 0 1rem; padding: 0; border: 0; }
.form fieldset > legend { font-weight: 700; padding: 0; margin-bottom: 0.2rem; }
.form fieldset > div > div { display: inline-block; margin-right: 1rem; }
.form fieldset label, .form label:has(> input[type="checkbox"]) { font-weight: 400; display: inline-block; }
.form div:has(> input[type="checkbox"]) > label { display: inline-block; }
.form .helptext { color: var(--ink-soft); font-size: 0.875rem; margin-bottom: 0.25rem; max-width: 60ch; }
.errorlist { list-style: none; margin: 0 0 0.3rem; padding: 0.4rem 0.6rem; background: var(--danger-soft); border-left: 4px solid var(--danger); color: #7c1711; }

label.check { font-weight: 400; margin: 0.25rem 0 0.75rem; }
.filters fieldset { border: 0; padding: 0; margin: 0; }
.filters fieldset > div > div { display: inline-block; margin-right: 0.9rem; }
.filters fieldset label { font-weight: 400; font-size: 1rem; display: inline-block; }
.filters fieldset legend { font-weight: 700; font-size: 0.875rem; padding: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 0.6rem 0.9rem; align-items: end; margin-bottom: 1rem; }
.filters > div { min-width: 9rem; }
.filters label { font-size: 0.875rem; }
.filters select, .filters input { max-width: 14rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }
.inline-form > div { flex: 1 1 8rem; }
.inline-form input, .inline-form select { max-width: none; }
.inline-form .narrow-field { flex: 0 1 6rem; }

/* --- Tables ---------------------------------------------------------------- */

table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
thead th { font-size: 0.875rem; color: var(--ink-soft); border-bottom: 1px solid var(--line); white-space: nowrap; background: #f7f9f9; position: sticky; top: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
tbody tr:hover { background: #f7fafa; }
.empty { padding: 1.25rem; color: var(--ink-soft); }

.tag { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--line-soft); color: var(--ink); white-space: nowrap; }
.tag.open { background: var(--beacon-soft); color: #7a5200; }
.tag.ok { background: var(--ok-soft); color: #1d5a35; }
.tag.bad, .tag.urgent { background: var(--danger-soft); color: #7c1711; }
.tag.info { background: var(--info-soft); color: #25456f; }
.tag.warning { background: var(--beacon-soft); color: #7a5200; }
.dot { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--c); margin-right: 0.35rem; vertical-align: 0; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0; }
dl.facts dt { color: var(--ink-soft); }
dl.facts dd { margin: 0; }
.pre { white-space: pre-wrap; }

/* --- Shift lanes: the on-call bars ---------------------------------------- */

.lanes { display: grid; gap: 0.9rem; }
.lane { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: var(--radius); padding: 0.8rem 0.9rem; }
.lane.is-dispatched { border-color: var(--beacon); box-shadow: 0 0 0 2px var(--beacon-soft); }
.lane-head { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; }
.lane-head h3 { font-size: 1.15rem; margin-right: auto; }
.lane-clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; }
.track { position: relative; height: 1.5rem; background: var(--line-soft); border-radius: 2px; margin: 0.6rem 0 0.35rem; overflow: hidden; }
.track-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--c); opacity: 0.85; }
.track-seg { position: absolute; top: 0; bottom: 0; background: var(--beacon); border-left: 1px solid #b97c06; border-right: 1px solid #b97c06; min-width: 3px; }
.track-seg.is-live { background: repeating-linear-gradient(135deg, var(--beacon) 0 6px, #ffd375 6px 12px); }
.track-ends { display: flex; justify-content: space-between; font-size: 0.875rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.lane-foot { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin-top: 0.6rem; }
.lane-foot .stat { margin-right: auto; }
.legend { display: flex; gap: 1rem; font-size: 0.875rem; color: var(--ink-soft); margin-top: 0.5rem; }
.legend i { display: inline-block; width: 1.2rem; height: 0.7rem; vertical-align: -0.05em; margin-right: 0.3rem; background: var(--tide); }
.legend i.onsite { background: var(--beacon); }

.dispatch { background: var(--beacon-soft); border: 2px solid var(--beacon); border-radius: var(--radius); padding: 1rem; }
.dispatch.is-pending { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--beacon); }
.dispatch-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.dispatch-head h2 { margin-right: auto; }
.bigclock { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.dispatch h3 { margin: 1rem 0 0.4rem; }
.entries { list-style: none; margin: 0 0 0.5rem; padding: 0; }
.entries li { display: flex; gap: 0.75rem; align-items: baseline; padding: 0.3rem 0; border-bottom: 1px solid rgba(19, 38, 47, 0.12); }
.entries li > span:first-child { margin-right: auto; }
.entries form { margin: 0; }
.gps { border-top: 1px dashed rgba(19, 38, 47, 0.3); margin-top: 0.75rem; padding-top: 0.75rem; }
.gps-read { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* --- Calendar -------------------------------------------------------------- */

.cal-nav { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.cal-nav h2 { font-size: 1.3rem; min-width: 11rem; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); background: var(--surface); }
.cal-dow { padding: 0.3rem 0.4rem; font-size: 0.875rem; color: var(--ink-soft); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f7f9f9; }
.cal-day { min-height: 6.5rem; padding: 0.3rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-day.is-out { background: #f4f6f6; }
.cal-day.is-out .cal-date { color: #9aabaf; }
.cal-date { font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.cal-day.is-today .cal-date { background: var(--ink); color: #fff; padding: 0 0.4rem; border-radius: 999px; font-weight: 700; }
/* Chip bar = the employee's colour (grey while open); shift-type name = the type's colour. */
.chip { --c: #9aabaf; --t: var(--ink); display: block; margin-top: 0.25rem; padding: 0.2rem 0.35rem; font-size: 0.8rem; line-height: 1.25; text-decoration: none; color: var(--ink); border-left: 5px solid var(--c); background: var(--line-soft); border-radius: 0 3px 3px 0; overflow: hidden; }
.chip .type { color: var(--t); font-weight: 700; }
.chip:hover { background: var(--line); color: var(--ink); }
.chip.is-open { background: var(--beacon-soft); outline: 1px dashed #c58f12; outline-offset: -1px; }
.chip.is-mine { background: var(--ok-soft); }
.chip.is-cancelled { text-decoration: line-through; opacity: 0.6; }
.chip b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .t { font-variant-numeric: tabular-nums; }
@media (max-width: 44rem) {
  .cal { display: block; border: 0; background: none; }
  .cal-dow, .cal-day.is-out, .cal-day.is-empty { display: none; }
  .cal-day { min-height: 0; border: 1px solid var(--line); background: var(--surface); margin-bottom: 0.5rem; border-radius: var(--radius); padding: 0.5rem; }
  .cal-date::before { content: attr(data-long) " "; }
  .cal-date .d { display: none; }
  .chip { font-size: 0.95rem; padding: 0.4rem 0.5rem; }
}

dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(40rem, 94vw); color: var(--ink); }
dialog::backdrop { background: rgba(19, 38, 47, 0.55); }
.dialog-body { padding: 1rem; }
.dialog-close { position: absolute; top: 0.5rem; right: 0.5rem; }

/* --- Maps ------------------------------------------------------------------ */

.map { height: 62vh; min-height: 22rem; border: 1px solid var(--line); border-radius: var(--radius); background: #dfe7e8; }
.map.small-map { height: 15rem; min-height: 0; }
.pin { width: 1.25rem; height: 1.25rem; border-radius: 50% 50% 50% 0; background: var(--danger); border: 2px solid #fff; transform: rotate(-45deg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
/* Leaflet 1.9 blends every tile with "mix-blend-mode: plus-lighter" to hide hairline
   seams in Chromium. Firefox renders that mode wrongly for map tiles (tiles drawn out of
   place, light tiles washed out to white; Mozilla bug 1943529), so blend normally
   everywhere and keep plus-lighter only for Chromium and Safari. The extra
   ".leaflet-pane" makes these rules win over leaflet.css whatever order they load in. */
.leaflet-container .leaflet-pane img.leaflet-tile { mix-blend-mode: normal; }
@supports (-webkit-appearance: none) and (not (-moz-appearance: none)) {
  .leaflet-container .leaflet-pane img.leaflet-tile { mix-blend-mode: plus-lighter; }
}
.leaflet-popup-content { font: inherit; margin: 0.75rem 0.9rem; }
.leaflet-popup-content h3 { margin-bottom: 0.25rem; }
.leaflet-popup-content p { margin: 0 0 0.35rem; }
.leaflet-container { font: inherit; }
.loc-list { list-style: none; margin: 0; padding: 0; }
.loc-list li { padding: 0.6rem 0; border-bottom: 1px solid var(--line-soft); }
.loc-list button { font-weight: 700; }

/* --- Dashboard ------------------------------------------------------------- */

.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; }
.counts a { padding: 0.8rem 1rem; text-decoration: none; color: var(--ink); border-right: 1px solid var(--line-soft); }
.counts a:hover { background: #f7fafa; }
.counts strong { display: block; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counts a.is-hot strong { color: var(--danger); }

/* --- Metrics dashboard ------------------------------------------------------ */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 0.9rem; display: flex; flex-direction: column; gap: 0.15rem; }
.tile-label { font-size: 0.875rem; color: var(--ink-soft); }
.tile-value { font-size: 1.75rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 0.9rem; font-weight: 400; color: var(--ink-soft); }
.tile-note { font-size: 0.8rem; color: var(--ink-soft); }
.chart-grid { display: grid; gap: 1rem; }
@media (min-width: 60rem) { .chart-grid { grid-template-columns: 1fr 1fr; } .chart-card.is-wide { grid-column: 1 / -1; } }
.chart-card { margin: 0; min-width: 0; }
.chart-head { display: flex; align-items: baseline; gap: 1rem; }
.chart-head h2 { margin-right: auto; }
.chart-box { position: relative; height: 260px; margin-top: 0.5rem; }
.chart-box.is-line { height: 280px; }
.pie-wrap { display: grid; gap: 1rem; align-items: center; margin-top: 0.5rem; }
@media (min-width: 34rem) { .pie-wrap { grid-template-columns: 220px 1fr; } }
.chart-box.is-pie { height: 220px; margin: 0; }
.pie-legend { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.pie-legend li { display: grid; grid-template-columns: auto 1fr auto 3.6rem; gap: 0.5rem; align-items: baseline; padding: 0.3rem 0; border-bottom: 1px solid var(--line-soft); }
.pie-legend .num { text-align: right; font-variant-numeric: tabular-nums; }
.pie-legend .pie-pct { font-weight: 700; }
.pie-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-table { margin-top: 0.75rem; }
.chart-table summary { cursor: pointer; color: var(--tide-dark); font-size: 0.9rem; }
.chart-table table { margin-top: 0.5rem; font-size: 0.9rem; }
.chart-table[open] { max-height: 26rem; overflow: auto; }

.login { max-width: 24rem; margin: 8vh auto 0; }
.login h1 { margin-bottom: 1rem; }

@media print {
  .topbar, .nav, .actions, .filters, .flash, .no-print { display: none !important; }
  body { background: #fff; }
  .panel { border: 0; padding: 0; }
  main { padding: 0; max-width: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .track-fill { transition: width 1s linear; }
}
