/* SIMS design system, in line with the CRM (Nüdge) and AuFluence Core so staff moving
   between the apps find the same shell, colours and patterns. Ported from
   AUFLUENCE-CORE/app/static/css/app.css (rules: AUFLUENCE-CORE/uiux-rules.md) and trimmed
   to what the IAM admin portal uses. Every colour is a token below; components use
   var(--...) only. */

/* ── Fonts (self-hosted, SIL OFL: see static/fonts/OFL-*.txt) ─────────── */
@font-face {
  font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("../fonts/manrope-latin-wght.woff2") format("woff2-variations"),
       url("../fonts/manrope-latin-wght.woff2") format("woff2");
}
@font-face {
  font-family: "Sora"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("../fonts/sora-latin-wght.woff2") format("woff2-variations"),
       url("../fonts/sora-latin-wght.woff2") format("woff2");
}
@font-face {
  font-family: "DM Mono"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/dm-mono-latin-400.woff2") format("woff2");
}
@font-face {
  font-family: "DM Mono"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/dm-mono-latin-500.woff2") format("woff2");
}

/* ── 0. Tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Brand = gold/amber: identity only (logo, hero accents). Never on controls. */
  --color-brand:         #d97706;
  --color-brand-light:   #f59e0b;
  --color-brand-rgb:     217, 119, 6;
  /* Action = indigo: every interactive element. */
  --color-action:        #4f46e5;
  --color-action-dark:   #4338ca;
  --color-action-light:  #6366f1;
  --color-action-rgb:    79, 70, 229;
  /* Indigo tints for text on dark surfaces (WCAG AA on --surface-page dark). */
  --color-action-lighter:  #818cf8;
  --color-action-lighter-rgb: 129, 140, 248;
  --color-action-lightest: #a5b4fc;
  --color-action-lightest-rgb: 165, 180, 252;
  /* Semantic: dark enough for text on white and white text on them (WCAG AA). */
  --color-success:       #047857;
  --color-success-rgb:   4, 120, 87;
  --color-success-light: #34d399;
  --color-warning:       #f59e0b;
  --color-warning-rgb:   245, 158, 11;
  --color-danger:        #dc2626;
  --color-danger-rgb:    220, 38, 38;
  --color-danger-light:  #f87171;
  /* Neutrals (Slate) */
  --color-n950: #0f172a;
  --color-n900: #111827;
  --color-n700: #334155;
  --color-n500: #64748b;
  --color-n400: #94a3b8;
  --color-n300: #cbd5e1;
  --color-n100: #f1f5f9;
  --color-n50:  #f8fafc;
  --color-white: #ffffff;
  --color-black-rgb: 0, 0, 0;
  --color-white-rgb: 255, 255, 255;
  --color-border: rgba(var(--color-black-rgb), .09);

  /* Bootstrap kept in step with the system */
  --bs-primary:          var(--color-action);
  --bs-primary-rgb:      var(--color-action-rgb);
  --bs-link-color:       var(--color-action);
  --bs-link-color-rgb:   var(--color-action-rgb);
  --bs-link-hover-color: var(--color-action-dark);
  --bs-success:          var(--color-success);
  --bs-success-rgb:      var(--color-success-rgb);
  --bs-warning:          var(--color-warning);
  --bs-warning-rgb:      var(--color-warning-rgb);
  --bs-danger:           var(--color-danger);
  --bs-danger-rgb:       var(--color-danger-rgb);
  --bs-body-font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading:        "Sora", "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:           "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Spacing (multiples of 4px) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
  /* Radius */
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius-xl: 20px; --radius-circle: 50%;
  /* Elevation */
  --shadow-elevation-1: 0 1px 3px rgba(var(--color-black-rgb), .08);
  --shadow-elevation-2: 0 4px 12px rgba(var(--color-black-rgb), .12);
  --shadow-elevation-3: 0 4px 20px rgba(var(--color-black-rgb), .20);
  --shadow-elevation-4: 0 8px 32px rgba(var(--color-black-rgb), .24);
  /* Timing */
  --t-micro: 100ms ease-out;
  --t-standard: 200ms ease-in-out;
  --t-slide: 250ms cubic-bezier(.4, 0, .2, 1);
  /* Z stack */
  --z-sticky: 100; --z-sidebar: 1020; --z-navbar: 1025; --z-bottom-nav: 1030;
  --z-action-bar: 1031; --z-modal: 1060; --z-toast: 1070;
  /* Shell sizes (same as the CRM and AuFluence) */
  --sidebar-width: 232px;
  --sidebar-collapsed-width: 64px;
  --navbar-height: 57px;
  --bottom-nav-height: 64px;
  /* Tap targets (uiux-rules §3): 44px for anything tappable, 48px for a primary button. */
  --tap-min: 44px;
  --tap-primary: 48px;

  /* The four gradients: use no others. */
  --gradient-hero:    linear-gradient(135deg, var(--color-action), #6f42c1);
  --gradient-danger:  linear-gradient(135deg, #dc3545, #fd7e14);
  --gradient-success: linear-gradient(135deg, #198754, #20c997);
  --gradient-gold:    linear-gradient(135deg, var(--color-brand-light), var(--color-brand));

  /* Status pill pairs (tinted: safe in light and dark) */
  --pill-open-bg:   rgba(var(--color-action-rgb), .12);  --pill-open-fg:   var(--color-action-dark);
  --pill-active-bg: rgba(var(--color-warning-rgb), .16); --pill-active-fg: #92400e;
  --pill-done-bg:   rgba(var(--color-success-rgb), .14); --pill-done-fg:   #065f46;
  --pill-lost-bg:   rgba(var(--color-danger-rgb), .12);  --pill-lost-fg:   #b91c1c;
  --pill-hold-bg:   rgba(100, 116, 139, .14);            --pill-hold-fg:   var(--color-n700);

  --surface-page: var(--color-n50);
  --surface-sidebar: var(--color-n950);
  --surface-code: var(--color-n950);
  --bottom-nav-bg: rgba(var(--color-white-rgb), .9);

  /* Modals: the CRM's glass panel */
  --modal-glass-bg: rgba(var(--color-white-rgb), .85);
  --modal-border: rgba(var(--color-white-rgb), .5);
  --modal-shadow: 0 25px 50px -12px rgba(var(--color-black-rgb), .25);
  --modal-backdrop-overlay: rgba(var(--color-white-rgb), .7);
  --modal-backdrop-blur: 12px;
  --modal-title-color: var(--color-action);
}

[data-bs-theme="dark"] {
  --color-border: rgba(var(--color-white-rgb), .09);
  --surface-page: #0b1120;
  --surface-sidebar: #060a14;
  --surface-code: #060a14;
  --bottom-nav-bg: rgba(5, 9, 18, .9);
  --pill-open-fg: #a5b4fc; --pill-active-fg: #fcd34d; --pill-done-fg: #6ee7b7;
  --pill-lost-fg: #fca5a5; --pill-hold-fg: var(--color-n300);
  --bs-link-color: var(--color-action-lightest);
  --bs-link-color-rgb: var(--color-action-lightest-rgb);
  --bs-link-hover-color: var(--color-white);
  --bs-link-hover-color-rgb: var(--color-action-lighter-rgb);
  --modal-glass-bg: rgba(15, 23, 42, .92);
  --modal-border: rgba(var(--color-white-rgb), .08);
  --modal-shadow: 0 25px 50px -12px rgba(var(--color-black-rgb), .5);
  --modal-backdrop-overlay: rgba(var(--color-black-rgb), .5);
  --modal-title-color: var(--color-action-light);
}
/* Text in the action and state colours, lifted to tints that pass on dark surfaces. */
[data-bs-theme="dark"] .text-primary { color: var(--color-action-lighter) !important; }
[data-bs-theme="dark"] .text-success { color: var(--color-success-light) !important; }
[data-bs-theme="dark"] .text-danger { color: var(--color-danger-light) !important; }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: var(--color-action-lighter);
  --bs-btn-border-color: var(--color-action-lighter); --bs-btn-hover-color: var(--color-white); }
[data-bs-theme="dark"] .btn-outline-secondary { --bs-btn-color: var(--color-n300); --bs-btn-border-color: var(--color-n500);
  --bs-btn-hover-color: var(--color-n950); --bs-btn-hover-bg: var(--color-n300); --bs-btn-hover-border-color: var(--color-n300);
  --bs-btn-active-color: var(--color-n950); --bs-btn-active-bg: var(--color-n300); }
[data-bs-theme="dark"] .btn-outline-danger { --bs-btn-color: var(--color-danger-light); --bs-btn-border-color: var(--color-danger-light); }
[data-bs-theme="dark"] .btn-outline-success { --bs-btn-color: var(--color-success-light); --bs-btn-border-color: var(--color-success-light); }
[data-bs-theme="dark"] .initials, [data-bs-theme="dark"] .nt-icon,
[data-bs-theme="dark"] .docs-nav .nav-link.active { color: var(--color-action-lighter); }

/* ── 1. Base ───────────────────────────────────────────────────────────── */
body {
  background: var(--surface-page);
  font-family: var(--bs-body-font-family);
  font-size: .9375rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, .h1, .h2, .h3, .h4, .page-title { font-family: var(--font-heading); letter-spacing: -.01em; }
.num, .font-mono, code { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
a { text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--color-action); outline-offset: 2px; }
.btn:active { transform: scale(.97); transition: transform var(--t-micro); }
.btn:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; }
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary { --bs-btn-bg: var(--color-action); --bs-btn-border-color: var(--color-action);
  --bs-btn-hover-bg: var(--color-action-dark); --bs-btn-hover-border-color: var(--color-action-dark);
  --bs-btn-active-bg: var(--color-action-dark); --bs-btn-disabled-bg: var(--color-action);
  --bs-btn-disabled-border-color: var(--color-action); font-weight: 600; }
.btn-outline-primary { --bs-btn-color: var(--color-action); --bs-btn-border-color: var(--color-action);
  --bs-btn-hover-bg: var(--color-action); --bs-btn-hover-border-color: var(--color-action);
  --bs-btn-active-bg: var(--color-action-dark); }
/* Outline buttons in a state colour: Bootstrap's compiled colours fail contrast on white. */
.btn-outline-danger { --bs-btn-color: var(--color-danger); --bs-btn-border-color: var(--color-danger);
  --bs-btn-hover-bg: var(--color-danger); --bs-btn-hover-border-color: var(--color-danger);
  --bs-btn-active-bg: var(--color-danger); --bs-btn-active-border-color: var(--color-danger); }
.btn-outline-warning { --bs-btn-color: var(--pill-active-fg); --bs-btn-border-color: var(--color-warning);
  --bs-btn-hover-color: var(--color-n950); --bs-btn-active-color: var(--color-n950); }
.btn-outline-secondary { --bs-btn-color: var(--color-n700); }
.btn-primary-lg { min-height: var(--tap-primary); }
.form-control, .form-select { border-radius: var(--radius-sm); }
.card { border-radius: var(--radius-md); border-color: var(--color-border); box-shadow: var(--shadow-elevation-1); }
.card-header { background: transparent; font-weight: 600; border-bottom-color: var(--color-border); }
.alert { border-radius: var(--radius-md); }
.badge { font-weight: 600; }
.table { --bs-table-bg: transparent; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); }
.section-label { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--bs-secondary-color); margin: var(--space-5) 0 var(--space-2); }
.min-h-tap { min-height: var(--tap-min); }
.min-w-0 { min-width: 0; }

