/* ═══════════════════════════════════════════════════════════════════════════
   CRM UI  —  Global Design System  v1.0
   Covers: design tokens · toolbar · buttons · badges · tables · cards
           modals · forms · column-toggle · export menu · empty/load states
           print styles · dark-mode · responsive
   Primary colours are set dynamically in app.blade.php :root via PHP.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. DESIGN TOKENS ────────────────────────────────────────────────────── */
:root {
  /* Sizing */
  --crm-toolbar-h:      44px;
  --crm-th-h:           36px;
  --crm-row-h:          46px;
  --crm-btn-sz:         32px;
  --crm-btn-sz-sm:      26px;
  --crm-btn-sz-lg:      38px;

  /* Radii */
  --crm-r-xs:    4px;
  --crm-r-sm:    6px;
  --crm-r-md:   10px;
  --crm-r-lg:   16px;
  --crm-r-xl:   20px;
  --crm-r-pill: 999px;

  /* Shadows */
  --crm-sh-xs: 0 1px 3px rgba(0,0,0,.06);
  --crm-sh-sm: 0 2px 8px rgba(0,0,0,.08);
  --crm-sh-md: 0 4px 16px rgba(0,0,0,.10);
  --crm-sh-lg: 0 8px 32px rgba(0,0,0,.14);

  /* Type scale */
  --crm-fs-xs:   .68rem;
  --crm-fs-sm:   .76rem;
  --crm-fs-base: .86rem;
  --crm-fs-md:   .92rem;

  /* Motion */
  --crm-tx: .14s ease;

  /* Status palette */
  --s-success:  #15803d;  --s-bg-success:  #dcfce7;  --s-br-success:  #86efac;
  --s-warning:  #b45309;  --s-bg-warning:  #fef3c7;  --s-br-warning:  #fcd34d;
  --s-danger:   #b91c1c;  --s-bg-danger:   #fee2e2;  --s-br-danger:   #fca5a5;
  --s-info:     #1d4ed8;  --s-bg-info:     #dbeafe;  --s-br-info:     #93c5fd;
  --s-purple:   #6d28d9;  --s-bg-purple:   #ede9fe;  --s-br-purple:   #c4b5fd;
  --s-neutral:  #6b7280;  --s-bg-neutral:  #f3f4f6;  --s-br-neutral:  #d1d5db;
  --s-orange:   #c2410c;  --s-bg-orange:   #ffedd5;  --s-br-orange:   #fdba74;
  --s-teal:     #0f766e;  --s-bg-teal:     #ccfbf1;  --s-br-teal:     #5eead4;

  /* Table */
  --crm-stripe: rgba(0,0,0,.015);
  --crm-hover:  var(--crm-primary-soft, rgba(83,3,131,.06));
}


/* ── 2. CSS-ONLY TOOLTIP  (for dropdown-toggle buttons where Bootstrap  ──── */
/*    data-bs-toggle="tooltip" would conflict with data-bs-toggle="dropdown") */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,10,25,.85);
  color: #fff;
  font-size: .65rem;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 9000;
  letter-spacing: .02em;
}
[data-tip]:hover::after { opacity: 1; }

/* Card headers have overflow:hidden on the parent .crm-card — tooltip must
   appear BELOW the button so it is never clipped by the card boundary.     */
.crm-card-header [data-tip]::after {
  bottom: auto;
  top: calc(100% + 6px);
}


/* ── 2b. HELP TIP "?" BADGE — replaces all inline form-field descriptions ─ */
/* Usage: <span class="crm-help-tip" data-tip="Description here">?</span>    */
.crm-help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--crm-primary, #530383);
  color: #fff;
  font-size: .58rem;
  font-weight: 700;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 5px;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
  text-decoration: none;
  transition: background .15s;
}
.crm-help-tip:hover { background: var(--crm-primary-dark, #3d0260); }
.crm-help-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,10,25,.93);
  color: #fff;
  font-size: .72rem;
  font-weight: 400;
  padding: 7px 11px;
  border-radius: 7px;
  width: max-content;
  max-width: 260px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 9999;
  letter-spacing: .01em;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
}
.crm-help-tip:hover::after { opacity: 1; }
/* Keep badge on same baseline as label text */
.form-label .crm-help-tip,
label .crm-help-tip { margin-bottom: 2px; }
/* Standalone tip below an input: add top margin */
.mb-3 > .crm-help-tip,
.mb-2 > .crm-help-tip { margin-top: 4px; margin-left: 0; }


/* ── Date field labels inside filter bars ───────────────────────────────── */
/* Every date input-group must be preceded by a .crm-filter-date-label span
   showing the column header name (Created, Due Date, Period, etc.)          */
.crm-filter-date-label,
.crm-filter-wrap span[style*="font-weight:500"] {
  font-size: .75rem;
  color: #9ca3af;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .02em;
  text-transform: none;
}

/* ── 3. STANDARD FILTER BAR — universal across CRM, super-admin, addons ─── */
/*
 * Usage: add class="crm-filter-bar" to any filter container div.
 * Children: .form-select-sm (auto-width), input-group date pickers,
 *           .crm-icon-btn apply/clear buttons — all auto-aligned.
 */
.crm-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #f9fafb;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
}
/* Hides crm-filter-left even when d-flex is present — !important needed to beat Bootstrap */
.crm-filter-left--hidden { display: none !important; }

