/* ============================================================
   Atlas — v2 design language · page skin
   --------------------------------------------------------------
   Drop this into any page's $pageStylesheets *after* the Atlas
   Tailwind bundle and Bootstrap. It supplies:

     1. CSS variables for the cool, sky-led palette
     2. Bootstrap surface / border / text rescues for dark mode
     3. Form-control, button, alert, modal uplifts
     4. The atlas motif primitives (hero, btn-pill-gradient,
        avatar bubble, chip, tag, health-bar, kpi-card, panel,
        topbar, bulkbar, pagination, shadow utilities)

   Last edited 2026-05-13. Source of truth: docs/design-system-v2.md.
   ============================================================ */


/* ============================================================
   §1 · Design tokens
   ============================================================ */

:root {
  /* Surfaces */
  --sa-bg:          #F4F7FB;
  --sa-surface:     #FFFFFF;
  --sa-surface-2:   #EEF3F8;
  --sa-surface-3:   #E1E8F0;

  /* Borders */
  --sa-border:      #DBE2EC;
  --sa-border-soft: rgba(15, 23, 42, .07);

  /* Ink */
  --sa-text:        #0F172A;
  --sa-text-muted:  #64748B;
  --sa-text-dim:    #475569;

  /* Brand · sky */
  --sa-brand:        #0EA5E9;
  --sa-brand-strong: #0369A1;
  --sa-brand-soft:   #E0F2FE;
  --sa-brand-glow:   rgba(14, 165, 233, .26);

  /* Accent · plum (focus, selected highlight) */
  --sa-accent:       #7C3AED;
  --sa-accent-soft:  #F1E8FE;
  --sa-accent-text:  #5B21B6;

  /* Semantic */
  --sa-success:      #0F9E76;
  --sa-success-soft: #DCFAEF;
  --sa-success-text: #065F46;

  --sa-warning:      #D97706;
  --sa-warning-soft: #FFF1D6;
  --sa-warning-text: #8A4B00;

  --sa-danger:       #D72660;
  --sa-danger-soft:  #FFE3EC;
  --sa-danger-text:  #9C1840;

  --sa-info:         #0369A1;
  --sa-info-soft:    #DCF1FF;
  --sa-info-text:    #075985;

  /* Signature gradient (hero blob, gradient pill, active chip) */
  --sa-gradient-brand: linear-gradient(135deg, #7DD3FC 0%, #0EA5E9 45%, #6366F1 100%);

  /* Shadows */
  --sa-shadow-soft: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -8px rgba(15, 23, 42, .10);
  --sa-shadow-lift: 0 2px 4px rgba(15, 23, 42, .05), 0 16px 32px -10px rgba(15, 23, 42, .14);
  --sa-shadow-glow: 0 8px 24px -8px var(--sa-brand-glow);
  --sa-shadow-pop:  0 12px 32px rgba(15, 23, 42, .18);

  color-scheme: light;
}

html.dark {
  --sa-bg:          #070C1A;
  --sa-surface:     #0F172A;
  --sa-surface-2:   #152033;
  --sa-surface-3:   #1E293B;

  --sa-border:      #1E293B;
  --sa-border-soft: rgba(255, 255, 255, .06);

  --sa-text:        #E2E8F0;
  --sa-text-muted:  #94A3B8;
  --sa-text-dim:    #CBD5E1;

  --sa-brand:        #38BDF8;
  --sa-brand-strong: #7DD3FC;
  --sa-brand-soft:   rgba(56, 189, 248, .14);
  --sa-brand-glow:   rgba(56, 189, 248, .32);

  --sa-accent:       #A78BFA;
  --sa-accent-soft:  rgba(167, 139, 250, .14);
  --sa-accent-text:  #C4B5FD;

  --sa-success:      #34D399;
  --sa-success-soft: rgba(52, 211, 153, .14);
  --sa-success-text: #6EE7B7;

  --sa-warning:      #FBBF24;
  --sa-warning-soft: rgba(251, 191, 36, .14);
  --sa-warning-text: #FDE68A;

  --sa-danger:       #F472B6;
  --sa-danger-soft:  rgba(244, 114, 182, .14);
  --sa-danger-text:  #FBCFE8;

  --sa-info:         #38BDF8;
  --sa-info-soft:    rgba(56, 189, 248, .14);
  --sa-info-text:    #7DD3FC;

  --sa-shadow-soft: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -8px rgba(0, 0, 0, .5);
  --sa-shadow-lift: 0 2px 4px rgba(0, 0, 0, .4), 0 16px 32px -10px rgba(0, 0, 0, .6);

  color-scheme: dark;
}


/* ============================================================
   §2 · Base
   ============================================================ */

html, body {
  background: var(--sa-bg);
  color: var(--sa-text);
}
body {
  /* Phones blow horizontal-scroll the moment any descendant declares a
     fixed width larger than the viewport (legacy `.btn-group`, wide
     tables before they hit their `.table-responsive` wrapper, etc.).
     Pinning the body to the viewport width keeps a single wide child
     from dragging the whole page sideways. Individual scrollers
     (tables, code blocks) still scroll inside their own wrappers.
     Kept off `html` so `position: fixed` topbar / sidebar continue
     to use the viewport as their containing block on iOS Safari. */
  overflow-x: hidden;
}
body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Atlas chrome relies on flexbox + CSS grid heavily. The default flex
   item `min-width: auto` lets long words / inline content push the row
   wider than the viewport. Reset the standard atlas shells so children
   are free to shrink to fit. */
main,
section,
.atlas-hero,
.atlas-panel,
.atlas-kpi,
.atlas-modal-card { min-width: 0; }

/* Hard cap: every direct page section must fit inside the viewport.
   Without this, a single legacy widget (Bootstrap `.btn-group`, a 1024-px
   chart canvas, a wide table without `.table-responsive`) can dilate the
   document to its natural width — iOS Safari then auto-scales the whole
   page down to fit, leaving everything looking like a shrunken desktop
   view. The cap pins each layout root to `100vw`; legitimate scrollers
   (table wrappers, code blocks) still scroll inside their box. */
main,
main > section,
main > div,
.atlas-hero,
.atlas-panel,
.atlas-kpi { max-width: 100%; }

/* Bootstrap leftovers that ship inside migrated pages — these are the
   most common culprits behind desktop-width rendering on phones. Cap
   them and let their children wrap so nothing pushes wider than its
   flex row. */
.btn-group,
.input-group { min-width: 0; max-width: 100%; flex-wrap: wrap; }

/* Tables without an explicit `.table-responsive` / `overflow-x` wrapper
   should still constrain themselves to their column. */
main table { max-width: 100%; }

/* Selection */
::selection { background: var(--sa-brand-soft); color: var(--sa-brand-strong); }

/* Slim scrollbars (WebKit) — opt-in via .scrollbar-thin */
.scrollbar-thin { scrollbar-width: thin; scrollbar-color: var(--sa-border) transparent; }
.scrollbar-thin::-webkit-scrollbar           { width: 10px; height: 10px; }
.scrollbar-thin::-webkit-scrollbar-track     { background: transparent; }
.scrollbar-thin::-webkit-scrollbar-thumb     { background: var(--sa-border); border-radius: 9999px; border: 2px solid transparent; background-clip: content-box; }
.scrollbar-thin::-webkit-scrollbar-thumb:hover { background: var(--sa-text-muted); background-clip: content-box; border: 2px solid transparent; }


/* ============================================================
   §3 · Bootstrap dark-mode rescues
   --------------------------------------------------------------
   Bootstrap utilities ship with !important. The dark variants
   must also be !important to win the cascade.
   ============================================================ */

html.dark .bg-white,
html.dark .bg-body,
html.dark .bg-light {
  background: var(--sa-surface) !important;
}
html.dark .border,
html.dark .border-top,
html.dark .border-end,
html.dark .border-bottom,
html.dark .border-start {
  border-color: var(--sa-border) !important;
}
html.dark .text-body          { color: var(--sa-text) !important; }
html.dark .text-muted,
html.dark .text-body-secondary { color: var(--sa-text-muted) !important; }
html.dark .text-secondary      { color: var(--sa-text-dim) !important; }


/* ============================================================
   §4 · Form controls
   ============================================================ */

.form-control,
.form-select {
  background-color: var(--sa-surface);
  color: var(--sa-text);
  border-color: var(--sa-border);
  border-radius: 0.75rem;          /* 12px — atlas radius for inputs */
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.form-control::placeholder { color: var(--sa-text-muted); opacity: .9; }
.form-control:focus,
.form-select:focus {
  background-color: var(--sa-surface);
  color: var(--sa-text);
  border-color: var(--sa-accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .25);  /* plum focus halo */
}

html.dark .form-control,
html.dark .form-select {
  background-color: var(--sa-surface) !important;
  color: var(--sa-text) !important;
  border-color: var(--sa-border) !important;
}
html.dark .form-control::placeholder { color: var(--sa-text-muted) !important; }
html.dark .form-control:disabled,
html.dark .form-select:disabled {
  background-color: var(--sa-surface-2) !important;
  color: var(--sa-text-muted) !important;
}

.form-check-input {
  border-color: var(--sa-border);
}
.form-check-input:checked {
  background-color: var(--sa-brand);
  border-color: var(--sa-brand);
}
.form-check-input:focus {
  border-color: var(--sa-accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .25);
}


/* ============================================================
   §5 · Bootstrap buttons (legacy markup still works)
   ============================================================ */

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--sa-brand);
  --bs-btn-border-color: var(--sa-brand);
  --bs-btn-hover-bg: var(--sa-brand-strong);
  --bs-btn-hover-border-color: var(--sa-brand-strong);
  --bs-btn-active-bg: var(--sa-brand-strong);
  --bs-btn-active-border-color: var(--sa-brand-strong);
  --bs-btn-disabled-bg: var(--sa-brand);
  --bs-btn-disabled-border-color: var(--sa-brand);
}
.btn-outline-primary {
  --bs-btn-color: var(--sa-brand-strong);
  --bs-btn-border-color: var(--sa-brand);
  --bs-btn-hover-bg: var(--sa-brand-soft);
  --bs-btn-hover-color: var(--sa-brand-strong);
  --bs-btn-hover-border-color: var(--sa-brand);
  --bs-btn-active-bg: var(--sa-brand-soft);
  --bs-btn-active-color: var(--sa-brand-strong);
}
.btn-outline-secondary {
  --bs-btn-color: var(--sa-text-dim);
  --bs-btn-border-color: var(--sa-border);
  --bs-btn-hover-bg: var(--sa-surface-2);
  --bs-btn-hover-color: var(--sa-text);
  --bs-btn-hover-border-color: var(--sa-border);
}