@media (max-width: 991.98px) {
  .btn, .form-control, .form-select { min-height: var(--tap-min); }
  .btn { min-width: var(--tap-min); }
  .form-control, .form-select { font-size: 1rem; } /* no iOS zoom on focus */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* ── 2. Shell ──────────────────────────────────────────────────────────── */
#wrapper { display: flex; min-height: 100vh; min-height: 100dvh; }

#appSidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface-sidebar); color: var(--color-white);
  z-index: var(--z-sidebar);
  transition: width var(--t-slide), transform var(--t-slide);
  display: flex; flex-direction: column;
}
#appSidebar .sidebar-brand {
  display: flex; align-items: center; gap: var(--space-2); min-height: 60px;
  padding: var(--space-3) var(--space-4); color: var(--color-white); text-decoration: none;
  border-bottom: 1px solid rgba(var(--color-white-rgb), .08);
}
.brand-mark { width: 32px; height: 32px; flex-shrink: 0; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gradient-gold); color: var(--color-white); font-size: 1.05rem; }
.brand-name { font-family: var(--font-heading); font-weight: 700; font-size: 1rem; white-space: nowrap; }
.brand-name small { display: block; font-family: var(--bs-body-font-family); font-weight: 500;
  font-size: .68rem; color: rgba(var(--color-white-rgb), .5); letter-spacing: .04em; }
