/* ==========================================================================
   NIFSEN HR PORTAL — CORE DESIGN SYSTEM
   Hand-written, dependency-free CSS. No frameworks, no imports, no
   external fonts. Safe to re-skin per tenant by overriding the custom
   properties defined in :root below (values are injected server-side
   from a per-tenant settings table).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS — LIGHT PALETTE (the canonical/default palette)
   -------------------------------------------------------------------------- */
:root {
  /* Brand — white-label, override per tenant */
  --brand-primary: #1a3a6b;
  --brand-primary-dark: #12294c;
  --brand-primary-light: #e8eef7;
  /* Link colour is derived from the brand so white-labelling carries through. */
  --link: var(--brand-primary);
  --brand-accent: #c9a227;
  --brand-sidebar-bg: #12294c;
  --brand-sidebar-fg: #dbe4f0;

  /* Neutral surfaces */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #f8f9fc;
  --border: #dde3ec;
  --text: #1c2530;
  --text-muted: #667085;

  /* Semantic colours + soft tints */
  --success: #1e7a3d;
  --success-bg: #e6f4ea;
  --warning: #9a6400;
  --warning-bg: #fbf1d8;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --info: #205a9e;
  --info-bg: #e5eefb;

  /* Radii */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 1px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10), 0 2px 4px rgba(16, 24, 40, 0.06);

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* Fonts */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "Consolas", "Liberation Mono", Menlo, monospace;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 60px;
}

/* --------------------------------------------------------------------------
   1a. TOKENS — DARK PALETTE (explicit user choice via data-theme="dark")
   Light is the default whatever the computer's own setting - dark only ever
   applies when the user picks it (public/js/theme.js).
   Wins over both the light default and the OS preference block above.
   -------------------------------------------------------------------------- */
:root[data-theme="dark"] {
  --brand-primary-light: #1b2a44;
    /* The raw brand colour is too dark on a dark ground: lighten it.
       The flat value is the fallback for browsers without color-mix(). */
    --link: #8fb3e8;
    --link: color-mix(in srgb, var(--brand-primary) 45%, #ffffff);

  --bg: #10151d;
  --surface: #171d27;
  --surface-alt: #1d2430;
  --border: #2b3444;
  --text: #e7ebf2;
  --text-muted: #97a2b4;

  --success: #4ade80;
  --success-bg: #123723;
  --warning: #fbbf24;
  --warning-bg: #3a2e0d;
  --danger: #f87171;
  --danger-bg: #3b1615;
  --info: #7fb3f5;
  --info-bg: #142b45;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45), 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   2. RESET + BASE
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  max-width: 100%;
  display: block;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--s-3);
  font-weight: 650;
  line-height: 1.25;
  color: var(--text);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
h5, h6 { font-size: 0.9rem; }

p {
  margin: 0 0 var(--s-3);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code, pre, kbd {
  font-family: var(--font-mono);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--s-4) 0;
}

/* Consistent, visible keyboard focus everywhere */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ==========================================================================
   3. APP SHELL — sidebar + topbar + main, CSS grid
   ========================================================================== */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
}

/* ---- Sidebar ---- */
.sidebar {
  grid-area: sidebar;
  background: var(--brand-sidebar-bg);
  color: var(--brand-sidebar-fg);
  padding: var(--s-4) 0;
  /* Stay in place while the main column scrolls - the nav must always be
     reachable on the long list and report pages. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-4) var(--s-4);
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
}

.sidebar__brand img,
.sidebar__brand svg {
  width: 28px;
  height: 28px;
}

.nav-group {
  margin-bottom: var(--s-4);
}

.nav-group__label {
  padding: 0 var(--s-4);
  margin-bottom: var(--s-1);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(219, 228, 240, 0.55);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-4);
  color: var(--brand-sidebar-fg);
  border-left: 3px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  border-left-color: var(--brand-accent);
  color: #fff;
  font-weight: 600;
}

.nav-item__icon {
  width: 20px;
  height: 20px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

/* ---- Topbar ---- */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-5);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__left,
.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--s-1) var(--s-2);
  cursor: pointer;
  color: var(--text);
}

