/* ibjx-asset-rev: 2026-07-08b (grid layout fix — cache-bust marker) */
/* ============================================================================
   IbejuPay (ibjx) — Enterprise Design System
   Hand-authored, design-token based. Self-contained (no framework, no build
   step required). Light + dark mode via [data-theme]. WCAG-AA color choices.
   ============================================================================ */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Brand — ETHIOPE (navy wordmark + gold→orange building mark, river-blue) */
  --primary:        #12244d;
  --primary-dk:     #0e1a3c;
  --primary-lt:     #1d3a7a;
  --accent:         #f26522;
  --accent-2:       #fbb040;
  --river:          #5b9bd5;
  /* Semantic */
  --success:        #059669;
  --success-bg:     #f0fdf4;
  --warning:        #d97706;
  --warning-bg:     #fffbeb;
  --danger:         #dc2626;
  --danger-bg:      #fef2f2;
  --info:           #2563eb;
  --info-bg:        #eff6ff;
  /* Neutrals (slate ramp) */
  --slate-50:  #f8fafc;  --slate-100: #f1f5f9;  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;  --slate-400: #94a3b8;  --slate-500: #64748b;
  --slate-600: #475569;  --slate-700: #334155;  --slate-800: #1e293b;
  --slate-900: #0f172a;
  /* Surfaces */
  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e2e8f0;
  --border-strong: #cbd5e1;
  --text:      #1e293b;
  --text-muted:#64748b;
  --text-faint:#94a3b8;
  /* Effects */
  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow:    0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,.08), 0 2px 4px -2px rgba(15,23,42,.06);
  --shadow-lg: 0 10px 25px -5px rgba(15,23,42,.12), 0 8px 10px -6px rgba(15,23,42,.08);
  --shadow-xl: 0 20px 45px -12px rgba(15,23,42,.28);
  /* Layout */
  --sidebar-w:     256px;
  --sidebar-w-collapsed: 68px;
  --topbar-h:      60px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: .18s cubic-bezier(.4,0,.2,1);
}