.sidebar-group {
  padding: var(--space-4) var(--space-5) var(--space-1); font-size: .65rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: rgba(var(--color-white-rgb), .6); white-space: nowrap;
}
#appSidebar .nav-link {
  display: flex; align-items: center; gap: 10px; height: 40px; margin: 2px var(--space-2);
  padding: 0 var(--space-3); border-radius: var(--radius-sm);
  color: rgba(var(--color-white-rgb), .78); font-size: .875rem; white-space: nowrap; overflow: hidden;
  transition: background var(--t-micro), color var(--t-micro);
}
#appSidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
#appSidebar .nav-link:hover { background: rgba(var(--color-white-rgb), .07); color: var(--color-white); }
#appSidebar .nav-link.active { background: rgba(var(--color-white-rgb), .12); color: var(--color-white); font-weight: 600; }
#appSidebar .nav-link.active i { color: var(--color-brand-light); }
.sidebar-user {
  margin-top: auto; padding: var(--space-3) var(--space-4); border-top: 1px solid rgba(var(--color-white-rgb), .08);
  display: flex; align-items: center; gap: var(--space-2); font-size: .8rem;
}
.avatar {
  width: 32px; height: 32px; border-radius: var(--radius-circle); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-action); color: var(--color-white); font-weight: 700; font-size: .8rem;
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .who .sub { color: rgba(var(--color-white-rgb), .5); font-size: .72rem; }
.sidebar-logout {
  background: none; border: 1px solid rgba(var(--color-white-rgb), .15); color: rgba(var(--color-white-rgb), .78);
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-logout:hover { background: rgba(var(--color-white-rgb), .07); color: var(--color-white); }
.sidebar-collapse-btn {
  background: none; border: 0; color: rgba(var(--color-white-rgb), .6); width: 40px; height: 40px;
  border-radius: var(--radius-sm); margin: var(--space-2) auto;
}
.sidebar-collapse-btn:hover { background: rgba(var(--color-white-rgb), .07); color: var(--color-white); }

/* The collapsed rail is a desktop setting only. */
@media (min-width: 992px) {
  .sidebar-collapsed #appSidebar { width: var(--sidebar-collapsed-width); }
  .sidebar-collapsed #appSidebar .nav-label, .sidebar-collapsed #appSidebar .brand-name,
  .sidebar-collapsed #appSidebar .sidebar-group, .sidebar-collapsed #appSidebar .who { display: none; }
  .sidebar-collapsed #appSidebar .nav-link { justify-content: center; padding: 0; }
  .sidebar-collapsed #appSidebar .sidebar-user { flex-direction: column; padding: var(--space-3) var(--space-2); }
  .sidebar-collapsed #appSidebar .sidebar-collapse-btn i { transform: rotate(180deg); }
}

#page-content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; overflow-x: clip; }

#topNavbar {
  position: sticky; top: 0; z-index: var(--z-navbar); min-height: var(--navbar-height);
  background: var(--bs-body-bg); border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-4);
}
#topNavbar .page-crumb { font-size: .85rem; color: var(--bs-secondary-color); }
#topNavbar .page-crumb a { color: inherit; text-decoration: none; }
#topNavbar .page-crumb a:hover { color: var(--color-action); }
#topNavbar .page-crumb .current { color: var(--bs-body-color); font-weight: 600; }
#topNavbar .mobile-title { font-family: var(--font-heading); font-weight: 600; font-size: 1rem;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--bs-body-bg); color: var(--bs-body-color); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.icon-btn:hover { background: var(--bs-tertiary-bg); color: var(--bs-body-color); }
@media (max-width: 991.98px) {
  .icon-btn, .sidebar-logout { width: var(--tap-min); height: var(--tap-min); }
}

