/* =========================================================================
   crm-core.css — the product's design language
   =========================================================================

   Brand-agnostic. This file is IDENTICAL for every client and must never
   contain a client's colour, logo, or name.

   It consumes the --brand-* variables a theme file supplies, plus any of the
   --crm-* palette tokens the theme chooses to re-point. If no theme is
   loaded, the fallbacks below produce a neutral blue CRM that still works.

   Load order in _Layout.cshtml / _AuthLayout.cshtml:
     1. tabler.min.css (+ vendors, icons, themes)
     2. crm-core.css        ← this file: geometry, components, responsive
     3. themes/{client}.css ← per-client palette

   Breakpoints follow Tabler / Bootstrap:
     phone  < 576px      tablet 576–991px      desktop ≥ 992px
   ========================================================================= */


/* -------------------------------------------------------------------------
   1. BRAND CONTRACT
   The variables a theme file must set. Fallbacks make core standalone.
   ------------------------------------------------------------------------- */
:root {
  --brand-primary:        #1B5FA8;
  --brand-primary-hover:  #164C87;
  --brand-primary-subtle: #EBF2FA;
  --brand-primary-rgb:    27, 95, 168;
  --brand-dark:           #1A1D21;
  --brand-font:           "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
}


/* -------------------------------------------------------------------------
   2. STRUCTURAL TOKENS
   The product's design decisions. A theme may re-point the COLOUR tokens
   (surfaces, text, semantic, status, sidebar); sizing and spacing stay here.
   ------------------------------------------------------------------------- */
:root {

  /* ---------- surfaces ---------- */
  --crm-bg-app:          #F6F7F9;
  --crm-surface:         #FFFFFF;
  --crm-surface-sunken:  #F1F3F5;
  --crm-surface-hover:   #FAFBFC;
  --crm-border:          #DFE3E8;
  --crm-border-strong:   #C4CBD4;
  --crm-divider:         #EDF0F3;

  /* ---------- text ---------- */
  --crm-text:            #1A1D21;
  --crm-text-secondary:  #5A6472;
  --crm-text-muted:      #8A93A0;
  --crm-text-inverse:    #FFFFFF;
  --crm-link:            var(--brand-primary);
  --crm-link-hover:      var(--brand-primary-hover);

  /* ---------- semantic ----------
     Kept independent of the brand so any brand colour still gets a red
     error state and a green success state. */
  --crm-success:         #0E8A5F;
  --crm-success-subtle:  #E8F5F0;
  --crm-warning:         #B36A00;
  --crm-warning-subtle:  #FDF4E7;
  --crm-error:           #C8102E;
  --crm-error-subtle:    #FDF2F4;
  --crm-info:            #1B5FA8;
  --crm-info-subtle:     #EBF2FA;

  /* ---------- tones ----------
     Used by icon tiles (KPI, card and page-title icons). An icon tile picks a
     tone with .tone-* and tints its own background from it. */
  --crm-tone-blue:       #2563EB;
  --crm-tone-green:      var(--crm-success);
  --crm-tone-amber:      var(--crm-warning);
  --crm-tone-violet:     #7048C8;
  --crm-tone-red:        var(--crm-error);
  --crm-tone-cyan:       #0E7490;
  --crm-tone-slate:      var(--crm-text-secondary);

  /* ---------- pipeline status ----------
     Deliberately desaturated. Nine saturated colours makes a board a toy.
     'Lost' is grey, not red — it is a routine outcome.
     'Overdue' is the only status permitted red, so red always means act now. */
  --crm-status-new:         #5A6472;
  --crm-status-contacted:   #1B5FA8;
  --crm-status-sample:      #6B4E9E;
  --crm-status-qualified:   #0F6E8C;
  --crm-status-quotation:   #B36A00;
  --crm-status-negotiation: #8A5A00;
  --crm-status-won:         #0E8A5F;
  --crm-status-lost:        #8A93A0;
  --crm-status-overdue:     #C8102E;

  --crm-status-new-bg:         #F1F3F5;
  --crm-status-contacted-bg:   var(--crm-info-subtle);
  --crm-status-sample-bg:      #F2EEF9;
  --crm-status-qualified-bg:   #E9F3F6;
  --crm-status-quotation-bg:   var(--crm-warning-subtle);
  --crm-status-negotiation-bg: #FBF1E2;
  --crm-status-won-bg:         var(--crm-success-subtle);
  --crm-status-lost-bg:        #F1F3F5;
  --crm-status-overdue-bg:     var(--crm-error-subtle);

  /* ---------- lead temperature ----------
     Hot is orange, deliberately not red: red stays reserved for overdue. */
  --crm-temp-hot:     #C2410C;
  --crm-temp-hot-bg:  #FFF0E6;
  --crm-temp-warm:    #A16207;
  --crm-temp-warm-bg: #FEF7E0;
  --crm-temp-cold:    #0369A1;
  --crm-temp-cold-bg: #E6F3FA;

  /* ---------- sidebar ----------
     The sidebar is always dark. A theme re-points these; it should not
     restyle the sidebar's rules. */
  --crm-sidebar-bg:          var(--brand-dark);
  --crm-sidebar-border:      transparent;
  --crm-sidebar-text:        #A8B0BC;
  --crm-sidebar-text-hover:  #FFFFFF;
  --crm-sidebar-hover-bg:    rgba(255,255,255,.06);
  --crm-sidebar-active-bg:   rgba(255,255,255,.09);
  --crm-sidebar-active-text: #FFFFFF;
  --crm-sidebar-indicator:   var(--brand-primary);
  --crm-sidebar-label:       #6B7480;
  --crm-sidebar-mark-bg:     var(--brand-primary);
  --crm-sidebar-mark-text:   #FFFFFF;
  --crm-sidebar-accent:      var(--brand-primary);

  /* ---------- typography scale ----------
     One step up from the original scale: 15px body, 14px tables. */
  --crm-text-xs:   12px;
  --crm-text-sm:   13px;
  --crm-text-base: 14px;
  --crm-text-md:   15px;
  --crm-text-lg:   16px;
  --crm-text-xl:   22px;
  --crm-text-2xl:  26px;
  --crm-text-kpi:  30px;

  --crm-weight-regular:  400;
  --crm-weight-medium:   500;
  --crm-weight-semibold: 600;
  --crm-weight-bold:     700;

  --crm-leading-tight:  1.25;
  --crm-leading-normal: 1.55;
  --crm-tracking-caps:  0.05em;

  /* ---------- spacing (4px base) ---------- */
  --crm-space-1:  4px;
  --crm-space-2:  8px;
  --crm-space-3:  12px;
  --crm-space-4:  16px;
  --crm-space-5:  20px;
  --crm-space-6:  24px;
  --crm-space-8:  32px;
  --crm-space-10: 40px;

  /* ---------- radius ---------- */
  --crm-radius-sm:   6px;
  --crm-radius:      8px;
  --crm-radius-lg:   12px;
  --crm-radius-pill: 999px;

  /* ---------- shadow ---------- */
  --crm-shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --crm-shadow:    0 4px 12px rgba(16,24,40,.08);
  --crm-shadow-lg: 0 20px 40px rgba(16,24,40,.18);

  /* ---------- component sizing ---------- */
  --crm-sidebar-w:         15rem;   /* Tabler's own; page-wrapper offsets by it */
  --crm-sidebar-collapsed-w: 4.75rem; /* icons only, see §21 */
  --crm-topbar-h:          60px;
  --crm-control-h:         40px;
  --crm-control-h-sm:      34px;
  --crm-row-h:             48px;
  --crm-row-h-compact:     38px;
  --crm-card-header-h:     56px;
  --crm-icon-tile:         44px;
  --crm-icon-tile-sm:      36px;

  /* ---------- motion ---------- */
  --crm-transition: 140ms ease-out;
}


/* -------------------------------------------------------------------------
   3. TABLER BRIDGE
   Maps our tokens onto Tabler's variables so its own components inherit.
   ------------------------------------------------------------------------- */
:root {
  --tblr-primary:              var(--brand-primary);
  --tblr-primary-rgb:          var(--brand-primary-rgb);
  --tblr-primary-lt:           var(--brand-primary-subtle);
  --tblr-primary-darken:       var(--brand-primary-hover);
  --tblr-primary-text-emphasis: var(--brand-primary-hover);
  --tblr-primary-bg-subtle:    var(--brand-primary-subtle);
  --tblr-link-color:           var(--crm-link);
  --tblr-link-color-rgb:       var(--brand-primary-rgb);
  --tblr-link-hover-color:     var(--crm-link-hover);

  --tblr-body-bg:              var(--crm-bg-app);
  --tblr-body-color:           var(--crm-text);
  --tblr-secondary-color:      var(--crm-text-secondary);
  --tblr-border-color:         var(--crm-border);
  --tblr-border-color-translucent: var(--crm-border);
  --tblr-font-sans-serif:      var(--brand-font);
  --tblr-border-radius:        var(--crm-radius);
  --tblr-border-radius-lg:     var(--crm-radius-lg);

  /* Type: 15px body, headings one step up from Tabler's defaults. */
  --tblr-font-size-base:  0.9375rem;
  --tblr-body-font-size:  0.9375rem;
  --tblr-font-size-h1:    1.75rem;
  --tblr-font-size-h2:    1.375rem;
  --tblr-font-size-h3:    1.0625rem;
  --tblr-font-size-h4:    0.9375rem;
  --tblr-font-size-h5:    0.8125rem;
  --tblr-font-size-h6:    0.6875rem;

  --tblr-bg-surface:           var(--crm-surface);
  --tblr-bg-surface-secondary: var(--crm-surface-sunken);
  --tblr-bg-forms:             var(--crm-surface);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--brand-font);
  font-size: var(--crm-text-md);
  line-height: var(--crm-leading-normal);
  color: var(--crm-text);
  background: var(--crm-bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

a { transition: color var(--crm-transition); }

.text-secondary { color: var(--crm-text-secondary) !important; }
.text-muted     { color: var(--crm-text-muted) !important; }
.small, small   { font-size: var(--crm-text-sm); }

/* Every Tabler icon font glyph sits on the text baseline the same way. */
.ti { line-height: 1; vertical-align: -0.125em; }


/* -------------------------------------------------------------------------
   4. NUMERALS
   Tabular figures keep columns aligned; units are always visible but never
   compete with the value.
   ------------------------------------------------------------------------- */
.text-num,
.table td.num,
.table th.num,
.kpi-value,
input[type="number"] {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.unit {
  font-size: var(--crm-text-xs);
  color: var(--crm-text-muted);
  margin-left: 2px;
}


/* -------------------------------------------------------------------------
   5. NAVIGATION
   Sidebar (desktop: fixed column; below lg: Tabler's collapsing top bar),
   then the desktop topbar.
   ------------------------------------------------------------------------- */
.navbar-vertical {
  background: var(--crm-sidebar-bg) !important;
  border-right: 1px solid var(--crm-sidebar-border);
  box-shadow: none;
}

/* Brand lock-up: a monogram tile and the product name. */
.crm-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-3);
  color: var(--crm-sidebar-active-text);
  text-decoration: none;
  font-size: var(--crm-text-lg);
  font-weight: var(--crm-weight-bold);
  letter-spacing: -0.01em;
}

