/* NAWEWE Ops design system
 * Brand taken from the public NAWEWE site: cyan #009CE0, soft teal #68CCD4, navy #0B3D4A,
 * Sora for headings, Geist for text. #009CE0 is decorative only (3.07:1 with white text);
 * interactive fills use --brand-strong (#0077AD, 4.95:1) to meet WCAG AA.
 * Layout: phone = top app bar + bottom tab bar; ≥768px = side rail; ≥1200px = labelled sidebar.
 */

@font-face { font-family: "Sora"; font-style: normal; font-display: swap; font-weight: 100 800;
  src: url("fonts/sora-latin-wght-normal.0d0e5e4d2f9f.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Sora"; font-style: normal; font-display: swap; font-weight: 100 800;
  src: url("fonts/sora-latin-ext-wght-normal.adf7c421da62.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Geist"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/geist-latin-wght-normal.a147f99cd533.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Geist"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/geist-latin-ext-wght-normal.4841e590e2a9.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }

:root {
  color-scheme: light;

  --brand: #009ce0;
  --brand-strong: #0077ad;
  --brand-stronger: #006c9c;
  --brand-soft: #68ccd4;
  --navy: #0b3d4a;

  --bg: #f4fbfc;
  --surface: #ffffff;
  --surface-2: #e5f6f8;
  --surface-3: #eef8fa;
  --text: #0b3d4a;
  --text-2: #4a6b73;
  --border: #cce6ea;
  --border-strong: #6b939d;

  --ok: #17703f;      --ok-bg: #e6f5ec;      --ok-line: #b5dfc5;
  --warn: #8a5300;    --warn-bg: #fff3d6;    --warn-line: #f0d58a;
  --danger: #b3261e;  --danger-bg: #fdecea;  --danger-line: #f3b8b2;
  --danger-solid: #b3261e;
  --clinical: #6b3fa0;

  --font-display: "Sora", "Segoe UI", system-ui, sans-serif;
  --font-text: "Geist", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-pill: 999px;
  --shadow-1: 0 1px 2px rgb(11 61 74 / .06), 0 1px 3px rgb(11 61 74 / .05);
  --shadow-2: 0 6px 24px -8px rgb(11 61 74 / .22), 0 2px 6px rgb(11 61 74 / .06);
  --shadow-3: 0 24px 60px -12px rgb(11 61 74 / .35);
  --focus: 0 0 0 3px #fff, 0 0 0 6px var(--brand);

  --appbar-h: 60px;
  --tabbar-h: 68px;
  --rail-w: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --gutter: 16px;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font: 400 16px/1.5 var(--font-text);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -8%, rgb(104 204 212 / .30), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgb(0 156 224 / .07), transparent);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: var(--font-display); letter-spacing: -.01em; color: var(--text); }
h1 { font-size: 1.45rem; line-height: 1.2; font-weight: 700; margin: 0; }
h2 { font-size: 1.08rem; line-height: 1.3; font-weight: 650; margin: 0; }
h3 { font-size: .95rem; font-weight: 650; margin: 0; }
p { margin: 0 0 .75rem; }
a { color: var(--brand-strong); text-underline-offset: 3px; }
img, svg { display: block; }
.i { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--font-mono); letter-spacing: .04em; }
.muted { color: var(--text-2); }
.small { font-size: .875rem; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--navy); color: #fff; padding: .6rem 1rem; border-radius: var(--r-sm); }
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------------ app shell */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  min-height: calc(var(--appbar-h) + var(--safe-t));
  padding: var(--safe-t) var(--gutter) 0;
  background: rgb(255 255 255 / .86);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid rgb(204 230 234 / .8);
}
.appbar-logo { width: 38px; height: 38px; flex: none; }
.appbar-back {
  display: grid; place-items: center; width: 40px; height: 40px; margin-left: -8px; flex: none;
  border-radius: var(--r-pill); color: var(--text); text-decoration: none;
}
.appbar-back:active { background: var(--surface-2); }
.appbar-title { min-width: 0; flex: 1; }
.appbar-title strong { display: block; font: 650 1.02rem/1.2 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title span { display: block; font-size: .78rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.conn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: .78rem; font-weight: 600; color: var(--ok); background: var(--ok-bg);
}
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.conn .conn-text { display: none; }
.conn.down { color: #fff; background: var(--danger-solid); }
.conn.down .conn-text { display: inline; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: 46vw;
  height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface); color: var(--text); font: 600 .82rem/1 var(--font-text); cursor: pointer;
}
.chip-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-btn.needs { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.avatar-btn { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%; }

.offline-banner {
  display: none; position: sticky; top: calc(var(--appbar-h) + var(--safe-t)); z-index: 35;
  align-items: center; gap: 10px; padding: 10px var(--gutter);
  background: var(--danger-solid); color: #fff; font-weight: 650; font-size: .92rem;
}
body.is-offline .offline-banner { display: flex; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 6px 4px var(--safe-b);
  background: rgb(255 255 255 / .94);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-2); text-decoration: none; font-size: .72rem; font-weight: 600; border-radius: var(--r);
}
.tab .tab-icon { display: grid; place-items: center; width: 56px; height: 30px; border-radius: var(--r-pill); transition: background .2s; }
.tab[aria-current="page"] { color: var(--text); }
.tab[aria-current="page"] .tab-icon { background: var(--surface-2); color: var(--brand-strong); }
.tab:active .tab-icon { background: var(--surface-2); }
.rail-brand, .rail-user { display: none; }

.content {
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 16px var(--gutter) calc(var(--tabbar-h) + var(--safe-b) + 28px);
}
.content.wide { max-width: 1120px; }
body.no-tabs .content { padding-bottom: 40px; }

/* Tablet & desktop: navigation becomes a side rail */
@media (min-width: 768px) {
  :root { --rail-w: 92px; --gutter: 28px; }
  body { padding-left: var(--rail-w); }
  .tabbar {
    top: 0; right: auto; width: var(--rail-w); height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 14px 8px 14px; border-top: 0; border-right: 1px solid var(--border);
  }
  .rail-brand { display: grid; place-items: center; margin-bottom: 14px; }
  .rail-brand img { width: 52px; height: 52px; }
  .tab { flex: none; max-width: none; padding: 8px 0; }
  .appbar .appbar-logo { display: none; }
  .content { padding-top: 24px; padding-bottom: 48px; }
}
@media (min-width: 1200px) {
  :root { --rail-w: 248px; }
  .tabbar { padding: 20px 14px; }
  .rail-brand { display: flex; align-items: center; gap: 10px; place-items: initial; padding: 0 8px 18px; }
  .rail-brand img { width: 44px; height: 44px; }
  .rail-brand strong { font: 700 1.05rem/1.1 var(--font-display); letter-spacing: .06em; }
  .rail-brand span { display: block; font-size: .72rem; color: var(--text-2); }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 4px; font-size: .92rem; }
  .tab .tab-icon { width: 44px; height: 40px; }
  .tab[aria-current="page"] { background: var(--surface-2); }
  .tab[aria-current="page"] .tab-icon { background: none; }
  .rail-user { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); }
  .rail-user .who { min-width: 0; font-size: .82rem; }
  .rail-user .who strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ------------------------------------------------------------------ surfaces */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: .92rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 2px 10px; }