main.page { flex: 1 1 auto; padding: var(--space-4); width: 100%; max-width: 1280px; margin: 0 auto; }
@media (min-width: 768px) { main.page { padding: var(--space-6); } }

#bottomNav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom-nav-height);
  background: var(--bottom-nav-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -8px 24px rgba(var(--color-black-rgb), .06);
  z-index: var(--z-bottom-nav); padding: 0 var(--space-1) env(safe-area-inset-bottom);
}
#bottomNav .bn-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--color-n500); font-size: .75rem; font-weight: 600; letter-spacing: .02em;
  transition: color var(--t-micro);
}
#bottomNav .bn-item i { font-size: 1.375rem; transition: transform var(--t-micro); }
#bottomNav .bn-item.active { color: var(--color-action); }
#bottomNav .bn-item.active i { transform: scale(1.08); }
#bottomNav .bn-item:active { opacity: .7; transform: scale(.93); }
[data-bs-theme="dark"] #bottomNav .bn-item { color: var(--color-n400); }
[data-bs-theme="dark"] #bottomNav .bn-item.active { color: var(--color-action-lighter); }

#sidebarBackdrop { display: none; position: fixed; inset: 0; background: rgba(var(--color-black-rgb), .45);
  z-index: calc(var(--z-sidebar) - 1); }

@media (max-width: 991.98px) {
  #appSidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar-open #appSidebar { transform: none; box-shadow: var(--shadow-elevation-4); }
  .sidebar-open #sidebarBackdrop { display: block; }
  .sidebar-collapse-btn { display: none; }
  /* Who is signed in sits under the logo in the drawer, not below every menu group. */
  #appSidebar .sidebar-brand { order: -2; }
  .sidebar-user { order: -1; margin-top: 0; border-top: 0; border-bottom: 1px solid rgba(var(--color-white-rgb), .08); }
  #bottomNav { display: flex; }
  /* Room for the bottom nav plus a page action bar, so neither covers the last row. */
  main.page { padding-bottom: calc(var(--bottom-nav-height) + var(--space-8) + 56px); }
}
@media (min-width: 992px) {
  main.page { padding-bottom: var(--space-8); }
}