/* Dark mode */
[data-theme="dark"] {
  --bg:        #0b1220;
  --surface:   #111a2e;
  --surface-2: #0e1626;
  --border:    #1e293b;
  --border-strong: #334155;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --text-faint:#64748b;
  --primary:   #1e3a5f;
  --success-bg:#052e1a;
  --warning-bg:#2a1c05;
  --danger-bg: #2a0d0d;
  --info-bg:   #0d1a33;
  --shadow:    0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.5);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.6);
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4,h5,h6 { margin: 0; font-weight: 600; color: var(--text); line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 12px; }
a { color: var(--primary-lt); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
:focus-visible { outline: 2px solid var(--primary-lt); outline-offset: 2px; }
::selection { background: rgba(37,99,235,.2); }

/* ── App shell layout ────────────────────────────────────────────────────── */
/* 100vh on iOS/iPadOS Safari resolves to the *largest* layout viewport (browser
   chrome retracted), so a short page pinned to min-height:100vh overshoots the
   visible area and leaves a tall white band at the bottom (seen on iPad Mini).
   100dvh tracks the *dynamic* viewport, eliminating the gap; 100vh stays as the
   fallback for browsers without dvh support. */
.app { min-height: 100vh; min-height: 100dvh; display: flex; }
.app__main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  margin-left: var(--sidebar-w); transition: margin-left var(--transition);
}
.app.is-collapsed .app__main { margin-left: var(--sidebar-w-collapsed); }
.app__content { flex: 1; padding: 24px; max-width: 1600px; width: 100%; margin: 0 auto; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--primary-dk); color: rgba(255,255,255,.85);
  display: flex; flex-direction: column; z-index: 40;
  transition: width var(--transition); overflow: hidden;
}
.app.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.sidebar__brand {
  display: flex; align-items: center; gap: 10px; height: var(--topbar-h);
  padding: 0 20px; border-bottom: 1px solid rgba(255,255,255,.08); flex-shrink: 0;
}
.sidebar__brand-mark {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: #fff; display: grid; place-items: center; overflow: hidden;
}
.sidebar__brand-logo { width: 30px; height: 30px; object-fit: contain; display: block; }
.sidebar__brand-text { font-weight: 700; font-size: 16px; color: #fff; white-space: nowrap; letter-spacing: .01em; }
.app.is-collapsed .sidebar__brand-text { display: none; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar__nav::-webkit-scrollbar { width: 6px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.nav-section { margin-bottom: 4px; }
.nav-section__label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: rgba(255,255,255,.35); padding: 12px 12px 6px;
}
.app.is-collapsed .nav-section__label { text-align: center; padding: 12px 0 6px; font-size: 0; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; margin: 1px 0;
  border-radius: 8px; color: rgba(255,255,255,.78); font-size: 13.5px; font-weight: 500;
  white-space: nowrap; transition: background var(--transition), color var(--transition);
  cursor: pointer; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.is-active {
  background: rgba(37,99,235,.22); color: #fff; border-left-color: var(--accent);
}
.nav-item svg { flex-shrink: 0; opacity: .85; }
.app.is-collapsed .nav-item { justify-content: center; padding: 10px; }
.app.is-collapsed .nav-item__text { display: none; }
.nav-item__badge {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 10px;
  font-weight: 700; padding: 1px 6px; border-radius: 10px;
}
.app.is-collapsed .nav-item__badge { display: none; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar__toggle, .topbar__icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 8px;
  border: none; background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.topbar__toggle:hover, .topbar__icon-btn:hover { background: var(--surface-2); color: var(--text); }
.topbar__search { flex: 1; max-width: 420px; position: relative; }
.topbar__search input {
  width: 100%; height: 38px; padding: 0 14px 0 38px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 13.5px; color: var(--text);
}
.topbar__search input:focus { outline: none; border-color: var(--primary-lt); background: var(--surface); }
.topbar__search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.topbar__spacer { flex: 1; }
.topbar__right { display: flex; align-items: center; gap: 6px; }
.topbar__user {
  display: flex; align-items: center; gap: 9px; padding: 5px 10px 5px 6px; border-radius: 10px;
  cursor: pointer; transition: background var(--transition); border: 1px solid transparent;
  /* Reset native <button> chrome (this is now a button for keyboard access). */
  background: transparent; font-family: inherit; text-align: left;
}
.topbar__user:hover { background: var(--surface-2); border-color: var(--border); }
.topbar__user-caret { display: inline-flex; color: var(--text-muted); transition: transform var(--transition); }
.dropdown__menu.is-open ~ .topbar__user-caret,
[aria-expanded="true"] .topbar__user-caret { transform: rotate(180deg); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-lt)); color: #fff; font-weight: 600; font-size: 13px;
}
.topbar__user-meta { line-height: 1.2; }
.topbar__user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.topbar__user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown__menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
  /* Hidden by default; shown only when JS adds .is-open (was persistently open
     because no hide rule existed). Animate in from a slight offset. */
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}
.dropdown__menu.is-open {
  opacity: 1; visibility: visible; transform: translateY(0);
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .dropdown__menu { transition: none; transform: none; }
}
.dropdown__item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px;
  color: var(--text); font-size: 13.5px; cursor: pointer; transition: background var(--transition);
}
.dropdown__item:hover { background: var(--surface-2); color: var(--primary-lt); }
.dropdown__item svg { color: var(--text-muted); }
.dropdown__divider { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown__header { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown__header b { display: block; font-size: 13px; color: var(--text); }
.dropdown__header small { color: var(--text-muted); font-size: 11.5px; }

/* ── Page header / breadcrumb ────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; margin-top: 4px; }
.page-header__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary-lt); }
.breadcrumb span[aria-current] { color: var(--text); font-weight: 500; }
.crumb-sep { display: inline-flex; color: var(--border-strong); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card__title { font-size: 14px; font-weight: 600; }
.card__body { padding: 18px; }
.card__footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ── Stat tiles ──────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-tile {
  display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat-tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary-lt); }
.stat-tile--primary::before { background: var(--primary-lt); }
.stat-tile--success::before { background: var(--success); }
.stat-tile--warning::before { background: var(--warning); }
.stat-tile--danger::before  { background: var(--danger); }
.stat-tile--info::before    { background: var(--accent); }
.stat-tile__icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0;
  background: rgba(37,99,235,.1); color: var(--primary-lt);
}
.stat-tile--success .stat-tile__icon { background: rgba(5,150,105,.1); color: var(--success); }
.stat-tile--warning .stat-tile__icon { background: rgba(217,119,6,.1); color: var(--warning); }
.stat-tile--danger .stat-tile__icon  { background: rgba(220,38,38,.1); color: var(--danger); }
.stat-tile--info .stat-tile__icon    { background: rgba(14,165,233,.1); color: var(--accent); }
.stat-tile__label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-tile__value { font-size: 22px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.stat-tile__sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.stat-tile__trend { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; }
.stat-tile__trend--up { color: var(--success); }
.stat-tile__trend--down { color: var(--danger); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap; line-height: 1.4;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform .05s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--primary-lt); color: #fff; }
.btn--primary:hover { background: #1d4ed8; color: #fff; }
.btn--navy { background: var(--primary); color: #fff; }
.btn--navy:hover { background: var(--primary-dk); color: #fff; }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: #047857; color: #fff; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #b91c1c; color: #fff; }
.btn--warning { background: var(--warning); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn--outline { background: transparent; border-color: var(--primary-lt); color: var(--primary-lt); }
.btn--outline:hover { background: var(--primary-lt); color: #fff; }
.btn--sm { padding: 5px 11px; font-size: 12px; }
.btn--xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
.btn--lg { padding: 11px 24px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { padding: 8px; width: 36px; height: 36px; }

/* ── Pills / status ──────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em; line-height: 1.5;
}
.pill--served, .pill--success, .pill--paid, .pill--active { background: var(--success-bg); color: #047857; }
.pill--overdue, .pill--danger, .pill--failed { background: var(--danger-bg); color: #b91c1c; }
.pill--pending, .pill--warning, .pill--processing { background: var(--warning-bg); color: #b45309; }
.pill--info, .pill--new { background: var(--info-bg); color: #1e40af; }
.pill--cancelled, .pill--neutral, .pill--inactive { background: var(--slate-100); color: var(--slate-600); }
[data-theme="dark"] .pill--served, [data-theme="dark"] .pill--paid { color: #4ade80; }
[data-theme="dark"] .pill--overdue { color: #f87171; }
[data-theme="dark"] .pill--pending { color: #fbbf24; }
[data-theme="dark"] .pill--info { color: #93c5fd; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
/* The shared list grid. Goals: columns never cramp or go ragged, long values
   (emails, refs, names) truncate instead of blowing a column out, and the whole
   table only scrolls horizontally as a last resort on very narrow screens.
   `table-layout: auto` lets text columns share slack while the width hints below
   pin the narrow columns (checkbox / amount / status / actions) to a sane size. */
/* The scroll container for a wide grid. It MUST be able to scroll horizontally
   independently — the parent `.card` uses `overflow:hidden` (to clip its rounded
   corners), which would otherwise trap this scroll and cut off the right-hand
   columns. `min-width:0` on this and its ancestors lets it shrink to the card
   width and scroll its own content instead of pushing the card wider. */
.grid, .card__body > .grid { min-width: 0; max-width: 100%; }
.table-wrap { overflow-x: auto; max-width: 100%; min-width: 0; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); -webkit-overflow-scrolling: touch; }
/* Fixed layout + a comfortable min-width: columns take the widths their headers
   imply and the table scrolls horizontally when the viewport is too narrow —
   rather than crushing every column and shattering the text inside them. */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; min-width: 760px; }