.section-title h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); font-family: var(--font-text); font-weight: 700; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-1);
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.badge-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand-strong); flex: none; }
.badge-icon.clinical { background: #f1eaf8; color: var(--clinical); }
.card-head h2 { margin: 0; }
.card-head p { margin: 2px 0 0; font-size: .85rem; color: var(--text-2); }
.card.flush { padding: 0; overflow: hidden; }
.card.tinted { background: linear-gradient(180deg, var(--surface) 0%, var(--surface-3) 100%); }
.divider { height: 1px; background: var(--border); margin: 16px -18px; border: 0; }

/* ------------------------------------------------------------------ buttons */
.btn, button.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border: 1px solid transparent; border-radius: var(--r);
  font: 650 1rem/1.1 var(--font-text); text-decoration: none; cursor: pointer; user-select: none;
  background: var(--brand-strong); color: #fff;
  box-shadow: 0 6px 16px -8px rgb(0 119 173 / .7);
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--brand-stronger); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; cursor: progress; transform: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn.secondary:hover { background: #d6eff3; }
.btn.outline { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: none; }
.btn.outline:hover { background: var(--surface-3); }
.btn.danger { background: var(--danger-solid); box-shadow: none; }
.btn.ghost { background: none; color: var(--brand-strong); box-shadow: none; min-height: 44px; padding: 0 12px; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .9rem; border-radius: 12px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-pill);
  border: 0; background: none; color: var(--text); cursor: pointer;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn-row > .btn { flex: 1 1 auto; }

/* Sticky bottom action bar for long forms (sits above the tab bar on phones) */
.actionbar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 20;
  margin: 18px -6px 0; padding: 10px; border-radius: calc(var(--r-lg) + 4px);
  background: rgb(255 255 255 / .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); box-shadow: var(--shadow-2);
}
@media (min-width: 768px) { .actionbar { bottom: 16px; } }