/* Toasts (SIMS.flash) */
#toastStack {
  position: fixed; top: calc(var(--navbar-height) + var(--space-3)); right: var(--space-4); left: auto;
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); width: min(420px, calc(100vw - 32px));
}
@media (max-width: 575.98px) { #toastStack { left: var(--space-4); right: var(--space-4); width: auto; } }
.app-toast {
  display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); background: var(--bs-body-bg); box-shadow: var(--shadow-elevation-3);
  border: 1px solid var(--color-border); border-left: 4px solid var(--color-action); font-size: .875rem;
  animation: toast-in var(--t-standard);
}
.app-toast.t-success { border-left-color: var(--color-success); }
.app-toast.t-danger { border-left-color: var(--color-danger); }
.app-toast.t-warning { border-left-color: var(--color-warning); }
.app-toast .t-icon { font-size: 1.1rem; line-height: 1.3; color: var(--color-action); }
.app-toast.t-success .t-icon { color: var(--color-success); }
.app-toast.t-danger .t-icon { color: var(--color-danger); }
.app-toast.t-warning .t-icon { color: var(--color-warning); }
.app-toast .t-body { flex: 1; }
.app-toast.hiding { opacity: 0; transform: translateY(-6px); transition: opacity var(--t-standard), transform var(--t-standard); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ── 3. Page header (Identity zone) ───────────────────────────────────── */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-5); }
.page-header .page-title { font-size: 1.5rem; font-weight: 700; margin: 0; line-height: 1.3; }
.page-header .page-sub { color: var(--bs-secondary-color); font-size: .875rem; margin-top: 2px; }
@media (max-width: 767.98px) { .page-header .page-title { font-size: 1.25rem; } }
.back-link { display: inline-flex; align-items: center; gap: var(--space-1); font-size: .82rem;
  color: var(--bs-secondary-color); text-decoration: none; margin-bottom: var(--space-1); min-height: 32px; }
.back-link:hover { color: var(--color-action); }

/* ── 4. Action bar (Action zone) ──────────────────────────────────────── */
/* Desktop: inline in the page header. Below lg: fixed above the bottom nav, full width. */
.action-bar-inner { display: flex; gap: var(--space-2); justify-content: flex-end; }
/* A bar whose buttons are all hidden (no permission to create) takes no room. */
.action-bar:not(:has(.btn:not(.d-none))) { display: none; }
.action-bar .btn { min-height: var(--tap-primary); }
@media (max-width: 991.98px) {
  .action-bar { position: fixed; left: 0; right: 0; bottom: var(--bottom-nav-height); margin: 0;
    z-index: var(--z-action-bar); padding: var(--space-2); background: var(--bs-body-bg);
    border-top: 1px solid var(--color-border); box-shadow: 0 -6px 18px rgba(var(--color-black-rgb), .06); }
  .action-bar .btn { flex: 1 1 0; min-width: 0; }
}

/* ── 5. Components ────────────────────────────────────────────────────── */
/* Status pill */
.status-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--radius-xl);
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; line-height: 1.5;
  white-space: nowrap; }
.sp-open { background: var(--pill-open-bg); color: var(--pill-open-fg); }
.sp-active { background: var(--pill-active-bg); color: var(--pill-active-fg); }
.sp-done { background: var(--pill-done-bg); color: var(--pill-done-fg); }
.sp-lost { background: var(--pill-lost-bg); color: var(--pill-lost-fg); }
.sp-hold { background: var(--pill-hold-bg); color: var(--pill-hold-fg); }

/* Stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat-tile { background: var(--bs-body-bg); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevation-1); padding: var(--space-3) var(--space-4); border-left: 4px solid transparent;
  color: var(--bs-body-color); text-decoration: none; display: flex; align-items: center; gap: var(--space-3);
  min-height: 84px; transition: box-shadow var(--t-micro); }
a.stat-tile:hover { box-shadow: var(--shadow-elevation-2); color: var(--bs-body-color); }
.stat-tile .st-value { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 500; line-height: 1.15; }
.stat-tile .st-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--bs-secondary-color); margin-top: 2px; }
.stat-tile.accent-primary { border-left-color: var(--color-action); }
.stat-tile.accent-success { border-left-color: var(--color-success); }
.stat-tile.accent-warning { border-left-color: var(--color-warning); }
.stat-tile.accent-gold { border-left-color: var(--color-brand); }
.nt-icon { width: 40px; height: 40px; border-radius: var(--radius-md); display: inline-flex; flex-shrink: 0;
  align-items: center; justify-content: center; font-size: 1.2rem;
  background: rgba(var(--color-action-rgb), .1); color: var(--color-action); }

/* Welcome hero (dashboard greeting) */
.welcome-hero { background: var(--gradient-hero); color: var(--color-white); border-radius: var(--radius-lg);
  padding: var(--space-5); margin-bottom: var(--space-5); box-shadow: 0 4px 20px rgba(var(--color-action-rgb), .28); }