.crm-brand:hover { color: var(--crm-sidebar-active-text); text-decoration: none; }

.crm-brand-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--crm-radius);
  background: var(--crm-sidebar-mark-bg);
  color: var(--crm-sidebar-mark-text);
  font-size: 18px;
  font-weight: var(--crm-weight-bold);
  box-shadow: 0 4px 12px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.18);
}

.crm-brand-name small {
  display: block;
  margin-top: 2px;
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-medium);
  letter-spacing: var(--crm-tracking-caps);
  text-transform: uppercase;
  color: var(--crm-sidebar-accent);
}

.navbar-vertical .navbar-brand {
  padding: var(--crm-space-4) var(--crm-space-5);
  justify-content: flex-start;
}

@media (min-width: 992px) {
  .navbar-vertical.navbar-expand-lg .navbar-brand {
    padding: var(--crm-space-5) var(--crm-space-5) var(--crm-space-3);
    justify-content: flex-start;
  }
}

.navbar-vertical .navbar-nav { padding-bottom: var(--crm-space-4); }

.navbar-vertical .nav-item { margin: 1px var(--crm-space-3); }

/* Tabler draws its own active bar on the <li>; ours sits on the anchor. */
.navbar-vertical .nav-item.active::after { display: none !important; }

.navbar-vertical .navbar-nav .nav-link,
.navbar-vertical.navbar-expand-lg .navbar-collapse .navbar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  min-height: 42px;
  padding: 0 var(--crm-space-3);
  border-radius: var(--crm-radius);
  font-size: var(--crm-text-md);
  font-weight: var(--crm-weight-medium);
  color: var(--crm-sidebar-text);
  transition: background var(--crm-transition), color var(--crm-transition);
}

.navbar-vertical .nav-link-icon {
  display: inline-grid !important;
  place-items: center;
  width: 22px;
  height: 22px;
  margin: 0;
  font-size: 20px;
  opacity: .85;
}

.navbar-vertical .navbar-nav .nav-link:hover {
  color: var(--crm-sidebar-text-hover);
  background: var(--crm-sidebar-hover-bg);
}

/* The only brand colour in the sidebar: the indicator and the active icon. */
.navbar-vertical .navbar-nav .nav-link.active,
.navbar-vertical.navbar-expand-lg .navbar-collapse .navbar-nav .nav-link.active {
  color: var(--crm-sidebar-active-text);
  background: var(--crm-sidebar-active-bg);
  box-shadow: inset 3px 0 0 var(--crm-sidebar-indicator);
}

.navbar-vertical .nav-link.active .nav-link-icon {
  color: var(--crm-sidebar-accent);
  opacity: 1;
}

.navbar-vertical .nav-group-label {
  margin: var(--crm-space-5) var(--crm-space-3) var(--crm-space-2);
  padding: 0 var(--crm-space-3);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--crm-sidebar-label);
  list-style: none;
}

.navbar-vertical .nav-group-label:first-child { margin-top: var(--crm-space-2); }

/* Below lg the sidebar is a top bar: brand left, avatar + menu toggle right. */
@media (max-width: 991.98px) {
  .navbar-vertical {
    position: sticky;
    top: 0;
    z-index: 1030;
    min-height: var(--crm-topbar-h);
    border-right: 0;
    border-bottom: 1px solid var(--crm-sidebar-border);
    box-shadow: 0 2px 12px rgba(0,0,0,.18);
  }

  .navbar-vertical .navbar-brand { padding: var(--crm-space-3) 0; }

  .navbar-vertical .navbar-toggler {
    order: 3;
    margin-left: var(--crm-space-2);
    padding: 6px;
    border: 0;
    border-radius: var(--crm-radius);
    color: var(--crm-sidebar-text-hover);
  }

  .navbar-vertical .navbar-toggler:focus { box-shadow: 0 0 0 2px var(--crm-sidebar-indicator); }

  .navbar-vertical > .container-fluid > .navbar-nav { order: 2; margin-left: auto; }

  .navbar-vertical .navbar-collapse {
    order: 4;
    max-height: calc(100vh - var(--crm-topbar-h));
    overflow-y: auto;
  }

  .navbar-vertical .nav-item { margin: 1px 0; }
  .navbar-vertical .nav-group-label { margin-left: 0; margin-right: 0; }
  .navbar-vertical .crm-topbar-meta { display: none !important; }
}

/* ---------- desktop topbar ---------- */
.page > header.navbar {
  min-height: var(--crm-topbar-h);
  background: var(--crm-surface);
  border-bottom: 1px solid var(--crm-border);
  box-shadow: none;
}

.crm-topbar-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  font-size: var(--crm-text-sm);
  color: var(--crm-text-secondary);
}

.crm-topbar-meta .ti { font-size: 18px; color: var(--crm-text-muted); }

.crm-topbar-icon {
  display: inline-grid !important;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--crm-radius);
  font-size: 20px;
  color: var(--crm-text-secondary);
  transition: background var(--crm-transition), color var(--crm-transition);
}

.crm-topbar-icon:hover { background: var(--crm-surface-sunken); color: var(--crm-text); }

/* The same icon buttons on the dark mobile bar. */
.navbar-vertical .crm-topbar-icon { color: var(--crm-sidebar-text); }
.navbar-vertical .crm-topbar-icon:hover { background: var(--crm-sidebar-hover-bg); color: var(--crm-sidebar-text-hover); }

.crm-user {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  padding: 4px 10px 4px 4px !important;
  border-radius: var(--crm-radius-pill);
  border: 1px solid var(--crm-border);
  transition: background var(--crm-transition), border-color var(--crm-transition);
}

.crm-user:hover { background: var(--crm-surface-sunken); }
.crm-user .avatar { background: var(--brand-primary); color: var(--crm-text-inverse); font-weight: var(--crm-weight-semibold); }
.crm-user-name { font-size: var(--crm-text-sm); font-weight: var(--crm-weight-semibold); color: var(--crm-text); line-height: 1.2; }
.crm-user-role { font-size: var(--crm-text-xs); color: var(--crm-text-muted); line-height: 1.2; }

.navbar-vertical .crm-user { border-color: rgba(255,255,255,.12); padding: 3px !important; }

/* Logo slot. The theme file supplies the image; core owns the geometry. */
.navbar-brand-logo {
  height: 28px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
}


/* -------------------------------------------------------------------------
   6. PAGE CHROME
   Page header with an icon tile, wrapping actions, and page padding.
   ------------------------------------------------------------------------- */
.page-body { margin-top: var(--crm-space-5); margin-bottom: var(--crm-space-6); }

.page-header { margin-bottom: var(--crm-space-5); }

.page-title {
  gap: var(--crm-space-3);
  font-weight: var(--crm-weight-bold);
  letter-spacing: -0.015em;
  color: var(--crm-text);
}

.page-pretitle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: var(--crm-text-xs);
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-muted);
}

.page-subtitle {
  margin-top: var(--crm-space-1);
  font-size: var(--crm-text-base);
  color: var(--crm-text-secondary);
}

/* Icon tiles share one look; a .tone-* class picks the colour. */
.page-title-icon,
.card-icon,
.kpi-icon {
  --tone: var(--brand-primary);
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--crm-radius);
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 12%, transparent);
}

.page-title-icon { width: 40px; height: 40px; font-size: 22px; }
.card-icon       { width: var(--crm-icon-tile-sm); height: var(--crm-icon-tile-sm); font-size: 19px; }
.kpi-icon        { width: var(--crm-icon-tile); height: var(--crm-icon-tile); font-size: 23px; border-radius: var(--crm-radius-lg); }

.tone-primary { --tone: var(--brand-primary); }
.tone-blue    { --tone: var(--crm-tone-blue); }
.tone-green   { --tone: var(--crm-tone-green); }
.tone-amber   { --tone: var(--crm-tone-amber); }
.tone-violet  { --tone: var(--crm-tone-violet); }
.tone-red     { --tone: var(--crm-tone-red); }
.tone-cyan    { --tone: var(--crm-tone-cyan); }
.tone-slate   { --tone: var(--crm-tone-slate); }

/* Page-header action clusters: full-width search on a phone, buttons share
   the next line. Applies to every list page's header without markup changes. */
@media (max-width: 767.98px) {
  .page-header > .row > .col-auto.ms-auto { width: 100%; margin-left: 0 !important; }
  .page-header > .row > .col-auto.ms-auto > .d-flex,
  .page-header > .row > .col-auto.ms-auto > .btn-list { justify-content: flex-start !important; }
  .page-header input[type="search"] { flex: 1 1 100% !important; width: 100% !important; order: -1; }
  .page-header .col-auto.ms-auto > .d-flex { position: relative; }
  .page-header .col-auto.ms-auto > .d-flex > .htmx-indicator { position: absolute; top: 12px; right: 12px; z-index: 3; }
  .page-header .col-auto.ms-auto .btn { flex: 1 1 auto; }
}

