/* Layout: sticky navy app bar over a light clinical canvas; content in cards, step colours from the referral flow chart. */
:root {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --hover: #eef2f9;
  --ink: #18223a;
  --muted: #5d6a84;
  --line: #e1e6ef;
  --line-strong: #cbd3e2;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-ink: #ffffff;
  --focus: #bcd0ff;
  --chip: #edf0f6;
  --ok: #15803d;
  --ok-bg: #e6f5ec;
  --warn: #a75207;
  --warn-bg: #fdf1df;
  --bad: #b91c1c;
  --bad-bg: #fdeaea;
  --info-bg: #edf3ff;
  --info-line: #c8d8fb;
  --info-ink: #1e3a8a;
  --bar: #0f2a5c;
  --bar-ink: #ffffff;
  --bar-muted: #c3d2ef;
  --bar-field: rgba(255, 255, 255, .1);
  --bar-line: rgba(255, 255, 255, .25);
  --overlay: rgba(15, 23, 42, .45);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, "Cascadia Mono", ui-monospace, monospace;
  --radius: 12px;
  --brand-ink: #162b58;   /* the logo's navy wordmark */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1220; --surface: #141c2d; --surface-2: #182136; --hover: #1d2840;
    --ink: #e3e8f2; --muted: #95a1b9; --line: #253049; --line-strong: #34425f;
    --primary: #5b8cff; --primary-hover: #7aa2ff; --primary-ink: #0a1122; --focus: #2c4680;
    --chip: #1f2a42; --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33270b;
    --bad: #f87171; --bad-bg: #3a1618; --info-bg: #15233f; --info-line: #2a3f6a; --info-ink: #b9cdfb;
    --bar: #0a1630; --bar-ink: #ffffff; --bar-muted: #a9b9d9; --overlay: rgba(0, 0, 0, .6);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --brand-ink: #e3e8f2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1220; --surface: #141c2d; --surface-2: #182136; --hover: #1d2840;
  --ink: #e3e8f2; --muted: #95a1b9; --line: #253049; --line-strong: #34425f;
  --primary: #5b8cff; --primary-hover: #7aa2ff; --primary-ink: #0a1122; --focus: #2c4680;
  --chip: #1f2a42; --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33270b;
  --bad: #f87171; --bad-bg: #3a1618; --info-bg: #15233f; --info-line: #2a3f6a; --info-ink: #b9cdfb;
  --bar: #0a1630; --bar-ink: #ffffff; --bar-muted: #a9b9d9; --overlay: rgba(0, 0, 0, .6);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --brand-ink: #e3e8f2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bar);
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; text-wrap: balance; }
h2 { font-size: 16px; margin: 0 0 12px; text-wrap: balance; }
h3 { font-size: 14px; margin: 0 0 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  /* Reaches under the status bar when opened from the home screen (black-translucent status bar). */
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: 10px;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  background: var(--bar);
  color: var(--bar-ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--bar-ink); }