/* ------------------------------------------------------------------ forms */
.field { margin: 0 0 18px; }
.field > label, .field > legend, .label {
  display: block; margin: 0 0 8px; padding: 0; font-weight: 650; font-size: .95rem; color: var(--text);
}
.field .optional { font-weight: 500; color: var(--text-2); font-size: .82rem; }
fieldset.field { border: 0; padding: 0; min-width: 0; }
.helptext { display: block; margin-top: 6px; color: var(--text-2); font-size: .84rem; }
.input, input[type=text], input[type=tel], input[type=date], input[type=number], input[type=password],
input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 52px; padding: 12px 14px;
  font: 400 1rem/1.4 var(--font-text); color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--r);
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; -webkit-appearance: none; padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%234a6b73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-strong); box-shadow: 0 0 0 4px rgb(0 156 224 / .2); }
input::placeholder, textarea::placeholder { color: #7d979e; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
ul.errorlist { list-style: none; padding: 0; margin: 8px 0 0; color: var(--danger); font-weight: 600; font-size: .88rem; }
ul.errorlist.nonfield { margin: 0 0 14px; padding: 12px 14px; background: var(--danger-bg); border: 1px solid var(--danger-line); border-radius: var(--r); }

/* Choice chips (Django RadioSelect / CheckboxSelectMultiple render <div><div><label><input>) */
.chips > div { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label {
  position: relative; display: inline-flex; align-items: center; gap: 8px; margin: 0;
  min-height: 48px; padding: 10px 16px; border: 1.5px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface); font-weight: 550; font-size: .95rem; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chips label:hover { border-color: var(--brand-soft); }
.chips label:has(input:checked) { background: var(--navy); border-color: var(--navy); color: #fff; }
.chips label:has(input:checked)::before {
  content: ""; width: 16px; height: 16px; margin-left: -4px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.chips label:has(input:focus-visible) { box-shadow: var(--focus); }
.chips.stack > div { flex-direction: column; }
.chips.stack label { border-radius: var(--r); justify-content: flex-start; }

/* Switch rows for consents and yes/no options */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--border); cursor: pointer; margin: 0;
}
.switch-row:last-child { border-bottom: 0; }
.switch-row .switch-text { font-weight: 550; }
.switch-row .switch-text small { display: block; color: var(--text-2); font-weight: 400; font-size: .84rem; margin-top: 2px; }
.switch-row input {
  -webkit-appearance: none; appearance: none; position: relative; flex: none; margin: 0;
  width: 52px; height: 32px; border-radius: var(--r-pill); background: #b8cdd2; cursor: pointer;
  transition: background .2s;
}
.switch-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s;
}
.switch-row input:checked { background: var(--brand-strong); }
.switch-row input:checked::after { transform: translateX(20px); }
.switch-row input:focus-visible { box-shadow: var(--focus); }
.switch-group { padding: 0 2px; }

.search-field { position: relative; }
.search-field .i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search-field input { padding-left: 48px; min-height: 56px; border-radius: var(--r-lg); font-size: 1.05rem; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }
.input-with-btn .btn { flex: none; min-height: 52px; padding: 0 16px; }

/* ------------------------------------------------------------------ feedback */
.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; margin-bottom: 14px;
  border-radius: var(--r); border: 1px solid; font-size: .95rem; font-weight: 550;
}
.alert .i { margin-top: 1px; }
.alert.success { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.alert.warning { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.alert.error { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.alert.info { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.alert p { margin: 4px 0 0; font-weight: 400; }
.alert a { color: inherit; font-weight: 700; }

.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(var(--appbar-h) + var(--safe-t) + 10px);
  width: min(560px, calc(100% - 24px)); display: grid; gap: 8px; pointer-events: none;
}
@media (min-width: 768px) { .toasts { left: calc(50% + var(--rail-w) / 2); } }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px; border-radius: var(--r);
  background: var(--navy); color: #fff; box-shadow: var(--shadow-3); font-weight: 600;
  animation: toast-in .25s ease-out;
}
.toast .i { color: #7ee2b0; }
.toast .toast-text { flex: 1; }
.toast .icon-btn { color: #fff; width: 36px; height: 36px; }
.toast.leaving { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

.save-state { display: none; align-items: flex-start; gap: 10px; margin-top: 10px; padding: 12px 14px; border-radius: var(--r); font-weight: 650; font-size: .92rem; }
.save-state.saving { display: flex; background: var(--surface-2); color: var(--text); }
.save-state.failed { display: flex; background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-line); }
.save-state.saving::before { content: ""; width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2.5px solid var(--brand-soft); border-top-color: var(--brand-strong); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.escalate {
  display: flex; gap: 14px; align-items: flex-start; padding: 16px; margin-bottom: 14px;
  border-radius: var(--r-lg); background: var(--danger-solid); color: #fff; box-shadow: var(--shadow-2);
}
.escalate strong { display: block; font: 700 1.1rem/1.25 var(--font-display); }
.escalate a.btn { margin-top: 12px; background: #fff; color: var(--danger); box-shadow: none; }

/* ------------------------------------------------------------------ badges & pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: .78rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--text);
}
.pill.ok, .pill.arrived, .pill.complete, .pill.completed, .pill.contacted, .pill.arranged { background: var(--ok-bg); color: var(--ok); }
.pill.registered, .pill.warn, .pill.priority, .pill.in_progress, .pill.queued, .pill.pending, .pill.attempted { background: var(--warn-bg); color: var(--warn); }
.pill.cancelled, .pill.not_completed, .pill.unable, .pill.declined { background: var(--danger-bg); color: var(--danger); }
.pill.urgent, .pill.escalated { background: var(--danger-solid); color: #fff; }
.pill.id { font-family: var(--font-mono); letter-spacing: .05em; background: var(--navy); color: #fff; }
.pill.clinical { background: #f1eaf8; color: var(--clinical); }

.avatar {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%;
  font: 700 .95rem/1 var(--font-display); color: var(--navy);
  background: linear-gradient(135deg, #bfeef2, #8fd9e0);
}
.avatar.lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar.sm { width: 36px; height: 36px; font-size: .8rem; }

/* ------------------------------------------------------------------ participant */
.idcard { position: relative; overflow: hidden; }
.idcard::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 6px;
  background: linear-gradient(90deg, var(--brand-soft), var(--brand));
}
.idcard-top { display: flex; gap: 14px; align-items: center; }
.idcard-name { min-width: 0; }
.idcard-name h1 { font-size: 1.3rem; overflow-wrap: anywhere; }
.idcard-name .pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.meta span, .meta a {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--surface-3); font-size: .85rem; color: var(--text); text-decoration: none;
}
.meta a { color: var(--brand-strong); font-weight: 600; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.quick-actions .qa {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 72px; padding: 8px; border-radius: var(--r); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font-size: .8rem; font-weight: 600; text-align: center;
  cursor: pointer; font-family: var(--font-text);
}
.quick-actions .qa .i { color: var(--brand-strong); }
.quick-actions .qa:active { background: var(--surface-2); }

.segmented {
  position: sticky; top: calc(var(--appbar-h) + var(--safe-t) + 8px); z-index: 15;
  display: flex; gap: 4px; padding: 4px; margin: 18px 0 14px; border-radius: var(--r-pill);
  background: rgb(229 246 248 / .95); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
}
.segmented button {
  flex: 1; min-height: 44px; border: 0; border-radius: var(--r-pill); background: none; cursor: pointer;
  font: 650 .9rem/1 var(--font-text); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.segmented .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--border); font-size: .72rem; display: inline-grid; place-items: center; }
.segmented button[aria-selected="true"] .count { background: var(--navy); color: #fff; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--brand-strong); }
.timeline .body { min-width: 0; flex: 1; }
.timeline .title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 650; }
.timeline .sub { font-size: .84rem; color: var(--text-2); margin-top: 2px; }
.timeline .note { margin-top: 8px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-3); font-size: .9rem; overflow-wrap: anywhere; }
.timeline .note.restricted { background: #f6f1fb; border-left: 3px solid var(--clinical); }
.timeline .row-action { margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; font-size: .88rem; font-weight: 650; text-decoration: none; }

.empty { text-align: center; padding: 22px 12px; color: var(--text-2); }
.empty .i { margin: 0 auto 10px; color: var(--brand-soft); }
.empty strong { display: block; color: var(--text); font-family: var(--font-display); margin-bottom: 4px; }

/* ------------------------------------------------------------------ lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 68px;
  color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border);
}
.list li:last-child .list-row { border-bottom: 0; }
.list-row:hover { background: var(--surface-3); }
.list-row:active { background: var(--surface-2); }
.list-row .main { min-width: 0; flex: 1; }
.list-row .main strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .main .sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 3px; font-size: .82rem; color: var(--text-2); }
.list-row > .i:last-child { color: var(--text-2); }

/* ------------------------------------------------------------------ lookup */
.scan-hero {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 20px; margin-bottom: 14px; border: 0; border-radius: var(--r-lg); cursor: pointer; text-align: left;
  color: #fff; font-family: var(--font-text);
  background: linear-gradient(135deg, var(--navy) 0%, #0d5c70 55%, var(--brand-strong) 100%);
  box-shadow: var(--shadow-2);
}
.scan-hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgb(104 204 212 / .45), transparent 70%);
}
.scan-hero .scan-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: rgb(255 255 255 / .16); flex: none; }
.scan-hero strong { display: block; font: 700 1.2rem/1.2 var(--font-display); }
.scan-hero span { font-size: .9rem; opacity: .85; }
.scan-hero:active { transform: scale(.99); }

.or { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; color: var(--text-2); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ------------------------------------------------------------------ sheets (dialog) */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 88dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 24px 24px 0 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-3); overflow: auto;
}
dialog.sheet[open] { animation: sheet-up .25s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop { background: rgb(11 61 74 / .45); backdrop-filter: blur(2px); }
.sheet-inner { padding: 10px 20px calc(24px + var(--safe-b)); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
@media (min-width: 768px) {
  dialog.sheet { margin: auto; border-radius: 24px; }
  .sheet-grip { display: none; }
}
.qr-big { display: grid; place-items: center; padding: 16px; border-radius: var(--r-lg); background: #fff; border: 1px solid var(--border); }
.qr-big img { width: min(260px, 70vw); height: auto; }

/* Scanner: full-screen camera view with viewfinder */
dialog.scanner {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: #fff;
}
dialog.scanner::backdrop { background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .viewfinder {
  position: absolute; left: 50%; top: 45%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 28px; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .55);
}
.scanner .viewfinder::before, .scanner .viewfinder::after {
  content: ""; position: absolute; inset: 0; border-radius: 28px; border: 4px solid var(--brand-soft);
  -webkit-mask: linear-gradient(#000 0 0) top/100% 28% no-repeat, linear-gradient(#000 0 0) bottom/100% 28% no-repeat;
          mask: linear-gradient(#000 0 0) top/100% 28% no-repeat, linear-gradient(#000 0 0) bottom/100% 28% no-repeat;
}
.scanner .scanline { position: absolute; left: 8%; right: 8%; height: 2px; top: 50%; background: var(--brand-soft); box-shadow: 0 0 12px var(--brand-soft); animation: scan 2s ease-in-out infinite alternate; }
@keyframes scan { from { top: 10%; } to { top: 90%; } }
.scanner .scanner-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 12px) 16px 12px; }
.scanner .scanner-top .icon-btn { color: #fff; background: rgb(255 255 255 / .16); }
.scanner .scanner-hint { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 36px); text-align: center; padding: 0 24px; font-weight: 600; }

/* ------------------------------------------------------------------ dashboard */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .kpis.people { grid-template-columns: repeat(6, minmax(0, 1fr)); } .kpis.volumes { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.kpi { position: relative; padding: 14px 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1); }
.kpi .kpi-label { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--text-2); }
.kpi .kpi-label .i { color: var(--brand-strong); }
.kpi .kpi-value { margin-top: 6px; font: 700 2rem/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--text); }
.kpi .kpi-value small { font-size: 1rem; font-weight: 600; color: var(--text-2); }
.kpi.hero { background: linear-gradient(135deg, var(--navy), #0d5c70); border: 0; }
.kpi.hero .kpi-label, .kpi.hero .kpi-label .i, .kpi.hero .kpi-value, .kpi.hero .kpi-value small { color: #fff; }
.dash-grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: 1fr 1fr; } .dash-grid .span-2 { grid-column: span 2; } }
.dash-grid .card { margin: 0; }

.meters { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.meter-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.meter-row .meter-label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-row .meter-value { font-variant-numeric: tabular-nums; font-weight: 700; font-size: .9rem; }
.meter-row .meter-value small { font-weight: 500; color: var(--text-2); }
.meter-track { display: block; grid-column: 1 / -1; height: 10px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter-fill { display: block; height: 100%; min-width: 0; border-radius: 0 4px 4px 0; background: var(--brand-strong); }
.meter-fill.zero { display: none; }

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 650; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

.dq { list-style: none; margin: 0; padding: 0; }
.dq li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.dq li:last-child { border-bottom: 0; }
.dq .dq-text { flex: 1; font-size: .92rem; }
.dq .dq-text small { display: block; color: var(--text-2); font-size: .8rem; }
.dq .dq-val { font: 700 1.1rem/1 var(--font-display); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ auth & error pages */
body.auth { padding-left: 0; display: flex; flex-direction: column; }
.auth-hero {
  position: relative; overflow: hidden; padding: calc(var(--safe-t) + 48px) 24px 84px; text-align: center; color: #fff;
  background: linear-gradient(160deg, var(--navy) 0%, #0d5c70 50%, var(--brand-strong) 100%);
}
.auth-hero::after { content: ""; position: absolute; left: -10%; right: -10%; bottom: -60px; height: 120px; background: var(--bg); border-radius: 50% 50% 0 0; }
.auth-logo { width: 96px; height: 96px; margin: 0 auto 16px; padding: 10px; border-radius: 28px; background: #fff; box-shadow: var(--shadow-3); }
.auth-hero h1 { color: #fff; font-size: 1.6rem; letter-spacing: .08em; }
.auth-hero p { margin: 6px auto 0; max-width: 340px; opacity: .9; font-size: .92rem; }
.auth-card { position: relative; z-index: 1; width: min(440px, calc(100% - 32px)); margin: -44px auto 32px; }
.auth-foot { text-align: center; color: var(--text-2); font-size: .82rem; padding: 0 24px 32px; }

.error-page { text-align: center; padding: 40px 12px; }
.error-page .code { font: 800 3.4rem/1 var(--font-display); color: var(--brand-soft); }

/* ------------------------------------------------------------------ misc */
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .chips label:has(input:checked) { outline: 3px solid CanvasText; }
  .meter-fill { background: CanvasText; }
}
@media print {
  .appbar, .tabbar, .offline-banner, .toasts, .no-print, .actionbar { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; }
}

body.auth .content { padding-top: 0; }

/* A single destination needs no tab bar on phones (e.g. event lead: dashboard only). */
@media (max-width: 767px) {
  .tabbar:not(:has(.tab ~ .tab)) { display: none; }
  body:has(.tabbar:not(:has(.tab ~ .tab))) .content { padding-bottom: calc(40px + var(--safe-b)); }
  body:has(.tabbar:not(:has(.tab ~ .tab))) .actionbar { bottom: calc(12px + var(--safe-b)); }
}

/* Phones: the station name already shows under the page title, so the chip shrinks to its pin. */
@media (max-width: 599px) {
  .chip-btn:not(.needs) { width: 40px; padding: 0; justify-content: center; }
  .chip-btn:not(.needs) span { display: none; }
  .conn { width: 32px; padding: 0; justify-content: center; }
  .conn.down { width: auto; padding: 0 10px; }
}

.segmented button { min-width: 0; padding: 0 6px; }
@media (max-width: 420px) {
  .segmented button .i { display: none; }
  .segmented button { font-size: .86rem; gap: 5px; }
}

.field > label.switch-row { display: flex; margin: 0; font-weight: 400; }

@media (min-width: 768px) and (max-width: 1199px) { .rail-brand div { display: none; } }