@media (max-width: 575.98px) {
  .page-body { margin-top: var(--crm-space-4); }
  .page-title-icon { width: 36px; height: 36px; font-size: 20px; }
  .page-wrapper .container-xl { padding-left: var(--crm-space-3); padding-right: var(--crm-space-3); }
}

.footer {
  font-size: var(--crm-text-sm);
  color: var(--crm-text-muted);
  border-top-color: var(--crm-divider);
}


/* -------------------------------------------------------------------------
   7. CARDS AND KPI
   ------------------------------------------------------------------------- */
.card {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  box-shadow: var(--crm-shadow-sm);
  background: var(--crm-surface);
}

.card-header {
  min-height: var(--crm-card-header-h);
  padding: 0 var(--crm-space-5);
  gap: var(--crm-space-3);
  border-bottom: 1px solid var(--crm-divider);
  font-size: var(--crm-text-lg);
  font-weight: var(--crm-weight-semibold);
}

.card-title {
  font-size: var(--crm-text-lg);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-text);
  display: flex;
  align-items: center;
  gap: var(--crm-space-2);
}

.card-subtitle {
  font-size: var(--crm-text-sm);
  color: var(--crm-text-muted);
}

.card-body   { padding: var(--crm-space-5); }

.card-footer {
  padding: var(--crm-space-3) var(--crm-space-5);
  background: var(--crm-surface-sunken);
  border-top: 1px solid var(--crm-divider);
  font-size: var(--crm-text-sm);
}

.card-footer:last-child { border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg); }

.card-header-tabs .nav-link { font-size: var(--crm-text-base); }

@media (max-width: 575.98px) {
  .card-header { padding: 0 var(--crm-space-4); }
  .card-body   { padding: var(--crm-space-4); }
  .card-footer { padding: var(--crm-space-3) var(--crm-space-4); }
}

.kpi-label {
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-muted);
}

/* Never coloured. The delta carries the meaning. */
.kpi-value {
  font-size: var(--crm-text-kpi);
  font-weight: var(--crm-weight-bold);
  line-height: var(--crm-leading-tight);
  letter-spacing: -0.02em;
  color: var(--crm-text);
}

.kpi-delta-up   { font-size: var(--crm-text-sm); color: var(--crm-success); }
.kpi-delta-down { font-size: var(--crm-text-sm); color: var(--crm-error); }

/* Lists inside cards */
.list-group-item {
  padding: var(--crm-space-3) var(--crm-space-5);
  border-color: var(--crm-divider);
  background: transparent;
}

.list-group-item-action:hover { background: var(--crm-surface-hover); }

@media (max-width: 575.98px) {
  .list-group-item { padding: var(--crm-space-3) var(--crm-space-4); }
}

.avatar { font-weight: var(--crm-weight-semibold); }

/* Datagrid (lead details) */
.datagrid { --tblr-datagrid-padding: 1.25rem; gap: var(--crm-space-5); }

.datagrid-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--crm-text-xs);
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-muted);
}

.datagrid-title .ti { font-size: 15px; }
.datagrid-content { font-size: var(--crm-text-md); font-weight: var(--crm-weight-medium); }


/* -------------------------------------------------------------------------
   8. TABLES
   The most important component in the system.
   ------------------------------------------------------------------------- */
.table {
  font-size: var(--crm-text-base);
  border-color: var(--crm-divider);
  --tblr-table-bg: transparent;
}

.table thead th {
  height: 44px;
  background: var(--crm-surface-sunken);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-secondary);
  border-bottom: 1px solid var(--crm-border);
  white-space: nowrap;
  vertical-align: middle;
}

.table tbody tr { height: var(--crm-row-h); transition: background var(--crm-transition); }
.table tbody tr:hover { background: var(--crm-surface-hover); }

/* No zebra striping — borders do the work, stripes add noise. */

.table tbody tr.selected {
  background: var(--brand-primary-subtle);
  box-shadow: inset 3px 0 0 var(--brand-primary);
}

/* A coloured edge, never a red row — unreadable in bulk. */
.table tbody tr.is-overdue {
  box-shadow: inset 3px 0 0 var(--crm-error);
}

.table-compact tbody tr { height: var(--crm-row-h-compact); }

/* Small muted icons in front of a cell's value. */
.cell-icon {
  margin-right: 6px;
  font-size: 16px;
  color: var(--crm-text-muted);
}

.cell-person {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  min-width: 0;
}

.cell-person .avatar { flex: 0 0 auto; }

.cell-sub {
  display: block;
  font-size: var(--crm-text-xs);
  color: var(--crm-text-muted);
}

.cell-link { font-weight: var(--crm-weight-semibold); color: var(--crm-text); }

/* An address can be long; two lines at most in a table cell, the full text
   in the title tooltip. */
.cell-address { min-width: 12rem; max-width: 22rem; }

.cell-address-line {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}
.cell-link:hover { color: var(--crm-link); }

/* ---------- stacked table ----------
   .table-stack turns rows into cards below the desktop breakpoint, two to a
   line on a tablet, one on a phone. Cells keep their DOM order except:
     .cell-title   first, takes the free width     (the record's name)
     .cell-end     beside the title                 (status badge)
     .cell-action  beside the title                 (row button)
     .cell-full    a full line under the title      (secondary name)
   [data-label] cells print the label before the value, since there is no
   header to read it from. The header row becomes a scrollable "Sort" bar, so
   sorting stays available on a phone. */
.table-stack td[data-label]::before { content: none; }

@media (max-width: 991.98px) {
  .table-responsive:has(> .table-stack) { overflow: visible; }

  .table-stack,
  .table-stack thead,
  .table-stack tbody { display: block; width: 100%; }

  .table-stack thead tr {
    display: flex;
    align-items: center;
    gap: 6px;
    height: auto;
    padding: var(--crm-space-3) var(--crm-space-4);
    overflow-x: auto;
    background: var(--crm-surface-sunken);
    border-bottom: 1px solid var(--crm-divider);
    scrollbar-width: none;
  }

  .table-stack thead tr::-webkit-scrollbar { display: none; }

  .table-stack thead tr::before {
    content: "Sort";
    flex: 0 0 auto;
    margin-right: 2px;
    font-size: var(--crm-text-xs);
    font-weight: var(--crm-weight-semibold);
    letter-spacing: var(--crm-tracking-caps);
    text-transform: uppercase;
    color: var(--crm-text-muted);
  }

  .table-stack thead th {
    display: block;
    flex: 0 0 auto;
    height: auto;
    padding: 0 !important;
    border: 0;
    background: none;
  }

  .table-stack thead th:empty { display: none; }

  .table-stack thead .table-sort {
    display: inline-flex;
    align-items: center;
    width: auto;
    margin: 0;
    padding: 5px 10px 5px 12px;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-pill);
    background: var(--crm-surface);
    font-size: var(--crm-text-sm);
    font-weight: var(--crm-weight-medium);
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
  }

  .table-stack thead .table-sort.asc,
  .table-stack thead .table-sort.desc {
    border-color: var(--brand-primary);
    background: var(--brand-primary-subtle);
    color: var(--brand-primary);
  }

  .table-stack tbody {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--crm-space-3);
    padding: var(--crm-space-3);
    background: var(--crm-surface-sunken);
  }

  .table-stack tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px var(--crm-space-4);
    height: auto;
    padding: var(--crm-space-3) var(--crm-space-4);
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-lg);
    box-shadow: var(--crm-shadow-sm);
  }

  .table-stack tbody tr:hover { background: var(--crm-surface); border-color: var(--crm-border-strong); }

  .table-stack tbody tr.is-overdue {
    box-shadow: var(--crm-shadow-sm);
    border-left: 4px solid var(--crm-error);
  }

  .table-stack tbody td {
    display: inline-flex;
    align-items: center;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    padding: 0 !important;
    border: 0 !important;
    font-size: var(--crm-text-sm);
    text-align: left;
  }

  .table-stack tbody td.num { justify-content: flex-start; }
  .table-stack tbody td.w-1 { width: auto !important; }

  .table-stack tbody td.cell-title {
    order: -3;
    flex: 1 1 0;
    font-size: var(--crm-text-md);
    font-weight: var(--crm-weight-semibold);
  }

  .table-stack tbody td.cell-title > * { min-width: 0; }
  .table-stack tbody td.cell-end    { order: -2; }
  .table-stack tbody td.cell-action { order: -1; margin-right: -8px; }
  .table-stack tbody td.cell-full   { order: 0; flex: 1 1 100%; margin-top: -4px; }
  .table-stack tbody td:not(.cell-title):not(.cell-end):not(.cell-action):not(.cell-full) { order: 1; }

  .table-stack tbody td[data-label]::before {
    content: attr(data-label);
    margin-right: 6px;
    color: var(--crm-text-muted);
    font-weight: var(--crm-weight-regular);
  }

  /* Empty state and the infinite-scroll sentinel: one full-width cell. */
  .table-stack tbody td[colspan] { flex: 1 1 100%; justify-content: center; display: flex; }
  .table-stack tbody tr:has(> td[colspan]) { grid-column: 1 / -1; }
}

@media (min-width: 640px) and (max-width: 991.98px) {
  .table-stack tbody { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}


/* -------------------------------------------------------------------------
   9. BADGES
   One style everywhere. Subtle fill, matching text, no borders.
   ------------------------------------------------------------------------- */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--crm-radius-pill);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  line-height: 16px;
  white-space: nowrap;
}

/* A dot in the badge's own colour; the lead-type badge (inline fill) has none. */
.badge-status:is(.badge-new, .badge-contacted, .badge-sample, .badge-qualified, .badge-quotation,
                 .badge-negotiation, .badge-won, .badge-lost, .badge-overdue, .badge-upcoming)::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .9;
}