/* ============================================================
   §6 · Alerts (dark-mode tone rescues)
   ============================================================ */

html.dark .alert-info {
  background-color: var(--sa-info-soft) !important;
  border-color: rgba(56, 189, 248, .25) !important;
  color: var(--sa-info-text) !important;
}
html.dark .alert-success {
  background-color: var(--sa-success-soft) !important;
  border-color: rgba(52, 211, 153, .25) !important;
  color: var(--sa-success-text) !important;
}
html.dark .alert-warning {
  background-color: var(--sa-warning-soft) !important;
  border-color: rgba(251, 191, 36, .25) !important;
  color: var(--sa-warning-text) !important;
}
html.dark .alert-danger {
  background-color: var(--sa-danger-soft) !important;
  border-color: rgba(244, 114, 182, .25) !important;
  color: var(--sa-danger-text) !important;
}


/* ============================================================
   §7 · Modal uplift
   ============================================================ */

.modal-content {
  background-color: var(--sa-surface);
  color: var(--sa-text);
  border: 1px solid var(--sa-border);
  border-radius: 1rem;             /* 16px — atlas modal radius */
  box-shadow: 0 30px 60px rgba(15, 23, 42, .25);
}
.modal-header,
.modal-footer {
  border-color: var(--sa-border);
}
html.dark .modal-content {
  background-color: var(--sa-surface) !important;
  border-color: var(--sa-border) !important;
  color: var(--sa-text) !important;
}
html.dark .modal-header,
html.dark .modal-footer {
  border-color: var(--sa-border) !important;
}