/* Grids with many columns (checkbox + 6 data columns or more) need more room
   before they start truncating hard — give them a wider floor so text columns
   stay legible and the table scrolls instead of crushing. */
.data-table.data-table--wide { min-width: 1040px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap;
  vertical-align: middle;
}
.data-table thead th.is-sortable { cursor: pointer; user-select: none; }
.data-table thead th.is-sortable:hover { color: var(--text); }
.data-table tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text);
  /* Default cell: one tidy line, ellipsis on overflow. Only opted-in columns
     (status, and .col-wrap) are allowed to wrap. This is what stops the ragged,
     shattered-text look when many columns share a row. */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .cell-actions { display: flex; gap: 5px; align-items: center; flex-wrap: nowrap; justify-content: flex-end; }

/* Column role hints — emitted on <th> by the data_table component (and mirrored
   onto <td>s the controllers render). They pin the narrow columns so the wide
   text columns get the remaining space. Widths are shares of table-layout:fixed. */
.data-table th.col-check, .data-table td.col-check { width: 40px; text-align: center; padding-left: 10px; padding-right: 10px; overflow: visible; }
.data-table th.col-actions, .data-table td.col-actions { width: 92px; white-space: nowrap; text-align: right; overflow: visible; }
.data-table th.col-num, .data-table td.col-num,
.data-table th[style*="text-align:right"], .data-table td[style*="text-align:right"] { text-align: right; white-space: nowrap; }
.data-table th.col-num, .data-table td.col-num { width: 130px; }
/* Status column: let whole pills sit inline and wrap as units (never break the
   pill text), and give the column enough room that it usually doesn't wrap. */
.data-table th.col-status { width: 150px; }
.data-table td.col-status { white-space: normal; overflow: visible; }
.data-table td.col-status .pill { margin: 1px 0; }
/* A column whose text should wrap to multiple lines instead of ellipsis. */
.data-table th.col-wrap, .data-table td.col-wrap { white-space: normal; overflow: visible; text-overflow: clip; }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* The identity chip (avatar + name + sub): the text block truncates within the
   cell so a long business name shows an ellipsis instead of forcing the column. */
.chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-width: 0; }
.chip > div { min-width: 0; overflow: hidden; }
.chip__name, .chip__sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__avatar { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--slate-100); color: var(--slate-600); font-weight: 700; font-size: 12px; flex-shrink: 0; }
.chip__name { font-weight: 600; color: var(--text); font-size: 13px; }
.chip__sub { font-size: 11px; color: var(--text-muted); }

/* Grid toolbar + pagination */
.grid-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.grid-toolbar__filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid-toolbar__spacer { flex: 1; }
/* Per-grid search box. Its own class (not .topbar__search, which the mobile
   breakpoint hides) so the in-table search stays available on every viewport. */
.grid-search { position: relative; max-width: 280px; flex: 1 1 200px; min-width: 160px; }
.grid-search input {
  width: 100%; height: 38px; padding: 0 14px 0 38px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 13.5px; color: var(--text);
}
.grid-search input:focus { outline: none; border-color: var(--primary-lt); background: var(--surface); }
.grid-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
/* Pagination lives in a full-width row at the foot of the tbody. Reset any cell
   truncation/alignment so the controls render cleanly across the whole width. */