.welcome-hero .wh-title { font-family: var(--font-heading); font-size: 1.35rem; font-weight: 700; margin: 0; }
.welcome-hero .wh-sub { opacity: .9; font-size: .875rem; }

/* Activity list (CRM list-card rows inside a card) */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border); }
.activity-list li:last-child { border-bottom: 0; }
.activity-list .al-main { flex: 1; min-width: 0; }
.activity-list .al-meta { font-size: .8rem; color: var(--bs-secondary-color); display: flex; flex-wrap: wrap;
  gap: var(--space-1) var(--space-3); margin-top: 2px; }

/* Initials avatar */
.initials { width: 40px; height: 40px; border-radius: var(--radius-circle); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
  background: rgba(var(--color-action-rgb), .12); color: var(--color-action); }
.initials-lg { width: 64px; height: 64px; font-size: 1.25rem; }

/* Empty state */
.empty-state { text-align: center; padding: var(--space-8) var(--space-4); color: var(--bs-secondary-color); }
.empty-state i { font-size: 3rem; color: var(--color-n400); display: block; margin-bottom: var(--space-2); }
.empty-state .es-title { font-weight: 700; font-size: 1rem; color: var(--bs-body-color); }
.empty-state .es-sub { font-size: .875rem; margin-top: 2px; }

/* Definition rows */
.kv { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: var(--space-2) var(--space-3);
  font-size: .875rem; margin: 0; }
.kv dt { color: var(--bs-secondary-color); font-weight: 500; }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* Filter panel */
.filter-card .card-body { padding: var(--space-3) var(--space-4); }

/* Organization logo thumbnails */
.logo-thumb { width: 32px; height: 32px; object-fit: contain; }
.logo-preview { max-height: 160px; max-width: 100%; object-fit: contain; }
.logo-placeholder { height: 120px; color: var(--bs-secondary-color); }

/* Office hierarchy tree: nesting draws the indent, not inline styles (CSP forbids them). */
.tree-node { border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--bs-body-bg);
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
.tree-node .tree-children { margin-top: var(--space-2); padding-left: var(--space-4);
  border-left: 2px solid var(--color-border); }
.tree-node .tree-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.tree-node .tree-actions { display: flex; gap: var(--space-2); }

/* Permission matrix */
.perm-module { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3); }
.perm-module h3 { font-family: var(--bs-body-font-family); font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--bs-secondary-color); margin-bottom: var(--space-2); }
@media (max-width: 991.98px) {
  .perm-module .form-check { min-height: var(--tap-min); display: flex; align-items: center; gap: var(--space-2); }
}

/* ── 6. Tables: DataTables themed; rows become labelled cards on a phone ─ */
.list-table { margin-bottom: 0; --bs-table-hover-bg: var(--bs-tertiary-bg); }
.list-table td { vertical-align: middle; overflow-wrap: anywhere; font-size: .875rem; }
.list-table .row-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select { border-radius: var(--radius-sm); border-color: var(--bs-border-color); }
.dataTables_wrapper .dataTables_info { font-size: .8rem; color: var(--bs-secondary-color); }
.dataTables_wrapper .pagination { --bs-pagination-font-size: .875rem; }
.dataTables_wrapper .page-link { border-radius: var(--radius-sm); margin: 0 2px; }
.dataTables_wrapper .page-item.active .page-link { background: var(--color-action); border-color: var(--color-action); }
@media (max-width: 767.98px) {
  /* Each row is a card; each cell shows its column name (data-label, set by the renderer). */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--bs-body-bg);
    box-shadow: var(--shadow-elevation-1); margin-bottom: var(--space-3); padding: var(--space-2) var(--space-3); }
  .table-stack td { border: 0; padding: var(--space-1) 0; display: flex; justify-content: space-between;
    align-items: center; gap: var(--space-3); text-align: right; }
  .table-stack td[data-label]::before { content: attr(data-label); font-size: .75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); text-align: left; flex-shrink: 0; }
  .table-stack td.td-actions { justify-content: flex-end; border-top: 1px solid var(--color-border);
    margin-top: var(--space-1); padding-top: var(--space-2); }
  .table-stack td.dataTables_empty, .table-stack td.td-full { justify-content: center; text-align: center; }
  .table-stack td.dataTables_empty::before, .table-stack td.td-full::before { content: none; }
  .table-stack tr:hover > * { --bs-table-bg-state: transparent; }
  .card-table > .card-body { padding: var(--space-2); background: transparent; }
  .card-table { background: transparent; border: 0; box-shadow: none; }
  .dataTables_wrapper .row { --bs-gutter-x: 0; }
}