.badge-new         { color: var(--crm-status-new);         background: var(--crm-status-new-bg); }
.badge-contacted   { color: var(--crm-status-contacted);   background: var(--crm-status-contacted-bg); }
.badge-sample      { color: var(--crm-status-sample);      background: var(--crm-status-sample-bg); }
.badge-qualified   { color: var(--crm-status-qualified);   background: var(--crm-status-qualified-bg); }
.badge-quotation   { color: var(--crm-status-quotation);   background: var(--crm-status-quotation-bg); }
.badge-negotiation { color: var(--crm-status-negotiation); background: var(--crm-status-negotiation-bg); }
.badge-won         { color: var(--crm-status-won);         background: var(--crm-status-won-bg); }
.badge-lost        { color: var(--crm-status-lost);        background: var(--crm-status-lost-bg); }
.badge-overdue     { color: var(--crm-status-overdue);     background: var(--crm-status-overdue-bg); }
.badge-upcoming    { color: var(--crm-info);               background: var(--crm-info-subtle); }

/* Follow-up state reads as a label, so it is set in small capitals. */
.badge-status-caps { text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }

/* Lead temperature. Icon instead of the dot: flame / sun / snowflake. */
.badge-temp-hot  { color: var(--crm-temp-hot);  background: var(--crm-temp-hot-bg); }
.badge-temp-warm { color: var(--crm-temp-warm); background: var(--crm-temp-warm-bg); }
.badge-temp-cold { color: var(--crm-temp-cold); background: var(--crm-temp-cold-bg); }
.badge-status .ti { font-size: 13px; vertical-align: 0; }

.badge { font-weight: var(--crm-weight-semibold); border-radius: var(--crm-radius-pill); }


/* -------------------------------------------------------------------------
   10. BUTTONS
   ------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--crm-control-h);
  padding: 0 var(--crm-space-4);
  border-radius: var(--crm-radius);
  font-size: var(--crm-text-base);
  font-weight: var(--crm-weight-semibold);
  text-transform: none;
  transition: background var(--crm-transition), border-color var(--crm-transition),
              color var(--crm-transition), box-shadow var(--crm-transition);
}

.btn .ti { font-size: 18px; vertical-align: 0; }

.btn-sm { height: var(--crm-control-h-sm); padding: 0 var(--crm-space-3); font-size: var(--crm-text-sm); }
.btn-sm .ti { font-size: 16px; }

.btn-icon { width: var(--crm-control-h); padding: 0; }
.btn-sm.btn-icon { width: var(--crm-control-h-sm); }

.btn-primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--crm-text-inverse);
  box-shadow: 0 1px 2px rgba(16,24,40,.08), inset 0 1px 0 rgba(255,255,255,.12);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
  color: var(--crm-text-inverse);
}

.btn-secondary {
  background: var(--crm-surface);
  border-color: var(--crm-border-strong);
  color: var(--crm-text);
  box-shadow: 0 1px 2px rgba(16,24,40,.05);
}

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--crm-text-secondary);
}

.btn-ghost:hover {
  background: var(--crm-surface-sunken);
  color: var(--crm-text);
}

.btn-danger-outline {
  background: var(--crm-surface);
  border-color: var(--crm-error);
  color: var(--crm-error);
}

.btn-danger-outline:hover { background: var(--crm-error-subtle); color: var(--crm-error); }

.btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  box-shadow: none;
}

.btn:disabled,
.btn.disabled { opacity: .45; cursor: not-allowed; }


/* -------------------------------------------------------------------------
   11. FORMS
   Labels above, never inside. Validation on blur, never on keystroke.
   ------------------------------------------------------------------------- */
.form-label {
  margin-bottom: 6px;
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-text-secondary);
}

.form-control,
.form-select {
  height: var(--crm-control-h);
  border-radius: var(--crm-radius);
  border-color: var(--crm-border);
  background-color: var(--crm-surface);
  font-size: var(--crm-text-md);
  color: var(--crm-text);
  transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}

.form-control-sm, .form-select-sm { height: var(--crm-control-h-sm); font-size: var(--crm-text-sm); }

.form-control::placeholder { color: var(--crm-text-muted); }

.form-control:hover,
.form-select:hover { border-color: var(--crm-border-strong); }

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(var(--brand-primary-rgb), .15);
}

/* Search boxes get a magnifier without changing their markup. */
input[type="search"].form-control {
  padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238A93A0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='10' cy='10' r='7'/%3E%3Cpath d='M21 21l-6 -6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
}

.form-check-input:checked {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
}

.form-check-input:focus { box-shadow: 0 0 0 3px rgba(var(--brand-primary-rgb), .15); }

.form-control.is-invalid,
.form-select.is-invalid { border-color: var(--crm-error); }

.invalid-feedback { font-size: var(--crm-text-sm); color: var(--crm-error); }
.form-hint        { font-size: var(--crm-text-sm); color: var(--crm-text-muted); }

textarea.form-control { min-height: 96px; height: auto; resize: vertical; }

/* An addon beside a fixed-height control stretches to match it, so a flat
   input group's borders meet (the password field's show/hide eye). */
.input-group > .input-group-text { height: auto; align-self: stretch; padding-top: 0; padding-bottom: 0; }

/* iOS zooms into any field under 16px on focus; keep phones at 16px. */
@media (max-width: 575.98px) {
  .form-control, .form-select { font-size: 16px; }
}


/* -------------------------------------------------------------------------
   12. OVERLAYS
   ------------------------------------------------------------------------- */
.modal-content {
  border: 0;
  border-radius: var(--crm-radius-lg);
  box-shadow: var(--crm-shadow-lg);
}

.modal-header {
  padding: var(--crm-space-4) var(--crm-space-5);
  border-bottom: 1px solid var(--crm-divider);
}

.modal-title { font-size: var(--crm-text-lg); font-weight: var(--crm-weight-bold); }

.modal-body   { padding: var(--crm-space-5); }

.modal-footer {
  padding: var(--crm-space-3) var(--crm-space-5);
  gap: var(--crm-space-2);
  background: var(--crm-surface-sunken);
  border-top: 1px solid var(--crm-divider);
  border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg);
}

.modal-footer > * { margin: 0; }

/* A phone gets the whole screen for a form. */
@media (max-width: 575.98px) {
  #app-modal .modal-dialog { margin: 0; max-width: none; width: 100%; min-height: 100%; align-items: stretch; }
  #app-modal .modal-content { min-height: 100vh; border-radius: 0; }
  #app-modal .modal-footer { position: sticky; bottom: 0; border-radius: 0; z-index: 2; }
  .modal-header, .modal-body { padding-left: var(--crm-space-4); padding-right: var(--crm-space-4); }
}

.dropdown-menu {
  --tblr-dropdown-font-size: var(--crm-text-base);
  border-color: var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  padding: 6px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--crm-space-2);
  border-radius: var(--crm-radius-sm);
  padding: 8px 10px;
  font-size: var(--crm-text-base);
}

.dropdown-item .ti { font-size: 18px; color: var(--crm-text-muted); }

.tooltip-inner {
  background: var(--brand-dark);
  border-radius: var(--crm-radius-sm);
  font-size: var(--crm-text-sm);
}

.toast { border-radius: var(--crm-radius); box-shadow: var(--crm-shadow-lg); font-size: var(--crm-text-base); }

@media (max-width: 575.98px) {
  #toast-host { left: 0; right: 0; padding: var(--crm-space-3) !important; }
  #toast-host .toast { width: 100%; }
}

.alert { border-radius: var(--crm-radius); font-size: var(--crm-text-base); }

.nav-tabs .nav-link { font-weight: var(--crm-weight-medium); }
.nav-tabs .nav-link .ti { font-size: 17px; }
.nav-tabs .nav-link.active { color: var(--crm-text); }


/* -------------------------------------------------------------------------
   13. KANBAN
   ------------------------------------------------------------------------- */
.kanban-cards { min-height: 120px; padding: var(--crm-space-2); }

.kanban-card {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow-sm);
  cursor: grab;
  touch-action: manipulation;
  transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}

.kanban-card:hover  { border-color: var(--crm-border-strong); box-shadow: var(--crm-shadow); }
.kanban-card:active { cursor: grabbing; }

.kanban-card .card-body { padding: var(--crm-space-3) !important; }

.kanban-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: var(--crm-text-sm);
  color: var(--crm-text-secondary);
  min-width: 0;
}

.kanban-meta .ti { font-size: 15px; color: var(--crm-text-muted); flex: 0 0 auto; }

.kanban-card-ghost  { opacity: .4; }
.kanban-card-chosen { box-shadow: 0 0 0 2px var(--brand-primary); }
.kanban-card-drag   { transform: rotate(2deg); }
.kanban-card-busy   { opacity: .6; pointer-events: none; }
.kanban-card-saved  { box-shadow: 0 0 0 2px var(--crm-success); transition: box-shadow .3s; }

/* Column chrome: the stage colour runs along the top of its column. */
.kanban-column { border-top: 3px solid var(--stage-color, var(--crm-border-strong)); }
.kanban-column > .card-header { background: var(--crm-surface); }
.kanban-column .kanban-cards { background: var(--crm-surface-sunken); }

/* Days-in-stage is the number that reveals stalled deals. */
.days-in-stage.is-warning { color: var(--crm-warning) !important; }
.days-in-stage.is-late    { color: var(--crm-error) !important; font-weight: var(--crm-weight-semibold); }

@media (max-width: 768px) {
  #kanban-board > .col-auto { width: 85vw !important; }
}


/* -------------------------------------------------------------------------
   14. CALENDAR
   FullCalendar reads its own --fc-* variables; point them at the tokens.
   ------------------------------------------------------------------------- */