/* Logo mark on a white tile, so its navy squares stay visible on the navy bar. */
.logo {
  width: 36px; height: 36px; border-radius: 9px; padding: 4px; flex: none;
  display: grid; place-items: center; background: #ffffff;
}
.logo img { display: block; width: 100%; height: 100%; }
.brand-name { font-weight: 600; font-size: 18px; text-transform: lowercase; letter-spacing: -.01em; line-height: 1.15; }
.brand-sub { font-size: 12px; color: var(--bar-muted); }
#nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#nav a { color: var(--bar-muted); padding: 8px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
#nav a:hover { background: rgba(255, 255, 255, .08); color: var(--bar-ink); }
#nav a.active { background: rgba(255, 255, 255, .16); color: var(--bar-ink); }
.nav-ico { display: none; }
.nav-ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.m-only { display: none; }
.who { display: flex; gap: 8px; align-items: center; }
.who input, .who select {
  background: var(--bar-field); color: var(--bar-ink); width: auto;
  border: 1px solid var(--bar-line); border-radius: 8px; padding: 6px 10px; font: inherit;
}
.who input { width: 140px; }
.who input::placeholder { color: var(--bar-muted); }
.who select option { color: #18223a; background: #ffffff; }
.who-ctl { display: flex; gap: 8px; align-items: center; }
.me {
  display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  background: var(--bar-field); border: 1px solid var(--bar-line); color: var(--bar-ink); font-weight: 500;
}
.me.warn { color: #fbbf24; border-color: #fbbf24; }
.bar-btn { background: transparent; color: var(--bar-ink); border-color: var(--bar-line); }
.bar-btn:hover { background: rgba(255, 255, 255, .12); }
.tbl .uname { min-width: 130px; max-width: 180px; }
.pw-cell { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.sync { font-size: 12px; color: var(--bar-muted); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.sync.live::before { background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .2); }
.sync.ro::before { background: #fbbf24; }
.sync.off::before { background: #f87171; }

main {
  max-width: 1400px; margin: 0 auto;
  padding-block: 24px;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
}

/* ---------- Generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grid { display: grid; gap: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--bad-bg); color: var(--bad); }

input, select, textarea {
  font: inherit; color: var(--ink);
  padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field.span2 { grid-column: span 2; }
.locked-time {
  display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 7px 10px; border-radius: 8px;
  border: 1px dashed var(--line-strong); background: var(--surface-2); color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums;
}
.req { color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); }
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--chip); color: var(--muted); white-space: nowrap;
}
.pill.stage { background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: color-mix(in srgb, var(--c) 75%, var(--ink)); }
.pill.urgent, .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.done { background: var(--chip); color: var(--ink); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.click tbody tr { cursor: pointer; }
.tbl.click tbody tr:hover { background: var(--hover); }
.tbl.edit td { padding: 5px 4px; }
.tbl.edit input, .tbl.edit select { padding: 5px 7px; min-width: 90px; }
.tbl.edit input[type=checkbox] { min-width: 0; }
.tbl.edit input.qty { width: 70px; min-width: 0; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.tbl tr.inactive td { color: var(--muted); }
.tbl tr.inactive td b { text-decoration: line-through; }
.inline-check { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.pick-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.pick-row input { flex: none; width: 18px; height: 18px; accent-color: var(--primary); }
.centre-picks { display: grid; gap: 2px; padding: 6px 0 0 28px; border-left: 2px solid var(--line); margin-left: 8px; }
.centre-pick { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; white-space: nowrap; }

.acct-field { position: relative; }
#u-acct-chip { display: flex; gap: 4px; align-items: center; }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 4px; max-height: 260px; overflow-y: auto;
}
.ac-item { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 0; border-radius: 6px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.ac-item:hover, .ac-item:focus-visible { background: var(--hover); }
.ac-item img { width: 24px; height: 24px; border-radius: 50%; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .value { color: var(--bad); }

.pipeline { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; }
.lane { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; min-height: 140px; display: flex; flex-direction: column; }
.lane-head { padding: 9px 10px; border-bottom: 3px solid var(--c); display: flex; gap: 8px; align-items: flex-start; }
.lane-head .num {
  flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #ffffff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.lane-head .t { font-size: 12px; font-weight: 600; line-height: 1.25; }
.lane-head .count { margin-left: auto; font-weight: 700; color: var(--c); }
.lane-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.mini {
  display: block; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--c);
  border-radius: 8px; padding: 7px 9px; color: var(--ink); font-size: 12px;
}
.mini:hover { box-shadow: var(--shadow); background: var(--hover); }
.mini .id { font-weight: 600; font-family: var(--font-mono); font-size: 12px; }
.mini .flag { color: var(--bad); font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alerts li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 11px; border-radius: 8px; background: var(--warn-bg); }
.alerts li.bad { background: var(--bad-bg); }
.alerts li .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-top: 6px; flex: none; }
.alerts li.bad .dot { background: var(--bad); }

.empty { text-align: center; padding: 56px 20px; }
.empty .big { font-size: 40px; }
.empty p { color: var(--muted); max-width: 540px; margin: 8px auto 18px; }

.auth-card { max-width: 420px; margin: 40px auto; padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card form .btn { justify-content: center; padding: 10px 14px; }
/* Logo lockup: mark on the left, wordmark with the tagline right under it. */
.auth-brand { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; margin-bottom: 8px; color: var(--brand-ink); }
.auth-brand img { grid-row: 1 / span 2; height: 56px; width: auto; }
.auth-brand span { font-size: 36px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.auth-brand .auth-tag { font-size: 14px; font-weight: 400; letter-spacing: 0; line-height: 1.3; color: var(--muted); margin-top: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
body.signed-out #nav { visibility: hidden; }
.install-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 12px 14px;
  background: var(--info-bg); border: 1px solid var(--info-line); border-radius: var(--radius);
}
.install-banner img { border-radius: 10px; flex: none; }
.install-text { flex: 1; min-width: 180px; }
.install-banner .actions { margin-left: auto; }
.install-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.banner { background: var(--info-bg); border: 1px solid var(--info-line); color: var(--info-ink); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

/* ---------- List ---------- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }

/* ---------- Detail ---------- */
.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head h1 { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-weight: 600; flex-wrap: wrap; }
.route { font-size: 15px; margin-top: 4px; }
.route b { color: var(--primary); }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.back { font-size: 13px; display: inline-block; margin-bottom: 6px; }

.stepper { display: flex; align-items: flex-start; margin: 4px 0 20px; overflow-x: auto; padding-bottom: 4px; }
.sn { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; min-width: 110px; cursor: pointer; }
.sn::before {
  content: ""; position: absolute; top: 16px; left: -50%; width: 100%; height: 3px; background: var(--line); z-index: 0;
}
.sn:first-child::before { display: none; }
.sn.done::before, .sn.current::before { background: var(--c); }
.sn .dot {
  position: relative; z-index: 1; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--surface); border: 3px solid var(--line); color: var(--muted);
}
.sn.done .dot { background: var(--c); border-color: var(--c); color: #ffffff; }
.sn.current .dot { border-color: var(--c); color: var(--c); box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 20%, transparent); }
.sn .lbl { font-size: 11.5px; margin-top: 6px; color: var(--muted); max-width: 130px; line-height: 1.25; }
.sn.current .lbl { color: var(--ink); font-weight: 700; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); max-height: calc(100vh - 92px); overflow-y: auto; }

.step {
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden;
}
.step-head { display: flex; align-items: center; gap: 12px; padding: 13px 16px; cursor: pointer; background: color-mix(in srgb, var(--c) 6%, var(--surface)); }
.step-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #ffffff;
  display: grid; place-items: center; font-weight: 700;
}
.step-title { font-weight: 700; font-size: 15px; }
.step-where { font-size: 12px; color: var(--muted); }
.step-status { margin-left: auto; text-align: right; font-size: 12px; }
.step-body { padding: 16px 18px 18px; border-top: 1px solid var(--line); }
.step.locked { opacity: .6; }
.step.locked .step-head { cursor: default; background: var(--surface-2); }
.step.locked .step-num { background: var(--muted); }
.step.current { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 40%, transparent), var(--shadow); }

.checklist { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checklist label { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.checklist label:hover { background: var(--hover); }
.checklist input:checked + span { color: var(--ok); }
.checks-done { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 3px; }
.checks-done li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 16px; margin: 0; }
.kv div dt { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kv div dd { margin: 0; font-weight: 500; }
.subhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 8px; font-weight: 700; flex-wrap: wrap; }
.step-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.notice { background: var(--info-bg); border: 1px solid var(--info-line); color: var(--info-ink); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.delivery { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.delivery-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
/* Step 5: one panel per department */
.dept { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.dept.done { background: var(--surface-2); }
.dept-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.dept-head b { font-size: 15px; }
.dept-status { margin-left: auto; display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.dept .subhead:first-of-type { margin-top: 6px; }
.dept .checklist { margin-top: 12px; }
.disclaimer { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 8px; font-size: 12.5px; margin-top: 10px; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 10px 12px; }
.timeline li::before {
  content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--c, var(--primary));
}
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo-tile { position: relative; margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo-open { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.photo-tile .photo { display: block; width: 100%; height: 110px; object-fit: cover; }
.photo-tile figcaption { font-size: 11px; color: var(--muted); padding: 5px 7px; }
.photo-del { position: absolute; top: 5px; right: 5px; background: var(--surface); box-shadow: var(--shadow); }
.photo.broken { visibility: hidden; }
.photo-tile:has(.photo.broken) .photo-open::after { content: "Photo not available"; display: grid; place-items: center; height: 110px; margin-top: -110px; font-size: 12px; color: var(--muted); }
.photo-full { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: 8px; }
.inline-form { display: grid; grid-template-columns: 2fr 1fr 2fr auto; gap: 8px; margin-top: 8px; }
.inline-form.centre-form { grid-template-columns: 1fr 2fr 1.5fr 1.2fr auto; }

.side h3 { display: flex; justify-content: space-between; align-items: center; }
.side .tbl td, .side .tbl th { padding: 6px 6px; font-size: 12.5px; }
.inc { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; }
.inc.open { border-color: var(--bad); background: var(--bad-bg); }
.inc .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }

/* ---------- Modal / toast ---------- */
.modal {
  position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); color: var(--ink); border-radius: 14px; width: min(520px, 100%); max-height: 100%; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-box.wide { width: min(980px, 100%); }
.modal-box ul { padding-left: 18px; }
.modal-box .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bar); color: var(--bar-ink); padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60; font-weight: 500; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); color: #ffffff; }

/* ---------- Manifest / acknowledgement document ---------- */
.docview { font-size: 13px; }
.docview h1 { font-size: 18px; margin-bottom: 2px; }
.docview .doc-sub { color: var(--muted); margin-bottom: 12px; }
.docview table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.docview th, .docview td { border: 1px solid var(--line-strong); padding: 5px 7px; text-align: left; }
.docview th { background: var(--surface-2); }
.docview .sig { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 36px; }
.docview .sig div { border-top: 1px solid var(--ink); padding-top: 4px; }
.docview .note { border: 1px solid var(--line-strong); padding: 6px 8px; margin-top: 10px; }
#print-area { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .brand-sub { display: none; }
  .topbar { gap: 12px; }
  .who input { width: 110px; }
}
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .two-col { grid-template-columns: 1fr; }
}
/* Phones: one-row app bar, bottom tab bar, card-style tables, 44px touch targets, 16px inputs (no iOS zoom). */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  h1 { font-size: 20px; }
  .d-only { display: none; }
  .m-only { display: inline; }

  /* App bar */
  .topbar {
    gap: 8px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); padding-bottom: 8px; min-height: 56px;
    padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .logo { width: 32px; height: 32px; border-radius: 8px; }
  .brand { gap: 8px; flex: none; }
  .brand-name { font-size: 17px; }
  .topbar .who { margin-left: auto; min-width: 0; gap: 8px; }
  .sync-label { display: none; }
  .sync::before { width: 10px; height: 10px; }
  .who-ctl { min-width: 0; gap: 6px; }
  .me { display: block; max-width: 132px; overflow: hidden; text-overflow: ellipsis; padding: 7px 9px; font-size: 13px; }
  .who input { width: 96px; }
  .topbar .btn.sm { min-height: 36px; padding: 7px 10px; }

  /* Bottom tab bar */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; overflow: visible;
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(16, 24, 40, .08);
    padding: 4px max(4px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px));
  }
  #nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; padding: 4px 2px; border-radius: 10px; font-size: 11.5px; color: var(--muted); background: none;
  }
  #nav a:hover { background: none; color: var(--muted); }
  #nav a.active, #nav a.active:hover { background: none; color: var(--primary); font-weight: 700; }
  .nav-ico { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 15px; }
  #nav a.active .nav-ico { background: color-mix(in srgb, var(--primary) 15%, transparent); }
  body.signed-out #nav { display: none; }
  main {
    padding-top: 14px; padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  body.signed-out main { padding-bottom: 24px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); width: max-content; text-align: center; }

  /* Touch targets and inputs */
  .btn { min-height: 44px; padding: 10px 14px; justify-content: center; }
  .btn.sm { min-height: 38px; padding: 8px 12px; font-size: 13px; }
  input, select, textarea, input.mono { font-size: 16px; min-height: 44px; padding: 9px 12px; }
  textarea { min-height: 76px; }
  .locked-time { min-height: 44px; font-size: 16px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; }
  .pick-row { padding: 9px 0; }
  input[type=file] { min-height: 0; }
  .icon-btn { min-width: 40px; min-height: 40px; font-size: 16px; }
  .field > span { font-size: 13px; }

  /* Cards and page heads */
  .card { padding: 14px; }
  .grid { gap: 12px; }
  .page-head { margin-bottom: 14px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .auth-card { margin: 12px auto; padding: 22px 18px; }
  .install-banner .actions { width: 100%; }
  .install-banner .actions .btn { flex: 1; }

  /* Dashboard */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 22px; }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .pipeline { grid-template-columns: 1fr; gap: 8px; overflow: visible; }
  .lane { min-height: 0; }
  .lane-head .t { font-size: 13.5px; }
  .lane-body:not(:has(.mini)) { display: none; }
  .mini { padding: 10px 12px; font-size: 13px; }
  .two-col { gap: 12px; margin-top: 12px; }

  /* Tables become a stack of cards (the side "Samples" table stays a table) */
  .table-wrap:has(> .tbl:not(.keep)) { overflow: visible; }
  .tbl:not(.keep), .tbl:not(.keep) tbody { display: block; }
  .tbl:not(.keep) thead { display: none; }
  .tbl:not(.keep) tr {
    position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px;
    padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  }
  .tbl:not(.keep) tr:last-child { margin-bottom: 0; }
  .tbl:not(.keep) td { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; padding: 0; border: 0; overflow-wrap: anywhere; }
  .tbl:not(.keep) td[data-label]:not([data-label=""])::before {
    content: attr(data-label); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  }
  .tbl:not(.keep) td:first-child { display: block; grid-column: 1 / -1; padding-right: 44px; font-size: 15px; font-weight: 600; }
  .tbl:not(.keep) td:first-child::before { display: none; }
  .tbl:not(.keep) td:empty { display: none; }
  .tbl:not(.keep) td:last-child:nth-child(even) { grid-column: 1 / -1; }
  .tbl.edit:not(.keep) tr { align-items: end; }
  .tbl:not(.keep) td:has(> .icon-btn:only-child) { position: absolute; top: 6px; right: 6px; }
  .tbl:not(.keep) td > input:not([type=checkbox]), .tbl:not(.keep) td > select { width: 100%; min-width: 0; }
  .tbl.edit input, .tbl.edit select { padding: 9px 10px; }
  .tbl.click tbody tr:active { background: var(--hover); }
  .tbl .uname { max-width: none; }
  .pill { max-width: 100%; }
  .pill.stage { white-space: normal; }
  /* Consignment cards: drop transport temperature and dispatch time (shown on the consignment page) */
  .tbl.click td:nth-child(6), .tbl.click td:nth-child(8) { display: none; }

  /* Lists and forms */
  .filters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters input, .filters select:first-of-type { grid-column: span 2; }
  .form-grid { gap: 10px; }
  .field.span2 { grid-column: auto; }
  .inline-form, .inline-form.centre-form { grid-template-columns: 1fr 1fr; }
  .inline-form > :first-child, .inline-form > .btn { grid-column: 1 / -1; }

  /* Consignment detail */
  .detail-head { gap: 12px; margin-bottom: 12px; }
  .detail-head h1 { font-size: 19px; overflow-wrap: anywhere; }
  .detail-head > div { min-width: 0; width: 100%; }
  .detail-head .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .detail-head .actions .btn { white-space: normal; text-align: center; padding-inline: 8px; font-size: 14px; }
  .stepper { overflow: visible; margin: 0 0 14px; padding-bottom: 0; }
  .sn { min-width: 0; }
  .sn::before { top: 14px; }
  .sn .dot { width: 30px; height: 30px; font-size: 13px; border-width: 2px; }
  .sn .lbl { display: none; }
  .step { margin-bottom: 10px; }
  .step-head { flex-wrap: wrap; gap: 6px 10px; padding: 12px; }
  .step-head > div:nth-child(2) { flex: 1; min-width: 0; }
  .step-status { flex-basis: 100%; margin-left: 40px; text-align: left; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
  .step-body { padding: 14px 12px; }
  .step-foot { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .step-foot .muted { text-align: center; }
  .checklist label { padding: 11px 12px; min-height: 48px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .subhead { margin-top: 16px; }
  .photos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side { gap: 12px; }
  .inc .top { flex-wrap: wrap; }

  /* Dialogs open as bottom sheets */
  .modal { place-items: end stretch; padding: 0; }
  .modal-box, .modal-box.wide {
    width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0;
    padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .modal-box .foot { gap: 8px; }
  .modal-box .foot .btn { flex: 1 1 40%; }
  .docview .sig { grid-template-columns: 1fr; }
}

/* ---------- Print (local copy only) ---------- */
@media print {
  body { background: #ffffff; }
  body::before { display: none; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000000; }
}