.data-table tr.grid-pagination-row td { padding: 4px 14px; background: var(--surface); white-space: normal; text-align: left; max-width: none; }
.data-table tr.grid-pagination-row:hover td { background: var(--surface); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; flex-wrap: wrap; }
.pagination__info { font-size: 12.5px; color: var(--text-muted); }
.pagination__pages { display: flex; gap: 4px; }
.page-btn {
  min-width: 34px; height: 34px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; display: grid; place-items: center;
}
.page-btn:hover { background: var(--surface-2); }
.page-btn.is-active { background: var(--primary-lt); color: #fff; border-color: var(--primary-lt); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field-label .req { color: var(--danger); }
.field-input { position: relative; display: flex; align-items: center; }
.field-icon { position: absolute; left: 12px; color: var(--text-faint); display: inline-flex; }
.field-control {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13.5px; font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field-control--with-icon .field-control, .field-input--with-icon input { padding-left: 38px; }
.field-input.field-control--with-icon input { padding-left: 38px; }
.field-control:focus { outline: none; border-color: var(--primary-lt); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
textarea.field-control { min-height: 90px; resize: vertical; }
select.field-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.field.has-error .field-control { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 11.5px; margin-top: 4px; }
.field-hint { color: var(--text-muted); font-size: 11.5px; margin-top: 4px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }

/* ── Alerts / flash ──────────────────────────────────────────────────────── */
.flash-stack { position: fixed; top: 74px; right: 24px; z-index: 60; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  border-left: 4px solid; font-size: 13px; background: var(--surface); box-shadow: var(--shadow-md);
}
.alert--success { border-left-color: var(--success); background: var(--success-bg); color: #166534; }
.alert--danger, .alert--error { border-left-color: var(--danger); background: var(--danger-bg); color: #991b1b; }
.alert--warning { border-left-color: var(--warning); background: var(--warning-bg); color: #92400e; }
.alert--info { border-left-color: var(--info); background: var(--info-bg); color: #1e40af; }
.alert__icon { flex-shrink: 0; display: inline-flex; margin-top: 1px; }
.alert__msg { flex: 1; }
.alert__close { background: none; border: none; cursor: pointer; color: inherit; opacity: .6; padding: 0; display: inline-flex; }
.alert__close:hover { opacity: 1; }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 70; display: grid; place-items: center; padding: 24px; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); width: 100%; max-width: 560px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; }
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--primary); color: #fff; }
.modal__title { font-size: 15px; font-weight: 600; }
.modal__close { background: none; border: none; color: rgba(255,255,255,.8); cursor: pointer; display: inline-flex; }
.modal__close:hover { color: #fff; }
.modal__body { padding: 20px; overflow-y: auto; }
/* Forms inside modals must inherit the flex chain, or a tall form prevents
   .modal__body from ever scrolling and clips the footer on short screens. */
.modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow: hidden; }
.modal__footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0{margin-top:0}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}
.mb-0{margin-bottom:0}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.hidden { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary-lt); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* htmx loading indicator */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* Top progress bar for htmx requests */
#progress-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: linear-gradient(90deg, var(--accent), var(--primary-lt)); z-index: 100; transition: width .2s; opacity: 0; }
body.htmx-request #progress-bar { opacity: 1; }

/* ── Record detail pages ─────────────────────────────────────────────────── */
/* Shared premium layout for single-record ("show") views: a header band with
   the primary identifier + status badges, then grouped field cards. Fields use
   a definition grid (label above value) with tabular-aligned numbers. */
.record { display: flex; flex-direction: column; gap: 16px; }
.record-band {
  display: flex; align-items: center; gap: 16px; padding: 18px 22px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: linear-gradient(120deg, var(--primary) 0%, var(--primary-dk) 100%);
  color: #fff; box-shadow: var(--shadow-md); position: relative; overflow: hidden;
}
.record-band::after {
  content: ''; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px;
  border-radius: 50%; background: rgba(255,255,255,.06);
}
.record-band__avatar {
  width: 54px; height: 54px; border-radius: 14px; flex-shrink: 0; display: grid; place-items: center;
  background: rgba(255,255,255,.14); color: #fff; font-weight: 700; font-size: 22px;
  border: 1px solid rgba(255,255,255,.18); overflow: hidden;
}
.record-band__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.record-band__main { flex: 1; min-width: 0; z-index: 1; }
.record-band__title {
  font-size: 19px; font-weight: 700; color: #fff; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.record-band__meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px;
  font-size: 12.5px; color: rgba(255,255,255,.78);
}
.record-band__id { font-variant-numeric: tabular-nums; font-weight: 600; color: rgba(255,255,255,.92); }
.record-band__sep { color: rgba(255,255,255,.4); }
.record-band__badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; z-index: 1; }
.record-band__badges .pill { background: rgba(255,255,255,.16); color: #fff; }

/* Sub-heading inside a card body that separates field groups. */
.record-subhead {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin: 22px 0 12px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.card__body > .def-grid:first-child + .record-subhead,
.card__body > .record-subhead:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* Definition grid: label above value, two columns on wide, one on narrow. */
.def-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.def-grid--single { grid-template-columns: 1fr; }
.def-grid__item { min-width: 0; }
.def-grid__label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 3px;
}
.def-grid__value {
  font-size: 13.5px; font-weight: 600; color: var(--text); word-break: break-word; line-height: 1.4;
}
.def-grid__value.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.def-grid__item--wide { grid-column: 1 / -1; }

/* Money callout inside a card (headline amount). */
.record-amount {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px; border-radius: var(--radius); background: var(--surface-2);
  border: 1px solid var(--border);
}
.record-amount__label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.record-amount__value { font-size: 26px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

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

/* ── Responsive ──────────────────────────────────────────────────────────────
   Breakpoint scale (kept consistent app-wide; the 1024 drawer BP is mirrored in
   app.js MOBILE_BP):
     1024px  tablet / mobile — sidebar becomes an off-canvas drawer
      768px  narrow — two/three-up content grids collapse to one column
      640px  phone — tighter chrome, hide non-essential topbar bits
   ──────────────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .app__main { margin-left: 0; }
  /* Off-canvas drawer: hidden by default, slid in when .is-mobile-open. */
  .sidebar { transform: translateX(-100%); transition: transform var(--transition); width: var(--sidebar-w); }
  .app.is-mobile-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-xl); }
  /* Scrim: full-viewport dim behind the drawer. app.js closes the drawer when a
     click lands outside .sidebar while .is-mobile-open, so this reads as tappable. */
  .app.is-mobile-open::after { content:''; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 39; }
  /* On mobile the collapse rail is meaningless — always show the full drawer width. */
  .app.is-collapsed .sidebar { width: var(--sidebar-w); }
  .app.is-collapsed .app__main { margin-left: 0; }
  /* The hamburger is the drawer opener here. */
  .topbar__toggle { display: inline-flex; }
}
/* Two/three-up content grids collapse to a single column on narrow screens. This
   covers the dashboard (chart + status) and ~12 detail/show pages using .grid-2. */
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app__content { padding: 16px 14px; }
  .topbar { padding: 0 14px; }
  /* Only the global TOPBAR search is hidden on phones — the per-grid search
     (.grid-search) stays visible so tables remain searchable on mobile. */
  .topbar__search { display: none; }
  .topbar__user-meta { display: none; }
  /* Grid toolbar stacks: filters wrap to full width, then a full-width search,
     so both the revenue-item/status filters and the search are usable on a phone.
     Each filter select and the search span the row instead of squeezing inline. */
  .grid-toolbar { align-items: stretch; }
  .grid-toolbar__filters { width: 100%; }
  .grid-toolbar__filters > select,
  .grid-toolbar__filters > .field-control { flex: 1 1 46%; min-width: 0; width: auto !important; }
  .grid-search { max-width: none; width: 100%; flex-basis: 100%; order: 5; }
  .grid-toolbar__spacer { display: none; }
  /* Tighter table cells + modal padding so grids and dialogs fit a phone. */
  .data-table td, .data-table th { padding: 8px 10px; }
  .modal-overlay { padding: 12px; }
  .page-header { flex-wrap: wrap; gap: 10px; }
  /* When the header wraps on a phone, the action buttons take their own full-width
     row — flow them from the left and let them wrap so a busy toolbar (Edit,
     Upload, Raise Bill, Generate Notice, Print…) never forces horizontal scroll. */
  .page-header__actions { width: 100%; justify-content: flex-start; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* ── Print (record detail pages) ─────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, #progress-bar, .page-header__actions,
  .flash-stack, .record-band__badges { display: none !important; }
  .app__main { margin-left: 0 !important; }
  .app__content { padding: 0 !important; max-width: none !important; }
  body { background: #fff !important; }
  .card, .record-band, .record-amount { box-shadow: none !important; break-inside: avoid; }
  .record-band { background: var(--primary) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .grid-2, .grid-3, .stats-grid { display: block !important; }
  .grid-2 > *, .grid-3 > *, .stats-grid > * { margin-bottom: 14px; }
}

/* ── AI Copilot chat drawer ──────────────────────────────────────────────── */
#copilot [x-cloak] { display: none !important; }
.copilot-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 900;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent, #0ea5e9));
  color: #fff; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(14,165,233,.4);
  transition: transform .15s, box-shadow .15s;
}
.copilot-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 30px rgba(14,165,233,.5); }
.copilot-scrim { position: fixed; inset: 0; z-index: 898; background: rgba(2,6,23,.35); }
.copilot-drawer {
  position: fixed; top: 0; right: 0; z-index: 899; height: 100vh; width: 420px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -12px 0 40px rgba(2,6,23,.18);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.copilot-drawer.is-open { transform: translateX(0); }
.copilot-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary), var(--primary-dk, #142943)); color: #fff;
}
.copilot-head__title { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; }
.copilot-head__dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.3); }
.copilot-head__actions { display: flex; gap: 4px; }
.copilot-iconbtn { background: rgba(255,255,255,.12); border: none; color: #fff; width: 30px; height: 30px;
  border-radius: 8px; display: grid; place-items: center; cursor: pointer; transition: background .15s; }
