: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; }

/* ---------- Phase 2: tenant logo, mobile bottom nav, PWA ---------- */
.sidebar .tenant-logo { background: #fff; border-radius: 10px; padding: 6px 10px; display: flex; align-items: center; justify-content: center; width: 100%; height: 52px; }
.sidebar .tenant-logo img { max-height: 40px; max-width: 100%; object-fit: contain; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; background: #fff; border-top: 1px solid var(--card-border); display: flex; justify-content: space-around; align-items: center; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 10px rgba(15,23,42,.06); }
.bottom-nav a { color: var(--muted); display: flex; flex-direction: column; align-items: center; font-size: .68rem; flex: 1; gap: 2px; }
.bottom-nav a i { font-size: 1.25rem; }
.bottom-nav a.active { color: var(--brand); font-weight: 600; }
.bottom-nav a.add { flex: 0 0 auto; width: 50px; height: 50px; border-radius: 50%; background: var(--brand); color: #fff; justify-content: center; margin-top: -24px; box-shadow: 0 4px 12px rgba(79,70,229,.35); }
.bottom-nav a.add i { font-size: 1.5rem; }
@media (max-width: 991.98px) { .content { padding-bottom: 90px; } }

/* ---------- AI sales: inbox, AI panel ---------- */
.inbox { overflow: hidden; }
.inbox-list { max-height: calc(100vh - 260px); overflow-y: auto; }
.inbox .chat { background: #efeae2; overflow-y: auto; height: calc(100vh - 330px); min-height: 320px; }
.inbox .msg { display: flex; flex-direction: column; margin-bottom: .6rem; max-width: 80%; }
.inbox .msg.in { align-items: flex-start; }
.inbox .msg.out { margin-left: auto; align-items: flex-end; }
.inbox .bubble { padding: .5rem .75rem; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); font-size: .88rem; word-break: break-word; }
.inbox .msg.out .bubble { background: #d9fdd3; }
.inbox .meta { font-size: .7rem; color: #64748b; margin-top: 2px; }
.ai-card { border-left: 3px solid #6366f1; }
.ai-card .score { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.coach-text { white-space: pre-line; font-size: .88rem; }

/* ---------- Sales workflow (v4) ---------- */
html, body { overflow-x: hidden; }
.main { min-width: 0; }
.chip-row { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.chip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .7rem; border-radius: 999px; background: #fff; border: 1px solid var(--card-border); color: #334155; font-size: .8rem; white-space: nowrap; text-decoration: none; }
.chip b { background: #f1f5f9; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.active b { background: rgba(255,255,255,.25); color: #fff; }
.chip.empty { opacity: .6; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
button.badge-soft { cursor: pointer; }
button.badge-soft:hover { filter: brightness(.92); }
.lead-cards { display: flex; flex-direction: column; }
.lead-card { padding: .8rem .9rem; border-bottom: 1px solid var(--card-border); }
.lead-card:last-child { border-bottom: 0; }
.lead-card-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; margin-top: .6rem; }
.lead-card-actions .btn { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .72rem; padding: .35rem .2rem; }
.lead-card-actions .btn i { font-size: 1.1rem; }
.lead-quick-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.lead-quick-actions .btn { flex: 1 1 auto; }
.call-results { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.call-results .btn { text-align: left; font-size: .85rem; padding: .5rem .6rem; }
.stage-pick { display: flex; flex-wrap: wrap; gap: .35rem; }
.stage-pick .btn { border: 1px solid var(--c); color: var(--c); background: #fff; font-weight: 600; }
.stage-pick .btn-check:checked + .btn { background: var(--c); color: #fff; }
.progress-thin { height: 6px; }
.stat-mini { border: 1px solid var(--card-border); border-radius: 10px; padding: .6rem .75rem; background: #fff; height: 100%; }
.stat-mini .v { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat-mini .l { font-size: .75rem; color: var(--muted); }
.table-report th, .table-report td { white-space: nowrap; font-size: .82rem; }
.table-report th.sticky-col, .table-report td.sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; }
.today-list .list-group-item { padding: .6rem .8rem; }
@media (max-width: 575.98px) {
  .call-results { grid-template-columns: 1fr; }
  .topbar .btn-sm { padding: .25rem .45rem; }
  .card-header { flex-wrap: wrap; gap: .35rem; }
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .modal-dialog { margin: .5rem; }
}