/* All selects inside any filter bar: auto-width, consistent height */
.crm-filter-bar .form-select,
.crm-filter-bar .form-select-sm,
.crm-filter-wrap .form-select,
.crm-filter-wrap .form-select-sm,
.card-header .form-select-sm,
.crm-card-header .form-select-sm {
  width: auto !important;
  min-width: 110px;
  max-width: 220px;
  height: 32px;
  border-radius: 8px !important;
  font-size: .8rem;
  border-color: var(--crm-border, #e8eaef);
  background-color: #fff;
}

/* Search inputs inside filter bars */
.crm-filter-bar .form-control,
.crm-filter-bar .form-control-sm {
  height: 32px;
  border-radius: 8px !important;
  font-size: .8rem;
  border-color: var(--crm-border, #e8eaef);
}

/* Date input-group inside filter bars */
.crm-filter-bar .input-group .form-control { border-radius: 0 8px 8px 0 !important; }
.crm-filter-bar .input-group .input-group-text {
  border-radius: 8px 0 0 8px !important;
  background: transparent;
  border-right: 0;
  color: #9ca3af;
  font-size: .82rem;
  padding: 0 8px;
}

/* Separator */
.crm-filter-bar .crm-filter-sep {
  width: 1px; height: 20px;
  background: var(--crm-border, #e8eaef);
  flex-shrink: 0;
}

/* ── SECTION CARD ────────────────────────────────────────────────────────── */
/* ── 3. SECTION CARD ────────────────────────────────────────────────────── */
.crm-card {
  background: #fff;
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: var(--crm-card-radius, 20px);
  box-shadow: var(--crm-card-shadow, 0 2px 12px rgba(0,0,0,.06));
  overflow: hidden;
}

.crm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
  background: #fff;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 54px;
}

.crm-card-title {
  font-size: var(--crm-fs-md);
  font-weight: 700;
  color: #2d2d3a;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.crm-card-title > i { font-size: 1.05rem; color: var(--crm-primary, #530383); }

.crm-card-body  { padding: 20px; }
.crm-card-flush { padding: 0; }

/* Round table top corners inside a card.
   crm-table-wrap has overflow-x:auto which breaks the parent overflow:hidden clip,
   so we round the th cells directly instead of relying on the card's border-radius. */
.crm-card .crm-table-wrap table.crm-table thead tr:first-child th:first-child {
  border-top-left-radius: calc(var(--crm-card-radius, 20px) - 2px);
}
.crm-card .crm-table-wrap table.crm-table thead tr:first-child th:last-child {
  border-top-right-radius: calc(var(--crm-card-radius, 20px) - 2px);
}
/* When table is the very first child (no card-header above it) */
.crm-card > .crm-table-wrap:first-child { overflow: hidden; }
.crm-card > .crm-table-wrap:first-child .crm-table-inner { overflow-x: auto; }


/* ── 4. TOOLBAR ─────────────────────────────────────────────────────────── */
.crm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
  background: #fff;
  flex-wrap: wrap;
  gap: 8px;
  min-height: var(--crm-toolbar-h);
}

.crm-toolbar-left,
.crm-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.crm-toolbar-right { margin-left: auto; }

/* Search — global, works in .crm-toolbar, .crm-card-header, .crm-btn-group */
.crm-search { position: relative; display: flex; align-items: center; }
.crm-search-icon {
  position: absolute; left: 9px;
  font-size: .82rem; color: #9ca3af;
  pointer-events: none; z-index: 1;
}
.crm-search-input {
  padding-left: 28px !important;
  border-radius: var(--crm-r-pill) !important;
  font-size: var(--crm-fs-sm);
  height: 32px;
  border: 1px solid var(--crm-border, #e8eaef);
  background: #f9f9fb;
  transition: border-color var(--crm-tx), box-shadow var(--crm-tx), width var(--crm-tx), background var(--crm-tx);
  width: 200px;
}
.crm-search-input:focus {
  background: #fff;
  border-color: var(--crm-primary, #530383);
  box-shadow: 0 0 0 3px rgba(83,3,131,.08);
  outline: none;
  width: 240px;
}

.crm-toolbar-sep {
  width: 1px; height: 20px;
  background: var(--crm-border, #e8eaef);
  margin: 0 2px;
}


/* ── 5. ICON-ONLY BUTTONS ───────────────────────────────────────────────── */
/* Rule: ALL toolbar/table action buttons are icon-only. Tooltip explains action. */

.crm-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width:  var(--crm-btn-sz);
  height: var(--crm-btn-sz);
  border-radius: var(--crm-r-sm);
  border: 1px solid var(--crm-border, #e8eaef);
  background: #fff;
  color: #5a5a72;
  font-size: .9rem;
  cursor: pointer;
  padding: 0;
  transition: all var(--crm-tx);
  flex-shrink: 0;
  text-decoration: none;
  line-height: 1;
}
.crm-btn-icon:hover {
  border-color: var(--crm-primary, #530383);
  color: var(--crm-primary, #530383);
  background: var(--crm-hover);
  transform: translateY(-1px);
  box-shadow: var(--crm-sh-xs);
}
.crm-btn-icon:active {
  transform: translateY(0);
  box-shadow: none;
}
.crm-btn-icon:focus-visible {
  outline: 2px solid var(--crm-primary, #530383);
  outline-offset: 2px;
}
/* Sizes */
.crm-btn-icon.sz-sm { width: var(--crm-btn-sz-sm); height: var(--crm-btn-sz-sm); font-size: .75rem; border-radius: var(--crm-r-xs); }
.crm-btn-icon.sz-lg { width: var(--crm-btn-sz-lg); height: var(--crm-btn-sz-lg); font-size: 1rem;   border-radius: var(--crm-r-md); }

/* Colour modifiers */
.crm-btn-icon.v-primary {
  background: var(--crm-primary, #530383);
  border-color:  var(--crm-primary, #530383);
  color: #fff;
}
.crm-btn-icon.v-primary:hover {
  background: var(--crm-primary-light, #7a12b8);
  border-color:  var(--crm-primary-light, #7a12b8);
  color: #fff;
  box-shadow: 0 3px 12px rgba(83,3,131,.35);
}
.crm-btn-icon.v-success { background: var(--s-bg-success); border-color: var(--s-br-success); color: var(--s-success); }
.crm-btn-icon.v-success:hover { background: var(--s-success); border-color: var(--s-success); color: #fff; }
.crm-btn-icon.v-danger  { background: var(--s-bg-danger);  border-color: var(--s-br-danger);  color: var(--s-danger);  }
.crm-btn-icon.v-danger:hover  { background: var(--s-danger);  border-color: var(--s-danger);  color: #fff; }
.crm-btn-icon.v-warning { background: var(--s-bg-warning); border-color: var(--s-br-warning); color: var(--s-warning); }
.crm-btn-icon.v-warning:hover { background: var(--s-warning); border-color: var(--s-warning); color: #fff; }
.crm-btn-icon.v-info    { background: var(--s-bg-info);    border-color: var(--s-br-info);    color: var(--s-info);    }
.crm-btn-icon.v-info:hover    { background: var(--s-info);    border-color: var(--s-info);    color: #fff; }

/* Strip Bootstrap's dropdown caret — icon-only buttons need no text/arrow */
.crm-btn-icon.dropdown-toggle::after,
.crm-btn-icon.dropdown-toggle::before { display: none !important; }

/* Active (toggled-on) state */
.crm-btn-icon.is-active {
  background: var(--crm-primary, #530383);
  border-color: var(--crm-primary, #530383);
  color: #fff;
}

/* Button group */
.crm-btn-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Ensure filter panel selects are consistent height */
.crm-card-header .form-select-sm,
.crm-card-header .form-control-sm { height: 32px; }


/* ── 6. TABLE ROW ACTION BUTTONS (smaller, inside td) ───────────────────── */
.crm-ab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--crm-r-xs);
  border: 1px solid transparent;
  background: transparent;
  font-size: .8rem;
  cursor: pointer;
  padding: 0;
  color: #9ca3af;
  transition: all var(--crm-tx);
}
.crm-ab:hover { transform: translateY(-1px); }

.crm-ab.ab-edit:hover     { background: var(--s-bg-info);    color: var(--s-info);    border-color: var(--s-br-info);    }
.crm-ab.ab-view:hover     { background: var(--s-bg-purple);  color: var(--s-purple);  border-color: var(--s-br-purple);  }
.crm-ab.ab-open:hover     { background: var(--s-bg-success); color: var(--s-success); border-color: var(--s-br-success); }
.crm-ab.ab-delete:hover   { background: var(--s-bg-danger);  color: var(--s-danger);  border-color: var(--s-br-danger);  }
.crm-ab.ab-settings:hover { background: var(--s-bg-warning); color: var(--s-warning); border-color: var(--s-br-warning); }
.crm-ab.ab-print:hover    { background: var(--s-bg-teal);    color: var(--s-teal);    border-color: var(--s-br-teal);    }
.crm-ab.ab-download:hover { background: var(--s-bg-info);    color: var(--s-info);    border-color: var(--s-br-info);    }

.crm-ab-group { display: inline-flex; align-items: center; gap: 3px; }

/* ── 6b. THREE-DOTS TRIGGER + ACTION POPUP ──────────────────────────────── */
/* Single ⋮ button shown in every action cell; other buttons hidden until click */
.crm-dots-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--crm-r-xs);
  border: 1px solid transparent;
  background: transparent;
  font-size: .88rem;
  cursor: pointer;
  padding: 0;
  color: #9ca3af;
  transition: all var(--crm-tx);
  vertical-align: middle;
}
.crm-dots-trigger:hover,
.crm-dots-trigger.crm-ap-open {
  background: var(--s-bg-neutral, #f3f4f6);
  color: #374151;
  border-color: var(--crm-border, #e5e7eb);
}
/* Floating popup panel — position:fixed so it escapes overflow:hidden containers */
.crm-action-popup {
  position: fixed;
  z-index: 10500;
  background: #fff;
  border: 1px solid var(--crm-border, #e5e7eb);
  border-radius: var(--crm-r-md);
  box-shadow: 0 6px 24px rgba(0,0,0,.13);
  min-width: 148px;
  padding: 4px 0;
  overflow: hidden;
}
/* Menu items inside popup */
.crm-ap-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 14px;
  font-size: .8rem;
  font-weight: 500;
  color: #374151;
  background: transparent;
  border: none;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--crm-tx), color var(--crm-tx);
}
.crm-ap-item:hover { background: var(--crm-hover, rgba(83,3,131,.06)); color: var(--crm-primary, #530383); }
.crm-ap-item i { font-size: .82rem; width: 16px; flex-shrink: 0; opacity: .7; }
.crm-ap-item:hover i { opacity: 1; }
.crm-ap-item.crm-ap-danger { color: var(--s-danger, #b91c1c); }
.crm-ap-item.crm-ap-danger:hover { background: var(--s-bg-danger, #fee2e2); color: var(--s-danger, #b91c1c); }
.crm-ap-sep { margin: 3px 10px; border: none; border-top: 1px solid var(--crm-border, #e5e7eb); }


/* ── 7. EXPORT MENU DROPDOWN ────────────────────────────────────────────── */
.crm-export-menu {
  min-width: 164px;
  padding: 4px;
  border-radius: var(--crm-r-md);
  border: 1px solid var(--crm-border, #e8eaef);
  box-shadow: var(--crm-sh-md);
}
.crm-export-menu .exp-section {
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 5px 12px 3px;
}
.crm-export-menu .dropdown-item {
  border-radius: var(--crm-r-sm);
  font-size: var(--crm-fs-sm);
  padding: 7px 12px;
  color: #444;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background var(--crm-tx), color var(--crm-tx);
}
.crm-export-menu .dropdown-item i { font-size: .9rem; width: 15px; text-align: center; }
.crm-export-menu .dropdown-item:hover {
  background: var(--crm-hover);
  color: var(--crm-primary, #530383);
}
.crm-export-menu hr.dropdown-divider { margin: 4px 0; border-color: var(--crm-border, #e8eaef); }


/* ── 8. COLUMN VISIBILITY PANEL ─────────────────────────────────────────── */
.crm-col-panel {
  min-width: 185px;
  padding: 6px 4px 4px;
  border-radius: var(--crm-r-md);
  border: 1px solid var(--crm-border, #e8eaef);
  box-shadow: var(--crm-sh-md);
}
.crm-col-panel .cp-title {
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0 12px 5px;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
  margin-bottom: 3px;
}
.crm-col-panel .cp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--crm-r-sm);
  cursor: pointer;
  font-size: var(--crm-fs-sm);
  color: #444;
  user-select: none;
  transition: background var(--crm-tx);
}
.crm-col-panel .cp-item:hover { background: var(--crm-hover); color: var(--crm-primary, #530383); }
.crm-col-panel .cp-eye { font-size: .8rem; width: 15px; text-align: center; color: var(--crm-primary, #530383); }
.crm-col-panel .cp-item.cp-off { color: #b0b0b8; }
.crm-col-panel .cp-item.cp-off .cp-eye { color: #d1d5db; }


/* ── 9. TABLE ───────────────────────────────────────────────────────────── */
/* Outer wrapper: overflow:hidden so th border-radius is clipped by the card corners.
   Inner wrapper: overflow-x:auto — the actual horizontal scroll container. */
.crm-table-wrap {
  width: 100%;
  overflow: hidden;
  border-radius: 12px 12px 0 0;  /* rounded purple header corners */
}
.crm-table-inner {
  width: 100%;
  overflow: hidden;               /* needed so border-radius clips in-flow content */
  overflow-x: auto;
  border-radius: 12px 12px 0 0;
  -webkit-overflow-scrolling: touch;
}

table.crm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--crm-fs-base);
  color: #3a3a4a;
}

/* Header — !important beats Bootstrap's .table > :not(caption) > * > * specificity */
table.crm-table thead th {
  background: var(--crm-primary, #530383) !important;
  color: #fff !important;
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 9px 14px;
  height: var(--crm-th-h);
  white-space: nowrap;
  border: none;
  position: relative;
  cursor: default;
}
/* Sort indicators via DataTables classes */
table.crm-table thead th.sorting,
table.crm-table thead th.sorting_asc,
table.crm-table thead th.sorting_desc { cursor: pointer; padding-right: 26px; }
table.crm-table thead th.sorting::after,
table.crm-table thead th.sorting_asc::after,
table.crm-table thead th.sorting_desc::after {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  font-family: 'Phosphor-Light'; font-size: .75rem;
  opacity: .5;
}
table.crm-table thead th.sorting::after      { content: '\e5d8'; }
table.crm-table thead th.sorting_asc::after  { content: '\e5ca'; opacity: 1; }
table.crm-table thead th.sorting_desc::after { content: '\e5c4'; opacity: 1; }

/* Column pin/freeze toggle button (added per scrollable header by crm-table.js) */
.crm-th-pin {
  background: transparent;
  border: 0;
  padding: 0 2px;
  margin-left: 5px;
  cursor: pointer;
  color: inherit;
  font-size: .82rem;
  line-height: 1;
  vertical-align: middle;
  opacity: .55;
  transition: opacity .12s ease, color .12s ease;
}
.crm-th-pin:hover   { opacity: 1; }
.crm-th-pin.pinned  { opacity: 1; color: #fbbf24; }

/* Body */
table.crm-table tbody tr {
  transition: background var(--crm-tx), box-shadow var(--crm-tx);
}
table.crm-table tbody tr:nth-child(even)  { background: var(--crm-stripe); }
table.crm-table tbody tr:hover            { background: var(--crm-hover) !important; box-shadow: inset 3px 0 0 var(--crm-primary, #530383); }
table.crm-table tbody tr.dt-selected,
table.crm-table tbody tr.crm-row-selected { background: var(--s-bg-purple) !important; }

table.crm-table tbody td {
  padding: 9px 14px;
  vertical-align: middle;
  border-bottom: 1px solid #f0f0f5;
  color: #3a3a4a;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.crm-table tbody tr:last-child td { border-bottom: none; }

/* Action (last) column */
table.crm-table tbody td.crm-td-actions { white-space: nowrap; text-align: right; padding: 5px 10px; }

/* ── BOTTOM SCROLLBAR GUTTER — keep the horizontal scrollbar off the last row ──
   WHY: .table-responsive (overflow-x:auto) draws its horizontal scrollbar at the
   container's bottom edge. When the last row is the only/short content, that bar
   sits right over the row's action ⋮ button and visually hides it ("hidden under
   the table's lower bar"). Reserve a small bottom gutter so the scrollbar always
   drops BELOW the row content, clear of the action button.                      */
.table-responsive { padding-bottom: 16px; }
.table-responsive > table.crm-table { margin-bottom: 0; }

/* ── STICKY ACTION (LAST) COLUMN — keep row actions reachable ────────────────
   WHY: every table lives in .table-responsive (overflow-x:auto). When the table
   is wider than its card the LAST column — in this CRM that is the action button
   group — scrolls off the right edge and Edit/Delete become unreachable. Pinning
   the last column to the right edge keeps it visible no matter the scroll. It is
   a no-op when the table fits (the column already sits at the right edge).
   Row stripe/hover colours are semi-transparent, so a pinned cell needs an
   OPAQUE background or scrolled content bleeds through: we composite the overlay
   over the solid card colour with a gradient layer over a solid base.          */
.table-responsive > table.crm-table > thead > tr > th:last-child {
  position: -webkit-sticky;
  position: sticky;
  right: 0;
  z-index: 3;
  background: var(--crm-primary, #530383) !important;
}
.table-responsive > table.crm-table > tbody > tr:not(.dtrg-group) > td:last-child {
  position: -webkit-sticky;
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--crm-card-bg, #fff);
  /* Breathing room: keep the ⋮ trigger off the right edge/scrollbar so it never
     reads as clipped or "tucked under" the table border. */
  min-width: 52px;
  padding-right: 14px;
  /* Left-cast divider so the pinned cell visually separates from content that
     scrolls underneath it (only noticeable once the table actually overflows). */
  box-shadow: -8px 0 8px -8px rgba(0, 0, 0, .18);
}
.table-responsive > table.crm-table > tbody > tr:not(.dtrg-group):nth-child(even) > td:last-child {
  background: linear-gradient(var(--crm-stripe), var(--crm-stripe)), var(--crm-card-bg, #fff);
}
.table-responsive > table.crm-table > tbody > tr:not(.dtrg-group):hover > td:last-child {
  background: linear-gradient(var(--crm-hover), var(--crm-hover)), var(--crm-card-bg, #fff) !important;
}
.table-responsive > table.crm-table > tbody > tr.dt-selected > td:last-child,
.table-responsive > table.crm-table > tbody > tr.crm-row-selected > td:last-child {
  background: var(--s-bg-purple) !important;
}
/* Dark theme: same composition over the dark card surface */
[data-bs-theme="dark"] .table-responsive > table.crm-table > tbody > tr:not(.dtrg-group) > td:last-child {
  background: var(--crm-card-bg, #1e1e2d);
}
[data-bs-theme="dark"] .table-responsive > table.crm-table > tbody > tr:not(.dtrg-group):nth-child(even) > td:last-child {
  background: linear-gradient(rgba(255,255,255,.03), rgba(255,255,255,.03)), var(--crm-card-bg, #1e1e2d);
}
[data-bs-theme="dark"] .table-responsive > table.crm-table > tbody > tr:not(.dtrg-group):hover > td:last-child {
  background: linear-gradient(var(--crm-hover), var(--crm-hover)), var(--crm-card-bg, #1e1e2d) !important;
}

/* Row-group header — transparent cell, oval pill label inside */
table.crm-table tr.dtrg-group td {
  background: transparent !important;
  border-bottom: 1px solid var(--crm-border, #e5e7eb) !important;
  padding: 7px 14px !important;
}
.crm-rg-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--crm-primary, #530383);
  color: #fff;
  padding: 4px 14px 4px 11px;
  border-radius: var(--crm-r-pill);
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.4;
}
.crm-rg-pill .crm-rg-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.22);
  border-radius: var(--crm-r-pill);
  font-size: .62rem;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-weight: 700;
}

/* ── Oval / pill table-section headers (inline tables in modals/forms) ── */
/* Wrap any plain <table> in a .crm-tbl-wrap to get oval headers           */
.crm-tbl-wrap {
  border-radius: var(--crm-r-lg);
  overflow: hidden;
  border: 1px solid var(--crm-border, #e5e7eb);
}
.crm-tbl-wrap table {
  border-collapse: separate !important;
  border-spacing: 0;
  width: 100%;
  margin-bottom: 0;
}
.crm-tbl-wrap thead tr:first-child th {
  background: var(--crm-primary, #530383) !important;
  color: #fff !important;
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  letter-spacing: .04em;
  border: none !important;
  padding: 9px 12px;
}
.crm-tbl-wrap thead tr:first-child th:first-child {
  border-top-left-radius: calc(var(--crm-r-lg) - 1px);
}
.crm-tbl-wrap thead tr:first-child th:last-child {
  border-top-right-radius: calc(var(--crm-r-lg) - 1px);
}
.crm-tbl-wrap tbody tr:last-child td:first-child { border-bottom-left-radius: calc(var(--crm-r-lg) - 1px); }
.crm-tbl-wrap tbody tr:last-child td:last-child  { border-bottom-right-radius: calc(var(--crm-r-lg) - 1px); }
.crm-tbl-wrap tbody tr:hover { background: var(--crm-hover, rgba(83,3,131,.04)); }
.crm-tbl-wrap tbody td { border-bottom: 1px solid var(--crm-border, #e5e7eb); padding: 7px 12px; vertical-align: middle; font-size: var(--crm-fs-sm); }
.crm-tbl-wrap tbody tr:last-child td { border-bottom: none; }

/* Hide native number spinners inside compact inline tables — too narrow */
.crm-tbl-wrap input[type=number]::-webkit-outer-spin-button,
.crm-tbl-wrap input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.crm-tbl-wrap input[type=number] { -moz-appearance: textfield; }

/* Checkbox column */
table.crm-table th.crm-th-chk,
table.crm-table td.crm-td-chk {
  width: 36px; min-width: 36px;
  padding: 8px 8px 8px 14px;
  text-align: center;
}

/* Empty cell */
table.crm-table tbody td.dataTables_empty {
  text-align: center;
  padding: 52px 20px;
  color: #bbb;
  font-size: var(--crm-fs-md);
  font-style: italic;
}


/* ── 9. FUNNEL-TOGGLE FILTER WRAP — see section 9c below for the canonical rule */

/* ── 9a. BULK ACTION BAR ────────────────────────────────────────────────────
   Rule: right-aligned, flat (no inner wrapper), bell first, apply last.
   justify-content:flex-end keeps the group tight on the right.
   min-height:42px + padding:4px 8px gives breathing room.                   */
.crm-bulk-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  padding: 4px 8px;
  background: #fff;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
}
.crm-bulk-bar .vr { margin: 0 2px; }

/* ── 9b. ROUNDED TABLE HEADER — clip-path approach (the only reliable method) ──
   WHY: overflow:hidden on .table-responsive clips the DataTables length-control
        injected ABOVE the header, not the header itself. The only reliable fix
        is clip-path on the thead tr — it clips the tr's painted background
        directly to a rounded shape, independent of any parent container.     */
table thead tr:first-child {
  clip-path: inset(0 round 12px 12px 0 0);
}
/* Keep border-collapse:separate so per-table border-radius overrides work   */
.crm-table-container table,
.card .table-responsive table,
.card-body .table-responsive table {
  border-collapse: separate !important;
  border-spacing: 0;
}

/* ── 9c. FILTER WRAP — always horizontal, max-height animation ──────────────
   WHY: jQuery slideToggle() sets display:block, breaking flex layout.
   FIX: keep display:flex always; animate via max-height instead.
   Show/hide by adding/removing class 'open' — never touch display directly.  */
.crm-filter-wrap {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #f9fafb;
  max-height: 0;
  overflow: hidden;
  padding: 0 16px;
  border-bottom: 1px solid transparent;
  transition: max-height .22s ease, padding .2s ease, border-color .2s ease;
}
.crm-filter-wrap.open {
  max-height: 300px;
  padding: 10px 16px;
  border-bottom-color: var(--crm-border, #e8eaef);
  overflow: visible; /* allow absolute dropdowns inside to render outside the bar bounds */
}

/* Filter wrap date input-groups: shrink to icon + compact text area */
.crm-filter-wrap .input-group:has(input.flatpickr-input) {
  width: 115px !important;
}
.crm-filter-wrap .input-group input.flatpickr-input {
  cursor: pointer;
  padding-left: 2px;
}

/* Filter wrap selects: match filter-bar height + radius */
.crm-filter-wrap .form-select,
.crm-filter-wrap .form-select-sm {
  height: 32px;
  border-radius: 8px !important;
  font-size: .8rem;
  border-color: var(--crm-border, #e8eaef);
  background-color: #fff;
}

/* ── 9d. STATUS BADGES — global, all layouts ────────────────────────────────
   Both .crm-inline-status (clickable, has arrow) and .crm-status-badge (read-only)
   share the same pill shape: white bg, colored border + dot, text in status color.
   Arrow is always pinned to the right end via margin-left:auto.
   Set color + border-color via inline style from PHP/JS — currentColor handles the rest. */

.crm-inline-status,
.crm-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 100px;
  padding: 3px 7px 3px 8px;
  border-radius: 20px;
  background: #fff;
  border: 1.5px solid;
  font-size: .74rem !important;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: middle;
  line-height: 1.3;
  box-sizing: border-box;
}
.crm-inline-status { cursor: pointer; user-select: none; }
.crm-inline-status:hover { filter: brightness(.96); }
.crm-inline-status--unset {
  border-color: #d1d5db !important;
  color: #9ca3af !important;
}

/* Colored dot on left — inherits currentColor from parent inline style */
.crm-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

/* Status text — grows to fill space */
.crm-status-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Caret arrow — always pinned to right */
.crm-status-arrow {
  font-size: .58rem; opacity: .55; flex-shrink: 0; margin-left: auto;
}

/* ── 9d2. STATUS CHANGE POPUP — global, body-level fixed overlay ────────────
   Used by leads (and any future module). Append to <body>, position:fixed.
   Uses .crm-sp-item (NOT Bootstrap .dropdown-item) to avoid color conflicts. */
.crm-status-popup {
  position: fixed; z-index: 9999;
  background: #fff;
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  padding: 5px 0;
  min-width: 200px;
  max-height: 300px;
  overflow-y: auto;
  display: none;
}
.crm-status-popup .crm-sp-title {
  font-size: .70rem; font-weight: 700; color: #9ca3af;
  padding: 5px 14px 4px; letter-spacing: .06em; text-transform: uppercase;
  border-bottom: 1px solid var(--crm-border, #e8eaef); margin-bottom: 3px;
}
.crm-sp-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; cursor: pointer;
  font-size: .82rem; font-weight: 500; color: #374151;
  border-radius: 0; transition: background .1s;
  text-decoration: none; border: none; background: none; width: 100%;
}
.crm-sp-item:hover { background: var(--crm-primary-soft, #f3e8ff); color: var(--crm-primary, #530383); }
.crm-sp-item.active { font-weight: 700; }
.crm-sp-item .crm-sp-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.crm-sp-item .crm-sp-check {
  margin-left: auto; font-size: .8rem;
  color: var(--crm-primary, #530383); flex-shrink: 0;
}

/* ── 9d3. INLINE ASSIGNEE — clickable cell + user-picker popup ──────────────
   Avatar-only display: name text is hidden globally; name visible on hover
   via title="" on the avatar circle. Click → floating picker → PATCH.      */
.crm-inline-assignee {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px 2px 2px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: border-color var(--crm-tx), background var(--crm-tx);
  white-space: nowrap;
  vertical-align: middle;
  max-width: 56px;
}
.crm-inline-assignee:hover {
  border-color: var(--crm-border, #e5e7eb);
  background: var(--s-bg-neutral, #f3f4f6);
}
.crm-inline-assignee.crm-ia--unset {
  color: #9ca3af;
  font-size: .74rem;
  font-weight: 600;
  max-width: 80px;
}
.crm-inline-assignee .crm-ia-label { font-size: .74rem; }
.crm-inline-assignee .crm-ia-arrow { font-size: .55rem; opacity: .5; flex-shrink: 0; }
/* Avatar-only: name text hidden globally — name shown via title="" tooltip */
.crm-inline-assignee .small { display: none !important; }

/* User-picker popup */
.crm-assignee-popup {
  position: fixed; z-index: 10400;
  background: #fff;
  border: 1px solid var(--crm-border, #e5e7eb);
  border-radius: var(--crm-r-md);
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  padding: 0;
  min-width: 220px;
  max-width: 260px;
  display: none;
  overflow: hidden;
}
.crm-assignee-popup .crm-ap-title {
  font-size: .70rem; font-weight: 700; color: #9ca3af;
  text-transform: uppercase; letter-spacing: .06em;
  padding: 8px 12px 5px;
  border-bottom: 1px solid var(--crm-border, #e5e7eb);
}
.crm-ai-search-wrap { padding: 6px 10px 4px; }
.crm-ai-search {
  width: 100%; padding: 4px 8px;
  border: 1px solid var(--crm-border, #e5e7eb);
  border-radius: var(--crm-r-sm);
  font-size: .78rem; outline: none;
}
.crm-ai-search:focus { border-color: var(--crm-primary, #530383); }
.crm-ai-list { max-height: 260px; overflow-y: auto; padding: 2px 0; }
.crm-ai-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 6px 12px;
  background: none; border: none; cursor: pointer;
  font-size: .8rem; font-weight: 500; color: #374151;
  text-align: left; transition: background var(--crm-tx);
}
.crm-ai-item:hover { background: var(--crm-hover, rgba(83,3,131,.06)); color: var(--crm-primary, #530383); }
.crm-ai-item.active { font-weight: 700; }
.crm-ai-avatar {
  width: 26px; height: 26px; border-radius: 50%; overflow: hidden;
  background: var(--crm-primary, #530383); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .68rem; font-weight: 700; flex-shrink: 0;
}
.crm-ai-avatar img { width: 100%; height: 100%; object-fit: cover; }
.crm-ai-avatar-none { background: #e5e7eb; color: #9ca3af; }
.crm-ai-unassign .crm-ai-avatar { background: #f3f4f6; color: #9ca3af; }
.crm-ai-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }


/* ── 9e. AVATAR CIRCLES — global, all layouts ───────────────────────────── */
.avatar-circle-sm {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--crm-primary, #530383); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .68rem; font-weight: 700; flex-shrink: 0; overflow: hidden;
}
.avatar-circle {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--crm-primary, #530383); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; flex-shrink: 0; overflow: hidden;
}
.crm-avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
/* Crisp, defined edge on every avatar circle (reduces the "soft/blurry" look
   of compressed staff photos). Subtle inner ring, no layout shift. */
.avatar-circle-sm, .avatar-circle, .crm-avatar {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
/* ── 9f. CRM-AVATAR generic circle (stat icons, show-page headers) ────────── */
.crm-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 700; flex-shrink: 0; overflow: hidden;
  background: var(--crm-primary, #530383);
}
.crm-avatar-xs { width: 22px; height: 22px; font-size: .63rem; }
.crm-avatar-sm { width: 28px; height: 28px; font-size: .70rem; }
.crm-avatar-md { width: 34px; height: 34px; font-size: .78rem; }
.crm-avatar-lg { width: 44px; height: 44px; font-size: 1.0rem; }
.crm-avatar-xl { width: 60px; height: 60px; font-size: 1.4rem; }

/* ── 9g. CRM-AVS — rounded-avatar dropdown (user / assignee selects) ──────── */
/* Enhances <select data-avatar-select>; native select is moved inside & hidden. */
.crm-avs { position: relative; }
.crm-avs > select[data-avatar-select] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); border: 0;
}
.crm-avs-control {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 38px; padding: 5px 10px; text-align: left;
  background: #fff; border: 1px solid var(--crm-border, #d7dae0);
  border-radius: 8px; font-size: .82rem; color: #1f2937; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.crm-avs-control:hover { border-color: #c2c6cf; }
.crm-avs.open .crm-avs-control {
  border-color: var(--crm-primary, #530383);
  box-shadow: 0 0 0 3px rgba(83, 3, 131, .12);
}
.crm-avs-ctrl-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-avs-caret { margin-left: auto; color: #9ca3af; font-size: .9rem; transition: transform .15s; }
.crm-avs.open .crm-avs-caret { transform: rotate(180deg); }
.crm-avs-ava { width: 24px; height: 24px; font-size: .64rem; }
.crm-avs-none { background: #eef0f3; color: #9ca3af; }
.crm-avs-none i { font-size: .8rem; }

.crm-avs-panel {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1080;
  background: #fff; border: 1px solid var(--crm-border, #e2e5ea); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(15, 10, 25, .16); padding: 6px;
  display: none; max-height: 280px; overflow: hidden;
}
.crm-avs.open .crm-avs-panel { display: flex; flex-direction: column; }
.crm-avs-search {
  width: 100%; border: 1px solid var(--crm-border, #e2e5ea); border-radius: 7px;
  padding: 6px 10px; font-size: .8rem; margin-bottom: 6px; flex-shrink: 0;
}
.crm-avs-search:focus { outline: none; border-color: var(--crm-primary, #530383); }
.crm-avs-options { overflow-y: auto; }
.crm-avs-opt {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 7px; cursor: pointer; font-size: .82rem; color: #1f2937;
}
.crm-avs-opt:hover { background: #f5f3f9; }
.crm-avs-opt.is-selected { background: rgba(83, 3, 131, .08); font-weight: 600; }
.crm-avs-opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 10. DATATABLE FOOTER (length + info + pagination — all bottom-right) ── */
/* Spacer pushes the right group to the far right */
.crm-dt-spacer { flex: 1; }

.crm-dt-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 8px 16px;
  border-top: 1px solid var(--crm-border, #e8eaef);
  background: #fafafa;
  font-size: var(--crm-fs-xs);
}

/* ── Length menu (rows per page selector) ── */
.crm-dt-footer .dataTables_length label {
  display: flex; align-items: center; gap: 5px;
  color: #9ca3af; margin: 0; white-space: nowrap;
}
.crm-dt-footer .dataTables_length select {
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: var(--crm-r-sm);
  padding: 2px 6px;
  font-size: var(--crm-fs-xs);
  color: #555;
  background: #fff;
  height: 26px;
  cursor: pointer;
}

/* ── Info text ("1–25 of 120") ── */
.crm-dt-footer .dataTables_info {
  color: #9ca3af;
  font-size: var(--crm-fs-xs);
  margin: 0; padding: 0;
  white-space: nowrap;
}

/* ── Pagination ── */
.crm-dt-footer .dataTables_paginate { margin: 0; }
.crm-dt-footer .paginate_button {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px;
  border-radius: var(--crm-r-sm);
  border: 1px solid transparent;
  font-size: var(--crm-fs-xs);
  cursor: pointer;
  transition: all var(--crm-tx);
  color: #555; background: transparent;
  margin: 0 1px; padding: 0 6px;
}
.crm-dt-footer .paginate_button:hover:not(.disabled):not(.current) {
  background: var(--crm-hover);
  color: var(--crm-primary);
}
.crm-dt-footer .paginate_button.current {
  background: var(--crm-primary, #530383);
  color: #fff !important;
  border-color: var(--crm-primary);
  font-weight: 700;
}
.crm-dt-footer .paginate_button.current:hover { background: var(--crm-primary-light, #7a12b8); }
.crm-dt-footer .paginate_button.disabled,
.crm-dt-footer .paginate_button.disabled:hover { color: #d1d5db !important; cursor: default; }

/* ── Suppress the default DataTables length control appearing above the table ── */
/* DataTables v1.x default renders .dataTables_length above the table when not in dom */
.dataTables_wrapper > .dataTables_length { display: none !important; }
.dataTables_wrapper > .dataTables_filter { display: none !important; }
.dataTables_wrapper > .dataTables_info   { display: none !important; }
/* Only show these when inside our .crm-dt-footer wrapper */
.crm-dt-footer .dataTables_length,
.crm-dt-footer .dataTables_info,
.crm-dt-footer .dataTables_paginate { display: block; }


/* ── 11. STATUS / TYPE BADGES ───────────────────────────────────────────── */
.crm-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: var(--crm-r-pill);
  font-size: var(--crm-fs-xs);
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
  min-width: 68px;
  justify-content: center;
  border: 1px solid transparent;
  line-height: 1.5;
}
/* Dot prefix variant */
.crm-badge.has-dot::before {
  content: '';
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  margin-right: 5px;
  flex-shrink: 0;
  background: currentColor;
}

/* Variants */
.crm-b-success  { background: var(--s-bg-success);  color: var(--s-success);  border-color: var(--s-br-success);  }
.crm-b-warning  { background: var(--s-bg-warning);  color: var(--s-warning);  border-color: var(--s-br-warning);  }
.crm-b-danger   { background: var(--s-bg-danger);   color: var(--s-danger);   border-color: var(--s-br-danger);   }
.crm-b-info     { background: var(--s-bg-info);     color: var(--s-info);     border-color: var(--s-br-info);     }
.crm-b-primary  { background: var(--s-bg-purple);   color: var(--s-purple);   border-color: var(--s-br-purple);   }
.crm-b-neutral  { background: var(--s-bg-neutral);  color: var(--s-neutral);  border-color: var(--s-br-neutral);  }
.crm-b-orange   { background: var(--s-bg-orange);   color: var(--s-orange);   border-color: var(--s-br-orange);   }
.crm-b-teal     { background: var(--s-bg-teal);     color: var(--s-teal);     border-color: var(--s-br-teal);     }


/* ── 12. EMPTY STATE ────────────────────────────────────────────────────── */
.crm-empty {
  text-align: center;
  padding: 60px 20px 48px;
}
.crm-empty-icon {
  font-size: 2.8rem;
  color: #d1d5db;
  display: block;
  margin-bottom: 14px;
}
.crm-empty-title {
  font-size: var(--crm-fs-md);
  font-weight: 700;
  color: #6b7280;
  margin-bottom: 6px;
}
.crm-empty-sub {
  font-size: var(--crm-fs-sm);
  color: #9ca3af;
  margin-bottom: 20px;
}


/* ── 13. LOADING STATE ─────────────────────────────────────────────────── */
.crm-loading {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 52px 20px;
  color: #9ca3af; font-size: var(--crm-fs-sm);
}


/* ── 14. STAT / KPI CARD ────────────────────────────────────────────────── */
.crm-stat {
  background: #fff;
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: var(--crm-r-lg);
  padding: 18px 20px;
  box-shadow: var(--crm-sh-xs);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: box-shadow var(--crm-tx), transform var(--crm-tx);
}
.crm-stat:hover { box-shadow: var(--crm-sh-sm); transform: translateY(-2px); }
.crm-stat-icon {
  width: 44px; height: 44px; border-radius: var(--crm-r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.crm-stat-body { flex: 1; min-width: 0; }
.crm-stat-val   { font-size: 1.8rem; font-weight: 800; line-height: 1.1; color: #2d2d3a; }
.crm-stat-label { font-size: var(--crm-fs-xs); color: #888; margin-top: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.crm-stat-delta { font-size: var(--crm-fs-xs); margin-top: 7px; display: flex; align-items: center; gap: 3px; }
.crm-stat-delta.up   { color: var(--s-success); }
.crm-stat-delta.down { color: var(--s-danger);  }


/* ── 15. MODAL STANDARDS ────────────────────────────────────────────────── */
.crm-modal-hdr {
  background: linear-gradient(135deg, var(--crm-primary, #530383) 0%, var(--crm-primary-light, #7a12b8) 100%);
  color: #fff;
  padding: 13px 20px;
  border-radius: calc(var(--crm-r-md) - 1px) calc(var(--crm-r-md) - 1px) 0 0;
}
.crm-modal-hdr .modal-title {
  font-size: .88rem;
  font-weight: 700;
  color: #fff;
  display: flex; align-items: center; gap: 8px;
}
.crm-modal-hdr .btn-close { filter: invert(1); opacity: .75; }
.crm-modal-hdr .btn-close:hover { opacity: 1; }

.crm-modal-ftr {
  border-top: 1px solid var(--crm-border, #e8eaef);
  padding: 12px 20px;
  background: #fafafa;
  border-radius: 0 0 calc(var(--crm-r-md) - 1px) calc(var(--crm-r-md) - 1px);
}


/* ── 16. FORM SECTION ───────────────────────────────────────────────────── */
.crm-form-sep {
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px dashed var(--crm-border, #e8eaef);
}
.crm-form-sec-title {
  font-size: var(--crm-fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--crm-primary, #530383);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 6px;
}


/* ── 17a. FILTER PANEL TOGGLE ───────────────────────────────────────────── */
/* Container that collapses/expands when funnel button is clicked.           */
/* JS sets max-height / opacity inline; this just supplies the transition.   */
.crm-fp-wrap {
  transition: max-height .26s ease, opacity .2s ease, margin-bottom .2s ease;
  overflow: hidden;
}
/* Pill style for standalone (non-.crm-filter-bar) filter controls */
.crm-fp-wrap select.form-select,
.crm-fp-wrap select.form-select-sm {
  border-radius: 20px !important;
  border: 1.5px solid var(--crm-border, #e8eaef);
  font-size: .79rem; font-weight: 500; color: #555;
  background: #f7f8fc; padding: 4px 28px 4px 12px;
  height: auto; cursor: pointer;
  transition: border-color .14s, box-shadow .14s;
}
.crm-fp-wrap select.form-select:focus,
.crm-fp-wrap select.form-select-sm:focus {
  border-color: var(--crm-primary, #530383);
  box-shadow: 0 0 0 3px rgba(83,3,131,.08);
}
.crm-fp-wrap input.form-control,
.crm-fp-wrap input.form-control-sm {
  border-radius: 20px !important;
  border: 1.5px solid var(--crm-border, #e8eaef);
  font-size: .79rem; background: #f7f8fc; padding: 4px 12px;
  height: auto;
  transition: border-color .14s, box-shadow .14s;
}
.crm-fp-wrap input.form-control:focus,
.crm-fp-wrap input.form-control-sm:focus {
  border-color: var(--crm-primary, #530383);
  box-shadow: 0 0 0 3px rgba(83,3,131,.08);
}


/* ── 17. RESPONSIVE ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .crm-toolbar { flex-direction: column; align-items: stretch; gap: 6px; }
  .crm-toolbar-left, .crm-toolbar-right { width: 100%; justify-content: flex-start; }
  .crm-toolbar-right { justify-content: flex-end; }
  .crm-search-input,
  .crm-search-input:focus { width: 100%; }
  .crm-stat-val { font-size: 1.4rem; }
}


/* ── 18. DARK MODE ──────────────────────────────────────────────────────── */
[data-bs-theme="dark"] .crm-card,
[data-bs-theme="dark"] .crm-toolbar       { background: var(--crm-card-bg, #1e1e2d); border-color: #2d2d40; }
[data-bs-theme="dark"] .crm-card-header   { background: var(--crm-card-bg, #1e1e2d); border-color: #2d2d40; }
[data-bs-theme="dark"] table.crm-table tbody td { color: #d1d5db; border-color: #2a2a3a; }
[data-bs-theme="dark"] table.crm-table tbody tr:nth-child(even) { background: rgba(255,255,255,.03); }
[data-bs-theme="dark"] .crm-dt-footer     { background: #1a1a2e; border-color: #2d2d40; }
[data-bs-theme="dark"] .crm-btn-icon      { background: #2a2a3a; border-color: #3a3a4a; color: #c4c4d4; }
[data-bs-theme="dark"] .crm-btn-icon:hover { background: var(--crm-hover); }
[data-bs-theme="dark"] .crm-export-menu,
[data-bs-theme="dark"] .crm-col-panel     { background: #1e1e2d; border-color: #2d2d40; }
[data-bs-theme="dark"] .crm-export-menu .dropdown-item,
[data-bs-theme="dark"] .crm-col-panel .cp-item { color: #c4c4d4; }
[data-bs-theme="dark"] .crm-stat          { background: var(--crm-card-bg, #1e1e2d); border-color: #2d2d40; }
[data-bs-theme="dark"] .crm-badge.crm-b-neutral { background: #2a2a3a; color: #9ca3af; border-color: #3a3a4a; }


/* ── 19. PRINT ──────────────────────────────────────────────────────────── */
@media print {
  .crm-toolbar,
  .crm-bulk-bar,
  .crm-filter-bar,
  .sidebar,
  .topbar,
  .crm-dt-footer,
  .crm-ab-group,
  .crm-btn-icon,
  .modal-footer,
  #btn-add-template,
  .btn-export,
  .btn-print { display: none !important; }

  .crm-card { border: none !important; box-shadow: none !important; border-radius: 0 !important; }

  table.crm-table { font-size: 9pt; }
  table.crm-table thead th {
    background: #f3f4f6 !important;
    color: #333 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  table.crm-table tbody tr:nth-child(even) {
    background: #f9f9fb !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   FORM TYPOGRAPHY HIERARCHY
   Level 1 – Card/section headers : .95rem  700  #111827
   Level 2 – Field labels         : .84rem  600  #374151
   Level 3 – Input content        : .82rem  400  #1f2937
   ───────────────────────────────────────────────────────────────────────── */
.form-label,
label.col-form-label {
  font-size: .84rem !important;
  font-weight: 600 !important;
  color: #374151 !important;
  margin-bottom: .3rem;
}
.form-control,
.form-select,
textarea.form-control {
  font-size: .82rem !important;
  color: #1f2937 !important;
}

/* ─────────────────────────────────────────────────────────────────────────
   RULE: NO PLACEHOLDER TEXT — globally hide all input/textarea placeholders
   Applied via CSS so all 300+ files are covered without touching each blade
   ───────────────────────────────────────────────────────────────────────── */
input::placeholder,
textarea::placeholder {
  opacity: 0 !important;
  color: transparent !important;
}

/* ─────────────────────────────────────────────────────────────────────────
   PHONE INPUT — intlTelInput Geex style
   Carrier: intlTelInput.css already loaded, these override/extend it
   ───────────────────────────────────────────────────────────────────────── */
.iti { width: 100%; }
.iti__flag-container { z-index: 9999 !important; }

/* Selected flag + dial-code button */
.iti--separate-dial-code .iti__selected-flag {
  background: #f5f5f8 !important;
  border-right: 1px solid var(--crm-border, #e8eaef) !important;
  border-radius: 8px 0 0 8px !important;
  padding: 0 10px !important;
  min-width: 80px;
  cursor: pointer;
  transition: background .13s;
}
.iti--separate-dial-code .iti__selected-flag:hover {
  background: #eeeef6 !important;
}
.iti--separate-dial-code .iti__selected-dial-code {
  font-size: .83rem;
  font-weight: 600;
  color: #464255;
  margin-left: 6px;
}

/* Dropdown */
.iti__dropdown-content {
  border-radius: 12px !important;
  border: 1px solid var(--crm-border, #e8eaef) !important;
  box-shadow: 0 8px 28px rgba(0,0,0,.13) !important;
  overflow: hidden;
}
.iti__search-input {
  border-bottom: 1px solid var(--crm-border, #e8eaef) !important;
  padding: 8px 12px !important;
  font-size: .82rem !important;
}
.iti__country-name { font-size: .82rem; }
.iti__dial-code    { font-size: .78rem; color: #888; }
.iti__country.iti__highlight,
.iti__country:hover { background: var(--crm-primary-soft, #f3eeff) !important; }

/* Digit-limit hint displayed below the field */
.crm-phone-limit {
  font-size: .72rem;
  color: #aaa;
  margin-top: 2px;
  display: none;
}
.crm-phone-limit.visible { display: block; }

/* ═══════════════════════════════════════════════════════════════════════
   Password show / hide toggle (auto-applied globally)
   ══════════════════════════════════════════════════════════════════════ */
.crm-pwd-wrap {
    position: relative;
    display: block;
}
.crm-pwd-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    color: #aaa;
    cursor: pointer;
    font-size: 1.05rem;
    line-height: 1;
    z-index: 5;
    transition: color .15s;
}
.crm-pwd-toggle:hover,
.crm-pwd-toggle:focus-visible { color: var(--crm-primary, #530383); outline: none; }
/* Variant for Bootstrap input-group (appended as input-group-text) */
.crm-pwd-toggle-ig {
    background: #f8f8fc;
    border-color: #e0e0e8;
    color: #aaa;
    cursor: pointer;
    transition: color .15s;
}
.crm-pwd-toggle-ig:hover,
.crm-pwd-toggle-ig:focus-visible { color: var(--crm-primary, #530383); outline: none; }

/* ═══════════════════════════════════════════════════════════════════════
   FIELD REARRANGE + MANDATORY TOGGLE  (crm-field-layout.js)
   Shared across all add/edit modals that support drag-to-rearrange and
   mandatory-field marking. DO NOT duplicate these rules in blade files.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Drag handle (top-right, shown only in rearrange mode) ── */
.lf-drag-handle {
    position: absolute; top: 6px; right: 6px;
    width: 24px; height: 24px;
    background: rgba(83, 3, 131, .09); border: none;
    border-radius: 6px; padding: 0;
    display: none; align-items: center; justify-content: center;
    cursor: grab; z-index: 10;
    color: var(--crm-primary, #530383); font-size: .8rem;
    transition: background .12s;
}
.lf-drag-handle:hover  { background: rgba(83, 3, 131, .22); }
.lf-drag-handle:active { cursor: grabbing; }

/* ── Mandatory toggle (top-left, shown only in rearrange mode) ── */
.lf-req-toggle {
    position: absolute; top: 6px; left: 6px;
    width: 24px; height: 24px;
    background: rgba(83, 3, 131, .09); border: none;
    border-radius: 6px; padding: 0;
    display: none; align-items: center; justify-content: center;
    cursor: pointer; z-index: 10;
    color: var(--crm-primary, #530383); font-size: .78rem;
    transition: background .15s, color .15s;
}
.lf-req-toggle:hover { background: rgba(83, 3, 131, .22); }
.lf-field-required > .lf-req-toggle              { background: #dc3545; color: #fff; }
.lf-field-required > .lf-req-toggle:hover        { background: #b91c1c; }

/* ── Sortable field wrapper in rearrange mode ── */
.crm-sort-active > .lf-sortable-field {
    position: relative;
    border: 1.5px dashed rgba(83, 3, 131, .25);
    border-radius: 10px; padding: 10px !important;
    background: rgba(83, 3, 131, .025);
    transition: border-color .15s, background .15s;
}
.crm-sort-active > .lf-sortable-field:hover {
    border-color: var(--crm-primary, #530383);
    background: rgba(83, 3, 131, .06);
}

/* Show controls only in rearrange mode */
.crm-sort-active > .lf-sortable-field > .lf-drag-handle,
.crm-sort-active > .lf-sortable-field > .lf-req-toggle { display: flex; }

/* Required field highlight in rearrange mode */
.crm-sort-active > .lf-field-required {
    border-color: #dc3545 !important;
    background: rgba(220, 53, 69, .04) !important;
}

/* ── Sortable ghost (placeholder during drag) ── */
.lf-ghost {
    opacity: .35;
    background: rgba(83, 3, 131, .08) !important;
    border: 2px dashed var(--crm-primary, #530383) !important;
}

/* ── Chosen item (being dragged) ── */
.lf-chosen {
    box-shadow: 0 8px 28px rgba(83, 3, 131, .22), 0 2px 8px rgba(0, 0, 0, .1) !important;
    border-color: var(--crm-primary, #530383) !important;
    transform: rotate(1.5deg) scale(1.03);
    z-index: 50;
}

/* ── Rearrange button — active state ── */
.lf-active,
.crm-reorder-btn.lf-active {
    background:    var(--crm-primary, #530383) !important;
    color:         #fff !important;
    border-color:  var(--crm-primary, #530383) !important;
    border-style:  solid !important;
}

/* ── Required star on label (always visible when field is required) ── */
.lf-req-star { font-weight: 700; }

/* ── Banner slide-in animation ── */
@keyframes crmLayoutBannerIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}
[id$="reorder-banner"]:not([style*="display: none"]),
[id$="ReorderBanner"]:not([style*="display: none"]) {
    animation: crmLayoutBannerIn .22s ease;
}

/* ═══════════════════════════════════════════════════════════════════════
   LIST / DASHBOARD VIEW TOGGLE — universal for all table card headers
   ══════════════════════════════════════════════════════════════════════ */
.crm-view-btn { transition: all var(--crm-tx); }
.crm-view-btn.active {
  background: var(--crm-primary, #530383);
  color: #fff !important;
  border-color: var(--crm-primary, #530383);
}
.crm-view-btn.active:hover {
  background: var(--crm-primary-dark, #3d0260);
  border-color: var(--crm-primary-dark, #3d0260);
}

/* ═══════════════════════════════════════════════════════════════════════
   DASHBOARD PANEL — inline analytics panel inside .crm-card
   ══════════════════════════════════════════════════════════════════════ */
.crm-dash-panel {
  padding: 20px 20px 24px;
  border-bottom: 1px solid var(--crm-border, #e8eaef);
  background: #f9fafb;
}

/* Date range row at top of dashboard panel */
.crm-dash-date-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.crm-dash-date-bar .crm-filter-date-label {
  font-size: .74rem;
  color: #6b7280;
  font-weight: 600;
}

/* Stat summary cards */
.crm-dash-stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.crm-dash-stat {
  flex: 1 1 120px;
  background: #fff;
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: 12px;
  padding: 14px 18px;
  min-width: 110px;
  position: relative;
  overflow: hidden;
}
.crm-dash-stat::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--crm-primary, #530383);
  opacity: .6;
}
.crm-dash-stat.accent-green::before  { background: #15803d; }
.crm-dash-stat.accent-red::before    { background: #b91c1c; }
.crm-dash-stat.accent-orange::before { background: #b45309; }
.crm-dash-stat-val {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--crm-primary, #530383);
  line-height: 1;
}
.crm-dash-stat.accent-green .crm-dash-stat-val  { color: #15803d; }
.crm-dash-stat.accent-red .crm-dash-stat-val    { color: #b91c1c; }
.crm-dash-stat.accent-orange .crm-dash-stat-val { color: #b45309; }
.crm-dash-stat-label {
  font-size: .7rem;
  color: #9ca3af;
  font-weight: 500;
  margin-top: 4px;
  white-space: nowrap;
}

/* Chart grid */
.crm-dash-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.crm-dash-chart-box {
  background: #fff;
  border: 1px solid var(--crm-border, #e8eaef);
  border-radius: 12px;
  padding: 16px;
}
.crm-dash-chart-title {
  font-size: .76rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.crm-dash-chart-title i { color: var(--crm-primary, #530383); font-size: .85rem; }
.crm-dash-chart-canvas-wrap {
  position: relative;
  height: 200px;
}
.crm-dash-chart-canvas-wrap.tall { height: 240px; }

/* Loading spinner inside dashboard */
.crm-dash-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #9ca3af;
  gap: 8px;
  font-size: .8rem;
}

/* ── CALENDAR & FULLCALENDAR STANDARDIZED STYLING ───────────────────────── */
/* Applied globally to all FullCalendar instances for consistency */

/* FullCalendar button group — add gaps between month/week/list buttons */
.fc .fc-button-group {
  gap: 6px !important;
  display: inline-flex !important;
}

/* Ensure button group buttons have proper spacing */
.fc .fc-button-group > .fc-button {
  border-radius: 6px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Remove negative margins from individual buttons since gap handles spacing */
.fc-direction-ltr .fc-button-group > .fc-button:not(:first-child) {
  margin-left: 0 !important;
  border-top-left-radius: 6px !important;
  border-bottom-left-radius: 6px !important;
}

.fc-direction-ltr .fc-button-group > .fc-button:not(:last-child) {
  border-top-right-radius: 6px !important;
  border-bottom-right-radius: 6px !important;
}

/* FullCalendar toolbar styling — consistent with CRM design */
.fc .fc-toolbar {
  padding: 12px 0;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}

.fc .fc-toolbar-title {
  font-size: 1.2em;
  font-weight: 600;
  color: #374151;
}

/* FullCalendar buttons — match CRM primary color scheme */
.fc .fc-button-primary {
  background-color: #fff !important;
  border-color: #ddd !important;
  color: #666 !important;
  border-radius: 6px !important;
  padding: 6px 12px !important;
  font-size: .86rem !important;
  transition: all 0.14s ease !important;
}

.fc .fc-button-primary:hover:not(:disabled) {
  background-color: #f9fafb !important;
  border-color: var(--crm-primary, #530383) !important;
  color: var(--crm-primary, #530383) !important;
}

.fc .fc-button-primary.fc-button-active,
.fc .fc-button-primary:not(:disabled).fc-button-active {
  background-color: var(--crm-primary, #530383) !important;
  border-color: var(--crm-primary, #530383) !important;
  color: #fff !important;
}

/* Generic view-toggle class for non-FullCalendar implementations */
.view-toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.view-toggle .btn {
  border-radius: 6px;
  padding: 5px 10px;
  color: #666;
  border-color: var(--crm-border, #e8eaef);
  background: #fff;
  font-size: .85rem;
  transition: all 0.14s ease;
}

.view-toggle .btn:hover {
  border-color: var(--crm-primary, #530383);
  color: var(--crm-primary, #530383);
}

.view-toggle .btn.active {
  background: var(--crm-primary, #530383);
  color: #fff;
  border-color: var(--crm-primary, #530383);
}
}

/* Package line-item editor — proposal "no-tax" mode hides VAT columns/rows (quote = gov + service only) */
.pli-no-tax .pli-col-disc,
.pli-no-tax .pli-col-vat,
.pli-no-tax .pli-col-vatamt,
.pli-no-tax .pli-tax-row { display: none !important; }