/* ----- Atlas modal scaffold (shared by every includes/*_modal.php).
   Previously these rules lived only inside includes/approval_modal.php,
   which the header chain conditionally included for admin/superadmin
   only. Pages opened by other roles (tellers, accountants, etc.) loaded
   the modal markup without the matching CSS, so dependent modals like
   request_modal.php and credit_sale_discount_modal.php rendered as
   plain inline text. Loading the scaffold here keeps every Atlas page
   covered regardless of role. ----- */
.atlas-modal-backdrop {
  position: fixed !important;
  top: 0 !important; right: 0 !important; bottom: 0 !important; left: 0 !important;
  width: 100vw; height: 100vh;
  z-index: 1100;
  background: rgba(15, 23, 42, .55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: none; overflow-y: auto;
  padding: 2rem 1rem; box-sizing: border-box;
}
.atlas-modal-backdrop.is-open { display: block; }
.atlas-modal-card {
  position: relative;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 18px;
  width: 100%; max-width: 720px;
  margin: 0 auto;
  box-shadow: 0 24px 56px rgba(15, 23, 42, .28);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 4rem);
  overflow: hidden;
}
.atlas-modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--sa-border);
  background: linear-gradient(135deg, var(--sa-info-soft) 0%, transparent 65%);
}
.atlas-modal-chip {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--sa-info-soft); color: var(--sa-info-text);
  font-size: 1rem; flex: 0 0 auto;
}
.atlas-modal-title { font-weight: 800; font-size: 1.02rem; color: var(--sa-text); line-height: 1.2; }
.atlas-modal-sub   { font-size: .8rem; color: var(--sa-text-muted); margin-top: .15rem; }
.atlas-modal-close {
  width: 32px; height: 32px; border-radius: 9999px;
  display: grid; place-items: center;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface); color: var(--sa-text-muted);
  cursor: pointer; transition: background .15s ease, color .15s ease;
  flex: 0 0 auto;
}
.atlas-modal-close:hover { background: var(--sa-surface-2); color: var(--sa-text); }
.atlas-modal-body { padding: 1.25rem; overflow-y: auto; flex: 1 1 auto; }
.atlas-modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: .5rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--sa-border);
  background: var(--sa-surface);
}
body.atlas-modal-open { overflow: hidden; }

/* Modal-head sub-elements used by stepup_modal / request_modal /
   credit_sale_discount_modal. Each modal still applies its own
   gradient via a prefixed selector (.arm-head, .sum-head, .csdm-head). */
.atlas-modal-head-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-size: 1rem; flex: 0 0 auto;
}
.atlas-modal-head-text  { min-width: 0; flex: 1 1 auto; }
.atlas-modal-head-title { font-weight: 800; font-size: 1.02rem; color: var(--sa-text); line-height: 1.2; }
.atlas-modal-head-sub   { font-size: .8rem; color: var(--sa-text-muted); margin-top: .15rem; }


/* ============================================================
   §8 · Topbar
   ============================================================ */

.atlas-topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--sa-surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--sa-border);
}
.atlas-topbar-logo {
  height: 38px; width: 38px;
  border-radius: 12px;
  background: var(--sa-gradient-brand);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: var(--sa-shadow-glow);
  flex: 0 0 auto;
}
.atlas-topbar-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .9rem; border-radius: 9999px;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface);
  color: var(--sa-text-dim);
  font-size: .82rem; font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.atlas-topbar-pill:hover { background: var(--sa-surface-2); color: var(--sa-text); }
.atlas-topbar-pill i { font-size: .78rem; opacity: .85; }
.atlas-topbar-pill-brand  { border-color: var(--sa-brand); color: var(--sa-brand-strong); }
.atlas-topbar-pill-brand:hover { background: var(--sa-brand-soft); color: var(--sa-brand-strong); }
.atlas-topbar-pill-amber  { border-color: var(--sa-warning); color: var(--sa-warning-text); background: var(--sa-warning-soft); }
.atlas-topbar-pill-amber:hover { background: var(--sa-warning-soft); filter: brightness(.97); }
.atlas-topbar-pill-rose   { border-color: var(--sa-danger); color: var(--sa-danger-text); }
.atlas-topbar-pill-rose:hover { background: var(--sa-danger-soft); }


/* ============================================================
   §9 · Hero
   ============================================================ */

.atlas-hero {
  position: relative; overflow: hidden;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 24px;
  box-shadow: var(--sa-shadow-soft);
  padding: 1.5rem 1.5rem 1.5rem 1.75rem;
}
.atlas-hero-blob {
  position: absolute; pointer-events: none;
  top: -90px; right: -70px;
  width: 340px; height: 340px;
  border-radius: 9999px;
  background: var(--sa-gradient-brand);
  filter: blur(60px);
  opacity: .35;
}
html.dark .atlas-hero-blob { opacity: .25; }

.atlas-hero-eyebrow {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .25rem .7rem; border-radius: 9999px;
  background: var(--sa-brand-soft); color: var(--sa-brand-strong);
  font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.atlas-page-title {
  font-size: 1.85rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em;
  margin: .6rem 0 0;
  background: var(--sa-gradient-brand);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.atlas-page-sub {
  color: var(--sa-text-muted); font-size: .9rem;
  margin-top: .5rem; max-width: 56ch;
}


/* ============================================================
   §10 · Buttons & icon button
   ============================================================ */

.btn-pill-gradient {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .68rem 1.35rem; border-radius: 9999px; border: 0;
  background: var(--sa-gradient-brand); color: #fff;
  font-weight: 700; font-size: .875rem; cursor: pointer;
  text-decoration: none;
  box-shadow: var(--sa-shadow-glow), 0 1px 0 rgba(255, 255, 255, .18) inset;
  transition: transform .12s ease, box-shadow .2s ease;
}
.btn-pill-gradient:hover {
  transform: translateY(-1px); color: #fff;
  box-shadow: 0 14px 28px -8px var(--sa-brand-glow), 0 1px 0 rgba(255, 255, 255, .18) inset;
}
.btn-pill-gradient:active { transform: translateY(0); }
.btn-pill-gradient:focus-visible {
  outline: 0;
  box-shadow: var(--sa-shadow-glow), 0 0 0 3px rgba(124, 58, 237, .35);
}

.btn-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem 1.05rem; border-radius: 9999px;
  border: 1px solid var(--sa-border); background: var(--sa-surface);
  color: var(--sa-text-dim); font-weight: 600; font-size: .82rem;
  cursor: pointer; text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-pill:hover { background: var(--sa-surface-2); color: var(--sa-text); }
.btn-pill:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(124, 58, 237, .25); }

.btn-pill-brand    { border-color: var(--sa-brand); color: var(--sa-brand-strong); }
.btn-pill-brand:hover { background: var(--sa-brand-soft); color: var(--sa-brand-strong); }
.btn-pill-amber    { border-color: var(--sa-warning); color: var(--sa-warning-text); background: var(--sa-warning-soft); }
.btn-pill-amber:hover { background: var(--sa-warning-soft); filter: brightness(.97); }
.btn-pill-rose     { border-color: var(--sa-danger); color: var(--sa-danger-text); }
.btn-pill-rose:hover { background: var(--sa-danger-soft); }
.btn-pill-emerald  { border-color: var(--sa-success); color: var(--sa-success-text); }
.btn-pill-emerald:hover { background: var(--sa-success-soft); }
.btn-pill-accent   { border-color: var(--sa-accent); color: var(--sa-accent-text); }
.btn-pill-accent:hover { background: var(--sa-accent-soft); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9999px;
  display: inline-grid; place-items: center;
  background: transparent; border: 1px solid var(--sa-border);
  color: var(--sa-text-dim); cursor: pointer; text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--sa-surface-2); color: var(--sa-text); }
