:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-ink: #ffffff; --danger: #dc2626; --ok: #16a34a; --wa: #25d366;
  --hot: #dc2626; --medium: #d97706; --cold: #2563eb; --big: #7c3aed; --small: #0891b2;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; --muted: #94a3b8; --line: #334155; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; }
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.wa { background: var(--wa); color: #fff; border-color: var(--wa); }
button.danger { color: var(--danger); }
button.sm { padding: 5px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
.topbar h1 .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav button { border: none; background: transparent; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.nav button.active { background: var(--bg); color: var(--text); }

.page { max-width: 1200px; margin: 0 auto; padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; border: 2px solid transparent; }
.stat.active { border-color: var(--primary); }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
@media (max-width: 600px) { .stats { grid-template-columns: repeat(3, 1fr); gap: 6px; } .stat { padding: 8px 10px; } .stat .n { font-size: 20px; } .stat .l { font-size: 11px; } .nav { margin-left: 0; width: 100%; } .nav button { padding: 6px 8px; font-size: 14px; } }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type=search] { flex: 1 1 200px; }

.stage-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: thin; }
.stage-tabs button { white-space: nowrap; border-radius: 999px; font-size: 13px; }
.stage-tabs button.active { color: #fff; border-color: transparent; }
.stage-tabs .count { opacity: .8; margin-left: 4px; }

.list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.lead { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; border-left: 4px solid var(--line); }
.lead:hover { outline: 2px solid var(--primary); }
.lead .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lead .name { font-weight: 700; font-size: 16px; }
.lead .sub { color: var(--muted); font-size: 13px; }
.lead .msg { font-size: 13px; margin-top: 6px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lead .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .03em; }
.tag.src-indiamart { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.tag.src-meta { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.tag.src-manual { background: #f3f4f6; color: #374151; }
.tag.hot { background: #fef2f2; color: var(--hot); border-color: #fecaca; }
.tag.medium { background: #fffbeb; color: var(--medium); border-color: #fde68a; }
.tag.cold { background: #eff6ff; color: var(--cold); border-color: #bfdbfe; }
.tag.big { background: #f5f3ff; color: var(--big); border-color: #ddd6fe; }
.tag.small { background: #ecfeff; color: var(--small); border-color: #a5f3fc; }
.tag.stage { color: #fff; border-color: transparent; }
.tag.due { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.tag.today { background: #f0fdf4; color: var(--ok); border-color: #bbf7d0; }
@media (prefers-color-scheme: dark) { .tag { filter: brightness(.9) saturate(1.1); } }

.empty { text-align: center; color: var(--muted); padding: 40px; }

/* Drawer / modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { background: var(--bg); width: min(640px, 100%); height: 100%; overflow-y: auto; box-shadow: -4px 0 24px rgba(0,0,0,.25); }
.drawer .head { position: sticky; top: 0; background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; z-index: 2; }
.drawer .head h2 { margin: 0; font-size: 18px; flex: 1; }
.drawer .body { padding: 16px; display: grid; gap: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.kv { font-size: 14px; margin: 4px 0; } .kv b { color: var(--muted); font-weight: 600; margin-right: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pipeline { display: flex; gap: 6px; flex-wrap: wrap; }
.pipeline button { border-radius: 999px; font-size: 13px; }
.pipeline button.current { color: #fff; border-color: transparent; }
.pipeline button.done { opacity: .55; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button.on { color: #fff; border-color: transparent; }
.chips button.on.hot { background: var(--hot); } .chips button.on.medium { background: var(--medium); } .chips button.on.cold { background: var(--cold); }
.chips button.on.big { background: var(--big); } .chips button.on.small { background: var(--small); }
.chips button.on.disp { background: #475569; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 10px; }
.timeline li:last-child { border: none; }
.timeline .t { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 90px; }
.timeline .ic { width: 20px; text-align: center; }
.tpl { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tpl:last-child { border: none; }
.tpl .n { font-weight: 600; }
.preview { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px; font-size: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px; z-index: 50; box-shadow: var(--shadow); font-size: 14px; }
.settings-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.help { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.help code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ok { color: var(--ok); font-weight: 600; } .err { color: var(--danger); font-weight: 600; }

/* Layout toggle */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 8px 10px; color: var(--muted); }
.seg button.on { background: var(--primary); color: #fff; }

/* Kanban board */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; scrollbar-width: thin; }
.col { flex: 0 0 272px; background: color-mix(in srgb, var(--card) 60%, var(--bg)); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 290px); display: flex; flex-direction: column; }
.col-head { padding: 10px 12px; font-weight: 700; font-size: 13px; border-top: 3px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; display: flex; align-items: center; gap: 6px; position: sticky; top: 0; background: inherit; }
.col-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.col-head .count { margin-left: auto; color: var(--muted); font-weight: 600; }
.col-body { padding: 8px; display: grid; gap: 8px; overflow-y: auto; min-height: 80px; flex: 1; border-radius: 0 0 var(--radius) var(--radius); transition: background .15s; }
.col-body.over { background: color-mix(in srgb, var(--primary) 12%, transparent); outline: 2px dashed var(--primary); outline-offset: -4px; }
.drop-hint { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 0; border: 1px dashed var(--line); border-radius: 8px; }
.lead[draggable=true] { cursor: grab; }
.lead.dragging { opacity: .4; cursor: grabbing; }
.lead.compact { padding: 10px 12px; }
.lead.compact .name { font-size: 15px; }
.lead.compact .msg { display: none; }
@media (max-width: 600px) { .col { flex-basis: 85vw; max-height: 70vh; } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 24px; }
.login h1 { font-size: 20px; margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.login .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; }
@media (max-width: 600px) { .who { margin-left: auto; } }
.tag.who-tag { background: var(--bg); color: var(--text); text-transform: none; letter-spacing: 0; }
.tag.who-tag.unassigned { color: var(--medium); border-color: #fde68a; }
/* Team table */
table.log th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
tr.inactive { opacity: .5; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 10px; }
/* Analytics */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.colbar { flex: 1; display: flex; flex-direction: column-reverse; height: 100%; min-width: 4px; }
.colbar div { width: 100%; border-radius: 2px 2px 0 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.frow { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.frow b { text-align: right; }
.bar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar div { height: 100%; border-radius: 999px; }
.lead.cust { cursor: pointer; }

/* Touch drag ghost */
.lead.ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .92; box-shadow: 0 12px 30px rgba(0,0,0,.3); transform: rotate(2deg); }
.handle { display: none; touch-action: none; cursor: grab; color: var(--muted); font-size: 16px; line-height: 1; padding: 2px 8px 2px 0; letter-spacing: -3px; user-select: none; -webkit-user-select: none; }
@media (hover: none), (pointer: coarse) { .handle { display: inline-block; } .board .lead .row { align-items: center; } }
.lead.ghost .handle { display: inline-block; }
.col-body.over .drop-hint { border-color: var(--primary); color: var(--primary); }

.move { display: none; width: auto; padding: 3px 6px; font-size: 12px; border-radius: 999px; margin-left: auto; }
@media (hover: none), (pointer: coarse) { .move { display: inline-block; } }

/* Targets */
.tgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tcol { background: var(--bg); border-radius: 10px; padding: 12px; }
.tcol h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.titem { margin: 8px 0; font-size: 14px; } .titem.none { opacity: .55; }
.titem .row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.tbar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.tbar div { height: 100%; border-radius: 999px; transition: width .3s; }
.mt { display: grid; grid-template-columns: 62px 1fr; gap: 2px 8px; font-size: 12px; align-items: center; margin: 3px 0; }
.mt .tbar { grid-column: 1 / -1; height: 5px; }
table.targets input { width: 90px; padding: 5px 7px; }
table.targets td { vertical-align: middle; }