.fc {
  --fc-border-color: var(--crm-divider);
  --fc-page-bg-color: var(--crm-surface);
  --fc-neutral-bg-color: var(--crm-surface-sunken);
  --fc-today-bg-color: rgba(var(--brand-primary-rgb), .07);
  --fc-button-bg-color: var(--crm-surface);
  --fc-button-border-color: var(--crm-border-strong);
  --fc-button-text-color: var(--crm-text);
  --fc-button-hover-bg-color: var(--crm-surface-sunken);
  --fc-button-hover-border-color: var(--crm-border-strong);
  --fc-button-active-bg-color: var(--brand-primary);
  --fc-button-active-border-color: var(--brand-primary);
  font-size: var(--crm-text-base);
}

.fc .fc-button { font-weight: var(--crm-weight-semibold); text-transform: capitalize; box-shadow: none !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: var(--crm-text-inverse); }
.fc .fc-col-header-cell-cushion { font-size: var(--crm-text-xs); text-transform: uppercase; letter-spacing: var(--crm-tracking-caps); color: var(--crm-text-secondary); }
.fc .fc-daygrid-day-number { color: var(--crm-text-secondary); }
.fc-event { border-radius: var(--crm-radius-sm); }
.fc-event.task-done { opacity: .55; text-decoration: line-through; }
.fc .fc-toolbar-title { font-size: 1.2rem; font-weight: var(--crm-weight-bold); }

@media (max-width: 768px) {
  .fc .fc-toolbar { flex-direction: column; gap: var(--crm-space-2); }
  .fc .fc-toolbar-chunk { display: flex; justify-content: center; }
}


/* -------------------------------------------------------------------------
   15. EMPTY AND LOADING STATES
   An icon in a soft disc, a title, one line. Skeletons match the layout.
   ------------------------------------------------------------------------- */
.empty { padding: var(--crm-space-10) var(--crm-space-5); text-align: center; }

.empty-icon {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto var(--crm-space-3);
  border-radius: 50%;
  background: var(--crm-surface-sunken);
  color: var(--crm-text-muted);
}

.empty-icon .ti, .empty-icon .icon { font-size: 26px; width: auto; height: auto; }

.empty-title {
  margin-bottom: var(--crm-space-1);
  font-size: var(--crm-text-md);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-text);
}

.empty-subtitle { font-size: var(--crm-text-base); color: var(--crm-text-muted); }

.skeleton {
  background: linear-gradient(90deg, #EDF0F3 25%, #F5F7F9 50%, #EDF0F3 75%);
  background-size: 200% 100%;
  border-radius: var(--crm-radius-sm);
  animation: skeleton-shift 1.2s ease-in-out infinite;
}

@keyframes skeleton-shift {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}


/* -------------------------------------------------------------------------
   16. VERTICAL MODULES
   Industry-specific, not brand-specific. Kept separate from core so they
   can be omitted per deployment.
   ------------------------------------------------------------------------- */

/* --- Materials / manufacturing: stock availability --- */
.stock {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  font-size: var(--crm-text-sm);
}

.stock::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.stock-ready   { color: var(--crm-success); }
.stock-partial { color: var(--crm-warning); }
.stock-made    { color: var(--crm-text-secondary); }

/* --- Certification / compliance chips --- */
.cert-chip {
  display: inline-block;
  padding: 1px var(--crm-space-2);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-sm);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-medium);
  color: var(--crm-text-secondary);
  background: var(--crm-surface);
}

.cert-chip + .cert-chip { margin-left: var(--crm-space-1); }


/* -------------------------------------------------------------------------
   17. DARK THEME
   Tabler switches on [data-bs-theme="dark"] (set on <html>, and always on the
   sidebar). Values only: every rule above consumes tokens.
   ------------------------------------------------------------------------- */
[data-bs-theme="dark"] {
  --crm-bg-app:          #0F1214;
  --crm-surface:         #171B1F;
  --crm-surface-sunken:  #1E2328;
  --crm-surface-hover:   #1C2126;
  --crm-border:          #2A3036;
  --crm-border-strong:   #3A424A;
  --crm-divider:         #23282D;

  /* --crm-text-inverse is deliberately NOT flipped: it sits on a brand-filled
     button, not on the page, so it stays white in both themes. */
  --crm-text:            #E4E8EC;
  --crm-text-secondary:  #A3ADB8;
  --crm-text-muted:      #78828E;

  --crm-success:         #3FBF8F;
  --crm-success-subtle:  #12302A;
  --crm-warning:         #E0A44A;
  --crm-warning-subtle:  #31260F;
  --crm-error:           #F2647C;
  --crm-error-subtle:    #331A20;
  --crm-info:            #6BA8E8;
  --crm-info-subtle:     #13243A;

  --crm-tone-blue:       #6BA8E8;
  --crm-tone-violet:     #AE92DC;
  --crm-tone-cyan:       #5FB0C9;

  --crm-status-new:         #9AA4B0;
  --crm-status-contacted:   #6BA8E8;
  --crm-status-sample:      #AE92DC;
  --crm-status-qualified:   #5FB0C9;
  --crm-status-quotation:   #E0A44A;
  --crm-status-negotiation: #D4A04A;
  --crm-status-won:         #3FBF8F;
  --crm-status-lost:        #8A93A0;
  --crm-status-overdue:     #F2647C;

  --crm-status-new-bg:         #22272C;
  --crm-status-contacted-bg:   var(--crm-info-subtle);
  --crm-status-sample-bg:      #241E33;
  --crm-status-qualified-bg:   #122A31;
  --crm-status-quotation-bg:   var(--crm-warning-subtle);
  --crm-status-negotiation-bg: #2E2412;
  --crm-status-won-bg:         var(--crm-success-subtle);
  --crm-status-lost-bg:        #22272C;
  --crm-status-overdue-bg:     var(--crm-error-subtle);

  --crm-temp-hot:     #FB8A4C;
  --crm-temp-hot-bg:  #3A1E10;
  --crm-temp-warm:    #F2C14E;
  --crm-temp-warm-bg: #33280C;
  --crm-temp-cold:    #5BB6EC;
  --crm-temp-cold-bg: #0E2738;

  --crm-shadow-sm: 0 1px 2px rgba(0,0,0,.40);
  --crm-shadow:    0 4px 12px rgba(0,0,0,.45);
  --crm-shadow-lg: 0 20px 40px rgba(0,0,0,.60);
}

/* --brand-primary-subtle is a pale wash owned by the theme file; on a dark
   ground the brand's own rgb at low alpha is the right equivalent. */
[data-bs-theme="dark"] .table tbody tr.selected,
[data-bs-theme="dark"] .table-stack thead .table-sort.asc,
[data-bs-theme="dark"] .table-stack thead .table-sort.desc {
  background: rgba(var(--brand-primary-rgb), .16);
}

[data-bs-theme="dark"] .page-title-icon,
[data-bs-theme="dark"] .card-icon,
[data-bs-theme="dark"] .kpi-icon {
  background: color-mix(in srgb, var(--tone) 18%, transparent);
}

[data-bs-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #1E2328 25%, #262C32 50%, #1E2328 75%);
  background-size: 200% 100%;
}


/* -------------------------------------------------------------------------
   18. IN-FLIGHT BUTTONS
   htmx puts .htmx-request on whatever started a request — the button for a
   button-initiated post, the form for a submit — and removes it when the
   response lands. Styling that one class covers every save, delete, assign
   and note in the app, including any added later, with no per-button markup.
   ------------------------------------------------------------------------- */
button.htmx-request,
a.htmx-request,
form.htmx-request button[type="submit"] {
  /* Blocks the double-click that would otherwise post twice. */
  pointer-events: none;
  opacity: .75;
}

button.htmx-request::before,
a.htmx-request::before,
form.htmx-request button[type="submit"]::before {
  content: "";
  display: inline-block;
  width: .9em;
  height: .9em;
  margin-right: var(--crm-space-1);
  vertical-align: -.1em;
  border: 2px solid currentColor;   /* inherits the button's own text colour,
                                       so it reads on filled and ghost alike */
  border-right-color: transparent;
  border-radius: 50%;
  animation: crm-spin .6s linear infinite;
}

@keyframes crm-spin {
  to { transform: rotate(360deg); }
}

/* The label is kept rather than swapped for the spinner: "Saving" next to a
   spinner is clearer than a button that appears to lose its text. */


/* -------------------------------------------------------------------------
   19. AUTH PAGES
   ------------------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(var(--brand-primary-rgb), .14), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(var(--brand-primary-rgb), .10), transparent 60%),
    var(--crm-bg-app);
}

.auth-page .crm-brand { color: var(--crm-text); font-size: 22px; }
.auth-page .crm-brand-name small { color: var(--brand-primary); }
.auth-page .card { box-shadow: var(--crm-shadow); }
.auth-page .card-body { padding: var(--crm-space-8); }

@media (max-width: 575.98px) {
  .auth-page .card-body { padding: var(--crm-space-5); }
}


/* -------------------------------------------------------------------------
   20. LEADS: FILTER BAR, CARDS, TEMPERATURE, DRAWER
   ------------------------------------------------------------------------- */
.min-w-0 { min-width: 0 !important; }

/* ---------- filter bar ---------- */
.lead-filters {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--crm-space-2) var(--crm-space-3);
  margin-bottom: var(--crm-space-4);
  padding: var(--crm-space-3) var(--crm-space-4);
}

.lead-filter-search { position: relative; flex: 1 1 100%; min-width: 0; }
.lead-filter-search .form-control { width: 100%; }
.lead-filter-search .htmx-indicator { position: absolute; top: 12px; right: 12px; z-index: 3; }

.lead-filter-field { position: relative; flex: 1 1 0; min-width: 10rem; }
.lead-filter-field .form-select { width: 100%; padding-left: 38px; font-weight: var(--crm-weight-medium); }

.lead-filter-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  z-index: 1;
  transform: translateY(-50%);
  font-size: 17px;
  color: var(--crm-text-muted);
  pointer-events: none;
}