/* ── 7. Modals (the CRM's glass panel) ────────────────────────────────── */
.modal          { z-index: var(--z-modal); overscroll-behavior: contain; }
.modal-backdrop { z-index: calc(var(--z-modal) - 1); }
.modal-backdrop.show {
  opacity: 1; background: var(--modal-backdrop-overlay);
  -webkit-backdrop-filter: blur(var(--modal-backdrop-blur)) saturate(180%);
  backdrop-filter: blur(var(--modal-backdrop-blur)) saturate(180%);
}
.modal-content {
  background: var(--modal-glass-bg); border: 1px solid var(--modal-border); border-radius: var(--radius-xl);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--modal-shadow), 0 8px 32px rgba(var(--color-action-rgb), .12);
  animation: modal-in var(--t-slide) both;
}
.modal-header { padding: var(--space-5) var(--space-6) var(--space-4); border-bottom: 1px solid var(--bs-border-color); }
.modal-header .modal-title {
  font-family: var(--font-heading); font-weight: 700; font-size: 1.2rem; letter-spacing: -.02em;
  display: flex; align-items: center; gap: var(--space-2); color: var(--modal-title-color);
}
.modal-header .btn-close {
  width: var(--tap-min); height: var(--tap-min); border-radius: var(--radius-md); background-color: rgba(var(--color-black-rgb), .05);
  opacity: .6; margin: calc(var(--space-1) * -1) calc(var(--space-1) * -1) calc(var(--space-1) * -1) auto;
  transition: transform var(--t-standard), opacity var(--t-standard), background-color var(--t-standard);
}
.modal-header .btn-close:hover { background-color: rgba(var(--color-danger-rgb), .1); opacity: 1; transform: rotate(90deg); }
[data-bs-theme="dark"] .modal-header .btn-close { background-color: rgba(var(--color-white-rgb), .06); }
.modal-body { padding: var(--space-5) var(--space-6); overscroll-behavior: contain; }
.modal-body h6, .modal-body .section-label:first-child { margin-top: 0; }
.modal-footer { padding: var(--space-4) var(--space-6) var(--space-5); gap: var(--space-2);
  border-top: 1px solid var(--bs-border-color); }
.modal-footer > * { margin: 0; }
.modal .form-control, .modal .form-select { border-width: 1.5px; border-radius: var(--radius-md); }
.modal .form-control:focus, .modal .form-select:focus {
  border-color: var(--color-action); box-shadow: 0 0 0 3px rgba(var(--color-action-rgb), .15);
}
.modal .form-label { font-weight: 600; font-size: .85rem; }
.modal .modal-footer .btn { border-radius: var(--radius-md); min-height: var(--tap-min); padding-left: var(--space-5);
  padding-right: var(--space-5); font-weight: 600; }
.modal .modal-footer .btn-primary { background: var(--gradient-hero); border: 0;
  box-shadow: 0 4px 14px rgba(var(--color-action-rgb), .3); }
@media (max-width: 575.98px) {
  .modal-fullscreen-sm-down .modal-content { border-radius: 0; border: 0; }
  .modal-fullscreen-sm-down .modal-footer .btn { flex: 1 1 0; min-height: var(--tap-primary); }
}
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(20px); } to { opacity: 1; transform: none; } }

/* ── 8. Sign-in pages (login, SSO, reset, invite) ─────────────────────── */
.auth-shell { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: var(--space-4); position: relative; overflow: hidden; }
.auth-shell::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 42vh; background: var(--gradient-hero);
  z-index: 0; }
.auth-wrap { width: 100%; max-width: 440px; position: relative; z-index: 1; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  color: var(--color-white); text-decoration: none; margin-bottom: var(--space-5); }
.auth-brand .brand-name small { color: rgba(var(--color-white-rgb), .75); }
.auth-card { border-radius: var(--radius-xl); border: 1px solid var(--color-border); background: var(--bs-body-bg);
  box-shadow: var(--shadow-elevation-3); padding: var(--space-6); }