.icon-btn-sm { width: 30px; height: 30px; }
.icon-btn-rose { color: var(--sa-danger-text); border-color: var(--sa-danger); }
.icon-btn-rose:hover { background: var(--sa-danger-soft); }

.badge-pill {
  display: inline-grid; place-items: center;
  height: 18px; min-width: 18px; padding: 0 5px;
  border-radius: 9999px;
  font-size: .65rem; font-weight: 800; line-height: 1;
  background: var(--sa-brand); color: #fff;
}
.badge-pill-amber { background: var(--sa-warning); color: #fff; }
.badge-pill-rose  { background: var(--sa-danger);  color: #fff; }


/* ============================================================
   §11 · Filter chips
   ============================================================ */

.atlas-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .9rem; border-radius: 9999px;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface); color: var(--sa-text-dim);
  font-size: .78rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .12s ease;
}
.atlas-chip:hover { background: var(--sa-surface-2); transform: translateY(-1px); color: var(--sa-text); }
.atlas-chip em    { font-style: normal; opacity: .65; font-weight: 700; }
.atlas-chip i     { font-size: .75rem; opacity: .85; }
.atlas-chip-active {
  border-color: transparent;
  background: var(--sa-gradient-brand);
  color: #fff;
  box-shadow: 0 6px 16px -6px var(--sa-brand-glow);
}
.atlas-chip-active em, .atlas-chip-active i { opacity: .85; color: #fff; }
.atlas-chip-active:hover { color: #fff; }


/* ============================================================
   §12 · Panel + KPI card
   ============================================================ */

.atlas-panel {
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 18px;
  box-shadow: var(--sa-shadow-soft);
}

.atlas-kpi {
  display: flex; align-items: center; gap: .85rem;
  padding: .9rem 1rem;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 18px;
  box-shadow: var(--sa-shadow-soft);
}
.atlas-kpi-chip {
  flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--sa-brand-soft); color: var(--sa-brand-strong);
  font-size: 1.05rem;
}
.atlas-kpi-chip.tone-accent  { background: var(--sa-accent-soft);  color: var(--sa-accent-text); }
.atlas-kpi-chip.tone-success { background: var(--sa-success-soft); color: var(--sa-success-text); }
.atlas-kpi-chip.tone-warning { background: var(--sa-warning-soft); color: var(--sa-warning-text); }
.atlas-kpi-chip.tone-danger  { background: var(--sa-danger-soft);  color: var(--sa-danger-text); }
.atlas-kpi-chip.tone-info    { background: var(--sa-info-soft);    color: var(--sa-info-text); }
.atlas-kpi-label {
  font-size: .68rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--sa-text-muted); font-weight: 700;
}
.atlas-kpi-value {
  font-size: 1.35rem; font-weight: 800; color: var(--sa-text);
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}


/* ============================================================
   §13 · Avatar bubbles
   --------------------------------------------------------------
   Deterministic 6-gradient palette. Server-side pick the class
   via helpers/atlas.php::atlas_avatar_class($name).
   ============================================================ */