/* The dropdowns' row. Always shown from md up (d-md-flex); on a phone it is a
   collapse opened by .lead-filter-toggle, two dropdowns to a line. */
.lead-filter-more {
  flex: 1 1 100%;
  flex-wrap: wrap;
  gap: var(--crm-space-2) var(--crm-space-3);
}

.lead-filter-more.show,
.lead-filter-more.collapsing { display: flex; }

.lead-filter-toggle { flex: 0 0 auto; }
.lead-filter-toggle.has-active { border-color: var(--brand-primary); color: var(--brand-primary); }

@media (max-width: 767.98px) {
  .lead-filter-search { flex: 1 1 0; }
  .lead-filter-field  { flex: 1 1 calc(50% - var(--crm-space-3)); min-width: 0; }
}

/* ---------- Cards / List toggle ---------- */
.view-toggle .btn {
  background: var(--crm-surface);
  border-color: var(--crm-border);
  color: var(--crm-text-secondary);
  box-shadow: none;
}

.view-toggle .btn:hover { background: var(--crm-surface-sunken); color: var(--crm-text); }

.view-toggle .btn.active {
  background: var(--brand-primary-subtle);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  z-index: 1;
}

[data-bs-theme="dark"] .view-toggle .btn.active { background: rgba(var(--brand-primary-rgb), .18); color: var(--crm-link); }

/* ---------- cards ---------- */
.lead-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--crm-space-3);
  padding: var(--crm-space-4);
  background: var(--crm-surface-sunken);
  border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg);
}

.lead-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--crm-space-3);
  padding: var(--crm-space-4) var(--crm-space-4) var(--crm-space-4) var(--crm-space-5);
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  box-shadow: var(--crm-shadow-sm);
  transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
}

.lead-card:hover { border-color: var(--crm-border-strong); box-shadow: var(--crm-shadow); }

/* Overdue: a red edge, as on the table row — never a red card. */
.lead-card.is-overdue {
  border-left: 4px solid var(--crm-error);
  padding-left: calc(var(--crm-space-5) - 3px);
}

.lead-card-body { flex: 1 1 auto; min-width: 0; }

.lead-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px var(--crm-space-4);
}

.lead-card-title {
  min-width: 0;
  font-size: 17px;
  font-weight: var(--crm-weight-semibold);
  line-height: 1.3;
  color: var(--crm-text);
  overflow-wrap: anywhere;
}

.lead-card-title:hover { color: var(--crm-link); text-decoration: none; }

.lead-card-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.lead-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--crm-space-5);
  margin-top: 10px;
  font-size: var(--crm-text-base);
  color: var(--crm-text-secondary);
}

.lead-meta {
  --tone: var(--crm-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.lead-meta .ti { font-size: 16px; color: var(--tone); }
.lead-meta .status-dot { width: 8px; height: 8px; }

a.lead-meta:hover,
.lead-meta-button:hover { color: var(--crm-link); text-decoration: none; }

.lead-meta-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.lead-meta-button:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; border-radius: var(--crm-radius-sm); }
.lead-meta-muted { color: var(--crm-text-muted); }
.lead-meta-address { max-width: 100%; }
.lead-meta-address > span { min-width: 0; }

.lead-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--crm-space-3);
  margin-top: var(--crm-space-3);
  padding-top: 10px;
  border-top: 1px solid var(--crm-divider);
}

.lead-card-next {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex: 1 1 260px;
  min-width: 0;
  font-size: var(--crm-text-base);
  color: var(--crm-text-secondary);
}

.lead-card-next.is-empty { align-items: center; color: var(--crm-text-muted); font-style: italic; }
.lead-card-next.is-empty .ti { font-style: normal; }

.lead-card-next strong { color: var(--crm-text); font-weight: var(--crm-weight-semibold); }
.lead-card-next-when   { flex: 0 0 auto; white-space: nowrap; color: var(--crm-text-muted); }

.lead-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.lead-card-actions .btn { color: var(--crm-text-secondary); padding: 0 8px; }
.lead-card-actions .btn:hover { color: var(--brand-primary); background: var(--brand-primary-subtle); }
[data-bs-theme="dark"] .lead-card-actions .btn:hover { background: rgba(var(--brand-primary-rgb), .16); color: var(--crm-link); }

.lead-cards-empty {
  background: var(--crm-surface);
  border: 1px dashed var(--crm-border-strong);
  border-radius: var(--crm-radius-lg);
}

.list-loading { grid-column: 1 / -1; }

/* The "No leads" message stays in the DOM when Create prepends the first lead
   above it; hide it as soon as any lead precedes it. */
.lead-cards > .lead-card ~ .lead-cards-empty,
tbody > tr[id^="lead-"] ~ tr.lead-empty-row { display: none; }

@media (max-width: 575.98px) {
  .lead-cards { padding: 10px; gap: 10px; }
  .lead-card  { padding: var(--crm-space-3) var(--crm-space-3) var(--crm-space-3) var(--crm-space-4); }
  .lead-card.is-overdue { padding-left: calc(var(--crm-space-4) - 3px); }
  .lead-card-badges { justify-content: flex-start; width: 100%; }
  .lead-card-meta { gap: 6px var(--crm-space-4); font-size: var(--crm-text-sm); }
  .lead-card-next { flex-wrap: wrap; flex-basis: 100%; }
  .lead-card-actions { margin-left: -8px; width: 100%; justify-content: space-between; }
  .lead-card-actions .btn span { display: none; }
  .lead-card-actions .btn .ti { font-size: 19px; }
}

/* ---------- Temperature picker (lead form) ---------- */
.temp-picker { display: flex; gap: var(--crm-space-2); }

.temp-option { position: relative; flex: 1 1 0; margin: 0; }

.temp-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.temp-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--crm-control-h);
  border: 1px solid var(--crm-border-strong);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
  font-size: var(--crm-text-base);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-text-secondary);
  transition: background var(--crm-transition), border-color var(--crm-transition), color var(--crm-transition);
}

.temp-option:hover span { border-color: var(--crm-text-muted); }
.temp-option input:focus-visible + span { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

.temp-hot  input:checked + span { color: var(--crm-temp-hot);  background: var(--crm-temp-hot-bg);  border-color: var(--crm-temp-hot); }
.temp-warm input:checked + span { color: var(--crm-temp-warm); background: var(--crm-temp-warm-bg); border-color: var(--crm-temp-warm); }
.temp-cold input:checked + span { color: var(--crm-temp-cold); background: var(--crm-temp-cold-bg); border-color: var(--crm-temp-cold); }

/* ---------- details drawer ---------- */
.crm-drawer.offcanvas-end { width: min(720px, 100vw); border-left: 1px solid var(--crm-border); }

.crm-drawer-content,
.lead-drawer {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.lead-drawer-header {
  align-items: flex-start;
  gap: var(--crm-space-3);
  padding: var(--crm-space-5) var(--crm-space-6);
  border-bottom: 1px solid var(--crm-divider);
}

.lead-drawer-header .lead-card-badges { justify-content: flex-start; }

.lead-drawer-title {
  margin: 2px 0;
  font-size: var(--crm-text-xl);
  font-weight: var(--crm-weight-bold);
  letter-spacing: -0.01em;
}

.lead-drawer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--crm-space-2);
  padding: var(--crm-space-3) var(--crm-space-6);
  background: var(--crm-surface-sunken);
  border-bottom: 1px solid var(--crm-divider);
}

.lead-drawer-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--crm-space-5) var(--crm-space-6);
}

.lead-drawer-next {
  display: flex;
  align-items: flex-start;
  gap: var(--crm-space-3);
  margin-bottom: var(--crm-space-5);
  padding: var(--crm-space-3) var(--crm-space-4);
  border: 1px solid color-mix(in srgb, var(--crm-info) 25%, transparent);
  border-radius: var(--crm-radius);
  background: var(--crm-info-subtle);
}

.lead-drawer-next > .ti { font-size: 22px; color: var(--crm-info); }

.lead-drawer-next.is-overdue {
  border-color: color-mix(in srgb, var(--crm-error) 30%, transparent);
  background: var(--crm-error-subtle);
}

.lead-drawer-next.is-overdue > .ti { color: var(--crm-error); }

.lead-drawer-section + .lead-drawer-section { margin-top: var(--crm-space-6); }

.lead-drawer-heading {
  display: flex;
  align-items: center;
  gap: var(--crm-space-2);
  margin-bottom: var(--crm-space-3);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-muted);
}

.lead-drawer-heading .ti { font-size: 16px; }

@media (max-width: 575.98px) {
  .lead-drawer-header,
  .lead-drawer-actions,
  .lead-drawer-body { padding-left: var(--crm-space-4); padding-right: var(--crm-space-4); }
}


/* -------------------------------------------------------------------------
   21. COLLAPSIBLE SIDEBAR (desktop only)
   html.sidebar-collapsed is set before first paint by _Layout and flipped by
   the [data-sidebar-toggle] button (app-init.js). Below lg the sidebar is
   already a collapsible top bar, so none of this applies there.
   ------------------------------------------------------------------------- */
.crm-sidebar-toggle { border: 0; background: none; }