@media (min-width: 576px) { .auth-card { padding: var(--space-8); } }
.auth-card .auth-icon { width: 52px; height: 52px; border-radius: var(--radius-lg); margin: 0 auto var(--space-3);
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  background: rgba(var(--color-action-rgb), .1); color: var(--color-action); }
[data-bs-theme="dark"] .auth-card .auth-icon { color: var(--color-action-lighter); }
.auth-card .auth-title { font-size: 1.35rem; font-weight: 700; margin-bottom: var(--space-1); }
.auth-card .auth-sub { color: var(--bs-secondary-color); font-size: .875rem; }
.auth-card .form-label { font-weight: 600; font-size: .85rem; }
.auth-card .btn { min-height: var(--tap-primary); }
.auth-card .btn-link { min-height: var(--tap-min); }
.auth-app-pill { display: inline-flex; align-items: center; gap: var(--space-1); padding: 3px 10px;
  border-radius: var(--radius-xl); background: var(--pill-open-bg); color: var(--pill-open-fg);
  font-size: .75rem; font-weight: 700; letter-spacing: .04em; }
.auth-divider { display: flex; align-items: center; gap: var(--space-3); color: var(--bs-secondary-color);
  font-size: .8rem; margin: var(--space-4) 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--color-border); }
.auth-footer { text-align: center; font-size: .75rem; color: var(--bs-secondary-color); margin-top: var(--space-4); }
.auth-theme-toggle { position: absolute; top: var(--space-4); right: var(--space-4); z-index: 2;
  background: rgba(var(--color-white-rgb), .15); border-color: rgba(var(--color-white-rgb), .3); color: var(--color-white); }
.auth-theme-toggle:hover { background: rgba(var(--color-white-rgb), .25); color: var(--color-white); }
.org-choice { min-height: var(--tap-primary); }
.org-choice img { width: 28px; height: 28px; object-fit: contain; }
.otp-input { font-family: var(--font-mono); font-size: 1.5rem; letter-spacing: .4em; text-align: center; }

/* ── 9. Public pages (landing, docs) ──────────────────────────────────── */
.public-nav { background: var(--bs-body-bg); border-bottom: 1px solid var(--color-border); }
.public-nav .navbar-brand { font-family: var(--font-heading); font-weight: 700; }
.landing-hero { background: var(--surface-sidebar); color: var(--color-white); position: relative; overflow: hidden; }
.landing-hero::before { content: ""; position: absolute; inset: -40% -10% auto auto; width: 70%; height: 140%;
  background: var(--gradient-hero); opacity: .35; filter: blur(80px); border-radius: var(--radius-circle); }
.landing-hero > .container { position: relative; }
.landing-hero .eyebrow { color: var(--color-brand-light); }
.feature-card { min-height: 100%; transition: transform var(--t-micro), box-shadow var(--t-micro); }
.feature-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-elevation-2); }
.step-num { width: var(--tap-min); height: var(--tap-min); display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-circle); font-weight: 700; background: rgba(var(--color-action-rgb), .12); color: var(--color-action); }
.api-status .spinner-border { width: 1rem; height: 1rem; }

.docs-nav { min-height: calc(100vh - var(--navbar-height)); }
.docs-nav .nav-link { border-radius: var(--radius-sm); color: var(--bs-body-color); min-height: 36px; display: flex; align-items: center; }
.docs-nav .nav-link:hover { background: var(--bs-tertiary-bg); color: var(--color-action); }
.docs-nav .nav-link.active { background: rgba(var(--color-action-rgb), .1); color: var(--color-action); font-weight: 600; }
.docs-content { max-width: 860px; line-height: 1.65; }
.docs-content h1 { font-size: 1.75rem; padding-bottom: var(--space-2); border-bottom: 1px solid var(--bs-border-color); }
.docs-content h2 { font-size: 1.35rem; }
.docs-content h3 { font-size: 1.1rem; }
.docs-content h1, .docs-content h2 { font-weight: 700; }
.docs-content h1, .docs-content h2, .docs-content h3 { margin-top: var(--space-8); }
.docs-content h1:first-child { margin-top: 0; }
.docs-content pre { background: var(--surface-code); color: var(--color-n100); padding: var(--space-4);
  border-radius: var(--radius-md); overflow-x: auto; font-size: .85rem; }
.docs-content code { font-size: .85em; }
.docs-content pre code { color: inherit; font-size: .85rem; }
.docs-content table { width: 100%; margin: var(--space-4) 0; border-collapse: collapse; font-size: .9rem; display: block; overflow-x: auto; }
.docs-content table th, .docs-content table td { border: 1px solid var(--bs-border-color); padding: var(--space-2) var(--space-3); }
.docs-content table th { background: var(--bs-tertiary-bg); }
.docs-content blockquote { border-left: 4px solid var(--color-action); padding: var(--space-1) var(--space-4); color: var(--bs-secondary-color); }
.docs-content hr { opacity: .15; }
.docs-content a { text-decoration: none; }