.copilot-iconbtn:hover { background: rgba(255,255,255,.24); }
.copilot-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.copilot-notice, .copilot-welcome { text-align: center; }
.copilot-notice { display: flex; gap: 10px; text-align: left; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 13px; color: var(--text); }
.copilot-notice svg { color: #d97706; flex: 0 0 auto; }
.copilot-welcome { margin: auto 0; padding: 20px 8px; }
.copilot-welcome__icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 12px;
  background: var(--surface-2); color: var(--primary-lt); }
.copilot-welcome__title { font-size: 17px; font-weight: 700; }
.copilot-welcome__sub { font-size: 13px; margin-top: 4px; }
.copilot-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.copilot-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 7px 13px;
  font-size: 12.5px; color: var(--text); cursor: pointer; transition: border-color .15s, background .15s; }
.copilot-chip:hover { border-color: var(--accent); background: var(--surface); }
.copilot-msg { display: flex; flex-direction: column; gap: 6px; max-width: 92%; }
.copilot-msg--user { align-self: flex-end; align-items: flex-end; }
.copilot-msg--assistant { align-self: flex-start; }
.copilot-msg__bubble { padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; word-wrap: break-word; }
.copilot-msg--user .copilot-msg__bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.copilot-msg--assistant .copilot-msg__bubble { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.copilot-msg__bubble p { margin: 0 0 8px; } .copilot-msg__bubble p:last-child { margin-bottom: 0; }
.copilot-msg__bubble ul { margin: 4px 0; padding-left: 18px; } .copilot-msg__bubble li { margin: 2px 0; }
.copilot-msg__bubble code { background: rgba(0,0,0,.08); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.copilot-action { align-self: flex-start; }
.copilot-typing { display: inline-flex; gap: 4px; }
.copilot-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: copilotBlink 1.2s infinite; }
.copilot-typing span:nth-child(2) { animation-delay: .2s; } .copilot-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes copilotBlink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }
.copilot-composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.copilot-composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  font: inherit; font-size: 13.5px; background: var(--surface-2); color: var(--text); max-height: 120px; line-height: 1.4; }
.copilot-composer textarea:focus { outline: none; border-color: var(--primary-lt); background: var(--surface); }
.copilot-send { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--primary); color: #fff; display: grid; place-items: center; transition: opacity .15s, transform .15s; }
.copilot-send:disabled { opacity: .45; cursor: not-allowed; }
.copilot-send:not(:disabled):hover { transform: scale(1.05); }
.copilot-history { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.copilot-history__title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 4px 6px; }
.copilot-history__item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  background: none; border: 1px solid transparent; border-radius: 9px; padding: 10px 12px; cursor: pointer; text-align: left;
  color: var(--text); transition: background .15s, border-color .15s; }