@media (min-width: 992px) {
  .navbar-vertical.navbar-expand-lg,
  .navbar-vertical.navbar-expand-lg ~ .navbar,
  .navbar-vertical.navbar-expand-lg ~ .page-wrapper {
    transition: width 200ms ease, margin-left 200ms ease;
  }

  html.sidebar-collapsed .navbar-vertical.navbar-expand-lg {
    width: var(--crm-sidebar-collapsed-w);
    overflow-x: hidden;
  }

  html.sidebar-collapsed .navbar-vertical.navbar-expand-lg ~ .navbar,
  html.sidebar-collapsed .navbar-vertical.navbar-expand-lg ~ .page-wrapper {
    margin-left: var(--crm-sidebar-collapsed-w);
  }

  html.sidebar-collapsed .navbar-vertical .nav-link-title,
  html.sidebar-collapsed .navbar-vertical .crm-brand-name { display: none; }

  /* Group headings become thin dividers, so the groups still read as groups. */
  html.sidebar-collapsed .navbar-vertical .nav-group-label {
    height: 1px;
    margin: var(--crm-space-3) var(--crm-space-4);
    padding: 0;
    overflow: hidden;
    font-size: 0;
    background: rgba(255,255,255,.10);
  }

  html.sidebar-collapsed .navbar-vertical.navbar-expand-lg .navbar-brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  html.sidebar-collapsed .navbar-vertical .nav-item { margin: 2px var(--crm-space-3); }

  html.sidebar-collapsed .navbar-vertical.navbar-expand-lg .navbar-collapse .navbar-nav .nav-link {
    justify-content: center;
    padding: 0;
  }

  html.sidebar-collapsed .navbar-vertical .nav-link-icon { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .navbar-vertical.navbar-expand-lg,
  .navbar-vertical.navbar-expand-lg ~ .navbar,
  .navbar-vertical.navbar-expand-lg ~ .page-wrapper { transition: none; }
}


/* -------------------------------------------------------------------------
   22. UX ROUND: AVATARS, CHIPS, BELL, STAGE MENU, DRAWER TABS, FORMS
   ------------------------------------------------------------------------- */

/* ---------- avatar tones (ViewFormat.AvatarTone) ----------
   Eight light fills with dark ink (contrast >= 4.7:1), lifted for dark mode
   (>= 6.3:1). A person keeps the same colour on every page. */
.avatar-tone-0 { background: #DBEAFE; color: #1E40AF; }
.avatar-tone-1 { background: #D1FAE5; color: #065F46; }
.avatar-tone-2 { background: #FEF3C7; color: #92400E; }
.avatar-tone-3 { background: #FCE7F3; color: #9D174D; }
.avatar-tone-4 { background: #EDE9FE; color: #5B21B6; }
.avatar-tone-5 { background: #CFFAFE; color: #0E7490; }
.avatar-tone-6 { background: #FFEDD5; color: #9A3412; }
.avatar-tone-7 { background: #ECFCCB; color: #3F6212; }

[data-bs-theme="dark"] .avatar-tone-0 { background: #1E3A5F; color: #93C5FD; }
[data-bs-theme="dark"] .avatar-tone-1 { background: #0F3B2E; color: #6EE7B7; }
[data-bs-theme="dark"] .avatar-tone-2 { background: #3D2E0A; color: #FCD34D; }
[data-bs-theme="dark"] .avatar-tone-3 { background: #4A1D33; color: #F9A8D4; }
[data-bs-theme="dark"] .avatar-tone-4 { background: #2E2154; color: #C4B5FD; }
[data-bs-theme="dark"] .avatar-tone-5 { background: #0E3A44; color: #67E8F9; }
[data-bs-theme="dark"] .avatar-tone-6 { background: #43230E; color: #FDBA74; }
[data-bs-theme="dark"] .avatar-tone-7 { background: #26360E; color: #BEF264; }

.avatar-xs { font-size: 10px; }

/* ---------- saved-view chips (Leads) ---------- */
.view-chips {
  display: flex;
  gap: var(--crm-space-2);
  margin-bottom: var(--crm-space-3);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.view-chips::-webkit-scrollbar { display: none; }

.view-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-pill);
  background: var(--crm-surface);
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-medium);
  color: var(--crm-text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--crm-transition), border-color var(--crm-transition), color var(--crm-transition);
}

.view-chip:hover { border-color: var(--crm-border-strong); color: var(--crm-text); text-decoration: none; }
.view-chip .ti { font-size: 16px; }

.view-chip.active {
  border-color: var(--brand-primary);
  background: var(--brand-primary);
  color: var(--crm-text-inverse);
}

.view-chip-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--crm-radius-pill);
  font-size: 11px;
  font-weight: var(--crm-weight-bold);
}

.view-chip-count.tone-red  { background: var(--crm-error-subtle); color: var(--crm-error); }
.view-chip-count.tone-blue { background: var(--crm-info-subtle); color: var(--crm-info); }
.view-chip.active .view-chip-count { background: rgba(255,255,255,.22); color: #fff; }

/* ---------- list dimming while a search / filter / sort loads ---------- */
.card[id$="-list"] > * { transition: opacity 150ms ease-out; }
.card[id$="-list"].htmx-request > * { opacity: .5; pointer-events: none; }

/* ---------- bell ---------- */
.crm-bell-badge {
  position: absolute;
  top: 3px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: var(--crm-radius-pill);
  border: 2px solid var(--crm-surface);
  background: var(--brand-primary);
  color: #fff;
  font-size: 10px;
  font-weight: var(--crm-weight-bold);
  line-height: 1;
}

.crm-bell-badge.is-overdue { background: var(--crm-error); }
.navbar-vertical .crm-bell-badge { border-color: var(--crm-sidebar-bg); }

.crm-bell-menu { width: min(380px, 92vw); padding: 0; }
.crm-bell-menu .card { border: 0; box-shadow: none; margin: 0; }
.crm-bell-header { min-height: 48px; }
.crm-bell-header .card-title { font-size: var(--crm-text-md); }

.crm-bell-item {
  display: flex !important;
  align-items: center;
  gap: var(--crm-space-3);
  padding-top: 10px;
  padding-bottom: 10px;
}

.crm-bell-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--crm-info);
}

.crm-bell-dot.is-overdue { background: var(--crm-error); }

.crm-bell-empty { display: flex; align-items: center; gap: var(--crm-space-3); }
.crm-bell-empty > .ti { font-size: 28px; color: var(--crm-success); }

/* ---------- stage menu on a card ---------- */
.badge-status-button {
  border: 0;
  cursor: pointer;
  transition: filter var(--crm-transition), box-shadow var(--crm-transition);
}

.badge-status-button:hover { filter: brightness(.96); box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 25%, transparent); }
.badge-status-button:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.badge-status-button .ti { font-size: 12px; margin-left: 2px; opacity: .7; }

.lead-card-badges .dropdown-item { display: flex; align-items: center; gap: var(--crm-space-2); }
.lead-card-badges .dropdown-item.active,
.lead-card-badges .dropdown-item:disabled { background: var(--crm-surface-sunken); opacity: 1; }

/* ---------- drawer tabs and tasks ---------- */
.lead-drawer-tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 0 var(--crm-space-6);
  border-bottom: 1px solid var(--crm-divider);
  scrollbar-width: none;
}

.lead-drawer-tabs .nav-link { white-space: nowrap; font-size: var(--crm-text-sm); }

.lead-drawer-next.is-empty {
  align-items: center;
  border-style: dashed;
  border-color: var(--crm-border-strong);
  background: var(--crm-surface-sunken);
}

.lead-drawer-next.is-empty > .ti { color: var(--crm-text-muted); }

.lead-task-list .list-group-item { padding-left: 0; padding-right: 0; }

@media (max-width: 575.98px) {
  .lead-drawer-tabs { padding: 0 var(--crm-space-4); }
}

/* ---------- Log call ---------- */
.log-call-who {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  padding: var(--crm-space-3);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-sunken);
}

.outcome-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--crm-space-2);
}

.outcome-option { position: relative; margin: 0; }

.outcome-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.outcome-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 6px 8px;
  border: 1px solid var(--crm-border-strong);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-text-secondary);
  text-align: center;
  transition: background var(--crm-transition), border-color var(--crm-transition), color var(--crm-transition);
}

.outcome-option:hover span { border-color: var(--crm-text-muted); }
.outcome-option input:focus-visible + span { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

.outcome-option input:checked + span {
  border-color: var(--brand-primary);
  background: var(--brand-primary-subtle);
  color: var(--brand-primary);
}

[data-bs-theme="dark"] .outcome-option input:checked + span { background: rgba(var(--brand-primary-rgb), .18); color: var(--crm-link); }

.outcome-picker.is-invalid .outcome-option span { border-color: var(--crm-error); }

@media (max-width: 479.98px) {
  .outcome-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- lead form: "More details" ---------- */
.more-details-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 var(--crm-space-2);
  padding: 0;
  border: 0;
  background: none;
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-semibold);
  color: var(--crm-link);
}

.more-details-toggle .ti { transition: transform var(--crm-transition); }
.more-details-toggle:not(.collapsed) .ti { transform: rotate(90deg); }

/* ---------- server validation: the field itself turns red ----------
   ASP.NET marks a failed field with .input-validation-error, which Tabler
   does not style; only the message under it was red. */
.form-control.input-validation-error,
.form-select.input-validation-error { border-color: var(--crm-error); }

.form-control.input-validation-error:focus,
.form-select.input-validation-error:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--crm-error) 18%, transparent); }

/* ---------- Board: empty column ---------- */
.kanban-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--crm-space-4) 0;
  font-size: var(--crm-text-sm);
  color: var(--crm-text-muted);
}

.kanban-empty .ti { font-size: 22px; }

/* ---------- Dashboard: the work queue scrolls rather than stretching the chart ---------- */
@media (min-width: 992px) {
  .dash-tab-content { max-height: 400px; overflow-y: auto; }
}


/* -------------------------------------------------------------------------
   23. PHASE 3: RANGE PILL, BULK BAR, BOARD FILTERS, COMPANY DRAWER
   ------------------------------------------------------------------------- */

/* Date range carried in from a dashboard KPI tile; ✕ clears it. */
.range-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  margin-bottom: var(--crm-space-3);
  padding: 6px 8px 6px 14px;
  border-radius: var(--crm-radius-pill);
  background: var(--brand-primary-subtle);
  color: var(--brand-primary);
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-semibold);
}

[data-bs-theme="dark"] .range-pill { background: rgba(var(--brand-primary-rgb), .16); color: var(--crm-link); }
.range-pill .btn-close { width: .6em; height: .6em; padding: 6px; }

