/* Manrope (self-hosted, OFL). Weights 400/500/700. CSP-safe. */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/vendor/fonts/manrope-400.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/vendor/fonts/manrope-500.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/vendor/fonts/manrope-700.woff2") format("woff2"); }

/* =====================================================================
   Roboto font family (self-hosted, Apache-2.0). Weights 400/500/700.
   CSP-safe (font-src 'self'). Swap the active font by editing the
   font stacks in base.html ("Roboto" vs "Geist").
   ===================================================================== */
@font-face {
  font-family: "Roboto"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/vendor/fonts/roboto-400.woff2") format("woff2");
}
@font-face {
  font-family: "Roboto"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/vendor/fonts/roboto-500.woff2") format("woff2");
}
@font-face {
  font-family: "Roboto"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/vendor/fonts/roboto-700.woff2") format("woff2");
}

/* =====================================================================
   Geist font family (self-hosted, OFL) — Vercel's Geist Sans + Mono.
   Variable fonts: one file covers weights 100–900. CSP-safe (font-src 'self').
   ===================================================================== */
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/vendor/fonts/Geist-Variable.woff2") format("woff2");
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/vendor/fonts/GeistMono-Variable.woff2") format("woff2");
}

/* Bootstrap Icons font path fix (local vendor) */
@font-face {
  font-display: block;
  font-family: "bootstrap-icons";
  src: url("/static/vendor/fonts/bootstrap-icons.woff2") format("woff2"),
       url("/static/vendor/fonts/bootstrap-icons.woff") format("woff");
}

/* =====================================================================
   ITPL Pipeline Manager — application theme
   Corporate Blue + slate palette (theme-driven via CSS variables).
   ===================================================================== */