.atlas-avatar {
  width: 44px; height: 44px; border-radius: 9999px;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: .92rem; letter-spacing: .02em;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .10), 0 4px 10px -4px rgba(0, 0, 0, .18);
  flex: 0 0 auto;
}
.atlas-avatar-sm { width: 32px; height: 32px; font-size: .72rem; }
.atlas-avatar-lg { width: 56px; height: 56px; font-size: 1.15rem; }
.atlas-avatar.g-1 { background: linear-gradient(135deg, #38BDF8, #3730A3); } /* sky → indigo */
.atlas-avatar.g-2 { background: linear-gradient(135deg, #22D3EE, #0F766E); } /* cyan → teal */
.atlas-avatar.g-3 { background: linear-gradient(135deg, #A78BFA, #6D28D9); } /* lilac → violet */
.atlas-avatar.g-4 { background: linear-gradient(135deg, #34D399, #047857); } /* mint → emerald */
.atlas-avatar.g-5 { background: linear-gradient(135deg, #3B82F6, #1E3A8A); } /* blue → navy */
.atlas-avatar.g-6 { background: linear-gradient(135deg, #06B6D4, #4338CA); } /* cyan → indigo */


/* ============================================================
   §14 · Tag pills
   ============================================================ */

.atlas-tag {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .15rem .55rem; border-radius: 9999px;
  font-size: .65rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
}
.atlas-tag-credit    { background: var(--sa-brand-soft);   color: var(--sa-brand-strong); }
.atlas-tag-cash      { background: var(--sa-surface-3);    color: var(--sa-text-dim); }
.atlas-tag-deposit   { background: var(--sa-accent-soft);  color: var(--sa-accent-text); }
.atlas-tag-active    { background: var(--sa-success-soft); color: var(--sa-success-text); }
.atlas-tag-inactive  { background: var(--sa-danger-soft);  color: var(--sa-danger-text); }
.atlas-tag-pending   { background: var(--sa-warning-soft); color: var(--sa-warning-text); }
.atlas-tag-info      { background: var(--sa-info-soft);    color: var(--sa-info-text); }
.atlas-tag-vip       { background: linear-gradient(135deg, #6366F1, #7C3AED); color: #fff; }
.atlas-tag-custom    { background: var(--sa-accent-soft);  color: var(--sa-accent-text); }


/* ============================================================
   §15 · Health-bar (credit utilisation, etc.)
   ============================================================ */

.atlas-health        { display: block; }
.atlas-health-head   {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .72rem; color: var(--sa-text-muted);
}
.atlas-health-head .v {
  color: var(--sa-text); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.atlas-health-bar {
  position: relative; height: 10px; border-radius: 9999px;
  background: var(--sa-surface-3); overflow: hidden;
  margin-top: .35rem;
}
.atlas-health-bar > span {
  display: block; height: 100%; border-radius: 9999px;
  background: linear-gradient(90deg, #0F9E76, #14B8A6);
  transition: width .3s ease;
}
.atlas-health-bar[data-state="warn"] > span { background: linear-gradient(90deg, #F2B23A, #EA580C); }
.atlas-health-bar[data-state="over"] > span { background: linear-gradient(90deg, #EA580C, #D72660); }


/* ============================================================
   §16 · Deposit pill (compact "Deposit on file" badge)
   ============================================================ */

.atlas-deposit-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .35rem .75rem; border-radius: 9999px;
  background: var(--sa-accent-soft); color: var(--sa-accent-text);
  font-size: .78rem; font-weight: 700;
}
.atlas-deposit-pill .v { font-variant-numeric: tabular-nums; font-weight: 800; }


/* ============================================================
   §17 · Custom form primitives (alternative to Bootstrap)
   ============================================================ */

.atlas-field        { display: block; }
.atlas-field-label  {
  display: block; font-size: .7rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--sa-text-muted); margin-bottom: .35rem;
}
.atlas-input-wrap   { position: relative; }
.atlas-input,
.atlas-select {
  width: 100%; padding: .65rem .9rem; border-radius: 12px;
  border: 1px solid var(--sa-border); background: var(--sa-surface);
  color: var(--sa-text); font-size: .88rem;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.atlas-input::placeholder { color: var(--sa-text-muted); opacity: .9; }
.atlas-input:focus,
.atlas-select:focus {
  outline: 0; border-color: var(--sa-accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .25);
}
.atlas-input-icon-left  { padding-left: 2.3rem; }
.atlas-input-icon-right { padding-right: 2.3rem; }
.atlas-input-icon {
  position: absolute; top: 50%; transform: translateY(-50%);
  color: var(--sa-text-muted); font-size: .9rem;
}
.atlas-input-icon.left  { left: .85rem; }
.atlas-input-icon.right { right: .85rem; cursor: pointer; }


/* ============================================================
   §18 · Bulk action bar
   ============================================================ */

.atlas-bulkbar {
  border-radius: 18px;
  background: linear-gradient(135deg, var(--sa-brand-soft), var(--sa-accent-soft));
  border: 1px solid color-mix(in srgb, var(--sa-brand) 30%, var(--sa-border));
  padding: .85rem 1rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.atlas-bulkbar-count {
  font-weight: 800; color: var(--sa-brand-strong);
  font-variant-numeric: tabular-nums;
}


/* ============================================================
   §19 · Pagination
   ============================================================ */

.atlas-pgn { display: inline-flex; align-items: center; gap: .25rem; }
.atlas-pgn a,
.atlas-pgn span {
  min-width: 32px; height: 32px; padding: 0 .55rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9999px; border: 1px solid var(--sa-border);
  background: var(--sa-surface); color: var(--sa-text-dim);
  font-size: .8rem; font-weight: 700;
  font-variant-numeric: tabular-nums; text-decoration: none;
  transition: background .15s ease;
}
.atlas-pgn a:hover { background: var(--sa-surface-2); color: var(--sa-text); }
.atlas-pgn .current {
  border-color: transparent;
  background: var(--sa-gradient-brand); color: #fff;
  box-shadow: 0 4px 12px -4px var(--sa-brand-glow);
}
.atlas-pgn .gap { border: 0; background: transparent; cursor: default; color: var(--sa-text-muted); }
.atlas-pgn a[aria-disabled="true"] { opacity: .4; pointer-events: none; }


/* ============================================================
   §20 · Shadow utilities (also generated as Tailwind utilities,
   but useful when you want to apply them via plain class names)
   ============================================================ */

.shadow-atlas-soft { box-shadow: var(--sa-shadow-soft); }
.shadow-atlas-lift { box-shadow: var(--sa-shadow-lift); }
.shadow-atlas-glow { box-shadow: var(--sa-shadow-glow); }
.shadow-atlas-pop  { box-shadow: var(--sa-shadow-pop);  }


/* ============================================================
   §21 · Misc
   ============================================================ */

.atlas-ring-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--sa-border), transparent);
  margin: 1.25rem 0;
}


/* ============================================================
   §22 · Entity card (customer/supplier/item)
   ============================================================ */

.atlas-card {
  position: relative;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 18px;
  box-shadow: var(--sa-shadow-soft);
  padding: 1rem 1rem 0.85rem;
  transition: transform .15s ease, box-shadow .2s ease, border-color .15s ease;
}
.atlas-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sa-shadow-lift);
  border-color: color-mix(in srgb, var(--sa-brand) 28%, var(--sa-border));
}
.atlas-card.is-inactive  { opacity: .72; }
.atlas-card.is-overlimit { border-color: color-mix(in srgb, var(--sa-danger) 30%, var(--sa-border)); }

.atlas-card-name {
  font-size: 1rem; font-weight: 700;
  color: var(--sa-text); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none;
}
.atlas-card-name:hover { color: var(--sa-brand-strong); }
.atlas-card-sub {
  font-size: .76rem; color: var(--sa-text-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.atlas-contact {
  margin-top: .75rem;
  background: var(--sa-surface-2);
  border: 1px solid var(--sa-border-soft);
  border-radius: 12px;
  padding: .55rem .7rem;
  font-size: .82rem;
}
.atlas-contact a       { color: var(--sa-text); text-decoration: none; }
.atlas-contact a:hover { color: var(--sa-brand-strong); }
.atlas-contact i       { color: var(--sa-text-muted); width: 14px; text-align: center; }
.atlas-contact .wa     { color: var(--sa-success); margin-left: .35rem; }

.atlas-card-actions {
  margin-top: .9rem; padding-top: .75rem;
  border-top: 1px dashed var(--sa-border);
  display: flex; gap: .35rem; flex-wrap: wrap; align-items: center;
}
.atlas-card-actions .spacer { margin-left: auto; }

/* Hover tooltip for compact action-row buttons */
.atlas-card-actions .icon-btn[data-tip] {
  position: relative;
  --tip-bg: #0F172A;
  --tip-fg: #FFFFFF;
}
html.dark .atlas-card-actions .icon-btn[data-tip] {
  --tip-bg: #E2E8F0;
  --tip-fg: #0F172A;
}
.atlas-card-actions .icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--tip-bg);
  color: var(--tip-fg);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.atlas-card-actions .icon-btn[data-tip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 5px solid transparent;
  border-top-color: var(--tip-bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 50;
}
.atlas-card-actions .icon-btn[data-tip]:hover::after,
.atlas-card-actions .icon-btn[data-tip]:hover::before,
.atlas-card-actions .icon-btn[data-tip]:focus-visible::after,
.atlas-card-actions .icon-btn[data-tip]:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ============================================================
   §23 · Empty state
   ============================================================ */

.atlas-empty {
  border-radius: 18px;
  border: 1px dashed var(--sa-border);
  padding: 2.5rem 1rem;
  text-align: center;
  background: var(--sa-surface);
}
.atlas-empty i {
  font-size: 1.75rem;
  color: var(--sa-text-muted);
  opacity: .5;
}
.atlas-empty p {
  margin: .75rem 0 .25rem;
  color: var(--sa-text-muted);
  font-size: .9rem;
}


/* ============================================================
   §24 · Reduced motion + print
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .btn-pill-gradient,
  .btn-pill,
  .atlas-chip,
  .icon-btn,
  .form-control,
  .form-select,
  .atlas-card { transition: none; }
  .btn-pill-gradient:hover { transform: none; }
  .atlas-chip:hover        { transform: none; }
  .atlas-card:hover        { transform: none; }
}

@media print {
  .atlas-topbar,
  .atlas-hero-blob,
  .btn-pill-gradient,
  .btn-pill,
  .atlas-bulkbar { display: none !important; }
  .atlas-hero,
  .atlas-panel,
  .atlas-kpi { box-shadow: none !important; border: 1px solid #999 !important; }
  body { background: #fff !important; color: #000 !important; }
}


/* ============================================================
   §25 · Mobile responsiveness baseline (≤ 640px)
   --------------------------------------------------------------
   Defaults assume desktop; this block shrinks the chrome so
   pages remain usable in the header's mobile offcanvas viewport.
   Page-specific overrides should still use Tailwind `sm:` /
   `md:` variants (see docs/design-system-v2.md §12).

   Breakpoints we standardise on (match Tailwind defaults):
     - sm  640px   (phone landscape / large phone)
     - md  768px   (tablet)
     - lg  1024px  (small laptop)
     - xl  1280px  (desktop)
     - 2xl 1536px  (wide desktop)
   ============================================================ */

@media (max-width: 640px) {
  /* Hero: less padding, smaller title, hidden blob to keep file size sane */
  .atlas-hero {
    padding: 1rem 1rem 1.05rem 1.1rem;
    border-radius: 18px;
  }
  .atlas-page-title {
    font-size: 1.45rem;
    line-height: 1.1;
    word-break: break-word;       /* long invoice numbers / names */
    overflow-wrap: anywhere;
  }
  .atlas-page-sub {
    font-size: .85rem;
    max-width: 100%;
  }
  .atlas-hero-eyebrow {
    font-size: .65rem;
    padding: .2rem .55rem;
  }
  .atlas-hero-blob {
    /* Keep the gradient flourish but smaller and softer on tiny screens. */
    width: 220px; height: 220px;
    top: -70px; right: -50px;
    opacity: .22;
  }

  /* KPI: a touch tighter so values don't wrap weirdly */
  .atlas-kpi {
    padding: .75rem .85rem;
    gap: .65rem;
    border-radius: 14px;
  }
  .atlas-kpi-chip {
    width: 38px; height: 38px;
    border-radius: 12px;
    font-size: .95rem;
  }
  .atlas-kpi-label { font-size: .62rem; }
  .atlas-kpi-value {
    font-size: 1.15rem;
    overflow-wrap: anywhere;       /* long GHS totals don't push card */
  }

  /* Pill buttons: keep them full-tap-target (≥ 40px) but slimmer side padding */
  .btn-pill-gradient,
  .btn-pill {
    padding: .55rem 1rem;
    font-size: .85rem;
    min-height: 40px;
  }

  /* Hero action rows: always allow wrapping. (Most pages already declare
     flex-wrap on the action div; this is a safety net for any that don't.) */
  .atlas-hero .relative > div:last-child {
    flex-wrap: wrap;
  }

  /* Modal: hug the viewport with consistent gutters, lower head/body padding */
  .atlas-modal-backdrop { padding: 1rem .75rem; }
  .atlas-modal-card     { max-width: 100%; border-radius: 16px; }
  .atlas-modal-head     { padding: .75rem 1rem; }
  .atlas-modal-body     { padding: 1rem; }
  .atlas-modal-foot     { padding: .75rem 1rem; }
  .atlas-modal-foot .btn-pill,
  .atlas-modal-foot .btn-pill-gradient { flex: 1 1 auto; justify-content: center; }

  /* ---- Legacy Bootstrap controls embedded in migrated pages ----
     Atlas pages still carry some Bootstrap widgets (`.btn-group`,
     `.input-group`, `.form-control`, `.table-responsive`). Force the
     mobile-friendly behaviour they need so individual pages don't
     have to re-derive these rules each time. */
  .btn-group { flex-wrap: wrap; }
  .btn-group > .btn { min-height: 38px; }
  .input-group { flex-wrap: wrap; }
  .form-control,
  .form-select { min-height: 40px; max-width: 100%; }
  /* Tables: any plain <table> inside a migrated page should scroll
     inside its parent rather than push the page. Pages should keep
     using `.table-responsive` / `overflow-x:auto` wrappers, but this
     fallback prevents the worst case. */
  main table { max-width: 100%; }

  /* Section titles that bleed past the viewport — keep them line-wrapping. */
  .dashboard-zone-title,
  .atlas-page-title { overflow-wrap: anywhere; }

  /* Inline content with deliberate min-width on desktop (date pickers,
     branch selectors). On a phone they should hug their flex row. */
  main [style*="min-width:"] { max-width: 100%; }
}

/* Slightly above mobile but still phone-ish (sm..md, 641–767px) — pull
   atlas-page-title back to fit a single line on most phones in landscape. */
@media (min-width: 641px) and (max-width: 767px) {
  .atlas-page-title { font-size: 1.6rem; }
}


/* ============================================================
   §26 · Chart & dashboard primitives
   --------------------------------------------------------------
   Shared building blocks for analytics-style pages — the
   dashboard migration consumes them first, but anything with
   chart cards, KPI strips with sparklines, zone-title rails,
   or filter pill bars should reuse these instead of growing
   new bespoke selectors. Everything is token-driven so dark
   mode + the §25 mobile rules are inherited for free.

   Tone variants (border-left rail + accent):
     .tone-brand    (default · sky)
     .tone-success  (jade)
     .tone-warning  (amber)
     .tone-danger   (rose)
     .tone-info     (cyan / softer sky)
     .tone-accent   (plum)
     .tone-slate    (no accent, neutral)
   ============================================================ */

/* ---- 26.1 · Chart card (replaces legacy `.chart-card`) ------- */
.atlas-chart-card {
  --atlas-cc-accent: var(--sa-brand);
  position: relative;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-left: 4px solid var(--atlas-cc-accent);
  border-radius: 14px;
  box-shadow: var(--sa-shadow-soft);
  overflow: hidden;
}
.atlas-chart-card.tone-success { --atlas-cc-accent: var(--sa-success); }
.atlas-chart-card.tone-warning { --atlas-cc-accent: var(--sa-warning); }
.atlas-chart-card.tone-danger  { --atlas-cc-accent: var(--sa-danger); }
.atlas-chart-card.tone-info    { --atlas-cc-accent: var(--sa-info); }
.atlas-chart-card.tone-accent  { --atlas-cc-accent: var(--sa-accent); }
.atlas-chart-card.tone-slate   { border-left-color: var(--sa-border); }

.atlas-chart-card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--sa-border);
}
.atlas-chart-card-title {
  margin: 0;
  display: inline-flex; align-items: center; gap: .55rem;
  font-weight: 800;
  font-size: .98rem;
  color: var(--sa-text);
}
.atlas-chart-card-title i { color: var(--atlas-cc-accent); }
.atlas-chart-card-sub {
  color: var(--sa-text-muted);
  font-size: .82rem;
}
.atlas-chart-card-body { padding: 1.1rem 1rem; }
.atlas-chart-card-foot {
  padding: .75rem 1rem;
  border-top: 1px solid var(--sa-border);
  display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap;
}

/* Tight variant for KPI-strip-style cards (smaller padding). */
.atlas-chart-card.is-tight .atlas-chart-card-body { padding: .85rem 1rem; }

/* ---- 26.2 · Zone title (icon chip + label) ------------------ */
.atlas-zone-title {
  display: inline-flex; align-items: center; gap: .55rem;
  margin: 1rem 0 .65rem;
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sa-text-muted);
  overflow-wrap: anywhere;
}
.atlas-zone-title-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--sa-brand-soft);
  color: var(--sa-brand-strong);
  font-size: .82rem;
  flex: 0 0 auto;
}
.atlas-zone-title.tone-success .atlas-zone-title-chip { background: var(--sa-success-soft); color: var(--sa-success-text); }
.atlas-zone-title.tone-warning .atlas-zone-title-chip { background: var(--sa-warning-soft); color: var(--sa-warning-text); }
.atlas-zone-title.tone-danger  .atlas-zone-title-chip { background: var(--sa-danger-soft);  color: var(--sa-danger-text); }
.atlas-zone-title.tone-info    .atlas-zone-title-chip { background: var(--sa-info-soft);    color: var(--sa-info-text); }
.atlas-zone-title.tone-accent  .atlas-zone-title-chip { background: var(--sa-accent-soft);  color: var(--sa-accent-text); }

/* ---- 26.3 · Stat card (replaces `.dashboard-stat`) ---------- *
   Renders as a card with a coloured left rail, an icon chip,
   uppercase label, large tabular value, and an optional hint.
   Use the `--atlas-stat-tone` CSS var to set the accent (a tone
   class also works). For drop-in compatibility with the legacy
   `--stat-color` var, that fallback is honoured too. */
.atlas-stat {
  /* If the page sets inline `style="--stat-color: #xxx"` (the legacy
     `.dashboard-stat` API), that wins; otherwise fall back to the
     atlas brand accent.  Tone classes (.tone-success / .tone-warning…)
     override the var below. */
  --atlas-stat-tone: var(--stat-color, var(--sa-brand));
  position: relative;
  min-height: 132px;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-left: 4px solid var(--atlas-stat-tone);
  border-radius: 16px;
  box-shadow: var(--sa-shadow-soft);
  padding: 1rem 1.05rem;
  overflow: hidden;
  display: flex; flex-direction: column; gap: .6rem;
}
.atlas-stat.tone-success { --atlas-stat-tone: var(--sa-success); }
.atlas-stat.tone-warning { --atlas-stat-tone: var(--sa-warning); }
.atlas-stat.tone-danger  { --atlas-stat-tone: var(--sa-danger); }
.atlas-stat.tone-info    { --atlas-stat-tone: var(--sa-info); }
.atlas-stat.tone-accent  { --atlas-stat-tone: var(--sa-accent); }
.atlas-stat.tone-slate   { --atlas-stat-tone: var(--sa-border); border-left-color: var(--sa-border); }

.atlas-stat-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .65rem;
}
.atlas-stat-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--atlas-stat-tone) 14%, transparent);
  color: var(--atlas-stat-tone);
  font-size: 1.05rem;
  flex: 0 0 auto;
}
.atlas-stat-label {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--sa-text-muted);
  line-height: 1.2;
}
.atlas-stat-value {
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  font-weight: 800;
  line-height: 1.1;
  color: var(--sa-text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.atlas-stat-hint {
  margin-top: auto;
  color: var(--sa-text-muted);
  font-size: .82rem;
}

/* Delta badge (matches atlas-tag tone palette but auto-sizes
   for inline use inside stat cards). */
.atlas-stat-delta {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 9999px;
  font-size: .72rem;
  font-weight: 700;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface-2);
  color: var(--sa-text-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}
.atlas-stat-delta.is-up   { background: var(--sa-success-soft); color: var(--sa-success-text); border-color: var(--sa-success); }
.atlas-stat-delta.is-down { background: var(--sa-danger-soft);  color: var(--sa-danger-text);  border-color: var(--sa-danger); }
.atlas-stat-delta.is-flat { background: var(--sa-surface-2);    color: var(--sa-text-muted);   border-color: var(--sa-border); }

/* ---- 26.4 · Sparkline wrapper (replaces `.kpi-sparkline-wrap`)
   Chart.js w/ maintainAspectRatio:false reads the parent's
   height. The fixed-height wrapper stops the canvas from growing
   ~1px per resize tick (sub-pixel rounding) until it fills the
   page. Canvas absolutely-positions inside so Chart.js owns its
   own width/height attributes without ever changing layout. */
.atlas-spark {
  position: relative;
  height: 36px;
  margin-top: .25rem;
  width: 100%;
}
.atlas-spark-canvas {
  position: absolute; inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ---- 26.5 · Filter bar (replaces `.dashboard-filter-bar`)
   A horizontal pill row that always wraps on mobile. Uses the
   atlas surface, plays nicely with embedded form-control / select
   widgets. Tonal "active" state on a date-range pill. */
.atlas-filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .65rem;
  padding: .75rem 1rem;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 14px;
  box-shadow: var(--sa-shadow-soft);
}
.atlas-filter-label {
  display: inline-flex; align-items: center; gap: .35rem;
  margin-right: .25rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--sa-text-muted);
  font-weight: 800;
}

/* Pill row (replaces Bootstrap .btn-group of date-range buttons).
   On mobile the row simply wraps; no horizontal scroll. */
.atlas-filter-pills {
  display: inline-flex; flex-wrap: wrap; gap: .35rem;
}
.atlas-filter-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .42rem .85rem;
  border-radius: 9999px;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface);
  color: var(--sa-text-dim);
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  min-height: 36px;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.atlas-filter-pill:hover {
  background: var(--sa-surface-2);
  color: var(--sa-text);
}
.atlas-filter-pill.is-active {
  background: var(--sa-gradient-brand);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--sa-shadow-glow);
}
.atlas-filter-pill.is-active:hover { color: #fff; }

/* Inline input / select inside the bar — keep the atlas height. */
.atlas-filter-bar input,
.atlas-filter-bar select {
  height: 36px;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface);
  color: var(--sa-text);
  border-radius: 9999px;
  padding: 0 .85rem;
  font-size: .85rem;
  min-width: 0;
}
.atlas-filter-bar input:focus,
.atlas-filter-bar select:focus {
  outline: 0;
  border-color: var(--sa-brand);
  box-shadow: 0 0 0 3px var(--sa-brand-soft);
}

/* ---- 26.6 · Mini KPI (replaces `.zone-e-kpi*`)
   The Zone E health row — three at-a-glance tiles with a tone
   that flips emerald / amber / rose based on the metric. */
.atlas-mini-kpi {
  --atlas-mini-tone: var(--sa-text-muted);
  position: relative;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-radius: 14px;
  box-shadow: var(--sa-shadow-soft);
  padding: .9rem 1rem .8rem;
  display: flex; flex-direction: column; gap: .35rem;
  min-height: 108px;
}
.atlas-mini-kpi.tone-fresh   { --atlas-mini-tone: var(--sa-success); }
.atlas-mini-kpi.tone-warn    { --atlas-mini-tone: var(--sa-warning); border-color: color-mix(in srgb, var(--sa-warning) 35%, var(--sa-border)); }
.atlas-mini-kpi.tone-stale   { --atlas-mini-tone: var(--sa-danger);  border-color: color-mix(in srgb, var(--sa-danger)  35%, var(--sa-border)); }
.atlas-mini-kpi.tone-info    { --atlas-mini-tone: var(--sa-info); }

.atlas-mini-kpi-head {
  display: flex; align-items: center; gap: .5rem;
  color: var(--sa-text-muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.atlas-mini-kpi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--atlas-mini-tone) 14%, transparent);
  color: var(--atlas-mini-tone);
  font-size: .82rem;
  flex: 0 0 auto;
}
.atlas-mini-kpi-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.atlas-mini-kpi-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--sa-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.atlas-mini-kpi-value.is-zero,
.atlas-mini-kpi-value > .is-zero {       /* allow the zero copy to sit inside the value div */
  font-size: .92rem;
  font-weight: 600;
  color: var(--atlas-mini-tone);
}
.atlas-mini-kpi-foot { margin-top: auto; }
.atlas-mini-kpi-link {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--sa-brand);
  text-decoration: none;
}
.atlas-mini-kpi-link:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .atlas-chart-card-head  { padding: .75rem .85rem; }
  .atlas-chart-card-body  { padding: .9rem .85rem; }
  .atlas-chart-card-title { font-size: .92rem; }
  .atlas-stat             { min-height: 0; padding: .85rem .9rem; gap: .5rem; }
  .atlas-stat-icon        { width: 34px; height: 34px; font-size: .95rem; }
  .atlas-stat-value       { font-size: 1.2rem; }
  .atlas-stat-hint        { font-size: .76rem; }
  .atlas-mini-kpi         { min-height: 92px; padding: .75rem .85rem; }
  .atlas-mini-kpi-value   { font-size: 1.1rem; }
  .atlas-filter-bar       { padding: .65rem .85rem; gap: .5rem; }
  .atlas-filter-pill      { padding: .35rem .7rem; font-size: .78rem; min-height: 34px; }
}


