/* Instrument Sans, self-hosted (Latin only; other scripts fall back to the system font). Variable weight 400-700. */
@font-face { font-family: 'Instrument Sans'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('../fonts/instrument-sans-latin.woff2') format('woff2');
  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: 'Instrument Sans'; font-style: italic; font-weight: 400 700; font-display: swap; src: url('../fonts/instrument-sans-italic-latin.woff2') format('woff2');
  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; }
/* ChurchBright staff-app design system — "refined & premium". Tokens first; components reference tokens only.
   Type: Instrument Sans (loaded by the layouts). Depth: hairlines + soft layered shadows. Motion: 150ms/220ms, no bounce. */
:root {
  color-scheme: light;
  --primary: #243247; --primary-hover: #1c2638; --primary-soft: #eaeef5; --primary-ink: #243247;
  --brand: #f59e0b; --brand-2: #f97316;
  --ink: #0b1224; --ink-2: #28324a; --muted: #5b6480; --faint: #687189;
  --bg: #f7f5f1; --surface: #ffffff; --surface-2: #fbf9f6; --surface-3: #f3f0ea;
  --border: rgba(11,18,36,.08); --border-strong: rgba(11,18,36,.14);
  /* Form-control outline: WCAG 1.4.11 needs 3:1 against the adjacent background (3.7:1 on white). Dividers keep the subtle --border. */
  --input-border: #7c859f; --input-border-hover: #5f6985;
  --sidebar: #243247; --sidebar-2: #1c2638; --sidebar-ink: #c7cde0; --sidebar-muted: #7f8aa6; --sidebar-active: rgba(255,255,255,.08);
  --sidebar-line: rgba(255,255,255,.07); --sidebar-card: rgba(255,255,255,.04);
  --success: #15803d; --success-soft: #e7f7ec; --warning: #b45309; --warning-soft: #fff4dc;
  --danger: #c81e1e; --danger-hover: #991b1b; --danger-soft: #feecec; --info: #1d4ed8; --info-soft: #e6efff;
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(11,18,36,.04);
  --shadow: 0 1px 2px rgba(11,18,36,.04), 0 6px 20px -12px rgba(11,18,36,.12);
  --shadow-lg: 0 12px 40px -12px rgba(11,18,36,.25), 0 0 0 1px rgba(11,18,36,.06);
  --shadow-btn: inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(11,18,36,.15);
  --ring: 0 0 0 3px rgba(36,50,71,.25);
  --row-hover: rgba(36,50,71,.04);
  --ease: cubic-bezier(.2,.8,.2,1); --t-fast: 150ms; --t-panel: 220ms;
  --font: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 260px; --topbar-h: 60px;
  /* Chart tokens (validated categorical palette) */
  --viz-surface: #ffffff; --viz-grid: #e8e7e1; --viz-axis: #c3c2b7; --viz-ink: #52514e; --viz-muted: #898781;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --viz-seq-1: #86b6ef; --viz-seq-2: #5598e7; --viz-seq-3: #2a78d6; --viz-seq-4: #1c5cab; --viz-seq-5: #0d366b; --viz-track: #cde2fb;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.55 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-variant-numeric: tabular-nums; }
img, svg { vertical-align: middle; }
a { color: var(--primary); text-decoration: none; transition: color var(--t-fast) var(--ease); }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--ink); letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 600; } h3 { font-size: 16px; font-weight: 600; } h4 { font-size: 14px; font-weight: 600; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
code, kbd, .mono { font-family: var(--mono); font-size: 12.5px; }
kbd { display: inline-flex; align-items: center; min-height: 20px; padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: var(--muted); font: 500 11px/1 var(--font); letter-spacing: .02em; }
.icon { flex-shrink: 0; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: var(--r-sm); }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:focus-visible, .input:focus-visible, .sb-link:focus-visible, .sb-church-btn:focus-visible, .sb-meter:focus-visible, .tab:focus-visible, .dropdown-item:focus-visible,
.search-item:focus-visible, .picker-item:focus-visible, .settings-nav a:focus-visible, .avatar-btn:focus-visible, .chip:focus-visible, .stat:focus-visible { outline: none; box-shadow: var(--ring); }
[hidden] { display: none !important; }
::selection { background: rgba(36,50,71,.18); }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%); color: var(--sidebar-ink); display: flex; flex-direction: column; z-index: 40; }
.sb-head { padding: 14px 12px 8px; }
.sb-church { width: 100%; }
.sb-church-btn { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; border: 1px solid var(--sidebar-line); border-radius: 12px; background: var(--sidebar-card); color: #fff; cursor: pointer; text-align: left; font: inherit; transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease); }
.sb-church-btn:hover { background: var(--sidebar-active); border-color: rgba(255,255,255,.1); text-decoration: none; }
.sb-church-btn > .icon { color: var(--sidebar-muted); }
.sb-logo { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; background: #fff; flex-shrink: 0; }
.sb-logo-fallback { display: inline-grid; place-items: center; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: .01em; }
.sb-church-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.sb-church-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.005em; }
.sb-church-sub { font-size: 12px; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-church .dropdown-menu { left: 0; right: 0; min-width: 0; }
.sb-nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; scrollbar-width: thin; scrollbar-color: #243152 transparent; }
.sb-section { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted); padding: 18px 10px 6px; font-weight: 600; }
.sb-link { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px; color: var(--sidebar-ink); font-size: 13.5px; font-weight: 500; margin: 1px 0; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.sb-link:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.sb-link.active { background: var(--sidebar-active); color: #fff; }
.sb-link .icon { color: var(--sidebar-muted); stroke-width: 1.75; transition: color var(--t-fast) var(--ease); }
.sb-link.active .icon, .sb-link:hover .icon { color: #fff; }
.sb-badge { margin-left: auto; background: var(--brand); color: #1a1200; font-size: 11px; font-weight: 700; line-height: 18px; padding: 0 6px; border-radius: 999px; }
.sb-foot { padding: 10px 12px 14px; border-top: 1px solid var(--sidebar-line); }
.sb-meter { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; background: var(--sidebar-card); border: 1px solid var(--sidebar-line); color: var(--sidebar-ink); font-size: 12.5px; transition: background var(--t-fast) var(--ease); }
.sb-meter:hover { text-decoration: none; background: var(--sidebar-active); }
.sb-meter-label { display: inline-flex; align-items: center; gap: 6px; color: var(--sidebar-muted); }
.sb-meter-value { font-weight: 600; color: #fff; }
.sb-scrim { position: fixed; inset: 0; background: rgba(11,18,36,.45); z-index: 35; backdrop-filter: blur(2px); }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 28px; background: rgba(255,255,255,.72); -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2); border-bottom: 1px solid var(--border); }
.topbar-menu { display: none; }
.topbar-title { font-size: 13.5px; font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; }
.topbar-title .icon { color: var(--primary); }
.topbar-search { position: relative; flex: 1; min-width: 0; max-width: 520px; display: flex; align-items: center; gap: 8px; background: rgba(11,18,36,.045); border: 1px solid transparent; border-radius: var(--r); padding: 0 8px 0 12px; height: 38px; color: var(--muted); transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.topbar-search:hover { background: rgba(11,18,36,.065); }
.topbar-search:focus-within { background: #fff; border-color: var(--primary); box-shadow: var(--ring); }
.topbar-search > .icon { color: var(--faint); }
.topbar-search input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--ink); outline: none; min-width: 0; }
.topbar-search input::placeholder { color: var(--faint); }
.topbar-search kbd { background: #fff; }
.search-results { position: absolute; top: 46px; left: 0; right: 0; background: #fff; border-radius: var(--r); box-shadow: var(--shadow-lg); max-height: 420px; overflow: auto; padding: 6px; animation: menu-in var(--t-panel) var(--ease); }
.search-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.search-item:hover, .search-item.active { background: var(--surface-3); text-decoration: none; }
.search-item small { color: var(--muted); display: block; font-size: 12px; }
.search-item .tag { margin-left: auto; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.branch-filter { display: flex; align-items: center; gap: 6px; border: 1px solid var(--input-border); border-radius: var(--r); padding: 0 8px 0 10px; height: 36px; color: var(--muted); background: #fff; box-shadow: var(--shadow-sm); transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.branch-filter:hover { border-color: var(--input-border-hover); }
.branch-filter:focus-within { border-color: var(--primary); box-shadow: var(--ring); }
.branch-filter select { border: 0; background: transparent; font: inherit; font-weight: 500; color: var(--ink); max-width: 180px; outline: none; }
.avatar-btn { border: 0; background: transparent; padding: 2px; border-radius: 999px; cursor: pointer; transition: box-shadow var(--t-fast) var(--ease); }
.avatar-btn:hover { box-shadow: 0 0 0 3px var(--surface-3); }
.notif { position: relative; }
.notif .dot { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px; display: grid; place-items: center; padding: 0 4px; box-shadow: 0 0 0 2px #fff; }
.notif-menu { width: 360px; padding: 0; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.notif-list { max-height: 360px; overflow: auto; }
.notif-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--ink); font-size: 13.5px; transition: background var(--t-fast) var(--ease); }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item.unread { background: #fbfbff; }
.notif-item.unread > div:first-child { font-weight: 600; }
.notif-item small { color: var(--muted); }
.notif-all { display: block; text-align: center; padding: 10px; font-size: 13px; font-weight: 500; }
.banner { display: flex; align-items: center; gap: 8px; padding: 9px 28px; font-size: 13px; border-bottom: 1px solid var(--border); }
.banner-warn { background: var(--warning-soft); color: #7c3d0a; }
.banner-info { background: var(--info-soft); color: #1e3a8a; }
.content { padding: 28px 32px 48px; max-width: 1400px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head-text { min-width: 0; }
.page-title { font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); margin: 4px 0 0; max-width: 72ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.crumbs { display: flex; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }
.crumbs span { color: var(--faint); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--border-strong); background: #fff; color: var(--ink); font: 500 14px/1 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important; box-shadow: var(--shadow-sm); transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.btn:hover { background: var(--surface-2); border-color: rgba(11,18,36,.22); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ''; position: absolute; width: 16px; height: 16px; top: 50%; left: 50%; margin: -8px 0 0 -8px; border: 2px solid currentColor; border-color: rgba(127,127,127,.45); border-top-color: var(--primary, #243247); border-radius: 50%; animation: btn-spin .7s linear infinite; }
.btn-primary.is-loading::after, .btn-danger.is-loading::after { border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn .icon { color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow-btn); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary .icon, .btn-danger .icon, .btn-success .icon { color: rgba(255,255,255,.85); }
.btn-secondary { background: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: var(--shadow-btn); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; box-shadow: var(--shadow-btn); }
.btn-success:hover { background: #166534; border-color: #166534; }
.btn-link { background: transparent; border-color: transparent; color: var(--primary); padding: 0 4px; box-shadow: none; }
.btn-link:hover { background: transparent; border-color: transparent; color: var(--primary-hover); }
.btn-link .icon { color: inherit; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: 12px; }
.btn-icon { width: 36px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn-lg.btn-icon { width: 44px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.inline-form { display: inline; margin: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Cards, grids ──────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head-text { min-width: 0; }
.card-title { font-weight: 600; font-size: 15px; line-height: 1.3; letter-spacing: -.01em; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.card-body { padding: 20px; }
.card-body + .card-body { border-top: 1px solid var(--border); }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card > .table-wrap:first-child .table thead th:first-child { border-top-left-radius: var(--r-lg); }
.card > .table-wrap:first-child .table thead th:last-child { border-top-right-radius: var(--r-lg); }
.card > .table-wrap:last-child { border-radius: 0 0 var(--r-lg) var(--r-lg); }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-side { grid-template-columns: 300px minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }

/* ── Stats ─────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px 20px 16px; box-shadow: var(--shadow); color: var(--ink); display: block; overflow: hidden; min-width: 0; transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
a.stat:hover { border-color: var(--border-strong); text-decoration: none; box-shadow: 0 1px 2px rgba(11,18,36,.04), 0 10px 28px -12px rgba(11,18,36,.18); }
.stat-top { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 30px; }
.stat-label { font-size: 11.5px; font-weight: 600; line-height: 1.25; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stat-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); flex-shrink: 0; }
.stat-icon .icon { stroke-width: 1.75; }
.stat-icon-success { background: var(--success-soft); color: var(--success); }
.stat-value { font-size: 28px; line-height: 1.1; font-weight: 700; letter-spacing: -.03em; margin-top: 14px; font-variant-numeric: tabular-nums; }
.stat-foot { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); min-height: 20px; margin-top: 8px; }
.stat-delta { display: inline-flex; align-items: center; gap: 2px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 20px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-delta.good { background: var(--success-soft); color: var(--success); }
.stat-delta.bad { background: var(--danger-soft); color: var(--danger); }
.stat-delta.flat { background: var(--surface-3); color: var(--muted); }
.stat .sparkline { position: absolute; right: 18px; bottom: 18px; width: 88px; height: 28px; opacity: .9; }
.stat:has(> .sparkline) .stat-foot { padding-right: 100px; }
.stat-hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sparkline { overflow: visible; }
.sparkline .spark-line { fill: none; stroke: var(--faint); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.sparkline .spark-area { fill: var(--faint); opacity: .12; stroke: none; }
.sparkline circle { fill: var(--primary); stroke: var(--surface); stroke-width: 1.5; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th { position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; height: 44px; padding: 0 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.table tbody th { position: static; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); background: transparent; height: 48px; }
.table td { height: 48px; padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tbody tr:hover td, .table tbody tr:hover th { background: var(--row-hover); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .check-col { width: 36px; }
.table-sm td, .table-sm th { height: 38px; padding: 6px 12px; }
.table tr[data-href] { cursor: pointer; }
.table a.row-title { font-weight: 600; color: var(--ink); }
.table a.row-title:hover { color: var(--primary); text-decoration: none; }
.table tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: 0; background: var(--surface-2); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); }
.pager-links { display: flex; gap: 6px; }
.bulk-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 16px; background: var(--primary-soft); color: var(--primary-ink); border-bottom: 1px solid var(--border); font-size: 13px; }
.bulk-bar .bulk-fields { flex: 1 1 200px; display: flex; align-items: center; min-height: 30px; min-width: 0; }
.bulk-bar .bulk-field { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; }
.bulk-bar .bulk-field[hidden] { display: none; }
.bulk-bar .bulk-field .input { flex: 1 1 90px; min-width: 0; max-width: 240px; }

/* ── Filters ───────────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filters .input { height: 36px; width: auto; min-width: 140px; }
.filters .search { flex: 1; min-width: 200px; }
.filters .field { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: #fff; color: var(--ink-2); font-size: 12.5px; font-weight: 500; border: 1px solid var(--border-strong); transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease); }
.chip.active { background: var(--primary-soft); color: var(--primary-ink); border-color: rgba(36,50,71,.25); }
a.chip:hover { text-decoration: none; border-color: rgba(11,18,36,.24); background: var(--surface-2); }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2, .form-grid-3 .span-3 { grid-column: 1 / -1; }
.field { margin-bottom: 16px; min-width: 0; }
.field > label, .field .label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.field > label.check, .field > label.switch { display: inline-flex; font-weight: 400; font-size: 14px; color: var(--ink); margin-bottom: 0; }
.req { color: var(--danger); }
.input { display: block; width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--input-border); border-radius: var(--r-sm); background: #fff; color: var(--ink); font: 14px/1.4 var(--font); box-shadow: var(--shadow-sm); transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease); }
.input::placeholder { color: var(--faint); }
.input:hover:not(:focus):not(:disabled):not([readonly]) { border-color: var(--input-border-hover); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 88px; line-height: 1.5; }
select.input { padding-right: 32px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b6480' 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 10px center; }
select.input[multiple] { height: auto; min-height: 100px; background-image: none; padding: 6px; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input[readonly] { background: var(--surface-2); box-shadow: none; }
.input:disabled { background: var(--surface-3); color: var(--muted); box-shadow: none; }
input[type="file"].input { height: auto; padding: 8px; font-size: 13px; }
input[type="color"].input { width: 64px; padding: 3px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.45; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 6px; font-weight: 500; }
.has-error .input { border-color: var(--danger); }
.has-error .input:hover:not(:focus):not(:disabled):not([readonly]) { border-color: var(--danger); }
.has-error .input:focus { box-shadow: 0 0 0 3px rgba(220,38,38,.2); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0; flex: 1; min-width: 0; }
.input-group > :first-child { border-top-left-radius: var(--r-sm); border-bottom-left-radius: var(--r-sm); }
.input-group > :last-child { border-top-right-radius: var(--r-sm); border-bottom-right-radius: var(--r-sm); }
.input-group > * + * { margin-left: -1px; }
.input-group .input:focus { position: relative; z-index: 1; }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; background: var(--surface-3); border: 1px solid var(--input-border); color: var(--muted); font-size: 14px; white-space: nowrap; }
.input-group .btn { border-radius: 0; height: 40px; box-shadow: none; }
.field-check { margin-bottom: 12px; }
.check, .switch { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 14px; color: var(--ink); font-weight: 400; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 36px; height: 20px; border-radius: 999px; background: var(--input-border); position: relative; flex-shrink: 0; transition: background var(--t-fast) var(--ease); margin-top: 1px; box-shadow: inset 0 1px 2px rgba(11,18,36,.08); }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(11,18,36,.2); transition: transform var(--t-fast) var(--ease); }
.switch input:checked + .switch-ui { background: var(--primary); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { box-shadow: var(--ring); }
.radio-group { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.form-actions { display: flex; gap: 8px; align-items: center; padding-top: 8px; flex-wrap: wrap; }
.form-section { padding-bottom: 8px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; margin-bottom: 0; }
.form-section-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; letter-spacing: -.01em; }
.form-section-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.copy-field label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.person-picker { position: relative; }
.picker-results { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin-top: 4px; background: #fff; border-radius: var(--r); box-shadow: var(--shadow-lg); max-height: 280px; overflow: auto; padding: 4px; animation: menu-in var(--t-panel) var(--ease); }
.picker-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; font: inherit; color: var(--ink); }
.picker-item:hover, .picker-item.active { background: var(--surface-3); }
.picker-item small { color: var(--muted); }

/* ── Badges, alerts, misc ──────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap; letter-spacing: .005em; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; flex-shrink: 0; }
.badge-gray { background: var(--surface-3); color: var(--ink-2); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-purple { background: #eee9fd; color: #5b21b6; }
.badge-teal { background: #daf5f0; color: #115e59; }
.badge-pink { background: #fbe7f1; color: #9d174d; }
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--r); margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; line-height: 1.45; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert > .icon { margin-top: 1px; }
.alert-success { background: var(--success-soft); color: #14532d; border-color: rgba(21,128,61,.18); }
.alert-success > .icon { color: var(--success); }
.alert-error { background: var(--danger-soft); color: #7f1d1d; border-color: rgba(220,38,38,.18); }
.alert-error > .icon { color: var(--danger); }
.alert-info { background: var(--info-soft); color: #1e3a8a; border-color: rgba(29,78,216,.18); }
.alert-info > .icon { color: var(--info); }
.alert-warning { background: var(--warning-soft); color: #78350f; border-color: rgba(180,83,9,.2); }
.alert-warning > .icon { color: var(--warning); }
.alert > span { flex: 1; }
.alert-close { background: none; border: 0; color: inherit; opacity: .55; cursor: pointer; padding: 0; margin-left: auto; display: inline-grid; place-items: center; transition: opacity var(--t-fast) var(--ease); }
.alert-close:hover { opacity: 1; }
.empty { text-align: center; padding: 48px 20px; }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); }
.empty-icon .icon { stroke-width: 1.5; }
.empty-title { font-weight: 600; font-size: 16px; margin-bottom: 4px; letter-spacing: -.01em; }
.empty-text { color: var(--muted); max-width: 46ch; margin: 0 auto 18px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--ink-2); object-fit: cover; flex-shrink: 0; background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(11,18,36,.06); letter-spacing: .01em; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 72px; height: 72px; font-size: 24px; }
.avatar-xl { width: 96px; height: 96px; font-size: 30px; }
.av-0 { background: #dde5f0; color: #243247; } .av-1 { background: #d6f3f9; color: #155e75; } .av-2 { background: #d5f3e6; color: #065f46; } .av-3 { background: #fdeccb; color: #92400e; }
.av-4 { background: #fde3e3; color: #991b1b; } .av-5 { background: #ebe5fd; color: #5b21b6; } .av-6 { background: #fbe3ee; color: #9d174d; } .av-7 { background: #dbe8fd; color: #1e40af; }
.av-8 { background: #d3f2ec; color: #115e59; } .av-9 { background: #f1e6fd; color: #6b21a8; } .av-10 { background: #fde8d5; color: #9a3412; } .av-11 { background: #e4e8f1; color: #334155; }
.person-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); min-width: 0; }
a.person-chip:hover { text-decoration: none; }
a.person-chip:hover .chip-name { color: var(--primary); }
.chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.chip-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--t-fast) var(--ease); }
.chip-sub { color: var(--muted); font-size: 12px; }
.progress { height: 6px; border-radius: 999px; background: var(--primary-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width .4s var(--ease); }
.progress-green { background: var(--success-soft); } .progress-green > span { background: var(--success); }
.progress-amber { background: var(--warning-soft); } .progress-amber > span { background: var(--brand); }
.progress-red { background: var(--danger-soft); } .progress-red > span { background: var(--danger); }
.progress-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--ink); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; background: var(--surface-3); }
.timeline li { position: relative; padding: 0 0 18px 36px; }
.timeline .tl-dot { position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 1px solid var(--border-strong); display: grid; place-items: center; color: var(--muted); box-shadow: var(--shadow-sm); }
.timeline .tl-time { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; } .strong { font-weight: 600; }
.nowrap { white-space: nowrap; } .text-right { text-align: right; } .text-center { text-align: center; }
.pad { padding: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.tip { color: var(--faint); cursor: help; position: relative; display: inline-flex; }
.tip:hover::after, .tip:focus::after { content: attr(data-tip); position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; width: max-content; max-width: 260px; z-index: 50; font-weight: 400; line-height: 1.4; box-shadow: var(--shadow-lg); }
.code-block { background: var(--ink); color: #dfe4f2; border-radius: var(--r); padding: 14px 16px; font: 12.5px/1.6 var(--mono); overflow-x: auto; white-space: pre; }
.callout { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border); }
.callout .icon { color: var(--primary); margin-top: 2px; }
.qr-box { display: inline-block; padding: 8px; background: #fff; border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.skeleton { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3) 25%, #fbfbfd 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; color: transparent; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; padding: 10px 12px; color: var(--muted); font-weight: 500; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; border-radius: 8px 8px 0 0; transition: color var(--t-fast) var(--ease); }
.tab::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--border-strong); transform: scaleX(0); transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease); }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab:hover::after { transform: scaleX(1); }
.tab.active { color: var(--ink); font-weight: 600; }
.tab.active::after { transform: scaleX(1); background: var(--primary); }
.tab .count { background: var(--surface-3); color: var(--muted); font-size: 11.5px; line-height: 18px; padding: 0 7px; border-radius: 999px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tab.active .count { background: var(--primary-soft); color: var(--primary-ink); }

/* ── Dropdowns & dialogs ───────────────────────────────────────────────── */
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.985); } }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; background: #fff; border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; color: var(--ink); transform-origin: top; }
.dropdown-menu.right { left: auto; right: 0; transform-origin: top right; }
.dropdown.open > .dropdown-menu { display: block; animation: menu-in var(--t-panel) var(--ease); }
.dropdown-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 7px; color: var(--ink); background: none; border: 0; font: inherit; font-size: 13.5px; cursor: pointer; text-align: left; transition: background var(--t-fast) var(--ease); }
.dropdown-item:hover, .dropdown-item.active { background: var(--surface-3); text-decoration: none; }
.dropdown-item .icon { color: var(--muted); }
.dropdown-item.danger { color: var(--danger); } .dropdown-item.danger .icon { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }
.dropdown-menu form { margin: 0; }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-label { padding: 6px 10px; font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.4; }
dialog.modal { border: 0; border-radius: var(--r-xl); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: var(--shadow-lg); color: var(--ink); background: #fff; }
dialog.modal[open] { animation: menu-in var(--t-panel) var(--ease); }
dialog.modal.wide { width: min(820px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(11,18,36,.45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.modal-body { padding: 24px; overflow-y: auto; max-height: calc(100vh - 200px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.toast-host { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--r); box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 500; max-width: 360px; animation: toast-in var(--t-panel) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Settings layout ───────────────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 28px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 0 10px; border-radius: 8px; color: var(--ink-2); font-size: 13.5px; font-weight: 500; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.settings-nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.settings-nav a.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.settings-nav .icon { color: var(--faint); stroke-width: 1.75; }
.settings-nav a:hover .icon { color: var(--muted); }
.settings-nav a.active .icon { color: var(--primary); }

/* ── Platform admin (same kit, related header colour) ──────────────────── */
body.admin .sidebar { background: linear-gradient(180deg, #1a2538 0%, #101826 100%); }
body.admin .sb-church-btn { text-decoration: none; }
body.admin .topbar { background: rgba(250,250,255,.78); }

/* ── Auth pages ────────────────────────────────────────────────────────── */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 16px; background: radial-gradient(900px 420px at 50% -8%, rgba(36,50,71,.09) 0%, transparent 65%), radial-gradient(600px 320px at 100% 100%, rgba(245,158,11,.07) 0%, transparent 60%), var(--bg); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--ink); margin-bottom: 24px; letter-spacing: -.02em; }
.auth-brand:hover { text-decoration: none; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: 0 1px 2px rgba(11,18,36,.04), 0 24px 60px -24px rgba(11,18,36,.2); padding: 32px; }
.auth-card.wide { max-width: 640px; }
.auth-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 6px; }
.auth-card .lead { color: var(--muted); margin-bottom: 24px; line-height: 1.5; }
.auth-card .alert { margin-bottom: 20px; }
.auth-foot { margin-top: 20px; color: var(--muted); font-size: 13.5px; text-align: center; }
.auth-foot a { font-weight: 500; }
.auth-legal { margin-top: 28px; color: var(--faint); font-size: 12px; text-align: center; }
.auth-legal a { color: var(--faint); }
.auth-body > .alert { max-width: 420px; width: 100%; }
.auth-logo img, img.auth-logo { display: block; height: 76px; width: auto; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 1px 2px rgba(11,18,36,.12), 0 6px 16px -8px rgba(249,115,22,.5); }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-side { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 24px; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--t-panel) var(--ease); box-shadow: 0 0 0 1px rgba(255,255,255,.04), 24px 0 60px -20px rgba(11,18,36,.5); }
  body.sidebar-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .topbar-menu { display: inline-flex; }
  .topbar { padding: 0 12px; gap: 8px; }
  .banner { padding-left: 16px; padding-right: 16px; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; scrollbar-width: none; }
  .settings-nav a { white-space: nowrap; }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .branch-filter select { max-width: 110px; }
}
@media (max-width: 640px) {
  .content { padding: 16px 16px 40px; }
  .grid-2, .grid-4, .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .page-title { font-size: 22px; }
  .page-head { align-items: stretch; margin-bottom: 20px; }
  .hide-sm { display: none !important; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 22px; margin-top: 10px; }
  .stat .sparkline { display: none; }
  .stat:has(> .sparkline) .stat-foot { padding-right: 0; }
  .topbar-search { height: 40px; padding-left: 10px; }
  .topbar-search kbd { display: none; }
  .stat-label { font-size: 11px; letter-spacing: .04em; overflow-wrap: anywhere; }
  .branch-filter { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 10px; }
  .auth-body { padding: 24px 16px; }
  .auth-card { padding: 24px 20px; }
  .notif-menu { width: calc(100vw - 24px); }
  .table { font-size: 13.5px; }
  .table td { padding-left: 14px; padding-right: 14px; }
  .table th { padding-left: 14px; padding-right: 14px; }
  .card-head, .card-body { padding: 16px; }
  .card-foot, .pager { padding-left: 16px; padding-right: 16px; }
  .modal-head, .modal-body, .modal-foot { padding-left: 18px; padding-right: 18px; }
  /* Touch targets ≥ 44px */
  .btn:not(.btn-sm) { height: 44px; }
  .btn-icon:not(.btn-sm) { width: 44px; }
  .btn-sm { height: 36px; }
  .btn-sm.btn-icon { width: 36px; }
  .input, .filters .input, .input-group .btn { height: 44px; }
  textarea.input, select.input[multiple], input[type="file"].input { height: auto; }
  .sb-link { height: 44px; }
  .tab { min-height: 44px; }
  .dropdown-item, .settings-nav a, .search-item { min-height: 44px; }
  .check input { width: 18px; height: 18px; }
}
@media print {
  .sidebar, .topbar, .page-actions, .no-print, .banner, .toast-host, .settings-nav, .filters, .pager { display: none !important; }
  .main { margin: 0; } .content { padding: 0; max-width: none; } body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
  .settings-grid { display: block; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ── Charts (.viz) ───────────────────────────────────────────────────────────
   Server-rendered SVG/HTML from app/core/charts.php; one shared hover layer in app.js. Identity = the validated categorical
   slots (--series-1…8, fixed order, never cycled); magnitude = one blue ramp (--viz-seq-*); status tones (good / warning /
   critical) only where a fill means a state. Every mark reads its colour from --sc so text never wears a series colour. */
.viz { position: relative; color: var(--viz-ink); min-width: 0; }
.viz:focus { outline: none; }
.viz:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
.viz-plot { position: relative; }
.viz[data-viz-kind] > .viz-plot { container-type: inline-size; }
.viz-svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz-grid.viz-base { stroke: var(--viz-axis); }
.viz-tick { fill: var(--viz-muted); font-size: 11.5px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.viz-rowlabel { fill: var(--ink-2); font-size: 12px; }
.viz-endlabel { fill: var(--ink-2); font-size: 12px; font-weight: 600; font-family: var(--font); font-variant-numeric: tabular-nums; }
.viz-empty { display: grid; place-items: center; min-height: 140px; padding: 16px; text-align: center; color: var(--muted); font-size: 13px; background: repeating-linear-gradient(45deg, transparent 0 8px, var(--surface-2) 8px 9px); border-radius: var(--r); }
/* Colour slots: series identity, then status tones (declared after so a tone wins on the same element) */
.viz .s1 { --sc: var(--series-1); } .viz .s2 { --sc: var(--series-2); } .viz .s3 { --sc: var(--series-3); } .viz .s4 { --sc: var(--series-4); }
.viz .s5 { --sc: var(--series-5); } .viz .s6 { --sc: var(--series-6); } .viz .s7 { --sc: var(--series-7); } .viz .s8 { --sc: var(--series-8); }
.viz .tone-good { --sc: var(--success); } .viz .tone-warning { --sc: var(--brand); } .viz .tone-critical { --sc: var(--danger); }
.viz .ord-1, .viz .hm-1 { --sc: var(--viz-seq-1); } .viz .ord-2, .viz .hm-2 { --sc: var(--viz-seq-2); } .viz .ord-3, .viz .hm-3 { --sc: var(--viz-seq-3); }
.viz .ord-4, .viz .hm-4 { --sc: var(--viz-seq-4); } .viz .ord-5, .viz .hm-5 { --sc: var(--viz-seq-5); } .viz .hm-0 { --sc: var(--surface-3); }
/* Marks (thin: bars ≤ 24px, 2px lines, 2px surface gaps and rings) */
.viz-hit { outline: none; }
.viz-hit:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.viz-hitbox { fill: transparent; }
.viz-bar { fill: var(--sc, var(--series-1)); transition: opacity var(--t-fast) var(--ease); }
.viz-bar.viz-muted { opacity: .45; }
.viz-hit:hover .viz-bar, .viz-hit:focus .viz-bar { opacity: .8; }
.viz-line { fill: none; stroke: var(--sc, var(--series-1)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-ghost { fill: none; stroke: var(--sc, var(--series-1)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 5 4; opacity: .45; }
.viz-area { fill: var(--sc, var(--series-1)); opacity: .1; }
.viz-dot { fill: var(--sc, var(--series-1)); stroke: var(--viz-surface); stroke-width: 2; }
.viz-seg { fill: var(--sc, var(--series-1)); stroke: var(--viz-surface); stroke-width: 2; transition: opacity var(--t-fast) var(--ease); }
.viz-ring { fill: none; stroke: var(--sc, var(--series-1)); }
.viz-hit:hover .viz-seg, .viz-hit:focus .viz-seg { opacity: .8; }
.viz-cross { stroke: var(--viz-axis); stroke-width: 1; pointer-events: none; }
.viz-band { fill: transparent; outline: none; }
.viz-ref { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 4 3; }
.viz-reflabel { fill: var(--ink-2); font-weight: 600; }
.viz-center { font: 700 19px var(--font); fill: var(--ink); letter-spacing: -.02em; }
.viz-center-sub { font: 11.5px var(--font); fill: var(--viz-muted); }
/* Legend: quiet, mirrors the mark (rect for fills, line for lines, dashes for a previous period, a dashed rule for a reference) */
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; font-size: 12.5px; color: var(--ink-2); }
.viz-key { display: inline-flex; align-items: center; gap: 7px; min-height: 18px; }
.viz-swatch { display: inline-block; flex-shrink: 0; background: var(--sc, var(--series-1)); }
.viz-swatch.viz-rect { width: 10px; height: 10px; border-radius: 3px; }
.viz-swatch.viz-line { width: 16px; height: 2px; border-radius: 2px; }
.viz-swatch.viz-dash { width: 18px; height: 2px; background: repeating-linear-gradient(90deg, var(--sc, var(--series-1)) 0 4px, transparent 4px 7px); opacity: .7; }
.viz-swatch.viz-ref { width: 18px; height: 2px; background: repeating-linear-gradient(90deg, var(--ink-2) 0 4px, transparent 4px 7px); }
/* Tooltip: hairline, soft shadow, 12.5px; values lead, names follow; keys are short strokes */
.viz-tip { position: absolute; z-index: 20; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.4; color: var(--ink); min-width: 120px; max-width: 280px; white-space: nowrap; }
.viz-tip .tip-title { color: var(--muted); font-size: 12px; margin-bottom: 4px; white-space: normal; }
.viz-tip .tip-row { display: flex; align-items: center; gap: 8px; }
.viz-tip .tip-row + .tip-row { margin-top: 2px; }
.viz-tip .tip-row strong { font-weight: 600; font-variant-numeric: tabular-nums; white-space: normal; }
.viz-tip .tip-row .muted { color: var(--muted); white-space: normal; }
.viz-tip .tip-key { width: 12px; height: 2px; border-radius: 2px; background: var(--sc, var(--ink-2)); flex-shrink: 0; }
.viz-tip .tip-key.ghost { background: repeating-linear-gradient(90deg, var(--sc, var(--ink-2)) 0 3px, transparent 3px 5px); opacity: .75; }
.viz-tip .tip-total { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 5px; }
/* Table view: the accessible twin of every chart */
.viz-table { margin-top: 10px; font-size: 12.5px; }
.viz-table > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); padding: 2px 4px 2px 0; border-radius: 4px; user-select: none; }
.viz-table > summary::-webkit-details-marker { display: none; }
.viz-table > summary::before { content: ''; width: 6px; height: 6px; margin-left: 2px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg) translateY(-1px); transition: transform var(--t-fast) var(--ease); }
.viz-table[open] > summary::before { transform: rotate(45deg) translateY(-2px); }
.viz-table > summary:hover { color: var(--ink); }
.viz-table > summary:focus-visible { outline: none; box-shadow: var(--ring); }
.viz-table .table-wrap { margin-top: 8px; max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.viz-table .table { font-size: 12.5px; }
.viz-table .table th { font-size: 11px; height: 34px; padding: 0 12px; }
.viz-table .table td, .viz-table .table tbody th { height: 34px; padding: 6px 12px; font-size: 12.5px; }
/* Ranked bars (HTML) */
.viz-hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; outline: none; border-radius: 4px; }
.hbar:focus-visible { box-shadow: var(--ring); }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.hbar-label a { color: var(--ink-2); }
.hbar-track { height: 10px; border-radius: 0 4px 4px 0; }
.hbar-fill { display: block; height: 100%; background: var(--sc, var(--series-1)); border-radius: 0 4px 4px 0; transition: opacity var(--t-fast) var(--ease); }
.hbar:hover .hbar-fill, .hbar:focus .hbar-fill { opacity: .8; }
.hbar-value { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); min-width: 56px; text-align: right; white-space: nowrap; }
/* Compare: ranked bars against a reference line */
.viz-compare a .viz-rowlabel { fill: var(--ink-2); }
.viz-compare a:hover .viz-rowlabel { fill: var(--primary); }
/* Progress bars with target markers (track = a lighter step of the same ramp) */
.viz-progress { display: flex; flex-direction: column; gap: 12px; }
.pg-row { outline: none; border-radius: 6px; }
.pg-row:focus-visible { box-shadow: var(--ring); }
.pg-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; margin-bottom: 6px; }
.pg-label { color: var(--ink-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-label a { color: var(--ink-2); }
.pg-value { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; flex-shrink: 0; }
.pg-max { font-weight: 400; color: var(--muted); }
.pg-pct { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 8px; }
.pg-track { position: relative; height: 8px; border-radius: 999px; background: var(--viz-track); }
.pg-track.tone-good { background: var(--success-soft); } .pg-track.tone-warning { background: var(--warning-soft); } .pg-track.tone-critical { background: var(--danger-soft); }
.pg-fill { display: block; height: 100%; max-width: 100%; border-radius: 999px; background: var(--sc, var(--series-1)); transition: width .4s var(--ease); }
.pg-target { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-inline-start: -1px; border-radius: 1px; background: var(--ink-2); }
.pg-target::after { content: ''; position: absolute; left: -3px; top: -4px; border: 4px solid transparent; border-top: 4px solid var(--ink-2); border-bottom: 0; }
.pg-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
/* Funnel: ordered steps in one hue, darker as the journey deepens; conversion from the previous step beside the value */
.viz-funnel { display: block; }
.fn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fn-step { display: grid; grid-template-columns: minmax(96px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; outline: none; border-radius: 4px; }
.fn-step:focus-visible { box-shadow: var(--ring); }
.fn-label { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fn-label a { color: var(--ink-2); }
.fn-track { display: block; height: 22px; }
.fn-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--sc, var(--series-1)); transition: opacity var(--t-fast) var(--ease); }
.fn-step:hover .fn-bar, .fn-step:focus .fn-bar { opacity: .8; }
.fn-value { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; min-width: 64px; }
.fn-pct { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 2px; }
/* Heatmap: one sequential hue, 5 bins, scale legend */
.hm { fill: var(--sc); transition: opacity var(--t-fast) var(--ease); outline: none; }
.hm:hover, .hm:focus { opacity: .75; }
.hm:focus-visible { outline: none; stroke: var(--primary); stroke-width: 2; }
.viz-scale { display: flex; align-items: center; gap: 3px; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.viz-scale i { display: inline-block; width: 18px; height: 10px; border-radius: 2px; background: var(--sc); }
.viz-scale > span:first-child { margin-right: 3px; } .viz-scale > span:nth-last-child(2) { margin-left: 3px; }
.viz-scale-max { margin-left: auto; font-variant-numeric: tabular-nums; }
/* Ring (one share of a max) and segment ring; big centre value, text in ink tokens */
.viz-ring, .viz-gauge, .viz-donut { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.viz-ring > .viz-plot, .viz-gauge > .viz-plot, .viz-donut > .viz-plot { flex: 0 0 auto; }
.viz-ring > .viz-table, .viz-gauge > .viz-table, .viz-donut > .viz-table { flex: 1 1 100%; }
.ring-svg { width: 112px; height: 112px; display: block; overflow: visible; }
.ring-sm .ring-svg { width: 84px; height: 84px; } .ring-lg .ring-svg { width: 148px; height: 148px; }
.viz-donut .ring-svg { width: 150px; height: 150px; }
.ring-track { fill: none; stroke: var(--viz-track); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--sc, var(--series-1)); stroke-width: 10; stroke-linecap: butt; transition: stroke-dasharray .5s var(--ease); }
.ring-value { font: 700 22px var(--font); fill: var(--ink); letter-spacing: -.02em; }
.ring-sub { font: 11px var(--font); fill: var(--viz-muted); }
.ring-text, .gauge-text { flex: 1 1 140px; min-width: 0; }
.ring-label, .gauge-label { font-weight: 600; font-size: 14px; color: var(--ink); }
.ring-caption, .gauge-caption { font-size: 13px; color: var(--muted); }
.ring-hint, .gauge-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1 1 180px; min-width: 0; font-size: 13px; }
.donut-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 40px; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--surface-3); }
.donut-legend li:last-child { border-bottom: 0; }
.dl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.dl-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dl-pct { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
/* Gauge: a semicircle meter against a limit; the fill turns to a status tone only past a real threshold */
.gauge-svg { width: 168px; height: auto; display: block; overflow: visible; }
.gauge-track { fill: none; stroke: var(--viz-track); stroke-width: 12; }
.gauge-fill { fill: none; stroke: var(--sc, var(--series-1)); stroke-width: 12; transition: stroke-dasharray .5s var(--ease); }
.gauge-mark { stroke: var(--sc, var(--ink-2)); stroke-width: 2; }
.gauge-target { stroke: var(--ink); stroke-width: 2.5; }
.gauge-value { font: 700 22px var(--font); fill: var(--ink); letter-spacing: -.02em; }
/* Narrow containers (phones): the SVG scales down, so ticks grow to stay legible and every other x label hides */
@container (max-width: 520px) {
  .viz-svg:not(.viz-svg-rows) .viz-tick { font-size: 15px; }
  .viz-svg:not(.viz-svg-rows) .viz-endlabel { font-size: 15px; }
  .viz-x-thin { display: none; }
}
@container (max-width: 430px) {
  .viz-svg:not(.viz-svg-rows) .viz-tick { font-size: 18px; }
  .viz-svg:not(.viz-svg-rows) .viz-endlabel { font-size: 17px; }
  /* Row grids (heatmap, compare) keep their labels legible and scroll inside the card instead of shrinking to nothing */
  .viz-svg-rows { min-width: 520px; }
  .viz[data-viz-kind="rows"] > .viz-plot, .viz[data-viz-kind="cells"] > .viz-plot { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
  .viz-svg-rows .viz-tick { font-size: 13.5px; }
  .viz-svg-rows .viz-endlabel { font-size: 13.5px; }
}
@media (max-width: 640px) {
  .viz-legend { gap: 4px 12px; font-size: 12px; }
  .hbar, .fn-step { grid-template-columns: minmax(80px, 36%) 1fr auto; }
  .viz-ring, .viz-gauge, .viz-donut { gap: 14px; }
}

/* ── Phone frame (phone_frame()) ──────────────────────────────────────────────
   An iPhone-style handset: titanium band, black bezel, glass with a Dynamic Island, status bar and home indicator, plus
   the action, volume and power buttons standing just proud of the frame. Every measure is a share of the phone's width
   (cqw), so the one frame is right at any size; the screen inside keeps its own font sizes. */
.cb-phone { position: relative; width: 100%; max-width: 300px; margin: 0 auto; container-type: inline-size; color: #0b1224; }
.cb-phone-dark { color: #fff; }
.cb-phone-btn { position: absolute; width: 1.4cqw; background: linear-gradient(180deg, #5b5e64, #2a2b2f 50%, #4d5055); }
.cb-phone-btn-action, .cb-phone-btn-up, .cb-phone-btn-down { left: -.9cqw; border-radius: .9cqw 0 0 .9cqw; }
.cb-phone-btn-action { top: 42cqw; height: 10.5cqw; }
.cb-phone-btn-up { top: 60.5cqw; height: 19.3cqw; }
.cb-phone-btn-down { top: 84cqw; height: 19.3cqw; }
.cb-phone-btn-power { right: -.9cqw; top: 66cqw; height: 30cqw; border-radius: 0 .9cqw .9cqw 0; }
.cb-phone-band { position: relative; padding: 1.3cqw; border-radius: 19.3cqw; background: linear-gradient(140deg, #9a9da3 0%, #44464b 18%, #202125 46%, #2c2d31 64%, #6e7176 86%, #b4b7bc 100%); box-shadow: 0 46px 70px -28px rgba(0, 0, 0, .55), 0 18px 28px -18px rgba(0, 0, 0, .45); }
.cb-phone-bezel { padding: 2.6cqw; border-radius: 18cqw; background: #000; }
.cb-phone-glass { position: relative; display: flex; flex-direction: column; aspect-ratio: 9 / 19.5; overflow: hidden; border-radius: 15.4cqw; background: #f5f6fb; }
.cb-phone-light .cb-phone-glass { background: #fff; }
.cb-phone-dark .cb-phone-glass { background: #0b0c0f; }
.cb-phone-island { position: absolute; top: 3.9cqw; left: 50%; width: 31.6cqw; height: 9.6cqw; transform: translateX(-50%); border-radius: 999px; background: #000; z-index: 3; }
.cb-phone-status { display: flex; flex: none; align-items: center; justify-content: space-between; height: 17.4cqw; padding: 0 8cqw 0 9.5cqw; font-size: 4.4cqw; font-weight: 600; line-height: 1; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.cb-phone-status span:last-child { display: inline-flex; align-items: center; gap: 1.8cqw; }
.cb-phone-status svg { display: block; width: auto; height: 3.7cqw; }
.cb-phone-screen { position: relative; z-index: 1; display: flex; flex: 1; flex-direction: column; min-height: 0; padding: 0 4.6cqw 9cqw; font-size: 12px; }
.cb-phone-home { position: absolute; left: 50%; bottom: 2.8cqw; z-index: 3; width: 36.8cqw; height: 1.6cqw; transform: translateX(-50%); border-radius: 999px; background: currentColor; opacity: .85; }
.cb-phone-glare { position: absolute; inset: 0; z-index: 2; pointer-events: none; background: linear-gradient(115deg, rgba(255, 255, 255, .16) 0%, transparent 30%); }
/* ── Staff mobile app: bottom navigation, quick-add sheet, safe areas, phone polish ───────────────── */
.bottom-nav { display: none; }
.sheet-grip { display: none; }
.staffapp-steps { margin: 12px 0 0; padding-left: 18px; }
.staffapp-cats { border: 0; margin: 14px 0; padding: 0; display: grid; gap: 2px; }
.staffapp-cats legend { padding: 0 0 6px; }
.staffapp-pref { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.staffapp-pref input { width: 20px; height: 20px; flex: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

@media (max-width: 900px) {
  .topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 640px) {
  body.app { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .content { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast-host { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: stretch;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.94); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--border-strong); box-shadow: 0 -8px 24px -16px rgba(11,18,36,.25);
  }
  body.kbd-open .bottom-nav { display: none; }
  body.kbd-open .content { padding-bottom: 24px; }
  .bn-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; min-width: 44px; padding: 4px 2px; border: 0; border-radius: var(--r);
    background: none; color: var(--muted); font: 600 11px/1.1 var(--font); text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .bn-item svg { display: block; }
  .bn-item.active { color: var(--primary); }
  .bn-item.active svg { stroke-width: 2.2; }
  .bn-item:focus-visible { outline: none; box-shadow: var(--ring); }
  .bn-item:active { background: var(--surface-3); }
  .bn-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bn-add-btn { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin-top: -22px; border-radius: 50%; color: #fff; background: linear-gradient(140deg, var(--primary), var(--primary-hover)); box-shadow: 0 8px 18px -6px rgba(36,50,71,.7), 0 0 0 4px #fff; }
  .bn-add { color: var(--ink-2); gap: 1px; }
  .bn-add .bn-label { margin-top: 0; }

  /* Bottom sheet */
  dialog.modal.sheet { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: none; max-height: 85vh; border-radius: var(--r-xl) var(--r-xl) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  dialog.modal.sheet[open] { animation: sheet-up var(--t-panel) var(--ease); }
  .sheet-grip { display: block; width: 40px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: var(--border-strong); }
  .sheet .modal-head { padding-top: 10px; padding-bottom: 10px; }

  /* Phone-first polish */
  .input, select.input, textarea.input { font-size: 16px; } /* stops iOS zooming into fields */
  .page-actions { width: 100%; margin-left: 0; }
  .page-actions .btn, .page-actions .dropdown { flex: 1 1 auto; }
  .page-actions .btn { justify-content: center; }
  .tabs, .tab-list { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .input, .filters .search { width: 100%; min-width: 0; }
  .table tr[data-href] td { padding-top: 14px; padding-bottom: 14px; }
  .table-wrap { margin: 0; }
  .card { border-radius: var(--r-lg); }
  .stat { min-height: 88px; }
  .list > *, .list-item { min-height: 48px; }
  .btn-row .btn { flex: 1 1 140px; justify-content: center; }
  .chip { min-height: 36px; display: inline-flex; align-items: center; }
  .pager .btn { min-width: 44px; }
  .check-col input { width: 22px; height: 22px; }
}
.sheet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px 18px 20px; }
.sheet-action { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sheet-action:hover { border-color: var(--primary); background: var(--primary-soft); }
.sheet-action:focus-visible { outline: none; box-shadow: var(--ring); }
.sheet-ico { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-ink); }
.sheet-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sheet-text small { color: var(--muted); font-size: 12px; }
@keyframes sheet-up { from { transform: translateY(32px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 380px) { .sheet-grid { grid-template-columns: minmax(0, 1fr); } }
@media (display-mode: standalone) { body.app { overscroll-behavior-y: none; } }
@media print { .bottom-nav, dialog.sheet { display: none !important; } }

/* ── Touch targets (phones / coarse pointers): controls reach 40px; dense list controls get a bigger hit area ───────── */
.alert-close { opacity: .7; }
@media (max-width: 640px), (pointer: coarse) {
  .btn, .btn-sm { min-height: 40px; height: auto; }
  .btn-icon, .btn-sm.btn-icon { width: 40px; }
  .btn-link { min-height: 40px; }
  .chip { min-height: 40px; padding-top: 0; padding-bottom: 0; align-items: center; }
  .person-chip { min-height: 40px; display: inline-flex; align-items: center; }
  .avatar-btn { min-width: 40px; min-height: 40px; display: inline-grid; place-items: center; }
  .alert-close { min-width: 40px; min-height: 40px; margin: -10px -10px -10px auto; }
  .dropdown-item, .picker-item, .search-item { min-height: 40px; }
  .inline-edit { position: relative; }
  .inline-edit::after { content: ""; position: absolute; inset: -10px; }
  .table td > a.grow, .list a.grow { display: block; padding-block: 9px; }
  .tab { min-height: 44px; }
  .filters .search { flex: 0 0 auto; }
  .topbar-search input::placeholder { text-overflow: ellipsis; }
}

/* Row-select checkboxes (WCAG 2.2 SC 2.5.8 target size): a ~20px accent box drawn in place, with an invisible ::after hit area that
   grows the real input's target to 24px on desktop and 44px on touch/coarse pointers without changing row height. */
.check-col input[type="checkbox"], td > input[type="checkbox"][name="ids[]"] {
  -webkit-appearance: none; appearance: none; position: relative; box-sizing: border-box; flex-shrink: 0;
  width: 20px; height: 20px; margin: 0; padding: 0; vertical-align: middle; cursor: pointer;
  background: var(--surface) center / 14px 14px no-repeat; border: 2px solid var(--muted); border-radius: 5px;
}
.check-col input[type="checkbox"]::after, td > input[type="checkbox"][name="ids[]"]::after { content: ""; position: absolute; inset: -4px; }
.check-col input[type="checkbox"]:checked, td > input[type="checkbox"][name="ids[]"]:checked {
  background-color: var(--primary-solid, var(--primary)); border-color: var(--primary-solid, var(--primary));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M2.5 7.4l3 3 6-6.4' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.check-col input[type="checkbox"]:indeterminate {
  background-color: var(--primary-solid, var(--primary)); border-color: var(--primary-solid, var(--primary));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7h8' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
}
.check-col input[type="checkbox"]:hover:not(:disabled), td > input[type="checkbox"][name="ids[]"]:hover:not(:disabled) { border-color: var(--primary); }
.check-col input[type="checkbox"]:focus-visible, td > input[type="checkbox"][name="ids[]"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: 0 0 0 5px var(--primary-soft); }
.check-col input[type="checkbox"]:disabled { opacity: .45; cursor: not-allowed; }
@media (pointer: coarse), (hover: none) {
  .check-col input[type="checkbox"]::after, td > input[type="checkbox"][name="ids[]"]::after { inset: -14px; }
}

/* ── Sidebar v2: plain-language accordion groups (app layout only; admin keeps the flat .sb-link list) ───────────── */
body.app:not(.admin) { --sidebar-w: 288px; }
.sb-nav[data-nav-groups] .sb-group-btn { gap: 10px; font-size: 14px; }
.content { padding-top: 32px; }
.page-head { margin-bottom: 24px; }
.sb-head { padding: 16px 16px 8px; }
.sb-nav[data-nav-groups] { padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.sb-nav[data-nav-groups] .sb-link, .sb-foot .sb-direct { gap: 12px; margin: 0; border-radius: 10px; }
.sb-group { position: relative; border-radius: 12px; }
.sb-group-btn, .sb-direct { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--sidebar-ink); font: inherit; font-size: 14.5px; font-weight: 600; text-align: left; cursor: pointer; letter-spacing: -.003em; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.sb-direct { height: auto; }
.sb-group-btn > .icon:first-child, .sb-direct > .icon:first-child { color: var(--sidebar-muted); stroke-width: 1.75; flex-shrink: 0; transition: color var(--t-fast) var(--ease); }
.sb-group-btn:hover, .sb-direct:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sb-group-btn:hover > .icon:first-child { color: #fff; }
.sb-group-btn .sb-text, .sb-direct .sb-text, .sb-sublink .sb-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-group-btn > .icon:last-child { margin-left: auto; color: var(--sidebar-muted); transition: transform var(--t-panel) var(--ease); flex-shrink: 0; }
.sb-group-btn .sb-badge + .icon:last-child { margin-left: 0; }
.sb-group.open > .sb-group-btn > .icon:last-child { transform: rotate(180deg); }
.sb-group.has-active > .sb-group-btn { color: #fff; }
.sb-group.has-active > .sb-group-btn > .icon:first-child { color: var(--brand); }
.sb-group.has-active::before { content: ""; position: absolute; left: -12px; top: 10px; width: 4px; height: 24px; border-radius: 0 4px 4px 0; background: var(--brand); }
.sb-group-btn:focus-visible, .sb-user-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.sb-sub { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows var(--t-panel) var(--ease), visibility 0s linear var(--t-panel); }
.sb-group.open > .sb-sub { grid-template-rows: 1fr; visibility: visible; transition: grid-template-rows var(--t-panel) var(--ease), visibility 0s; }
.sb-group.no-anim > .sb-sub, .sb-group.no-anim .sb-group-btn > .icon:last-child { transition: none; }
.sb-sub-inner { overflow: hidden; min-height: 0; margin-left: 21px; padding: 2px 0 6px 12px; border-left: 1px solid var(--sidebar-line); display: flex; flex-direction: column; gap: 2px; }
.sb-sublink { height: 40px; padding: 0 12px; font-size: 14px; font-weight: 500; }
.sb-sublink .icon { display: none; }
.sb-sublink:hover { background: rgba(255,255,255,.06); }
/* Active page = filled pill (white on the dark sidebar, so it reads at a glance). */
.sb-nav[data-nav-groups] .sb-link.active, .sb-foot .sb-link.active { background: #fff; color: #0b1224; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.sb-nav[data-nav-groups] .sb-link.active .icon, .sb-foot .sb-link.active .icon { color: var(--primary-solid, #243247); }
.sb-nav[data-nav-groups] .sb-link.active:hover, .sb-foot .sb-link.active:hover { background: #fff; color: #0b1224; }
.sb-group-btn .sb-badge, .sb-direct .sb-badge, .sb-sublink .sb-badge { margin-left: auto; min-width: 20px; text-align: center; }
.sb-link.active .sb-badge { background: var(--primary-solid, #243247); color: #fff; }
.sb-foot { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.sb-foot .sb-settings { min-height: 44px; }
.sb-meter { margin: 0; }
.sb-user { display: block; width: 100%; padding-top: 8px; border-top: 1px solid var(--sidebar-line); }
.sb-user-btn { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 6px 8px; border: 0; border-radius: 12px; background: transparent; color: var(--sidebar-ink); font: inherit; text-align: left; cursor: pointer; transition: background var(--t-fast) var(--ease); }
.sb-user-btn:hover, .sb-user.open .sb-user-btn { background: rgba(255,255,255,.07); }
.sb-user-btn > .icon { margin-left: auto; color: var(--sidebar-muted); flex-shrink: 0; }
.sb-user-btn .avatar { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: none; }
.sb-user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.sb-user-name { font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-sub { font-size: 12px; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dropdown-menu.up { top: auto; bottom: calc(100% + 8px); left: 0; right: 0; min-width: 0; max-height: calc(100vh - 96px); overflow-y: auto; transform-origin: bottom; }
.sb-user .dropdown-label { overflow-wrap: anywhere; }
@media (min-width: 901px) { .topbar-account { display: none; } }
@media (max-width: 900px) {
  .sb-user { display: none; }
  .sidebar { width: min(86vw, 320px); }
  .sb-group-btn, .sb-direct { min-height: 48px; }
  .sb-sublink { height: 44px; }
}
.sb-sublink { flex-shrink: 0; }
@media (max-width: 640px) {
  .sidebar { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .sb-sub, .sb-group-btn > .icon:last-child { transition: none !important; }
}
/* ── /Sidebar v2 ─────────────────────────────────────────────────────────────────────────────────────────────── */