:root {
  /* Bridge to the active THEME (theme_service.py injects --primary,
     --accent, --gradient-* into :root from base.html AFTER this file loads).
     Fallbacks keep the app working if no theme var is present. */
  --app-primary: var(--primary, #2563eb);
  --app-primary-rgb: var(--primary-rgb, 37, 99, 235);
  --app-primary-dark: var(--primary-dark, #1d4ed8);
  --app-accent: var(--accent, #f59e0b);
  --app-gradient-start: var(--gradient-start, #1e3a8a);
  --app-gradient-end: var(--gradient-end, #3b82f6);
  --app-gradient: linear-gradient(135deg, var(--app-gradient-start), var(--app-gradient-end));
  --app-sidebar-bg: #ffffff;       /* light sidebar */
  --app-sidebar-fg: #475569;       /* slate-600 text */
  --app-sidebar-active: var(--primary, #2563eb);
  --app-sidebar-active-bg: #eff4ff;
  --app-sidebar-active-fg: var(--primary, #2563eb);
  --app-sidebar-hover: #f1f5f9;
  --app-sidebar-border: #e6eaf0;
  --app-topbar-bg: #ffffff;
  --app-border: #e2e8f0;
  --app-muted: #475569;            /* slate-600 — darker for legibility (was too light) */
  --app-radius: 12px;
  --app-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 16px rgba(15,23,42,0.06);
}

[data-bs-theme="dark"] {
  --app-topbar-bg: rgba(15,23,42,0.7);
  --app-border: #1e293b;
  --app-muted: #94a3b8;
  --app-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 18px rgba(0,0,0,0.35);
}

/* ---- Bootstrap primary recolour to teal ---- */
.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-dark);
  --bs-btn-hover-border-color: var(--app-primary-dark);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
  --bs-btn-disabled-bg: var(--app-primary);
  --bs-btn-disabled-border-color: var(--app-primary);
}
.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary);
  --bs-btn-hover-border-color: var(--app-primary);
  --bs-btn-active-bg: var(--app-primary);
  --bs-btn-active-border-color: var(--app-primary);
}
.text-primary { color: var(--app-primary) !important; }
a { color: var(--app-primary-dark); }
[data-bs-theme="dark"] a { color: #2dd4bf; }
.bg-body-tertiary { background: rgba(148,163,184,0.12) !important; }
.form-control:focus, .form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .2);
}

/* ---- Base ---- */
html, body { height: 100%; }
body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
}
[data-bs-theme="dark"] body { background: #0b1220; color: #e2e8f0; }

* { scrollbar-width: thin; scrollbar-color: var(--app-muted) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--app-muted); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Shell / sidebar ---- */
.app-shell { min-height: 100vh; }

.app-sidebar {
  width: 250px;
  background: var(--app-sidebar-bg);
  color: var(--app-sidebar-fg);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
  border-right: 1px solid var(--app-sidebar-border);
}
.sidebar-brand {
  display: flex; flex-direction: column; align-items: stretch; gap: .5rem;
  padding: 0.9rem 0.75rem;
  font-weight: 700;
  color: var(--app-primary, #2563eb);
  text-align: center;
  border-bottom: 1px solid var(--app-sidebar-border);
}
/* Logo spans the full sidebar width (left-to-right coverage) */
.sidebar-logo-full {
  display: block; width: auto; max-width: 100%;
  height: var(--brand-logo-height, 48px);
  object-fit: contain; border-radius: 8px;
}
/* App name on a single line */
.brand-name {
  font-family: inherit;   /* use the app-wide font (Roboto/Geist/Manrope), not system */
  font-weight: 800; font-size: 1rem;
  /* Match the "inspace" logo wordmark colour (brand blue). */
  color: var(--brand-logo-color, #017cc2) !important;
  opacity: 1 !important;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand i { color: var(--app-sidebar-active); font-size: 1.4rem; }
.sidebar-brand .brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-logo { width: 46px; height: 46px; object-fit: contain; border-radius: 10px; flex: 0 0 auto; }
.sidebar-logo-icon { font-size: 1.7rem; line-height: 1; flex: 0 0 auto; }
/* Stacked two-line brand: logo left, App Name over two lines */
.sidebar-brand { align-items: center; }
.brand-stack { display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 0; width: 100%; }
.brand-line1 {
  font-family: inherit;
  font-weight: 700; font-size: 1.02rem; color: var(--app-primary, #2563eb) !important;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-line2 {
  font-family: inherit;
  font-weight: 500; font-size: 0.78rem; letter-spacing: .02em;
  color: #94a3b8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-nav { padding: .75rem .65rem 1rem; }
.sidebar-nav .nav-section {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .68rem;
  color: #94a3b8;
  padding: 1rem .85rem .35rem;
  font-weight: 600;
}
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: .7rem;
  color: var(--app-sidebar-fg);
  border-radius: 8px;
  padding: .55rem .75rem;
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: var(--app-sidebar-hover); color: #0f172a; }
.sidebar-nav .nav-link.active {
  background: var(--app-sidebar-active-bg);
  color: var(--app-sidebar-active-fg);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--app-sidebar-active);
}
.sidebar-footer { padding: .9rem 1.1rem; color: #94a3b8; border-top: 1px solid var(--app-sidebar-border); }

/* ---- Main column ---- */
.app-main { background: #f1f5f9; min-height: 100vh; }
[data-bs-theme="dark"] .app-main { background: #0b1220; }
.app-topbar {
  position: sticky; top: 0; z-index: 1030;
  background: var(--app-topbar-bg);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--app-border);
  padding: .6rem 1rem;
}
.app-topbar .topbar-title h1 { font-weight: 700; }
.app-content { padding: 1.25rem; }

/* ---- Sticky footer ---- */
.app-footer {
  margin-top: auto;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--app-border);
  background: var(--app-topbar-bg);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  font-size: .8rem; color: var(--app-muted);
  flex-wrap: wrap;
}

/* ---- Cards ---- */
.card { border: 1px solid var(--app-border); border-radius: var(--app-radius); box-shadow: var(--app-shadow); }
.card-header { background: transparent; font-weight: 600; border-bottom: 1px solid var(--app-border); }

/* ---- KPI cards ---- */
.kpi-card {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-radius: var(--app-radius);
  color: #fff;
  box-shadow: var(--app-shadow);
  position: relative; overflow: hidden;
}
.kpi-card::after {
  content: ""; position: absolute; right: -30px; top: -30px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.kpi-icon { font-size: 1.9rem; opacity: .95; z-index: 1; }
.kpi-body { z-index: 1; }
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; opacity: 1; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(15,23,42,.35); }
.kpi-value { font-size: 1.5rem; font-weight: 800; line-height: 1.15; color: #fff; text-shadow: 0 1px 3px rgba(15,23,42,.35); }
.kpi-sub { font-size: .76rem; opacity: 1; color: rgba(255,255,255,.95); text-shadow: 0 1px 2px rgba(15,23,42,.30); }
/* Bold, high-contrast KPI gradients (deep -> vivid) so white text always pops. */
.kpi-1 { background: linear-gradient(135deg,#1e3a8a,#2563eb); }   /* navy -> blue */
.kpi-2 { background: linear-gradient(135deg,#4338ca,#7c3aed); }   /* indigo -> violet */
.kpi-3 { background: linear-gradient(135deg,#065f46,#16a34a); }   /* deep -> emerald */
.kpi-4 { background: linear-gradient(135deg,#b45309,#f59e0b); }   /* amber deep -> gold */
.kpi-5 { background: linear-gradient(135deg,#0f766e,#14b8a6); }   /* teal deep -> teal */
.kpi-6 { background: linear-gradient(135deg,#7e22ce,#a855f7); }   /* purple deep -> violet */
.kpi-card { transition: transform .18s ease, box-shadow .18s ease; }
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(15,23,42,0.18); }

/* ---- KPI row: fill width evenly regardless of card count (4/5/6) ---- */
@media (min-width: 1200px) {
  .kpi-row { flex-wrap: nowrap; }
  .kpi-row > .col { flex: 1 1 0; width: auto; min-width: 0; }
}


/* ---- Stage badges ---- */
.stage-badge {
  font-weight: 700; padding: .32em .62em; border-radius: 999px;
  font-size: .72rem; letter-spacing: .02em; color: #fff !important;
  box-shadow: 0 1px 2px rgba(15,23,42,.15);
}
/* Vibrant SOLID badges with white text — WCAG AA and they pop. */
.stage-badge[data-stage="Enquiry"]                 { background:#475569; }
.stage-badge[data-stage="Qualified"]                { background:#0891b2; }
.stage-badge[data-stage="Proposal Submitted"]       { background:#7c3aed; }
.stage-badge[data-stage="Negotiation"]              { background:#d97706; }
.stage-badge[data-stage="Verbal Commit / Awaiting PO"] { background:#0d9488; }
.stage-badge[data-stage="Closed Won"]               { background:#16a34a; }
.stage-badge[data-stage="Closed Lost"]              { background:#dc2626; }
.stage-badge[data-stage="On Hold"]                  { background:#64748b; }
[data-bs-theme="dark"] .stage-badge[data-stage="Enquiry"]           { background:#334155; color:#e2e8f0; }
[data-bs-theme="dark"] .stage-badge[data-stage="Qualified"]          { background:#155e75; color:#cffafe; }
[data-bs-theme="dark"] .stage-badge[data-stage="Proposal Submitted"] { background:#5b21b6; color:#ede9fe; }
[data-bs-theme="dark"] .stage-badge[data-stage="Negotiation"]       { background:#92400e; color:#fef3c7; }
[data-bs-theme="dark"] .stage-badge[data-stage="Verbal Commit / Awaiting PO"] { background:#166534; color:#dcfce7; }
[data-bs-theme="dark"] .stage-badge[data-stage="Closed Won"]         { background:#15803d; color:#bbf7d0; }
[data-bs-theme="dark"] .stage-badge[data-stage="Closed Lost"]         { background:#991b1b; color:#fee2e2; }
[data-bs-theme="dark"] .stage-badge[data-stage="On Hold"]            { background:#1e293b; color:#cbd5e1; }

/* ---- Sort links ---- */
.sort-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; }
/* --app-primary-dark, not --app-primary: the org's configured branding
   color can override --app-primary to something too light to read as text
   (see the "brand_primary" AppSetting) — --app-primary-dark is untouched
   by that override, so text/outlines that use it stay readable no matter
   what primary color a customer picks. --app-primary itself is still fine
   for BACKGROUND fills (buttons, gradients) since those pair it with
   white text and get their contrast from being a solid block of color,
   not from the color being dark enough to read against white. */
.sort-link:hover { color: var(--app-primary-dark); }
.sort-link.active { color: var(--app-primary-dark); font-weight: 600; }
.th-sort-dropdown { display: inline-block; }
.th-sort-dropdown .sort-link { cursor: pointer; }
.th-sort-dropdown .dropdown-menu-sm { min-width: 150px; font-size: .82rem; }
.th-sort-dropdown .dropdown-item.active { background: var(--app-primary-dark); color: #fff; }
.th-sort-dropdown .dropdown-menu-scroll { max-height: 320px; overflow-y: auto; }
.th-sort-dropdown .dropdown-header { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Tables ---- */
.table > :not(caption) > * > * { padding: .6rem .65rem; }
.table thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--app-muted); }

/* ---- Settings nav ---- */
.nav-settings .nav-link {
  color: #334155; border-radius: 8px; font-weight: 600;
  background: rgba(148,163,184,0.12);
}
.nav-settings .nav-link.active {
  background: var(--app-gradient); color: #fff !important;
  box-shadow: 0 2px 8px rgba(var(--app-primary-rgb), .35);
}
.nav-settings .nav-link:hover:not(.active) {
  background: rgba(var(--app-primary-rgb),0.14); color: var(--app-primary-dark);
}
[data-bs-theme="dark"] .nav-settings .nav-link { color: #cbd5e1; background: rgba(148,163,184,0.16); }

/* ---- Login ---- */
.app-body:has(.auth-wrap) { background: radial-gradient(1200px 600px at 70% -10%, rgba(20,184,166,.25), transparent), linear-gradient(135deg,#0f172a,#0b1220); }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 430px; border-radius: 16px; overflow: hidden; border: 0; }
.auth-hero { background: var(--app-gradient); color: #fff; padding: 1.8rem 1.5rem 1.3rem; text-align: center; }
.auth-hero .auth-logo { font-size: 2.2rem; margin-bottom: .4rem; }
.auth-hero .auth-logo-img { max-height: 64px; max-width: 220px; object-fit: contain; margin-bottom: .5rem; border-radius: 14px; background: rgba(255,255,255,.9); padding: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.auth-hero h2 { font-weight: 700; font-size: 1.4rem; }
.auth-hero p { font-size: .85rem; color: rgba(255,255,255,.9) !important; }
.demo-creds code { background: rgba(var(--app-primary-rgb),0.1); color: var(--app-primary); padding: .12rem .4rem; border-radius: 5px; }

/* ---- Misc ---- */
.stat-card { border-left: 4px solid var(--app-primary); }
.text-prewrap { white-space: pre-wrap; }
.cursor-pointer { cursor: pointer; }
.flash-wrap { margin-bottom: 1rem; }
legend { border: 0; }
.progress-bar { background: var(--app-primary); }

/* ==== NEW: Enhanced UI Components ==== */

/* Gradient backgrounds for cards */
.card-gradient {
  background: linear-gradient(135deg, rgba(var(--app-primary-rgb),0.05), rgba(var(--app-primary-rgb),0.03));
  border: 1px solid var(--app-border);
}

/* Micro-interactions on buttons and links */
.btn, .nav-link, .dropdown-item {
  transition: all 0.2s ease !important;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.btn:active { transform: translateY(0); }

/* Floating action button */
.fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; box-shadow: 0 4px 16px rgba(var(--app-primary-rgb),0.4);
  z-index: 1040; transition: all 0.2s ease;
}
.fab:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(var(--app-primary-rgb),0.5); }

/* Quick action bar */
.quick-action-bar {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.75rem; background: rgba(var(--app-primary-rgb),0.05);
  border-radius: var(--app-radius); margin-bottom: 1rem;
}

/* Widget card for dashboard */
.widget-card {
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.widget-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15,23,42,0.12);
}

/* Traffic light indicators */
.traffic-light {
  width: 12px; height: 12px; border-radius: 50%;
  display: inline-block; margin-right: 6px;
}
.traffic-light.green { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,0.5); }
.traffic-light.yellow { background: #f59e0b; box-shadow: 0 0 8px rgba(245,158,11,0.5); }
.traffic-light.red { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,0.5); }

/* Heat map cells */
.heatmap-cell {
  min-width: 40px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-weight: 600; font-size: 0.85rem;
  transition: transform 0.15s ease;
}
.heatmap-cell:hover { transform: scale(1.05); }
.heatmap-low { background: rgba(34,197,94,0.2); color: #15803d; }
.heatmap-med { background: rgba(245,158,11,0.2); color: #b45309; }
.heatmap-high { background: rgba(239,68,68,0.2); color: #b91c1c; }

/* Inline editing indicator */
.inline-edit-active {
  border: 2px solid var(--app-primary);
  border-radius: 6px; padding: 2px 6px;
  background: rgba(var(--app-primary-rgb),0.05);
}

/* Toast notifications */
.toast-container {
  position: fixed; top: 80px; right: 24px; z-index: 1050;
}
.toast-notification {
  background: #fff; border-left: 4px solid var(--app-primary);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  border-radius: 8px; padding: 1rem 1.25rem;
  margin-bottom: 0.75rem; min-width: 280px;
  animation: slideIn 0.3s ease;
}
[data-bs-theme="dark"] .toast-notification { background: #1e293b; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Empty state illustration */
.empty-state {
  text-align: center; padding: 3rem 1.5rem;
  color: var(--app-muted);
}
.empty-state-icon {
  font-size: 4rem; margin-bottom: 1rem;
  opacity: 0.5; display: block;
}

/* Print-friendly styles */
@media print {
  .app-sidebar, .app-topbar, .app-footer, .btn, .fab, .quick-action-bar {
    display: none !important;
  }
  .app-main { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .kpi-card { break-inside: avoid; }
}

/* Global search overlay */
.search-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.8); z-index: 2000;
  display: flex; align-items: flex-start;
  justify-content: center; padding-top: 100px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.search-overlay.active { opacity: 1; pointer-events: auto; }
.search-box {
  background: #fff; border-radius: 12px;
  width: 90%; max-width: 600px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  overflow: hidden;
}
[data-bs-theme="dark"] .search-box { background: #1e293b; }
.search-input {
  width: 100%; border: 0; padding: 1.25rem 1.5rem;
  font-size: 1.1rem; outline: none; background: transparent;
}
.search-results {
  max-height: 400px; overflow-y: auto;
  border-top: 1px solid var(--app-border);
}
.search-result-item {
  padding: 0.75rem 1.5rem; cursor: pointer;
  transition: background 0.15s ease;
}
.search-result-item:hover,
.search-result-item.active { background: rgba(var(--app-primary-rgb),0.08); }
.search-result-item:focus-visible { outline: 2px solid var(--app-primary-dark); outline-offset: -2px; }

/* View switcher tabs */
.view-switcher {
  display: inline-flex; background: rgba(var(--app-primary-rgb),0.08);
  border-radius: 8px; padding: 4px;
}
.view-switcher .view-btn {
  padding: 0.4rem 0.75rem; border: 0; background: transparent;
  border-radius: 6px; font-size: 0.85rem;
  color: var(--app-muted); cursor: pointer;
  transition: all 0.15s ease;
}
.view-switcher .view-btn:hover { color: var(--app-primary); }
.view-switcher .view-btn.active {
  background: var(--app-primary); color: #fff;
}

/* Kanban board */
.kanban-board {
  display: flex; gap: 1rem; overflow-x: auto;
  padding: 1rem 0; min-height: 500px;
}
.kanban-column {
  min-width: 300px; max-width: 300px;
  background: rgba(148,163,184,0.1);
  border-radius: var(--app-radius);
  padding: 0.75rem; display: flex; flex-direction: column;
}
.kanban-header {
  font-weight: 700; padding: 0.5rem;
  margin-bottom: 0.75rem; display: flex;
  justify-content: space-between; align-items: center;
}
.kanban-cards { flex: 1; overflow-y: auto; min-height: 400px; }
.kanban-card {
  background: #fff; border-radius: 8px;
  padding: 1rem; margin-bottom: 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: grab; transition: all 0.2s ease;
}
.kanban-card:focus-visible {
  outline: 2px solid var(--app-primary-dark); outline-offset: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
[data-bs-theme="dark"] .kanban-card { background: #1e293b; }
.kanban-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.kanban-card:active { cursor: grabbing; }

/* Calendar view */
.calendar-view {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--app-border);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius); overflow: hidden;
}
.calendar-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: rgba(var(--app-primary-rgb),0.08);
  padding: 0.75rem; text-align: center;
  font-weight: 600; font-size: 0.85rem;
}
.calendar-day-header {
  padding: 0.5rem; text-align: center;
  font-weight: 600; font-size: 0.75rem;
  color: var(--app-muted);
}
.calendar-days {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--app-border);
}
.calendar-day {
  background: var(--app-topbar-bg);
  min-height: 120px; padding: 0.5rem;
  font-size: 0.85rem; position: relative;
}
.calendar-day-other { opacity: 0.5; }
.calendar-today { background: rgba(var(--app-primary-rgb),0.15) !important; border: 2px solid var(--app-primary); }
.calendar-day-number {
  font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem;
}
.calendar-events { display: flex; flex-direction: column; gap: 2px; }
.calendar-event {
  background: var(--app-primary-dark); color: #fff;
  padding: 4px 6px; border-radius: 4px;
  font-size: 0.7rem; cursor: pointer;
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; display: flex; align-items: center; gap: 4px;
  transition: all 0.15s ease;
}
.calendar-event:hover { transform: translateX(2px); filter: brightness(1.1); }
.calendar-event .event-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.8);
}
.calendar-more {
  font-size: 0.65rem; color: var(--app-muted);
  cursor: pointer; padding: 2px 4px;
  text-align: center;
}
.calendar-more:hover { background: rgba(148,163,184,0.15); border-radius: 4px; }

/* Funnel chart container */
.funnel-container {
  padding: 1rem; background: rgba(var(--app-primary-rgb),0.05);
  border-radius: var(--app-radius);
}

/* Bulk action toolbar */
.bulk-toolbar {
  display: none; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; background: rgba(var(--app-primary-rgb),0.06);
  border-radius: var(--app-radius); margin-bottom: 1rem;
}
.bulk-toolbar.active { display: flex; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, rgba(148,163,184,0.2) 25%, rgba(148,163,184,0.3) 50%, rgba(148,163,184,0.2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Tooltip enhancement */
.tooltip-inner {
  background: #0f172a; padding: 0.5rem 0.75rem;
  font-size: 0.8rem; border-radius: 6px;
}
[data-bs-theme="dark"] .tooltip-inner { background: #e2e8f0; color: #0f172a; }

/* Progress ring */
.progress-ring {
  width: 48px; height: 48px;
  position: relative; display: inline-flex;
  align-items: center; justify-content: center;
}
.progress-ring-circle {
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.progress-ring-text {
  position: absolute; font-size: 0.7rem;
  font-weight: 600;
}

/* Comparison table */
.comparison-table th.compare-header {
  background: linear-gradient(135deg, rgba(var(--app-primary-rgb),0.1), rgba(var(--app-primary-rgb),0.07));
}

/* Admin quick stats */
.admin-stat-card {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #fff; border-radius: var(--app-radius);
  padding: 1.25rem; position: relative; overflow: hidden;
}
.admin-stat-card::before {
  content: ""; position: absolute; top: -50%; right: -50%;
  width: 150px; height: 150px;
  background: radial-gradient(circle, rgba(var(--app-primary-rgb),0.2), transparent);
  border-radius: 50%;
}

/* Infinite scroll loader */
.infinite-loader {
  text-align: center; padding: 1.5rem;
  color: var(--app-muted);
}
.infinite-loader i { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Keyboard shortcut hint */
.kbd-hint {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7rem; color: var(--app-muted);
  background: rgba(148,163,184,0.15);
  padding: 2px 6px; border-radius: 4px;
}

/* Stage progression wizard */
.wizard-step {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem; border-radius: 8px;
  margin-bottom: 0.5rem; cursor: pointer;
  transition: all 0.15s ease;
}
.wizard-step:hover { background: rgba(var(--app-primary-rgb),0.08); }
.wizard-step.active { background: rgba(var(--app-primary-rgb),0.15); border-left: 3px solid var(--app-primary); }
.wizard-step.completed { color: #22c55e; }
.wizard-step-number {
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(148,163,184,0.2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem;
}
.wizard-step.active .wizard-step-number { background: var(--app-primary); color: #fff; }
.wizard-step.completed .wizard-step-number { background: #22c55e; color: #fff; }

/* Saved filter chips */
.filter-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: rgba(var(--app-primary-rgb),0.1); color: var(--app-primary-dark);
  padding: 0.35rem 0.65rem; border-radius: 20px;
  font-size: 0.8rem; cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover { background: rgba(var(--app-primary-rgb),0.2); }
.filter-chip .remove-chip {
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(var(--app-primary-rgb),0.2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.65rem;
}

/* Drag handle for sortable items */
.drag-handle {
  cursor: grab; color: var(--app-muted);
  padding: 0.25rem; opacity: 0.6;
  transition: opacity 0.15s ease;
}
.drag-handle:hover { opacity: 1; }

/* Timestamp display */
.timestamp-tooltip {
  font-size: 0.75rem; color: var(--app-muted);
  cursor: help; border-bottom: 1px dotted var(--app-muted);
}

/* Data visualization variations */
.chart-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.chart-tab {
  padding: 0.4rem 0.8rem; border-radius: 6px;
  background: rgba(148,163,184,0.1);
  font-size: 0.8rem; cursor: pointer;
  transition: all 0.15s ease;
}
.chart-tab:hover { background: rgba(var(--app-primary-rgb),0.15); }
.chart-tab.active { background: var(--app-primary); color: #fff; }

/* Benchmark indicator */
.benchmark-line { stroke-dasharray: 4,4; stroke-width: 2; opacity: 0.6; }
.benchmark-label { font-size: 0.7rem; fill: var(--app-muted); }

/* Export scheduling panel */
.export-panel {
  background: rgba(var(--app-primary-rgb),0.05);
  border: 1px dashed var(--app-primary);
  border-radius: var(--app-radius);
  padding: 1rem; margin-top: 1rem;
}

/* Real-time update indicator */
.realtime-indicator {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.75rem; color: #22c55e;
}
.realtime-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e; animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

/* ==== Responsive (Updated) ==== */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed; left: 0; top: 0; z-index: 1045;
    width: 260px; max-width: 82vw;
    height: 100vh; transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.35);
  }
  .app-sidebar.show { transform: translateX(0); }
  .app-content { padding: 1rem; }
  .kpi-value { font-size: 1.3rem; }
  .kanban-board { flex-direction: column; }
  .kanban-column { max-width: 100%; }
  .calendar-view { grid-template-columns: repeat(1, 1fr); }
  .fab { bottom: 80px; right: 16px; }
  /* backdrop shown behind the open drawer */
  .sidebar-backdrop.show {
    display: block; position: fixed; inset: 0;
    background: rgba(15,23,42,0.45); z-index: 1040;
  }
}

/* Sidebar toggle (hamburger): visible only below the lg breakpoint */
.sidebar-toggle { display: inline-flex; align-items: center; }
@media (min-width: 992px) {
  .sidebar-toggle { display: none !important; }
  .sidebar-backdrop { display: none !important; }
}

/* ---- Desktop sidebar collapse-to-rail ---- */
/* The collapse button shows only on desktop; the mobile hamburger shows only below lg. */
.sidebar-collapse-btn { display: none; align-items: center; }
@media (min-width: 992px) {
  .sidebar-collapse-btn { display: inline-flex !important; }
}
/* Collapsed rail: shrink the sidebar to an icon-only strip. */
.app-shell.sidebar-collapsed .app-sidebar { width: 68px; }
.app-shell.sidebar-collapsed .app-sidebar .brand-name,
.app-shell.sidebar-collapsed .app-sidebar .brand-line1,
.app-shell.sidebar-collapsed .app-sidebar .brand-line2,
.app-shell.sidebar-collapsed .app-sidebar .sidebar-logo-full,
.app-shell.sidebar-collapsed .app-sidebar .nav-section,
.app-shell.sidebar-collapsed .app-sidebar .sidebar-footer,
.app-shell.sidebar-collapsed .app-sidebar .sidebar-nav .nav-link span { display: none; }
.app-shell.sidebar-collapsed .app-sidebar .sidebar-brand { padding: .9rem .5rem; align-items: center; }
.app-shell.sidebar-collapsed .app-sidebar .sidebar-nav .nav-link {
  justify-content: center; padding: .6rem 0;
}
.app-shell.sidebar-collapsed .app-sidebar .sidebar-nav .nav-link i { width: auto; font-size: 1.15rem; }
.app-sidebar { transition: width .18s ease; }
/* Tooltip-on-hover for collapsed items (uses the link's title attr via ::after) */
.app-shell.sidebar-collapsed .sidebar-nav .nav-link { position: relative; }

/* Backdrop is hidden by default; JS toggles the .show class */
.sidebar-backdrop { display: none; }
/* Prevent body scroll when the mobile drawer is open */
body.sidebar-open { overflow: hidden; }
@media (max-width: 575.98px) {
  /* responsive topbar polish */
  .topbar-title h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
  .app-topbar { padding: .5rem .6rem; }
  .dropdown-menu { max-width: 92vw; }
  .app-footer { font-size: .72rem; }
  .kpi-card { padding: .9rem; }
  .quick-action-bar { flex-direction: column; }
  .view-switcher { width: 100%; justify-content: space-between; }
  .filter-chips { max-width: 100%; overflow-x: auto; }
  .toast-container { left: 16px; right: 16px; top: auto; bottom: 80px; }

  /* Data tables -> stacked cards. Opt-in via .table-reflow (Pipeline and
     Orders lists) so tables that haven't been given data-label attributes
     on their <td>s aren't silently broken by this. The header row is
     hidden; each cell becomes its own row with the column name shown via
     ::before from data-label, set inline by the template. tfoot (totals)
     is left as a normal scrolling row — it's a short summary line, not
     primary content. */
  .table-reflow thead { display: none; }
  .table-reflow tbody tr {
    display: block;
    border: 1px solid var(--ui-border, var(--app-border));
    border-radius: var(--ui-radius, 10px);
    margin-bottom: .75rem;
    padding: .25rem .75rem;
    background: var(--app-topbar-bg, #fff);
  }
  .table-reflow tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    text-align: right;
    padding: .5rem 0;
    border-bottom: 1px dashed var(--app-border);
    white-space: normal;
  }
  .table-reflow tbody tr td:last-child { border-bottom: 0; }
  .table-reflow tbody td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--app-muted);
    text-align: left;
    flex: 0 0 auto;
    margin-right: auto;
  }
  /* Actions cell holds buttons, not a value — let it wrap under its label
     instead of squeezing onto one line. */
  .table-reflow tbody td[data-label="Actions"] {
    flex-direction: column;
    align-items: flex-start;
  }
  .table-reflow tbody td[data-label="Actions"]::before { margin-right: 0; margin-bottom: .35rem; }
}


/* === SHADCN-INSPIRED POLISH LAYER === */
/* Refined tokens: softer radii, layered shadows, calmer borders, tighter
   focus rings. Additive only — refines the look without changing structure. */
:root {
  --ui-radius: 10px;
  --ui-radius-sm: 7px;
  --ui-border: #e5e7eb;
  --ui-ring: rgba(15, 118, 110, 0.35);      /* teal focus ring */
  --ui-shadow-xs: 0 1px 2px rgba(16,24,40,0.05);
  --ui-shadow-sm: 0 1px 3px rgba(16,24,40,0.08), 0 1px 2px rgba(16,24,40,0.04);
  --ui-shadow-md: 0 4px 12px rgba(16,24,40,0.08), 0 2px 4px rgba(16,24,40,0.04);
}
[data-bs-theme="dark"] {
  --ui-border: #23324a;
  --ui-ring: rgba(45, 212, 191, 0.35);
}

/* Cards: subtle border + soft layered shadow, no heavy drop shadow */
.card, .widget-card {
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--ui-radius) !important;
  box-shadow: var(--ui-shadow-sm) !important;
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
.card.shadow-sm { box-shadow: var(--ui-shadow-sm) !important; }
.widget-card:hover { box-shadow: var(--ui-shadow-md) !important; }

/* Buttons: crisper radius, medium weight, smooth press */
.btn {
  border-radius: var(--ui-radius-sm);
  font-weight: 500;
  letter-spacing: .01em;
  transition: background-color .15s ease, border-color .15s ease,
              box-shadow .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(0.5px); }
.btn-sm { border-radius: 6px; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--ui-ring) !important; outline: none; }

/* Inputs / selects: consistent radius + calm focus ring (no thick glow) */
.form-control, .form-select {
  border-radius: var(--ui-radius-sm);
  border-color: var(--ui-border);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--app-primary) !important;
  box-shadow: 0 0 0 3px var(--ui-ring) !important;
}

/* Tables: airy rows, quiet header, hairline separators */
.table { --bs-table-border-color: var(--ui-border); }
.table > :not(caption) > * > * { padding-top: .7rem; padding-bottom: .7rem; }
.table thead th, .table > thead > tr > th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--app-muted); font-weight: 600; border-bottom: 1px solid var(--ui-border);
}
.table-hover > tbody > tr { transition: background-color .12s ease; }

/* Badges / stage pills: pill shape, soft weight */
.badge { border-radius: 999px; font-weight: 600; letter-spacing: .01em; padding: .35em .7em; }

/* Dropdown menus: rounded, soft shadow, roomy items */
.dropdown-menu {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-md);
  padding: .35rem;
}
.dropdown-item { border-radius: var(--ui-radius-sm); padding: .45rem .7rem; }

/* Nav pills (settings sub-nav) */
.nav-pills .nav-link { border-radius: var(--ui-radius-sm); }

/* Sidebar links: rounded hover targets */
.sidebar-nav .nav-link { border-radius: var(--ui-radius-sm); margin: 1px 6px; transition: background-color .12s ease, color .12s ease; }

/* Calendar chips: pill, readable, subtle */
.calendar-event { border-radius: 6px; box-shadow: var(--ui-shadow-xs); }
.calendar-event .event-text { font-weight: 500; }

/* Modal + card headers */
.modal-content { border: 1px solid var(--ui-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow-md); }
.card-header { background: transparent; border-bottom: 1px solid var(--ui-border); font-weight: 600; }


/* inline-edit affordance */
.inline-editable { cursor: text; position: relative; }
.inline-editable:hover { background: rgba(15,118,110,0.06); outline: 1px dashed rgba(15,118,110,0.35); outline-offset: -2px; }
.inline-editable:focus-visible { background: rgba(15,118,110,0.08); outline: 2px solid var(--app-primary-dark); outline-offset: -2px; }
.inline-edit-active { min-width: 90px; }
td.inline-edit[data-type="select"]:hover, td.inline-edit[data-type="date"]:hover { cursor: pointer; }


/* prevent wide content (kanban) from pushing topbar off-screen */
.app-main { overflow-x: hidden; min-width: 0; }
.app-content { min-width: 0; max-width: 100%; overflow-x: hidden; padding: 1rem; }
.app-topbar { position: sticky; left: 0; right: 0; width: 100%; }
/* the kanban board itself scrolls horizontally, not the page */
.kanban-board { max-width: 100%; }


/* calendar full-text chips */
.calendar-events { max-height: 150px; overflow-y: auto; }
.calendar-event {
  white-space: normal;            /* allow full text to wrap */
  overflow: visible; text-overflow: clip;
  align-items: flex-start;
  line-height: 1.25;
  text-decoration: none;          /* it is now an <a> */
}
.calendar-event .event-text { white-space: normal; word-break: break-word; }
.calendar-event .event-dot { margin-top: 5px; flex: 0 0 auto; }
.calendar-event:hover { text-decoration: none; }


/* =====================================================================
   VIBRANCY LAYER — high-impact, theme-driven polish (loaded last).
   Uses the active theme's gradient + accent so every theme looks
   distinct and lively, while keeping text WCAG-legible.
   ===================================================================== */

/* Theme-aware focus ring (was hardcoded teal) */
:root { --ui-ring: rgba(var(--app-primary-rgb), 0.35); }

/* --- Gradient card headers: gives every panel a colored identity --- */
.card > .card-header {
  background: linear-gradient(135deg,
              rgba(var(--app-primary-rgb), 0.10),
              rgba(var(--app-primary-rgb), 0.02)) !important;
  border-bottom: 1px solid rgba(var(--app-primary-rgb), 0.18) !important;
  color: var(--app-primary-dark);
  font-weight: 700;
}
.card > .card-header i { color: var(--app-primary); }
[data-bs-theme="dark"] .card > .card-header { color: #e2e8f0; }

/* --- Card hover lift for interactivity --- */
.card { transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(15,23,42,0.10) !important; }

/* --- Page title accent bar --- */
.app-topbar .topbar-title h1 {
  position: relative; padding-left: .7rem;
}
.app-topbar .topbar-title h1::before {
  content: ""; position: absolute; left: 0; top: 12%; bottom: 12%;
  width: 4px; border-radius: 4px;
  background: var(--app-gradient);
}

/* --- Sidebar brand gets a subtle gradient wash + accent underline --- */
.sidebar-brand {
  background: var(--app-sidebar-bg);
  border-bottom: 2px solid var(--app-sidebar-active);
}

/* --- Primary buttons: gradient + lift for the hero action --- */
.btn-primary {
  background-image: var(--app-gradient) !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(var(--app-primary-rgb), 0.30);
}
.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 4px 14px rgba(var(--app-primary-rgb), 0.42);
  transform: translateY(-1px);
}

/* --- Stat cards: accent left border derived from theme --- */
.stat-card { border-left: 4px solid var(--app-accent) !important; }

/* --- Kanban cards: crisp hover + colored top edge by column --- */
.kanban-card { transition: transform .15s ease, box-shadow .15s ease; }
.kanban-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,23,42,0.14) !important; }

/* --- Progress bars / rings pick up the gradient --- */
.progress-bar { background: var(--app-gradient) !important; }

/* --- Section headings + KPI values use theme primary for pop --- */
.kpi-card { border: none; }

/* --- Links a touch bolder for affordance --- */
a { font-weight: 500; }
.sidebar-nav a, .nav-link a { font-weight: inherit; }


/* --- KPI legibility: dark scrim under text so white always reads on any
       theme gradient (fixes washed-out label on light-blue cards) --- */
.kpi-card::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, rgba(15,23,42,0.22), rgba(15,23,42,0.0) 62%);
  pointer-events: none; z-index: 0;
}
.kpi-card > * { position: relative; z-index: 1; }

/* --- View switcher: make INACTIVE Table/Kanban/Calendar clearly visible
       (was dull grey). Active keeps the solid primary. --- */
.view-switcher .btn.btn-outline-secondary {
  color: #334155 !important;
  border-color: var(--app-border) !important;
  background: #fff !important;
  font-weight: 600;
}
.view-switcher .btn.btn-outline-secondary:hover {
  color: var(--app-primary-dark) !important;
  border-color: var(--app-primary) !important;
  background: rgba(var(--app-primary-rgb), 0.10) !important;
}
.view-switcher .btn.btn-primary.active,
.view-switcher .btn.btn-primary {
  background: var(--app-gradient) !important;
  border-color: transparent !important;
  color: #fff !important;
  box-shadow: 0 2px 8px rgba(var(--app-primary-rgb), .35);
}
[data-bs-theme="dark"] .view-switcher .btn.btn-outline-secondary {
  color: #e2e8f0 !important; background: #1e293b !important; border-color: #334155 !important;
}


/* =====================================================================
   SECONDARY / OUTLINE BUTTONS — remove the washed-out grey look app-wide.
   Applies to status filters (All/Open/Won/Lost), Default view, Columns,
   Export CSV, row action buttons, etc.
   ===================================================================== */
.btn-outline-secondary {
  --bs-btn-color: #334155;
  --bs-btn-border-color: #cbd5e1;
  --bs-btn-bg: #ffffff;
  --bs-btn-hover-color: #0f172a;
  --bs-btn-hover-bg: #f1f5f9;
  --bs-btn-hover-border-color: #94a3b8;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #475569;
  --bs-btn-active-border-color: #475569;
  font-weight: 600;
}
[data-bs-theme="dark"] .btn-outline-secondary {
  --bs-btn-color: #e2e8f0;
  --bs-btn-border-color: #334155;
  --bs-btn-bg: #1e293b;
  --bs-btn-hover-bg: #273449;
}

/* Status filter group: the ACTIVE segment gets a solid, confident fill. */
.filter-status .btn.active,
.filter-status .btn-outline-secondary.active {
  background: #334155 !important;
  border-color: #334155 !important;
  color: #fff !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.filter-status .btn-outline-warning.active {
  background: #f59e0b !important; border-color: #f59e0b !important; color: #fff !important;
}
/* Inactive segments: clearly readable, not ghost-grey. */
.filter-status .btn-outline-secondary:not(.active) { color: #475569 !important; background: #fff !important; }

/* Dropdown toggle buttons (Default view / Columns / Export) — same treatment
   already covered by .btn-outline-secondary above; ensure the caret + icon
   inherit the darker text. */
.btn-outline-secondary .bi { color: inherit; }


/* Slightly darker muted text app-wide for better legibility (user prefers
   more contrast; avoids the "dull grey text" look). */
.text-secondary { color: #475569 !important; }
.text-muted { color: #52627a !important; }
[data-bs-theme="dark"] .text-secondary { color: #94a3b8 !important; }
[data-bs-theme="dark"] .text-muted { color: #94a3b8 !important; }


/* =====================================================================
   STAT TILES (widget-card text-center) — lift the flat white tiles used
   on Reports (index/pipeline/orders) and Client detail so pages aren't dull.
   ===================================================================== */
.widget-card.text-center, .widget-card.p-3.text-center, .widget-card.text-center.p-3 {
  background: linear-gradient(160deg, rgba(var(--app-primary-rgb),0.06), #ffffff 55%);
  border: 1px solid var(--ui-border) !important;
  border-top: 3px solid var(--app-primary) !important;
  position: relative;
}
.widget-card.text-center:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(15,23,42,0.12) !important;
}
/* Big number pops in slate-900 / bold */
.widget-card.text-center h3, .widget-card.text-center h4 {
  font-weight: 800; color: #0f172a; letter-spacing: -0.01em;
}
[data-bs-theme="dark"] .widget-card.text-center h3,
[data-bs-theme="dark"] .widget-card.text-center h4 { color: #f1f5f9; }
/* The big bootstrap-colored icons: give them more presence */
.widget-card.text-center .display-6 { opacity: 1; }
[data-bs-theme="dark"] .widget-card.text-center {
  background: linear-gradient(160deg, rgba(var(--app-primary-rgb),0.16), #1e293b 55%);
}

/* Report "launcher" tiles (Pipeline Analysis / Orders / Custom / Dashboard):
   add a left accent + hover so the Standard Reports card isn't flat. */
.card .widget-card.h-100 {
  border-left: 3px solid var(--app-primary) !important;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.card .widget-card.h-100:hover {
  transform: translateY(-2px);
  background: rgba(var(--app-primary-rgb),0.05);
  box-shadow: 0 8px 20px rgba(15,23,42,0.10) !important;
}

/* =====================================================================
   FORM SECTION BLOCKS — professional single-tone panels. Each fieldset is
   a clean neutral card separated by whitespace, with a subtle theme-colored
   left accent. Consistent and corporate (no multi-hue "rainbow").
   ===================================================================== */
.form-section {
  border-radius: 12px;
  padding: 1rem 1.15rem 1.15rem;
  margin-bottom: 1.1rem;
  border: 1px solid #e5e7eb !important;
  /* Thin neutral accent for subtle edge definition (not theme-colored). */
  border-left: 3px solid #cbd2dc !important;
  /* Mild neutral panel (standard, theme-independent) so white fields pop. */
  background: #f7f8fa;
  box-shadow: 0 1px 2px rgba(16,24,40,0.05);
  min-width: 0;
}
.form-section > legend {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: .85rem;
  color: #334155;
  display: flex; align-items: center; gap: .45rem;
}
[data-bs-theme="dark"] .form-section {
  background: #111a2e; border-color: var(--ui-border);
}
[data-bs-theme="dark"] .form-section > legend { color: #cbd5e1; }

/* .section-1..6 kept as no-ops (templates reference them) — all sections now
   share one professional tone; the class only marks a section, no color. */
.section-1, .section-2, .section-3, .section-4, .section-5, .section-6 {}

/* Fields inside the tinted panel stay WHITE with a crisp border so they
   stand out against the mild grey section background. */
.form-section .form-control,
.form-section .form-select {
  background-color: #ffffff;
  border-color: #d7dce3;
}
.form-section .input-group-text { background-color: #eef1f5; border-color: #d7dce3; }
/* keep the intentionally-greyed read-only fields visibly disabled */
.form-section .form-control.bg-body-secondary { background-color: #e4e8ee !important; }
[data-bs-theme="dark"] .form-section .form-control,
[data-bs-theme="dark"] .form-section .form-select { background-color: #0f172a; border-color: #26324a; }
[data-bs-theme="dark"] .form-section .form-control.bg-body-secondary { background-color: #1e293b !important; }


/* ── Help system ─────────────────────────────────────────────── */
.help-trigger { transition: transform .2s, opacity .2s; }
.help-trigger:hover { transform: scale(1.15); opacity: .9 !important; }

#helpPanel .offcanvas-body h6 { color: var(--app-primary); font-weight: 600; margin-top: 1rem; }
#helpPanel .offcanvas-body h6:first-child { margin-top: 0; }
#helpPanel .offcanvas-body p { font-size: .875rem; line-height: 1.6; color: #475569; }
#helpPanel .offcanvas-body ul { padding-left: 1.25rem; font-size: .875rem; }
#helpPanel .offcanvas-body li { margin-bottom: .35rem; }
#helpPanel .offcanvas-body .help-tip {
  background: #f0fdf4; border-left: 3px solid #22c55e; padding: .5rem .75rem;
  border-radius: 4px; margin: .75rem 0; font-size: .8rem;
}
#helpPanel .offcanvas-body .help-warn {
  background: #fefce8; border-left: 3px solid #eab308; padding: .5rem .75rem;
  border-radius: 4px; margin: .75rem 0; font-size: .8rem;
}
#helpPanel .offcanvas-body kbd {
  background: #e2e8f0; color: #1e293b; padding: .15rem .4rem; border-radius: 3px; font-size: .8rem;
}

/* Inline help tooltips via data-help attribute */
[data-help] { position: relative; cursor: help; border-bottom: 1px dashed #94a3b8; }
[data-help]:hover::after {
  content: attr(data-help);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: .35rem .6rem; border-radius: 5px;
  font-size: .75rem; white-space: nowrap; max-width: 280px; white-space: normal;
  z-index: 9999; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  pointer-events: none; line-height: 1.4;
}
[data-help]:hover::before {
  content: ''; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%) translateY(6px);
  border: 5px solid transparent; border-top-color: #1e293b; z-index: 9999;
}


/* ── Guided Tour ─────────────────────────────────────────────── */
.tour-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999; display: flex; align-items: center; justify-content: center;
}
.tour-backdrop {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
}
.tour-popup {
  position: relative; z-index: 1; width: 90%; max-width: 440px;
  border-radius: 12px; overflow: hidden; animation: tourSlideIn .25s ease;
}
.tour-popup .card-body { padding: 1.5rem; min-height: 140px; }
.tour-popup .card-footer { background: #f8fafc; }
@keyframes tourSlideIn {
  from { transform: translateY(20px) scale(.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* ── Respect reduced-motion preference ──────────────────────────────
   Neutralize ambient/decorative keyframe animations (pulse, shimmer,
   spin, slide-ins) for users who've asked the OS to minimize motion.
   Brief state-change transitions (hover lift, focus ring) are left
   alone — they're short and don't repeat, so they aren't the concern
   this preference targets. */
@media (prefers-reduced-motion: reduce) {
  .realtime-dot,
  .skeleton,
  .infinite-loader i,
  .toast-notification,
  .tour-popup,
  .filter-chip {
    animation: none !important;
  }
  .card:hover,
  .widget-card:hover,
  .kpi-card:hover,
  .kanban-card:hover,
  .btn:hover,
  .btn:active {
    transform: none !important;
  }
}

/* ==== Searchable <select> (type to filter, existing values only) ==== */
.searchable-select {
  position: relative;
}
.searchable-select-native {
  /* Kept in the DOM (still submits with the form) but not shown —
     the text input above it is the visible control. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.searchable-select-menu {
  display: none;
  position: absolute;
  z-index: 1050;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 2px;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}
.searchable-select-item {
  padding: 0.375rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.searchable-select-item:hover {
  background: var(--bs-tertiary-bg, #f1f3f5);
}


/* Hot/Warm/Cold label pill + swatch popover */
.label-pill { cursor: pointer; user-select: none; }
.label-pill-empty { border: 1px dashed var(--bs-border-color); color: var(--bs-secondary-color); }
.label-pop { position: absolute; z-index: 1080; background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color); border-radius: .5rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.15); padding: .35rem; display: flex; gap: .3rem; }
.label-pop .swatch { width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; display: inline-flex; align-items: center; justify-content: center; }
.label-pop .swatch:hover { border-color: var(--bs-body-color); }
.label-pop .swatch.hot { background: var(--bs-danger); }
.label-pop .swatch.warm { background: var(--bs-warning); }
.label-pop .swatch.cold { background: var(--bs-info); }
.label-pop .swatch.none { background: var(--bs-light); border: 1px solid var(--bs-border-color); color: var(--bs-secondary-color); }


/* =====================================================================
   Accessibility: label filter chips (Hot/Warm/Cold) + "Stale 30d+".
   Instead of colour-on-white text (fails WCAG AA), use a FILLED style like
   the Table/Kanban view-switcher: inactive = light tinted background with
   dark readable text + vivid dot; active = solid colour with white text.
   ===================================================================== */
/* --- inactive: tinted background, dark text (>=4.5:1), vivid dot --- */
.btn-outline-danger:not(.active) {
  --bs-btn-color: #991b1b; --bs-btn-bg: #fef2f2; --bs-btn-border-color: #fecaca;
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #dc2626; --bs-btn-hover-border-color: #dc2626;
}
.btn-outline-warning:not(.active) {
  --bs-btn-color: #92400e; --bs-btn-bg: #fffbeb; --bs-btn-border-color: #fde68a;
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #b45309; --bs-btn-hover-border-color: #b45309;
}
.btn-outline-info:not(.active) {
  --bs-btn-color: #155e75; --bs-btn-bg: #ecfeff; --bs-btn-border-color: #a5f3fc;
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #0e7490; --bs-btn-hover-border-color: #0e7490;
}
/* --- active: solid fill + white text (like the view-switcher) --- */
.btn-outline-danger.active  { color:#fff !important; background:#dc2626 !important; border-color:#dc2626 !important; }
.btn-outline-warning.active { color:#fff !important; background:#b45309 !important; border-color:#b45309 !important; }
.btn-outline-info.active    { color:#fff !important; background:#0e7490 !important; border-color:#0e7490 !important; }
/* --- the little dot keeps its vivid identity hue; white when active --- */
.btn-outline-danger .bi-circle-fill  { color:#dc2626; }
.btn-outline-warning .bi-circle-fill { color:#f59e0b; }
.btn-outline-info .bi-circle-fill    { color:#06b6d4; }
.btn-outline-danger.active .bi-circle-fill,
.btn-outline-warning.active .bi-circle-fill,
.btn-outline-info.active .bi-circle-fill { color: #fff; }