.copilot-history__item:hover { background: var(--surface-2); border-color: var(--border); }
.copilot-history__name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copilot-history__meta { font-size: 11px; color: var(--text-faint); flex: 0 0 auto; }
.copilot-empty { padding: 20px; text-align: center; font-size: 13px; }
@media (max-width: 480px) { .copilot-drawer { width: 100vw; } .copilot-fab { right: 16px; bottom: 16px; } }

/* ── Dashboard quick links ───────────────────────────────────────────────── */
.ql-head { display:flex; align-items:center; justify-content:space-between; margin:22px 0 12px; }
.ql-head__title { display:inline-flex; align-items:center; gap:7px; font-size:13px; font-weight:700;
  text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); }
.ql-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(250px, 1fr)); gap:12px; margin-bottom:20px; }
.ql-card { display:flex; align-items:center; gap:12px; padding:14px 16px; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--radius); text-decoration:none; color:inherit;
  transition:transform .14s, box-shadow .14s, border-color .14s; }
.ql-card:hover { transform:translateY(-2px); box-shadow:var(--shadow-md); border-color:var(--accent); }
.ql-card__icon { width:42px; height:42px; border-radius:11px; display:grid; place-items:center; flex:0 0 auto; }
.ql-card__body { display:flex; flex-direction:column; min-width:0; flex:1; }
.ql-card__name { font-size:14px; font-weight:700; color:var(--text); }
.ql-card__desc { font-size:12px; color:var(--text-muted); line-height:1.4; overflow:hidden;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; }
.ql-card__go { color:var(--text-faint); flex:0 0 auto; transition:color .14s, transform .14s; }
.ql-card:hover .ql-card__go { color:var(--primary-lt); transform:translateX(2px); }

