:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1e293b;
  --body: #f5f7fb;
  --card-border: #e8ecf3;
  --muted: #64748b;
  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: #4f46e5;
  --bs-link-color-rgb: 79, 70, 229;
  --bs-link-hover-color-rgb: 67, 56, 202;
  --bs-link-hover-color: #4338ca;
}

body { background: var(--body); font-size: .925rem; color: #1e293b; }
a { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-label { font-weight: 500; font-size: .85rem; color: #334155; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: var(--sidebar); color: var(--sidebar-text); position: fixed; top: 0; bottom: 0; left: 0; z-index: 1040; display: flex; flex-direction: column; transition: transform .2s; }
.sidebar .brand { padding: 1.1rem 1.25rem; color: #fff; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .6rem; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #06b6d4); display: grid; place-items: center; font-size: 1rem; }
.sidebar .nav-scroll { overflow-y: auto; flex: 1; padding: .75rem .65rem 1rem; }
.sidebar .nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #475569; padding: .9rem .75rem .35rem; }
.sidebar a.nav-item { display: flex; align-items: center; gap: .7rem; color: var(--sidebar-text); padding: .55rem .75rem; border-radius: 8px; margin-bottom: 2px; font-weight: 500; }
.sidebar a.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar a.nav-item:hover { color: #e2e8f0; background: rgba(255,255,255,.04); }
.sidebar a.nav-item.active { color: #fff; background: var(--brand); }
.sidebar .tenant-box { margin: .75rem; padding: .75rem; border-radius: 10px; background: var(--sidebar-active); font-size: .8rem; }
.main { flex: 1; margin-left: 250px; min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--card-border); padding: .7rem 1.5rem; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 1030; }
.topbar .page-title { font-weight: 600; font-size: 1.05rem; margin: 0; }
.content { padding: 1.5rem; }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .sidebar.open + .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
  .main { margin-left: 0; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}

/* ---------- Components ---------- */
.card { border: 1px solid var(--card-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.03); }
.card-header { background: #fff; border-bottom: 1px solid var(--card-border); font-weight: 600; padding: .85rem 1.1rem; border-radius: 12px 12px 0 0 !important; }
.stat-card { padding: 1.1rem 1.2rem; display: flex; align-items: center; gap: 1rem; }
.stat-card .icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .label { color: var(--muted); font-size: .8rem; }
a.stat-link { color: inherit; display: block; }
a.stat-link:hover .card { border-color: #c7d2fe; }
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .7rem .9rem; border-color: #eef1f6; vertical-align: middle; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
.table-hover tbody tr:hover { background: #fafbff; }
.badge-soft { padding: .35em .65em; border-radius: 6px; font-weight: 600; font-size: .72rem; }
.stage-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem; flex-shrink: 0; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; color: #cbd5e1; }
.filter-bar .form-control, .filter-bar .form-select { font-size: .85rem; }
.text-muted-sm { color: var(--muted); font-size: .8rem; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.kanban-col { background: #eef1f6; border-radius: 12px; min-width: 280px; width: 280px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.kanban-col .col-head { padding: .75rem .9rem; font-weight: 600; display: flex; justify-content: space-between; align-items: center; border-top: 3px solid; border-radius: 12px 12px 0 0; }
.kanban-col .col-body { padding: .5rem; overflow-y: auto; min-height: 80px; flex: 1; }
.kanban-card { background: #fff; border-radius: 9px; padding: .7rem .8rem; margin-bottom: .5rem; border: 1px solid var(--card-border); cursor: grab; font-size: .85rem; }
.kanban-card:active { cursor: grabbing; }
.kanban-card .name { font-weight: 600; color: #0f172a; }
.sortable-ghost { opacity: .4; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px dashed #eef1f6; }
.timeline li:last-child { border-bottom: 0; }
.timeline .t-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; flex-shrink: 0; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: linear-gradient(135deg, #312e81 0%, #4f46e5 55%, #06b6d4 100%); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: center; }
.auth-side h1 { font-weight: 800; font-size: 2.2rem; }
.auth-side ul { list-style: none; padding: 0; margin-top: 1.5rem; }
.auth-side li { margin-bottom: .6rem; opacity: .92; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; background: #fff; }
.auth-form .box { width: 100%; max-width: 400px; }
@media (max-width: 991.98px) { .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none; } }

.integration-card { transition: border-color .15s; }
.integration-card:hover { border-color: #c7d2fe; }
.integration-card.active-int { border-color: #22c55e; box-shadow: 0 0 0 1px #22c55e inset; }
.impersonate-bar { background: #fef3c7; color: #92400e; padding: .5rem 1.5rem; font-size: .85rem; display: flex; justify-content: space-between; align-items: center; }
.plan-card.current { border: 2px solid var(--brand); }
.pagination { margin: 0; }