/* ---- Main content ---- */
.main {
  grid-area: main;
  padding: var(--s-5);
  overflow-x: hidden;
}

/* ---- Mobile off-canvas sidebar ---- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.5);
  z-index: 25;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
  }

  .sidebar-backdrop.sidebar-backdrop--visible {
    display: block;
  }

  .sidebar-toggle {
    display: inline-flex;
  }
}

/* ==========================================================================
   4. COMPONENTS
   ========================================================================== */

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.card__header h1,
.card__header h2,
.card__header h3 {
  margin: 0;
}

.card__body {
  padding: var(--s-5);
}

.card__footer {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn--primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--brand-primary-dark);
  border-color: var(--brand-primary-dark);
}

.btn--secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn--secondary:hover {
  background: var(--surface-alt);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger:hover {
  filter: brightness(0.92);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand-primary);
}

.btn--ghost:hover {
  background: var(--brand-primary-light);
}

.btn--sm {
  padding: var(--s-1) var(--s-3);
  font-size: 0.8rem;
}

.btn--lg {
  padding: var(--s-3) var(--s-6);
  font-size: 1rem;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---- Forms ---- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4) var(--s-5);
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.field--span-2 {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--brand-primary);
  outline-offset: 1px;
  border-color: var(--brand-primary);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field__error {
  font-size: 0.78rem;
  color: var(--danger);
  display: none;
}

.field.is-invalid input,
.field.is-invalid select,
.field.is-invalid textarea {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.field.is-invalid .field__error {
  display: block;
}

.field-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.field-row input[type="checkbox"],
.field-row input[type="radio"] {
  width: auto;
  margin: 0;
}

.field-row label {
  font-weight: 400;
  font-size: 0.9rem;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 var(--s-4);
}

fieldset legend {
  width: 100%;
  padding-bottom: var(--s-2);
  margin-bottom: var(--s-4);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 480px;
}

.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  text-align: left;
  padding: var(--s-3) var(--s-4);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}

.table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:nth-child(even) {
  background: var(--surface-alt);
}

.table tbody tr:hover {
  background: var(--brand-primary-light);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
}

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.6;
}

.badge--success { background: var(--success-bg); color: var(--success); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger); }
.badge--info    { background: var(--info-bg);    color: var(--info); }
.badge--neutral { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }

/* ---- Alert ---- */
.alert {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 0.88rem;
  transition: opacity 0.4s ease;
}

.alert__title {
  font-weight: 700;
  margin-bottom: 2px;
  display: block;
}

.alert--success { background: var(--success-bg); color: var(--success); border-color: currentColor; }
.alert--warning { background: var(--warning-bg); color: var(--warning); border-color: currentColor; }
.alert--danger  { background: var(--danger-bg);  color: var(--danger);  border-color: currentColor; }
.alert--info    { background: var(--info-bg);    color: var(--info);    border-color: currentColor; }

.alert.is-hiding {
  opacity: 0;
}

/* ---- Stat tiles ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-sm);
}

.stat-tile__label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--s-1);
}

.stat-tile__value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-tile__delta {
  margin-top: var(--s-1);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-tile__delta--up { color: var(--success); }
.stat-tile__delta--down { color: var(--danger); }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  list-style: none;
  margin: var(--s-4) 0 0;
  padding: 0;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
}

.pagination a:hover {
  background: var(--surface-alt);
  text-decoration: none;
}

.pagination .active span,
.pagination .active a {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.pagination .disabled span {
  opacity: 0.45;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-1);
  list-style: none;
  margin: 0 0 var(--s-4);
  padding: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.breadcrumb li:not(:last-child)::after {
  content: "/";
  margin-left: var(--s-1);
  color: var(--border);
}

.breadcrumb a {
  color: var(--text-muted);
}

.breadcrumb li:last-child {
  color: var(--text);
  font-weight: 600;
}

/* ---- Tabs (underline style) ---- */
.tabs {
  display: flex;
  gap: var(--s-5);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s-5);
}

