/* ==========================================================================
   D&R Electronix — Lead & Quote CRM · Admin Template
   Built on Bootstrap 5.3 + jQuery. Operated by Neuvo WebTech.
   --------------------------------------------------------------------------
   1. Tokens          6. Cards & stats       11. Timeline
   2. Base            7. Badges & pills      12. Quote preview
   3. Sidebar         8. Tables              13. Auth pages
   4. Topbar          9. Forms & filters     14. Utilities
   5. Content         10. Lead detail        15. Responsive
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  --app-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --accent: #06b6d4;

  --sidebar-w: 264px;
  --sidebar-w-collapsed: 78px;
  --topbar-h: 68px;

  --sidebar-bg: #0f172a;
  --sidebar-bg-2: #111c35;
  --sidebar-text: #94a3b8;
  --sidebar-text-strong: #e2e8f0;
  --sidebar-hover: rgba(148, 163, 184, .10);
  --sidebar-active: rgba(99, 102, 241, .18);

  --body-bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f2;
  --text: #0f172a;
  --text-2: #475569;
  --text-muted: #64748b;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 4px 24px -6px rgba(15, 23, 42, .10);
  --shadow-lg: 0 20px 48px -12px rgba(15, 23, 42, .25);
  --radius: 14px;
  --radius-sm: 10px;

  /* Lead status colors (bg / fg) */
  --st-new-bg: #e0f2fe;            --st-new-fg: #0369a1;
  --st-review-bg: #ffedd5;         --st-review-fg: #c2410c;
  --st-details-bg: #f3e8ff;        --st-details-fg: #7e22ce;
  --st-owner-bg: #fef3c7;          --st-owner-fg: #b45309;
  --st-quoted-bg: #e0e7ff;         --st-quoted-fg: #4338ca;
  --st-won-bg: #dcfce7;            --st-won-fg: #15803d;
  --st-lost-bg: #fee2e2;           --st-lost-fg: #b91c1c;
  --st-noresp-bg: #f1f5f9;         --st-noresp-fg: #475569;
  --st-spam-bg: #e2e8f0;           --st-spam-fg: #334155;

  /* Age badges */
  --age-ok-bg: #dcfce7;   --age-ok-fg: #15803d;
  --age-warn-bg: #fef3c7; --age-warn-fg: #b45309;
  --age-late-bg: #fee2e2; --age-late-fg: #b91c1c;

  --bs-primary: var(--brand);
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: var(--brand);
  --bs-link-color-rgb: 79, 70, 229;
  --bs-link-hover-color: var(--brand-600);
  --bs-body-font-family: var(--app-font);
  --bs-border-color: var(--border);
}

[data-bs-theme="dark"] {
  --brand: #818cf8;
  --brand-600: #a5b4fc;
  --brand-50: rgba(129, 140, 248, .12);
  --brand-100: rgba(129, 140, 248, .20);

  --sidebar-bg: #0b1120;
  --sidebar-bg-2: #0e1528;

  --body-bg: #0b1120;
  --surface: #131c31;
  --surface-2: #18223a;
  --border: #243049;
  --text: #e2e8f0;
  --text-2: #cbd5e1;
  --text-muted: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 6px 24px -8px rgba(0, 0, 0, .55);
  --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, .7);

  --st-new-bg: rgba(56, 189, 248, .15);     --st-new-fg: #7dd3fc;
  --st-review-bg: rgba(251, 146, 60, .15);  --st-review-fg: #fdba74;
  --st-details-bg: rgba(192, 132, 252, .15);--st-details-fg: #d8b4fe;
  --st-owner-bg: rgba(251, 191, 36, .15);   --st-owner-fg: #fcd34d;
  --st-quoted-bg: rgba(129, 140, 248, .18); --st-quoted-fg: #c7d2fe;
  --st-won-bg: rgba(74, 222, 128, .15);     --st-won-fg: #86efac;
  --st-lost-bg: rgba(248, 113, 113, .15);   --st-lost-fg: #fca5a5;
  --st-noresp-bg: rgba(148, 163, 184, .15); --st-noresp-fg: #cbd5e1;
  --st-spam-bg: rgba(100, 116, 139, .25);   --st-spam-fg: #cbd5e1;

  --age-ok-bg: rgba(74, 222, 128, .15);   --age-ok-fg: #86efac;
  --age-warn-bg: rgba(251, 191, 36, .15); --age-warn-fg: #fcd34d;
  --age-late-bg: rgba(248, 113, 113, .15);--age-late-fg: #fca5a5;

  --bs-primary-rgb: 129, 140, 248;
  --bs-body-bg: var(--body-bg);
  --bs-border-color: var(--border);
}