/* ---------- Board filters and card markers ---------- */
.board-filters {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--crm-space-2) var(--crm-space-3);
  margin-bottom: var(--crm-space-4);
  padding: var(--crm-space-3) var(--crm-space-4);
}

.board-filters .lead-filter-field { flex: 0 1 13rem; }

.board-filters-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--crm-text-sm);
  font-weight: var(--crm-weight-semibold);
}

.board-filters-title .ti { font-size: 18px; color: var(--brand-primary); }

@media (max-width: 575.98px) {
  .board-filters .lead-filter-field { flex: 1 1 calc(50% - var(--crm-space-3)); min-width: 0; }
  .board-filters-title { flex-basis: 100%; }
}

.kanban-card.is-overdue { border-left: 3px solid var(--crm-error); }

.kanban-temp {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  border-radius: 50%;
  font-size: 13px;
}

.kanban-followup {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--crm-text-xs);
  color: var(--crm-info);
  white-space: nowrap;
}

.kanban-followup.is-overdue { color: var(--crm-error); font-weight: var(--crm-weight-semibold); }

/* ---------- bulk selection ---------- */
.lead-select { flex: 0 0 auto; margin: 3px 2px 0 0; cursor: pointer; }
.lead-card-head .lead-select { margin-right: var(--crm-space-1); }
.lead-card-head { align-items: flex-start; }
.lead-card-head .lead-card-title { flex: 1 1 auto; }

.lead-card.is-selected,
.table tbody tr.is-selected {
  background: var(--brand-primary-subtle);
  box-shadow: inset 0 0 0 2px rgba(var(--brand-primary-rgb), .45);
}

[data-bs-theme="dark"] .lead-card.is-selected,
[data-bs-theme="dark"] .table tbody tr.is-selected { background: rgba(var(--brand-primary-rgb), .14); }

.bulk-bar {
  position: fixed;
  left: 50%;
  bottom: var(--crm-space-5);
  z-index: 1040;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--crm-space-2) var(--crm-space-4);
  /* Size to the content: positioned from the centre, the bar would otherwise
     only get half the viewport to lay out in and wrap onto two lines. */
  width: max-content;
  max-width: calc(100vw - 2 * var(--crm-space-4));
  padding: var(--crm-space-2) var(--crm-space-3) var(--crm-space-2) var(--crm-space-4);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  background: var(--crm-surface);
  box-shadow: var(--crm-shadow-lg);
}

.bulk-bar[hidden] { display: none; }

.bulk-bar-count { display: inline-flex; align-items: center; gap: 6px; font-size: var(--crm-text-sm); font-weight: var(--crm-weight-medium); }

.bulk-bar-num {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: var(--crm-radius-pill);
  background: var(--brand-primary);
  color: var(--crm-text-inverse);
  font-weight: var(--crm-weight-bold);
}

.bulk-bar-action { display: inline-flex; align-items: center; gap: 6px; }
.bulk-bar-action .form-select { width: auto; min-width: 11rem; }

/* Room at the bottom of the page so the bar never hides the last lead. */
body.has-bulk-bar .page-body { padding-bottom: 88px; }

@media (max-width: 767.98px) {
  .bulk-bar { left: var(--crm-space-3); right: var(--crm-space-3); bottom: var(--crm-space-3); transform: none; width: auto; max-width: none; }
  .bulk-bar-action { flex: 1 1 100%; }
  .bulk-bar-action .form-select { flex: 1 1 auto; min-width: 0; }
  .bulk-bar-close { position: absolute; top: 12px; right: 12px; }
  body.has-bulk-bar .page-body { padding-bottom: 220px; }
}

/* ---------- company drawer / page ---------- */
.company-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--crm-space-3);
}

.company-stat {
  padding: var(--crm-space-3);
  border: 1px solid var(--crm-divider);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-sunken);
}

.company-stat-value {
  margin-top: 4px;
  font-size: var(--crm-text-xl);
  font-weight: var(--crm-weight-bold);
  line-height: var(--crm-leading-tight);
}

.company-stat-value.small { font-size: var(--crm-text-md); font-weight: var(--crm-weight-semibold); padding-top: 4px; }

.company-page .lead-drawer-tabs { padding-left: var(--crm-space-5); padding-right: var(--crm-space-5); }
.company-page .lead-drawer-body { overflow: visible; }

/* The pencil beside a company name only shows when the row is hovered or
   focused, so the list does not read as a column of pencils. Always shown on
   touch screens, which have no hover. */
.company-edit { opacity: 0; transition: opacity var(--crm-transition); }
tr:hover .company-edit, .company-edit:focus-visible { opacity: 1; }
@media (hover: none) { .company-edit { opacity: 1; } }


/* -------------------------------------------------------------------------
   24. PHASE 4: SEARCH PALETTE, + NEW, CALENDAR AGENDA, ORG CHART, MATRIX
   ------------------------------------------------------------------------- */

/* ---------- top-bar search trigger ---------- */
.crm-search-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--crm-space-2);
  width: clamp(220px, 28vw, 380px);
  height: 38px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-sunken);
  color: var(--crm-text-muted);
  font-size: var(--crm-text-sm);
  text-align: left;
  transition: border-color var(--crm-transition), background var(--crm-transition);
}

.crm-search-trigger:hover { border-color: var(--crm-border-strong); background: var(--crm-surface); }
.crm-search-trigger span { flex: 1 1 auto; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.crm-search-trigger .ti { font-size: 17px; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--crm-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--crm-surface);
  color: var(--crm-text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: var(--crm-weight-semibold);
  box-shadow: none;
}

.crm-new-btn { gap: 4px; padding: 0 12px; }

/* ---------- search palette ---------- */
.search-dialog { margin-top: 10vh; }
#search-modal .modal-content { overflow: hidden; }

.search-box {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  padding: var(--crm-space-3) var(--crm-space-4);
  border-bottom: 1px solid var(--crm-divider);
}

.search-box > .ti { font-size: 22px; color: var(--brand-primary); }

.search-box .form-control,
.search-box input[type="search"].form-control {
  height: 44px;
  padding-left: 0;
  border: 0;
  background-image: none;
  box-shadow: none;
  font-size: 17px;
}

.search-results { max-height: min(60vh, 520px); overflow-y: auto; padding: var(--crm-space-2); }

.search-group-label {
  padding: var(--crm-space-3) var(--crm-space-3) var(--crm-space-1);
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--crm-tracking-caps);
  color: var(--crm-text-muted);
}

.search-result {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  padding: 9px var(--crm-space-3);
  border-radius: var(--crm-radius);
  color: var(--crm-text);
  text-decoration: none;
}

.search-result:hover,
.search-result.is-active { background: var(--brand-primary-subtle); color: var(--crm-text); text-decoration: none; }
[data-bs-theme="dark"] .search-result:hover,
[data-bs-theme="dark"] .search-result.is-active { background: rgba(var(--brand-primary-rgb), .16); }

.search-see-all { color: var(--crm-link); font-size: var(--crm-text-sm); font-weight: var(--crm-weight-medium); }
.search-see-all .ti { font-size: 18px; }

.search-hint,
.search-empty { padding: var(--crm-space-5); color: var(--crm-text-secondary); font-size: var(--crm-text-sm); }
.search-hint > div { display: flex; align-items: center; gap: var(--crm-space-2); margin-bottom: 6px; }
.search-empty { display: grid; justify-items: center; gap: 4px; text-align: center; }
.search-empty > .ti { font-size: 30px; color: var(--crm-text-muted); }

@media (max-width: 575.98px) {
  .search-dialog { margin: 0; }
  #search-modal .modal-content { min-height: 100vh; border-radius: 0; }
  .search-results { max-height: none; }
}

/* ---------- calendar: legend and agenda ---------- */
.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--crm-space-4);
  margin-top: var(--crm-space-3);
  font-size: var(--crm-text-xs);
  color: var(--crm-text-secondary);
}

.calendar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.calendar-legend i { width: 10px; height: 10px; border-radius: 3px; }

.agenda-list { max-height: 70vh; overflow-y: auto; padding: 0 0 var(--crm-space-2); }

.agenda-group-label {
  --tone: var(--crm-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--crm-space-3) var(--crm-space-5) 6px;
  font-size: var(--crm-text-xs);
  font-weight: var(--crm-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--crm-tracking-caps);
  color: var(--tone);
}

.agenda-item {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  padding: 8px var(--crm-space-5);
  border-left: 3px solid transparent;
}

.agenda-item:hover { background: var(--crm-surface-hover); }
.agenda-item.is-overdue { border-left-color: var(--crm-error); }

@media (min-width: 1200px) {
  .agenda-card { position: sticky; top: var(--crm-space-4); }
}

/* ---------- org chart (users, in the drawer) ---------- */
.org-tree,
.org-tree ul { list-style: none; margin: 0; padding: 0; }

.org-tree ul {
  margin-left: 18px;
  padding-left: 16px;
  border-left: 2px solid var(--crm-divider);
}

.org-tree li { position: relative; padding: 4px 0; }

/* The elbow from the branch line into each child. */
.org-tree ul > li::before {
  content: "";
  position: absolute;
  top: 26px;
  left: -16px;
  width: 14px;
  border-top: 2px solid var(--crm-divider);
}

.org-node {
  display: flex;
  align-items: center;
  gap: var(--crm-space-3);
  padding: var(--crm-space-2) var(--crm-space-3);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface);
}

.org-node:hover { border-color: var(--crm-border-strong); }

/* ---------- permission matrix helpers ---------- */
.matrix-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--crm-space-2);
  margin-bottom: var(--crm-space-3);
}

.matrix-col {
  padding: 2px 6px;
  border: 0;
  border-radius: var(--crm-radius-sm);
  background: none;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.matrix-col:hover { background: var(--brand-primary-subtle); color: var(--brand-primary); }
.matrix-col:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 1px; }
.matrix-row { padding: 0 8px; height: 26px; font-size: var(--crm-text-xs); }
.perm-matrix tbody tr:hover { background: var(--crm-surface-hover); }