.tabs__item {
  padding: var(--s-3) 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tabs__item:hover {
  color: var(--text);
  text-decoration: none;
}

.tabs__item.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: var(--s-7) var(--s-4);
  color: var(--text-muted);
}

.empty-state__icon {
  font-size: 2.2rem;
  margin-bottom: var(--s-3);
  opacity: 0.6;
}

.empty-state__message {
  margin-bottom: var(--s-4);
  font-size: 0.92rem;
}

/* ---- Avatar ---- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  font-weight: 700;
  font-size: 0.85rem;
  overflow: hidden;
  flex: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar--sm { width: 26px; height: 26px; font-size: 0.7rem; }
.avatar--lg { width: 52px; height: 52px; font-size: 1.1rem; }

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.page-header__title {
  margin: 0;
}

.page-header__title p {
  margin: var(--s-1) 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.page-header__actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* ==========================================================================
   5. UTILITIES
   ========================================================================== */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }

.mt-1 { margin-top: var(--s-1); }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }

.mb-1 { margin-bottom: var(--s-1); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   6. PRINT — payslips, letters, and other printable documents
   ========================================================================== */
@media print {
  .sidebar,
  .topbar,
  .sidebar-backdrop,
  .btn,
  .page-header__actions,
  .pagination,
  .tabs,
  .no-print {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main {
    padding: 0;
    overflow: visible;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    box-shadow: none;
    border: none;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  .table-wrap {
    overflow-x: visible;
    border: none;
  }
}

/* ==========================================================================
   11. APP ADDITIONS
   Classes used by the EJS layout partials that sit outside the core system.
   ========================================================================== */

/* Fallback brand mark when no logo image is configured (white-label default) */
.sidebar__brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--brand-accent);
  color: #12294c;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Caption line under a KPI number (alias of the delta slot, without a trend) */
.stat-tile__caption {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--s-1);
}

/* Pagination state classes, applied directly to the anchor */
.pagination a.is-active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
  font-weight: 600;
}