/* 2. Base ------------------------------------------------------------------ */
html, body { min-height: 100%; }
body {
  font-family: var(--app-font);
  background: var(--body-bg);
  color: var(--text);
  font-size: .9rem;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { text-decoration: none; }
h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 700; letter-spacing: -.01em; }
.text-muted { color: var(--text-muted) !important; }
.text-2 { color: var(--text-2) !important; }
::selection { background: var(--brand-100); }

.btn { border-radius: var(--radius-sm); font-weight: 500; padding: .5rem 1rem; font-size: .875rem; }
.btn-sm { padding: .32rem .7rem; border-radius: 8px; font-size: .8rem; }
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600);
  --bs-btn-active-bg: var(--brand-600); --bs-btn-active-border-color: var(--brand-600);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
  box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .55);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0b1120; --bs-btn-hover-color: #0b1120; --bs-btn-active-color: #0b1120; }
.btn-soft {
  background: var(--brand-50); color: var(--brand); border: 1px solid transparent;
}
.btn-soft:hover, .btn-soft:focus { background: var(--brand-100); color: var(--brand); }
.btn-light-subtle {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
}
.btn-light-subtle:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-icon {
  width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
.btn-icon.btn-sm { width: 32px; height: 32px; }
.btn:focus-visible, .form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 .22rem rgba(var(--bs-primary-rgb), .22);
  border-color: var(--brand);
}

/* 3. Sidebar --------------------------------------------------------------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 1040;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  transition: width .25s ease, transform .25s ease;
}
.sidebar-brand {
  height: var(--topbar-h); display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem; border-bottom: 1px solid rgba(148, 163, 184, .08);
  color: #fff; white-space: nowrap; overflow: hidden;
}
.sidebar-brand img { width: 38px; height: 38px; flex-shrink: 0; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 1.02rem; line-height: 1.1; color: #fff; }
.sidebar-brand .brand-sub { font-size: .7rem; color: var(--sidebar-text); letter-spacing: .04em; text-transform: uppercase; }

.sidebar-tenant {
  margin: 1rem 1rem .25rem; padding: .65rem .8rem; border-radius: 12px;
  background: rgba(148, 163, 184, .07); border: 1px solid rgba(148, 163, 184, .1);
  display: flex; align-items: center; gap: .65rem; white-space: nowrap; overflow: hidden;
}
.sidebar-tenant .tenant-dot {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, #f97316, #ef4444); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .75rem;
}
.sidebar-tenant .small { color: var(--sidebar-text); font-size: .7rem; }
.sidebar-tenant .fw-semibold { color: var(--sidebar-text-strong); font-size: .82rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .75rem 1rem; scrollbar-width: thin; scrollbar-color: rgba(148,163,184,.2) transparent; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 600;
  color: #64748b; padding: 1.1rem .75rem .45rem; white-space: nowrap;
}
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: .8rem;
  color: var(--sidebar-text); padding: .6rem .75rem; border-radius: 10px;
  font-weight: 500; margin-bottom: 2px; white-space: nowrap; position: relative;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.12rem; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .nav-link.active::before {
  content: ""; position: absolute; left: -.75rem; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: #818cf8;
}
.sidebar-nav .nav-link.active i { color: #a5b4fc; }
.sidebar-nav .nav-badge {
  margin-left: auto; font-size: .68rem; font-weight: 600; padding: .15rem .5rem; border-radius: 99px;
  background: rgba(99, 102, 241, .25); color: #c7d2fe;
}
.sidebar-nav .nav-badge.warn { background: rgba(245, 158, 11, .2); color: #fcd34d; }

.sidebar-footer {
  padding: 1rem; border-top: 1px solid rgba(148, 163, 184, .08); white-space: nowrap; overflow: hidden;
}
.sidebar-help {
  border-radius: 12px; padding: .9rem; color: #c7d2fe;
  background: linear-gradient(135deg, rgba(79, 70, 229, .35), rgba(6, 182, 212, .2));
  border: 1px solid rgba(129, 140, 248, .25);
}
.sidebar-help .small { color: #a5b4fc; }

/* collapsed (desktop) */
@media (min-width: 992px) {
  body.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }
  body.sidebar-collapsed .app-main { margin-left: var(--sidebar-w-collapsed); }
  body.sidebar-collapsed .sidebar-brand { padding: 0 1.2rem; }
  body.sidebar-collapsed .sidebar-brand .brand-text,
  body.sidebar-collapsed .sidebar-tenant > div:not(.tenant-dot),
  body.sidebar-collapsed .sidebar-nav .nav-link span,
  body.sidebar-collapsed .sidebar-nav .nav-badge,
  body.sidebar-collapsed .sidebar-footer { display: none; }
  body.sidebar-collapsed .sidebar-tenant { margin: 1rem .9rem .25rem; padding: .5rem; justify-content: center; }
  body.sidebar-collapsed .nav-section { font-size: 0; padding: .6rem 0; border-top: 1px solid rgba(148,163,184,.08); margin: .5rem .5rem 0; }
  body.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding: .7rem 0; }
}

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 1035; background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: opacity .2s;
}