/* ── Settings colour picker (appearance.accent) ──────────────────────────── */
.field-control[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 64px; height: 40px; padding: 4px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.field-control[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.field-control[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.field-control[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; }
.field-control[type="color"]:focus { outline: none; border-color: var(--primary-lt); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }

/* ── DB-backed autocomplete (data-lookup typeahead) ──────────────────────── */
/* The menu positions against its .field wrapper (position:relative set in JS).
   Sits above modals via a high z-index; scrolls when long. */
.lta-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1200;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto; padding: 4px;
}
.lta-item {
  display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left;
  padding: 8px 10px; border: none; background: none; border-radius: 6px; cursor: pointer;
  font: inherit; color: var(--text);
}
.lta-item:hover, .lta-item.is-active { background: var(--surface-2); }
.lta-item.is-active { box-shadow: inset 0 0 0 1px var(--primary-lt); }
.lta-item__label { font-size: 13.5px; font-weight: 600; }
.lta-item__detail { font-size: 12px; color: var(--text-muted); }
/* A field hosting a lookup needs room for the absolutely-positioned menu. */
.field:has(input[data-lookup]) { position: relative; }

/* ── Staff PWA bottom navigation (phones) ────────────────────────────────────
   A native-app tab bar for the back-office on phones. Below the tablet drawer
   breakpoint the sidebar is an off-canvas drawer; at the PHONE breakpoint
   (≤640px) we replace it with this fixed bottom bar, hide the footer, and give
   the shell an app feel. RBAC-filtered server-side; safe-area aware. Hidden by
   default (desktop/tablet) — revealed only inside the phone media query. */
.abn { display: none; }
.abn-sheet { display: none; }
.abn-sheet[hidden] { display: none; }
/* While the More sheet is open, pin the page so the background can't scroll or
   rubber-band behind it on iOS (JS stores/restores the scroll offset via top:).
   Unconditional — the sheet only ever opens on phones, so this is inert
   elsewhere. */
body.abn-sheet-open { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }

@media (max-width: 640px) {
  /* ---- Bottom tab bar ---- */
  .abn {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    display: flex; align-items: stretch;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px -10px rgba(15,23,42,.22);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-backdrop-filter: saturate(1.6) blur(8px);
    backdrop-filter: saturate(1.6) blur(8px);
  }
  .abn__tab {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 2px 7px;
    background: none; border: none; cursor: pointer;
    color: var(--text-faint); text-decoration: none; font-family: inherit;
    -webkit-tap-highlight-color: transparent; transition: color .15s;
  }
  .abn__ic { display: grid; place-items: center; height: 24px; position: relative; }
  .abn__ic svg { width: 23px; height: 23px; }
  .abn__lbl { font-size: 10.5px; font-weight: 600; letter-spacing: .01em; line-height: 1;
              max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .abn__tab.is-active { color: var(--primary-lt); }
  .abn__tab.is-active .abn__ic::after {
    content: ''; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary-lt);
  }
  .abn__tab:active { background: var(--surface-2); }

  /* ---- More sheet (bottom drawer) ---- */
  /* Above the copilot FAB (z-900) so the sheet is never overlapped. */
  .abn-sheet { display: block; position: fixed; inset: 0; z-index: 1100; }
  .abn-sheet[hidden] { display: none; }
  .abn-sheet__scrim { position: absolute; inset: 0; background: rgba(15,23,42,.5); animation: abn-fade .2s ease; }
  .abn-sheet__panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    /* Clamp to the SMALL viewport (svh/dvh) so the panel can never be taller than
       what's actually visible when mobile-Safari's URL bar is shown — `vh` there
       resolves against the LARGEST viewport and pushed lower items (Settings /
       Sign out) off-screen, which read as a truncated ("incomplete") menu.
       The panel is a flex column so its body can own the scroll. */
    display: flex; flex-direction: column;
    max-height: 86vh; max-height: 86svh;
    background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-xl);
    padding: 8px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    animation: abn-up .26s cubic-bezier(.22,1,.36,1);
    overscroll-behavior: contain;
  }
  @supports (max-height: 100dvh) { .abn-sheet__panel { max-height: 86dvh; } }
  .abn-sheet__grip { flex: 0 0 auto; width: 40px; height: 4px; border-radius: 3px; background: var(--border); margin: 4px auto 10px; }
  /* Grip + head stay fixed at the top of the panel; only the body scrolls. */
  .abn-sheet__head { flex: 0 0 auto; background: var(--surface);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 0 2px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  .abn-sheet__who { display: flex; align-items: center; gap: 11px; min-width: 0; }
  .abn-sheet__avatar { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
    display: grid; place-items: center; background: var(--primary-dk); color: #fff; font-weight: 800; font-size: 16px; }
  .abn-sheet__idn { display: flex; flex-direction: column; min-width: 0; }
  .abn-sheet__name { font-weight: 700; font-size: 15px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .abn-sheet__role { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .abn-sheet__x { flex: 0 0 auto; width: 34px; height: 34px; border: none; background: var(--surface-2);
    border-radius: 50%; display: grid; place-items: center; color: var(--text-muted); cursor: pointer; }
  /* The body is the scroll container (min-height:0 lets a flex child actually
     scroll instead of expanding the panel). A bottom fade signals "more below"
     so a long admin menu never looks truncated; it fades out at the end via the
     JS-toggled .is-scrollend class. Extra bottom padding clears the home bar. */
  .abn-sheet__body { flex: 1 1 auto; min-height: 0; overflow-y: auto;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    display: flex; flex-direction: column; gap: 6px; padding-bottom: 4px;
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent 100%);
            mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent 100%); }
  .abn-sheet__body.is-scrollend { -webkit-mask-image: none; mask-image: none; }
  .abn-sheet__group-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-faint); padding: 12px 6px 4px; }
  .abn-sheet__links { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .abn-sheet__link { display: flex; align-items: center; gap: 11px; padding: 12px; border-radius: var(--radius);
    color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; background: var(--surface-2); }
  .abn-sheet__link svg { color: var(--primary-lt); flex: 0 0 auto; }
  .abn-sheet__link.is-active { background: color-mix(in srgb, var(--primary-lt) 12%, transparent); color: var(--primary-lt); }
  .abn-sheet__link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* "Tab" chip on items that also live on the bottom bar — keeps the sheet a
     complete mirror of the sidebar while explaining the small overlap. */
  .abn-sheet__link .abn-sheet__chip { flex: 0 0 auto; margin-left: auto; padding: 1px 6px;
    font-size: 9.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    border-radius: 6px; background: var(--surface); color: var(--text-faint); border: 1px solid var(--border); }
  /* Pinned footer (flex:0 0 auto) — sits below the scrolling body so Sign out is
     always visible. A hairline separates it from the fading list above. */
  .abn-sheet__signout { flex: 0 0 auto; margin: 0; padding-top: 10px; border-top: 1px solid var(--border); }
  .abn-sheet__out { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px; border: 1px solid var(--danger); background: var(--danger-bg); color: var(--danger);
    font-weight: 700; font-size: 15px; border-radius: var(--radius); cursor: pointer; }

  @keyframes abn-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
  @keyframes abn-fade { from { opacity: 0; } to { opacity: 1; } }

  /* ---- App-mode chrome (phones): full app shell for staff ---- */
  .app-shell .abn { display: flex; }
  /* Reserve space for the fixed bar so content isn't hidden behind it. */
  .app-shell .app__content { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  /* Hide the desktop footer + the topbar hamburger — the bottom bar replaces the
     drawer on phones. (The drawer + its scrim can't open when the toggle is gone.)
     The staff footer carries an inline `display:flex`, so !important is required
     to override it. */
  .app-shell .app__main > footer { display: none !important; }
  .app-shell .topbar__toggle { display: none !important; }
  /* Belt-and-suspenders: never leave the drawer/scrim showing on a phone. */
  .app-shell .app.is-mobile-open .sidebar { transform: translateX(-100%); }
  .app-shell .app.is-mobile-open::after { display: none; }
  /* Lift the copilot FAB above the tab bar. */
  .app-shell .copilot-fab { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  /* Hide the FAB while the More sheet is open. */
  body:has(.abn-sheet:not([hidden])) .copilot-fab,
  body.abn-sheet-open .copilot-fab { display: none; }
}

/* Installed-PWA polish: extra top safe-area for the sticky topbar in standalone. */
@media (max-width: 640px) and (display-mode: standalone) {
  .app-shell .topbar { padding-top: env(safe-area-inset-top, 0px); height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .abn-sheet__panel, .abn-sheet__scrim { animation: none; }
}

/* ── Notification centre (topbar bell) ────────────────────────────────────── */
.notif { position: relative; }
.notif__bell { position: relative; }
.notif__badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 800; line-height: 1; border-radius: 9px;
  border: 2px solid var(--surface); box-sizing: content-box;
}
/* [hidden] must beat display:grid (else a 0-count badge still shows). */
.notif__badge[hidden] { display: none; }
.notif.has-unread .notif__bell { color: var(--primary-lt); }
.notif__menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 360px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 500; overflow: hidden;
  opacity: 0; visibility: hidden; transform: translateY(-6px); transition: opacity .16s, transform .16s, visibility .16s;
}
.notif.is-open .notif__menu { opacity: 1; visibility: visible; transform: translateY(0); }
.notif__head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notif__title { font-weight: 700; font-size: 14px; color: var(--text); }
.notif__markall { background: none; border: none; color: var(--primary-lt); font-size: 12px; font-weight: 600; cursor: pointer; padding: 2px 4px; }
.notif__markall:hover { text-decoration: underline; }
.notif__list { max-height: min(60vh, 440px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.notif__empty { padding: 30px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.notif__item { display: flex; align-items: flex-start; gap: 11px; padding: 12px 14px; text-decoration: none;
  color: var(--text); border-bottom: 1px solid var(--border); position: relative; transition: background .12s; }
.notif__item:last-child { border-bottom: none; }
.notif__item:hover { background: var(--surface-2); }
.notif__item.is-unread { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.notif__ic { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-muted); }
.notif__item--primary .notif__ic { background: color-mix(in srgb, var(--primary-lt) 15%, transparent); color: var(--primary-lt); }
.notif__item--success .notif__ic { background: rgba(5,150,105,.14); color: var(--success); }
.notif__item--warning .notif__ic { background: rgba(217,119,6,.14); color: var(--warning, #d97706); }
.notif__item--danger  .notif__ic { background: rgba(220,38,38,.14); color: var(--danger); }
.notif__txt { min-width: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.notif__t { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.25; }
.notif__b { font-size: 12px; color: var(--text-muted); line-height: 1.3; word-break: break-word; }
.notif__time { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
.notif__dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--primary-lt); margin-top: 6px; }
.notif__foot { display: block; padding: 11px 14px; text-align: center; font-size: 12.5px; font-weight: 600;
  color: var(--primary-lt); text-decoration: none; border-top: 1px solid var(--border); }
.notif__foot:hover { background: var(--surface-2); }
@media (max-width: 640px) {
  .notif__menu { position: fixed; right: 8px; left: 8px; top: calc(var(--topbar-h, 60px) + env(safe-area-inset-top, 0px) + 6px); width: auto; max-width: none; }
}

/* ── Support ring-out banner (app-wide, support staff) ────────────────────── */
.sring {
  position: fixed; z-index: 1200; right: 20px; bottom: 20px; width: 360px; max-width: calc(100vw - 24px);
  opacity: 0; transform: translateY(14px) scale(.98); transition: opacity .24s, transform .24s;
  pointer-events: none;
}
.sring.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.sring__card {
  display: flex; align-items: center; gap: 14px; padding: 15px 16px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary-lt);
  border-radius: var(--radius); box-shadow: var(--shadow-xl);
}
.sring__pulse { position: relative; flex: 0 0 auto; width: 46px; height: 46px; display: grid; place-items: center; }
.sring__icon { position: relative; z-index: 1; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--primary); color: #fff; }
.sring__ring { position: absolute; inset: 0; border-radius: 50%; background: var(--primary-lt); opacity: .5;
  animation: sring-pulse 1.5s ease-out infinite; }
@keyframes sring-pulse { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(1.9); opacity: 0; } }
.sring__body { flex: 1; min-width: 0; }
.sring__eyebrow { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--primary-lt); }
.sring__name { font-size: 14.5px; font-weight: 800; color: var(--text); line-height: 1.2; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sring__subject { font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sring__more { font-size: 11px; color: var(--text-faint); margin-top: 3px; font-weight: 600; }
.sring__actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.sring__accept { display: inline-flex; align-items: center; gap: 6px; padding: 9px 13px; border: none;
  background: var(--success); color: #fff; font-weight: 700; font-size: 13px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.sring__accept:hover { filter: brightness(1.06); }
.sring__mute, .sring__dismiss { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted); border-radius: 8px; cursor: pointer; }
.sring__mute:hover, .sring__dismiss:hover { color: var(--text); border-color: var(--border-strong); }
@media (max-width: 640px) {
  .sring { right: 8px; left: 8px; bottom: calc(8px + 66px + env(safe-area-inset-bottom, 0px)); width: auto; }
  .sring__card { flex-wrap: wrap; }
  .sring__actions { width: 100%; justify-content: stretch; }
  .sring__accept { flex: 1; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .sring__ring { animation: none; }
  .sring { transition: opacity .2s; transform: none; }
}