.pagination a.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* Page footer, outside the app shell grid */
.app-footer {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* Hidden on narrow screens - used for the identity block in the top bar */
@media (max-width: 700px) {
  .hide-sm { display: none; }
}

@media print {
  .app-footer { display: none; }
}

/* ==========================================================================
   12. MOBILE PASS  (Phase 1E)
   The portal is used on a phone by field staff punching in from a client
   site, and by anyone approving leave between meetings. Everything below
   makes those journeys work without a horizontal scrollbar.
   ========================================================================== */

@media (max-width: 900px) {
  /* The sidebar is off-canvas below 900px, so it must not stay sticky-tall. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
  }

  .sidebar--open ~ .sidebar-backdrop,
  .sidebar-backdrop.is-visible {
    display: block;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .main {
    padding: var(--s-4) var(--s-3);
  }
}

@media (max-width: 640px) {
  /* Page headers stack rather than squeeze. */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-3);
  }

  .page-header__actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  .page-header__actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* One KPI tile per row reads better than four squeezed ones. */
  .stat-row {
    grid-template-columns: 1fr 1fr;
  }

  .stat-tile__value {
    font-size: 1.5rem;
  }

  /* Forms go single column. */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .field--span-2 {
    grid-column: auto;
  }

  /* Inputs at 16px stop iOS zooming the viewport on focus. */
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
  }

  /* Tables keep their own scrollbar and never push the page sideways. */
  .table-wrap {
    margin-inline: calc(var(--s-3) * -1);
    padding-inline: var(--s-3);
  }

  .table {
    font-size: 0.85rem;
  }

  .table thead th,
  .table tbody td {
    padding: var(--s-2);
    white-space: nowrap;
  }

  /* Buttons big enough to hit with a thumb. */
  .btn {
    min-height: 40px;
  }

  .btn--sm {
    min-height: 34px;
  }

  /* The identity block in the top bar is already hidden below 700px;
     tighten what remains so Sign out stays reachable. */
  .topbar {
    padding: 0 var(--s-3);
    gap: var(--s-2);
  }

  .topbar__right {
    gap: var(--s-1);
  }

  .card__header {
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  /* A details block used as an inline editor needs room on a phone. */
  details > summary {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 420px) {
  .stat-row {
    grid-template-columns: 1fr;
  }

  .main {
    padding: var(--s-3) var(--s-2);
  }
}

/* A file input is unstyled by default and looks broken next to the rest. */
.field input[type="file"] {
  padding: var(--s-2);
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  cursor: pointer;
}

.field input[type="file"]::file-selector-button {
  margin-right: var(--s-3);
  padding: var(--s-1) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

/* A letter or payslip body: readable measure, preserved paragraphing. */
.document-body {
  max-width: 42rem;
  line-height: 1.7;
}

.document-body p {
  margin: 0 0 var(--s-3);
  min-height: 1em;
}

@media print {
  .document-body {
    max-width: none;
  }
}

/* ==========================================================================
   TRACKING, MAPS AND THE MOBILE DOWNLOAD PAGE (Phase 2A)
   Appended rather than woven in: everything here is scoped to the /tracking
   and /mobile screens, and Leaflet's own stylesheet is loaded only on those
   pages, so none of it can affect the rest of the portal.
   ========================================================================== */

/* The map needs an explicit height - Leaflet measures its container, and a
   container sized by its contents collapses to nothing. */
.trk-map {
  height: 460px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
  z-index: 0; /* keeps Leaflet panes under the sidebar and its backdrop */
}

@media (max-width: 720px) {
  .trk-map {
    height: 320px;
  }
}

/* Leaflet draws its own light chrome. In dark mode the tiles stay as they are -
   a re-coloured map is harder to read, not easier - but the frame around them
   follows the theme. */
.leaflet-container {
  font: inherit;
  background: var(--surface-alt);
}

.leaflet-popup-content {
  margin: var(--s-3);
  line-height: 1.5;
}

/* The numbered start/end and check-in/out markers, drawn as text so the map
   does not depend on the sprite images loading. */
.trk-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.trk-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.trk-legend__item {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

.trk-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}

.trk-dot--fresh  { background: var(--success); }
.trk-dot--ageing { background: var(--warning); }
.trk-dot--stale  { background: var(--danger); }
.trk-dot--punch  { background: var(--info); }

/* One cause per block on the health report, each with its own explanation. */
.trk-problem + .trk-problem {
  margin-top: var(--s-3);
}

.trk-problem .badge {
  margin-bottom: var(--s-1);
}

/* A gap row must not read as just another ping. */
.trk-row--gap td {
  background: var(--warning-bg);
  color: var(--warning);
}

.trk-row--mocked td {
  background: var(--danger-bg);
}

/* --------------------------------------------------- mobile download page */

.trk-download {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-6);
  align-items: flex-start;
}

.trk-download__detail {
  flex: 1 1 22rem;
  min-width: 0;
}

.trk-download__qr {
  flex: 0 1 15rem;
  text-align: center;
}

/* The QR is drawn as an SVG by /static/js/qr.js. White stays white in dark
   mode with a light frame around it: a scanner needs the quiet zone to be
   genuinely light, and an inverted code will not read on many phones. */
.trk-qr {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 15rem;
  aspect-ratio: 1 / 1;
  padding: var(--s-2);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.trk-qr svg {
  width: 100%;
  height: 100%;
  display: block;
}

.trk-url {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* Install instructions: numbered, roomy, and readable at a phone's width
   because that is where they will actually be read. */
.trk-steps {
  margin: 0;
  padding-left: var(--s-5);
  max-width: 46rem;
  line-height: 1.7;
}

.trk-steps li + li {
  margin-top: var(--s-4);
}