/* 4. Topbar ---------------------------------------------------------------- */
.app-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .25s ease; }
.app-topbar {
  position: sticky; top: 0; z-index: 1020; height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
  background: color-mix(in srgb, var(--body-bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-search { position: relative; max-width: 380px; flex: 1; }
.topbar-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.topbar-search .form-control { padding-left: 2.4rem; background: var(--surface); border-color: var(--border); border-radius: 10px; height: 40px; }
.topbar-search kbd {
  position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
  font-size: .68rem; padding: .1rem .4rem; border-radius: 6px;
}
.tz-clocks { display: flex; gap: .5rem; }
.tz-clock {
  display: flex; align-items: center; gap: .45rem; padding: .35rem .7rem; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); font-size: .76rem; color: var(--text-2); white-space: nowrap;
}
.tz-clock b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tz-clock .tz-label { color: var(--text-muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; }
.topbar-btn {
  position: relative; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; transition: all .15s;
}
.topbar-btn:hover { color: var(--brand); border-color: var(--brand-100); }
.topbar-btn .dot {
  position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
  background: #ef4444; box-shadow: 0 0 0 2px var(--surface);
}
.topbar-user { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem .25rem .25rem; border-radius: 12px; color: var(--text); }
.topbar-user:hover { background: var(--surface); }
.topbar-user .lh-sm small { color: var(--text-muted); }

.avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: inline-grid; place-items: center; font-weight: 600; font-size: .8rem; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--accent)); object-fit: cover;
}
.avatar-sm { width: 30px; height: 30px; font-size: .7rem; border-radius: 8px; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.05rem; border-radius: 14px; }
.avatar.av-1 { background: linear-gradient(135deg, #f97316, #ef4444); }
.avatar.av-2 { background: linear-gradient(135deg, #10b981, #0ea5e9); }
.avatar.av-3 { background: linear-gradient(135deg, #8b5cf6, #ec4899); }
.avatar.av-4 { background: linear-gradient(135deg, #f59e0b, #84cc16); }

.dropdown-menu {
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: .4rem; background: var(--surface); font-size: .87rem;
}
.dropdown-item { border-radius: 8px; padding: .5rem .75rem; color: var(--text-2); display: flex; align-items: center; gap: .6rem; }
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }
.dropdown-item.active, .dropdown-item:active { background: var(--brand-50); color: var(--brand); }
.notif-menu { width: 360px; max-width: calc(100vw - 2rem); padding: 0; }
.notif-menu .notif-head { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
.notif-item { display: flex; gap: .75rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); color: var(--text-2); }
.notif-item:hover { background: var(--surface-2); }
.notif-item .notif-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.notif-item.unread { background: color-mix(in srgb, var(--brand-50) 60%, transparent); }

/* 5. Content --------------------------------------------------------------- */
.app-content { padding: 1.75rem 1.5rem 2rem; flex: 1; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; margin: 0; }
.page-header .page-sub { color: var(--text-muted); margin: .25rem 0 0; }
.breadcrumb { font-size: .78rem; margin-bottom: .35rem; --bs-breadcrumb-divider-color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb-item.active { color: var(--text-2); }
.app-footer {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .8rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem;
}

/* 6. Cards & stats --------------------------------------------------------- */
.card {
  --bs-card-bg: var(--surface);
  --bs-card-border-color: var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-header {
  background: transparent; border-bottom: 1px solid var(--border); padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.card-header:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card-title { font-size: 1rem; font-weight: 700; margin: 0; color: var(--text); }
.card-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }
.card-body { padding: 1.25rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); padding: .85rem 1.25rem; }

.stat-card { position: relative; overflow: hidden; height: 100%; transition: transform .18s, box-shadow .18s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem;
}
.stat-card .stat-label { color: var(--text-muted); font-size: .8rem; font-weight: 500; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin-top: .35rem; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-card .stat-meta { font-size: .76rem; color: var(--text-muted); margin-top: .5rem; }
.trend-up { color: #16a34a; font-weight: 600; }
.trend-down { color: #dc2626; font-weight: 600; }
[data-bs-theme="dark"] .trend-up { color: #4ade80; }
[data-bs-theme="dark"] .trend-down { color: #f87171; }

.icon-blue   { background: #e0f2fe; color: #0284c7; }
.icon-indigo { background: #e0e7ff; color: #4f46e5; }
.icon-amber  { background: #fef3c7; color: #d97706; }
.icon-green  { background: #dcfce7; color: #16a34a; }
.icon-rose   { background: #ffe4e6; color: #e11d48; }
.icon-purple { background: #f3e8ff; color: #9333ea; }
.icon-cyan   { background: #cffafe; color: #0891b2; }
.icon-slate  { background: #f1f5f9; color: #475569; }
[data-bs-theme="dark"] .icon-blue   { background: rgba(56,189,248,.14); color: #7dd3fc; }
[data-bs-theme="dark"] .icon-indigo { background: rgba(129,140,248,.16); color: #a5b4fc; }
[data-bs-theme="dark"] .icon-amber  { background: rgba(251,191,36,.14); color: #fcd34d; }
[data-bs-theme="dark"] .icon-green  { background: rgba(74,222,128,.14); color: #86efac; }
[data-bs-theme="dark"] .icon-rose   { background: rgba(251,113,133,.14); color: #fda4af; }
[data-bs-theme="dark"] .icon-purple { background: rgba(192,132,252,.14); color: #d8b4fe; }
[data-bs-theme="dark"] .icon-cyan   { background: rgba(34,211,238,.14); color: #67e8f9; }
[data-bs-theme="dark"] .icon-slate  { background: rgba(148,163,184,.14); color: #cbd5e1; }

.welcome-card {
  border: 0; color: #fff; overflow: hidden; position: relative;
  background: radial-gradient(1200px 300px at 100% 0%, rgba(6,182,212,.35), transparent 60%),
              linear-gradient(135deg, #4338ca 0%, #4f46e5 45%, #6366f1 100%);
}
.welcome-card h2, .welcome-card h3 { color: #fff; }
.welcome-card .text-white-75 { color: rgba(255,255,255,.8); }
.welcome-card .welcome-art { position: absolute; right: -10px; bottom: -14px; width: 230px; opacity: .95; pointer-events: none; }
.welcome-card .btn-light { color: #4338ca; font-weight: 600; }
.welcome-card .btn-outline-light { border-color: rgba(255,255,255,.45); }

.mini-progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.mini-progress > span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

.list-flush > * { padding: .85rem 0; border-bottom: 1px dashed var(--border); }
.list-flush > *:last-child { border-bottom: 0; padding-bottom: 0; }
.list-flush > *:first-child { padding-top: 0; }

.chart-wrap { position: relative; height: 280px; }
.chart-wrap.sm { height: 220px; }

/* 7. Badges & pills -------------------------------------------------------- */
.status-pill {
  display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .65rem; border-radius: 99px;
  font-size: .74rem; font-weight: 600; white-space: nowrap; line-height: 1.2;
}
.status-pill i { font-size: .8rem; }
.st-new { background: var(--st-new-bg); color: var(--st-new-fg); }
.st-needs_review { background: var(--st-review-bg); color: var(--st-review-fg); }
.st-needs_details { background: var(--st-details-bg); color: var(--st-details-fg); }
.st-awaiting_owner_price { background: var(--st-owner-bg); color: var(--st-owner-fg); }
.st-quoted { background: var(--st-quoted-bg); color: var(--st-quoted-fg); }
.st-won { background: var(--st-won-bg); color: var(--st-won-fg); }
.st-lost { background: var(--st-lost-bg); color: var(--st-lost-fg); }
.st-no_response { background: var(--st-noresp-bg); color: var(--st-noresp-fg); }
.st-spam { background: var(--st-spam-bg); color: var(--st-spam-fg); }

.age-badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .55rem; border-radius: 8px;
  font-size: .73rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.age-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.age-ok { background: var(--age-ok-bg); color: var(--age-ok-fg); }
.age-warn { background: var(--age-warn-bg); color: var(--age-warn-fg); }
.age-late { background: var(--age-late-bg); color: var(--age-late-fg); }

.tag {
  display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border-radius: 6px;
  font-size: .72rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.tag-brand { background: var(--brand-50); color: var(--brand); border-color: transparent; }
.tag-green { background: var(--age-ok-bg); color: var(--age-ok-fg); border-color: transparent; }
.tag-amber { background: var(--age-warn-bg); color: var(--age-warn-fg); border-color: transparent; }
.tag-red { background: var(--age-late-bg); color: var(--age-late-fg); border-color: transparent; }

.source-icon {
  width: 28px; height: 28px; border-radius: 8px; display: inline-grid; place-items: center; font-size: .85rem;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}

/* 8. Tables ---------------------------------------------------------------- */
.table {
  --bs-table-bg: transparent; --bs-table-color: var(--text-2);
  --bs-table-hover-bg: var(--surface-2); --bs-table-hover-color: var(--text);
  --bs-table-border-color: var(--border);
  margin: 0; vertical-align: middle;
}
.table > thead th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  color: var(--text-muted); background: var(--surface-2); border-bottom: 1px solid var(--border);
  padding: .75rem 1rem; white-space: nowrap;
}
.table > tbody td { padding: .85rem 1rem; border-color: var(--border); }
.table > tbody tr:last-child td { border-bottom: 0; }
.table .cell-strong { color: var(--text); font-weight: 600; }
.table-clickable tbody tr { cursor: pointer; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th.sortable i { font-size: .7rem; opacity: .6; }
.table-card .table > thead th:first-child { padding-left: 1.25rem; }
.table-card .table > tbody td:first-child { padding-left: 1.25rem; }
.table-card .table > thead th:last-child, .table-card .table > tbody td:last-child { padding-right: 1.25rem; }
.lead-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; color: var(--text-muted); }
.raw-text { font-size: .75rem; color: var(--text-muted); font-style: italic; }
.num { font-variant-numeric: tabular-nums; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.4rem; color: var(--brand); opacity: .55; display: block; margin-bottom: .5rem; }

.pagination { --bs-pagination-border-radius: 8px; --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-color: var(--text-2); --bs-pagination-bg: var(--surface); --bs-pagination-border-color: var(--border); gap: 4px; }
.pagination .page-link { border-radius: 8px !important; font-size: .8rem; min-width: 34px; text-align: center; }

/* 9. Forms & filters ------------------------------------------------------- */
.form-label { font-weight: 600; font-size: .8rem; color: var(--text-2); margin-bottom: .4rem; }
.form-control, .form-select {
  border-radius: var(--radius-sm); border-color: var(--border); background-color: var(--surface);
  font-size: .88rem; padding: .55rem .85rem; color: var(--text);
}
.form-control-sm, .form-select-sm { padding: .35rem .7rem; font-size: .82rem; border-radius: 8px; }
.form-text { color: var(--text-muted); font-size: .76rem; }
.input-group-text { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); border-radius: var(--radius-sm); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-switch .form-check-input { width: 2.3em; height: 1.25em; cursor: pointer; }

.filter-tabs { display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .85rem; border-radius: 10px;
  font-weight: 600; font-size: .8rem; color: var(--text-muted); background: transparent; border: 1px solid transparent; white-space: nowrap;
}
.filter-tab:hover { color: var(--text); background: var(--surface-2); }
.filter-tab.active { color: var(--brand); background: var(--brand-50); border-color: var(--brand-100); }
.filter-tab .count { font-size: .7rem; padding: .05rem .45rem; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.filter-tab.active .count { background: var(--brand); color: #fff; }
[data-bs-theme="dark"] .filter-tab.active .count { color: #0b1120; }

.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.search-input { position: relative; min-width: 220px; flex: 1; }
.search-input i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .85rem; }
.search-input .form-control { padding-left: 2.2rem; }

.nav-tabs-line { border-bottom: 1px solid var(--border); gap: 1.25rem; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.nav-tabs-line .nav-link {
  border: 0; border-bottom: 2px solid transparent; padding: .8rem 0; color: var(--text-muted); font-weight: 600; background: none; white-space: nowrap;
  border-radius: 0;
}
.nav-tabs-line .nav-link:hover { color: var(--text); }
.nav-tabs-line .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); background: none; }

.modal-content { border: 0; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border); padding: 1.1rem 1.4rem; }
.modal-body { padding: 1.4rem; }
.modal-footer { border-top: 1px solid var(--border); padding: .9rem 1.4rem; }
.offcanvas { background: var(--surface); }

/* 10. Lead detail ---------------------------------------------------------- */
.lead-hero { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.lead-hero .lead-avatar {
  width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; color: #fff;
  background: linear-gradient(135deg, #f97316, #ef4444);
}
.info-list { display: grid; grid-template-columns: 1fr; gap: .9rem; }
.info-list .info-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; }
.info-list .info-value { color: var(--text); font-weight: 500; word-break: break-word; }

.status-stepper { display: flex; align-items: center; gap: 0; overflow-x: auto; scrollbar-width: none; padding: .25rem 0; }
.status-stepper .step { display: flex; align-items: center; gap: .5rem; white-space: nowrap; color: var(--text-muted); font-size: .78rem; font-weight: 600; }
.status-stepper .step .dot {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem;
  background: var(--surface-2); border: 2px solid var(--border); color: var(--text-muted);
}
.status-stepper .step.done .dot { background: var(--brand); border-color: var(--brand); color: #fff; }
.status-stepper .step.current .dot { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 4px var(--brand-50); }
.status-stepper .step.done, .status-stepper .step.current { color: var(--text); }
.status-stepper .bar { flex: 1; min-width: 28px; height: 2px; background: var(--border); margin: 0 .6rem; }
.status-stepper .bar.done { background: var(--brand); }

.suggest-card {
  border: 1px dashed var(--brand); background: var(--brand-50); border-radius: var(--radius); padding: 1rem 1.1rem;
}
.suggest-card .price { font-size: 1.8rem; font-weight: 800; color: var(--brand); letter-spacing: -.02em; }
.confidence { display: inline-flex; gap: 3px; align-items: center; }
.confidence span { width: 14px; height: 6px; border-radius: 3px; background: var(--border); }
.confidence.high span { background: #16a34a; }
.confidence.low span:first-child { background: #d97706; }

.raw-payload {
  background: #0f172a; color: #cbd5e1; border-radius: 12px; padding: 1rem; font-size: .76rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 260px; overflow: auto; margin: 0;
}

/* 11. Timeline ------------------------------------------------------------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 17px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding-left: 52px; padding-bottom: 1.35rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .tl-icon {
  position: absolute; left: 0; top: 0; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: .95rem; box-shadow: 0 0 0 4px var(--surface);
}
.timeline .tl-head { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: baseline; }
.timeline .tl-head strong { color: var(--text); font-weight: 600; }
.timeline .tl-time { font-size: .74rem; color: var(--text-muted); }
.timeline .tl-body {
  margin-top: .45rem; padding: .7rem .9rem; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-2);
}

/* 12. Quote preview -------------------------------------------------------- */
.email-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.email-preview .email-meta { padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: .8rem; }
.email-preview .email-meta div { display: flex; gap: .5rem; padding: .12rem 0; }
.email-preview .email-meta span:first-child { color: var(--text-muted); width: 56px; flex-shrink: 0; }
.email-body { background: #f1f5f9; padding: 1.5rem 1rem; }
.email-sheet {
  max-width: 520px; margin: 0 auto; background: #fff; color: #1e293b; border-radius: 12px; overflow: hidden;
  box-shadow: 0 6px 24px -8px rgba(15,23,42,.18); font-size: .88rem;
}
.email-sheet .es-head { background: #0f172a; color: #fff; padding: 1.1rem 1.4rem; display: flex; align-items: center; gap: .7rem; }
.email-sheet .es-head img { width: 34px; height: 34px; }
.email-sheet .es-content { padding: 1.4rem; }
.email-sheet .es-price {
  margin: 1rem 0; padding: 1rem; border-radius: 10px; background: #eef2ff; display: flex; justify-content: space-between; align-items: center;
}
.email-sheet .es-price strong { font-size: 1.6rem; color: #4338ca; }
.email-sheet .es-btn { display: inline-block; background: #4f46e5; color: #fff; padding: .6rem 1.1rem; border-radius: 8px; font-weight: 600; }
.email-sheet .es-foot { padding: 1rem 1.4rem; background: #f8fafc; color: #64748b; font-size: .74rem; border-top: 1px solid #e2e8f0; }
[data-bs-theme="dark"] .email-body { background: #0e1528; }

/* 13. Auth pages ----------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.auth-aside {
  position: relative; overflow: hidden; color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(800px 400px at 0% 100%, rgba(6,182,212,.35), transparent 60%),
              radial-gradient(700px 380px at 100% 0%, rgba(236,72,153,.25), transparent 60%),
              linear-gradient(160deg, #0f172a 0%, #1e1b4b 55%, #312e81 100%);
}
.auth-aside h1 { color: #fff; font-size: 2.2rem; line-height: 1.15; }
.auth-aside .lead { color: rgba(255,255,255,.75); font-size: 1rem; }
.auth-aside .auth-feature { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: 1rem; color: rgba(255,255,255,.85); }
.auth-aside .auth-feature i { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.1); display: grid; place-items: center; flex-shrink: 0; }
.auth-aside .auth-art { position: absolute; right: -60px; bottom: 60px; width: 380px; opacity: .14; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-divider { display: flex; align-items: center; gap: .8rem; color: var(--text-muted); font-size: .78rem; margin: 1.25rem 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 2rem 1rem; }
.error-page .code {
  font-size: clamp(5rem, 18vw, 9rem); font-weight: 800; line-height: 1; letter-spacing: -.04em;
  background: linear-gradient(135deg, var(--brand), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* 14. Utilities ------------------------------------------------------------ */
.fw-600 { font-weight: 600 !important; }
.fs-xs { font-size: .74rem !important; }
.fs-sm { font-size: .82rem !important; }
.bg-surface { background: var(--surface) !important; }
.bg-surface-2 { background: var(--surface-2) !important; }
.border-dashed { border-style: dashed !important; }
.rounded-xl { border-radius: var(--radius) !important; }
.min-w-0 { min-width: 0; }
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.hover-lift { transition: transform .18s, box-shadow .18s; }
.hover-lift:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.toast-container { z-index: 1090; }
.app-toast { border: 0; border-radius: 12px; box-shadow: var(--shadow-lg); background: var(--surface); color: var(--text); min-width: 280px; }
.app-toast .toast-body { display: flex; gap: .7rem; align-items: center; padding: .85rem 1rem; }
.app-toast .toast-body i { font-size: 1.2rem; }

.fade-in { animation: fadeIn .35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 15. Responsive ----------------------------------------------------------- */
@media (max-width: 1199.98px) {
  .tz-clocks { display: none; }
}
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app-main { margin-left: 0; }
  body.sidebar-open .app-sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  body.sidebar-open { overflow: hidden; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}
@media (max-width: 767.98px) {
  .app-topbar { padding: 0 1rem; gap: .5rem; }
  .app-content { padding: 1.25rem 1rem 1.5rem; }
  .app-footer { padding: 1rem; }
  .topbar-search { display: none; }
  .topbar-user .lh-sm { display: none; }
  .page-header h1 { font-size: 1.3rem; }
  .page-header .page-actions { width: 100%; }
  .page-header .page-actions .btn { flex: 1; }
  .stat-card .stat-value { font-size: 1.45rem; }
  .card-body { padding: 1rem; }
  .card-header { padding: .9rem 1rem; }
  .welcome-card .welcome-art { display: none; }

  /* Stack tables into cards on phones */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack > tbody td { border: 0 !important; padding: .25rem 0 !important; display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: right; }
  .table-stack > tbody td::before {
    content: attr(data-label); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; color: var(--text-muted); text-align: left;
  }
  .table-stack > tbody td[data-label=""]::before, .table-stack > tbody td:not([data-label])::before { content: none; }
  .table-stack > tbody td.td-primary { justify-content: flex-start; text-align: left; padding-bottom: .5rem !important; }
  .table-stack > tbody td.td-primary::before { content: none; }
}
@media (min-width: 768px) {
  .info-list.cols-2 { grid-template-columns: 1fr 1fr; }
}

/* Additions ---------------------------------------------------------------- */
.icon-tile { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.icon-tile-lg { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 1.5rem; }
#settingsNav .dropdown-item { white-space: nowrap; font-weight: 500; }
#settingsNav .dropdown-item.active { background: var(--brand-50); color: var(--brand); }
@media (max-width: 991.98px) { #settingsNav .dropdown-item { width: auto; } }
.digest-pre { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: .8rem; font-size: .8rem; white-space: pre-wrap; color: #1e293b; }
.field-id-input { max-width: 80px; }

@media print {
  .app-sidebar, .app-topbar, .app-footer, .page-actions, .sidebar-backdrop { display: none !important; }
  .app-main { margin: 0 !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Fixes from visual QA ----------------------------------------------------- */
.card-header.flex-column { flex-wrap: nowrap; }
.card-header > * { min-width: 0; max-width: 100%; }
.form-select { padding-right: 2.25rem; }
.form-select-sm { padding-right: 2rem; }
.sidebar-help { white-space: normal; }
.sidebar-nav .nav-badge { font-style: normal; }
.table .cell-strong, .table .lead-id { white-space: nowrap; }
.table td .fs-xs { white-space: nowrap; }
@media (max-width: 767.98px) {
  .toolbar .search-input { flex-basis: 100%; min-width: 0; }
  .toolbar .form-select.w-auto { flex: 1 1 0; width: auto; min-width: 0; }
  .table-stack .raw-text { max-width: 60vw !important; }
  .table-stack > tbody td > * { min-width: 0; }
}
.th-check { width: 36px; }
@media (max-width: 767.98px) {
  .table-stack > tbody td,
  .table-stack > tbody td[data-label] {
    display: block !important; position: relative; padding: .3rem 0 .3rem 42% !important; text-align: right; min-height: 1.9rem;
  }
  .table-stack > tbody td::before { position: absolute; left: 0; top: .55rem; }
  .table-stack > tbody td > div { display: block; }
  .table-stack > tbody td > .d-flex { display: flex !important; justify-content: flex-end; }
  .table-stack > tbody td.td-primary { padding-left: 0 !important; text-align: left; }
  .table-stack > tbody td.td-primary > .d-flex { justify-content: flex-start; }
  .table-stack > tbody td.td-check { display: none !important; }
  .page-header .page-actions { flex-wrap: wrap; }
  .page-header .page-actions .btn { flex: 1 1 auto; white-space: nowrap; }
}
