:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --line: #e6e8ec;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --danger: #dc2626;
  --wa: #16a34a;
  --side: #111827;
  --side-text: #c7cbd3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --st-new: #3b82f6;
  --st-contacted: #8b5cf6;
  --st-qualified: #f59e0b;
  --st-proposal: #06b6d4;
  --st-won: #16a34a;
  --st-lost: #9ca3af;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e8eaed;
    --muted: #9aa1ad;
    --line: #262a33;
    --brand: #818cf8;
    --brand-soft: #1e2140;
    --side: #0a0c10;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
small { display: block; font-size: 12px; }
.muted { color: var(--muted); }
.late { color: var(--danger); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.side {
  width: 220px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; padding: 0 8px 18px; font-size: 15px; }
.brand:hover { text-decoration: none; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
}
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.side svg { width: 18px; height: 18px; fill: currentColor; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.me strong { color: #fff; font-size: 13px; display: block; }
.me div { flex: 1; min-width: 0; }
.logout { color: var(--side-text); font-size: 18px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1280px; }

.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.top p { margin: 4px 0 0; }
.back { font-size: 13px; display: inline-block; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.card-head a { font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .grid2 { margin-top: 16px; }
.grid-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack > .card:last-child { margin-bottom: 0; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.block { width: 100%; padding: 10px; }
.danger-link { border: 0; background: none; color: var(--danger); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-foot { display: flex; justify-content: space-between; margin-top: 16px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 8px; }
.inline-form input[type=date] { width: 150px; flex-shrink: 0; }
.add-task input[name=title] { flex: 2; }
.add-task select { flex: 1; }
.note-form { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; margin-bottom: 12px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.err { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat { margin: 0; }
.stat small { color: var(--muted); font-weight: 600; }
.stat strong { display: block; font-size: 26px; margin: 4px 0 2px; letter-spacing: -.5px; }
.stat span { font-size: 12px; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar { display: grid; grid-template-columns: 90px 1fr 32px; align-items: center; gap: 10px; color: var(--text); }
.bar:hover { text-decoration: none; }
.bar:hover .lbl { color: var(--brand); }
.track { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.fill { display: block; height: 100%; border-radius: 99px; min-width: 4px; }
.num { text-align: right; font-weight: 600; }

/* Stage colours come from Settings via --c */
.fill { background: var(--c, var(--brand)); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--c); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.row-link { display: flex; align-items: center; gap: 12px; padding: 10px 0; color: var(--text); }
.row-link:hover { text-decoration: none; }
.row-link:hover b { color: var(--brand); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.avatar.sm { width: 32px; height: 32px; }
.avatar.xs { width: 22px; height: 22px; font-size: 10px; }
.empty { color: var(--muted); padding: 12px 0; text-align: center; margin: 0; }

.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.task form { margin: 0; display: flex; }
.check {
  width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line); background: none;
  cursor: pointer; padding: 0; flex-shrink: 0; position: relative;
}
.check:hover { border-color: var(--brand); }
.check.on { background: var(--brand); border-color: var(--brand); }
.check.on::after { content: "✓"; color: #fff; font-size: 12px; position: absolute; inset: 0; display: grid; place-items: center; }
.task.done b, .task.done .grow { text-decoration: line-through; color: var(--muted); }
.due { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.due.late { color: var(--danger); }
.x { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 4px; }
.x:hover { color: var(--danger); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 14px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid var(--card); }
.timeline li.empty::before { display: none; }
.timeline p { margin: 0 0 2px; }

/* Leads table */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.filters input[type=search] { flex: 1 1 240px; }
.filters select { width: auto; flex: 0 1 160px; }
.clear { font-size: 13px; }
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--bg); }
.table td a { color: var(--text); }

.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs a { padding: 5px 14px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.tabs a.on { background: var(--brand-soft); color: var(--brand); }
.tabs a:hover { text-decoration: none; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kcol { background: color-mix(in srgb, var(--line) 45%, var(--bg)); border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; transition: background .15s; }
.kcol.over { background: var(--brand-soft); outline: 2px dashed var(--brand); }
.kcol header { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; font-size: 13px; }
.kcount { background: var(--card); border-radius: 99px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.ksum { margin-left: auto; font-size: 12px; color: var(--muted); }
.kbody { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.kcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); cursor: grab; box-shadow: var(--shadow); }
.kcard:hover { text-decoration: none; border-color: var(--brand); }
.kcard.dragging { opacity: .4; }
.kmeta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-weight: 600; font-size: 13px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login .brand { color: var(--text); padding: 0; }
.login p { margin: 0; }
.hint { font-size: 12px; color: var(--muted); text-align: center; background: var(--bg); padding: 8px; border-radius: 8px; }

/* ---------- v2 ---------- */
.pill { margin-left: auto; font-style: normal; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 0 7px; line-height: 18px; }
.notify-btn { margin: 8px 0; background: rgba(255,255,255,.08); color: #fff; border: 1px dashed rgba(255,255,255,.25); border-radius: 8px; padding: 8px; font: inherit; font-size: 12px; cursor: pointer; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; background: var(--side); color: #fff; padding: 12px 14px; border-radius: 10px; width: 320px; max-width: 100%; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: pop .2s ease-out; }
.toast:hover { text-decoration: none; }
.toast span { grid-column: 1; color: var(--side-text); font-size: 13px; }
.toast button { grid-column: 2; grid-row: 1 / 3; background: none; border: 0; color: var(--side-text); font-size: 18px; cursor: pointer; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.flash.warn { background: #fffbeb; color: #78350f; border-color: #fde68a; }
.flash.warn a { color: inherit; font-weight: 600; text-decoration: underline; }
.dupe-list { margin: 6px 0; padding-left: 18px; }
.check-label { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; color: var(--text); font-size: 13px; margin-top: 12px; white-space: nowrap; }
.check-label input { width: auto; }
.mt { margin-top: 24px; }
.pad { padding: 18px 18px 0; }
.narrow { width: auto; flex: 0 0 auto; }
.mini { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; padding: 2px 8px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.mini:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.mini:disabled { opacity: .35; cursor: default; }
.task form + form .mini + .mini { margin-left: 4px; }
.ticon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }

/* Schedule callback */
.schedule { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { flex-direction: row; }
.seg input { position: absolute; opacity: 0; width: 1px; }
.seg span { border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; color: var(--text); font-weight: 600; cursor: pointer; }
.seg input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }
.schedule .row { display: flex; gap: 8px; flex-wrap: wrap; }
.schedule .row input, .schedule .row select { flex: 1 1 120px; width: auto; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.quick button { border: 0; background: var(--bg); color: var(--text); border-radius: 6px; padding: 3px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.quick button:hover, .quick button.on { background: var(--brand-soft); color: var(--brand); }

/* Leads bulk */
.toggle { flex-direction: row; align-items: center; gap: 6px; font-weight: 600; color: var(--text); font-size: 13px; padding: 0 4px; white-space: nowrap; }
.toggle input { width: auto; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; position: sticky; top: 8px; z-index: 5; border-color: var(--brand); }
.bulkbar select { width: auto; }
.bulkbar b { margin-right: 4px; }
.cb { width: 36px; padding-right: 0 !important; }
.cb input { width: 16px; height: 16px; }
.table tbody tr.sel { background: var(--brand-soft); }

/* Import */
.upload input[type=file] { padding: 18px; border-style: dashed; margin: 8px 0; }
.form-foot a { align-self: center; }
.map td { vertical-align: middle; }
.map select { min-width: 200px; }
.map select.matched { border-color: var(--st-won); }
.fields.three { grid-template-columns: repeat(4, 1fr); }
.stats.compact { grid-template-columns: repeat(4, 1fr); margin: 8px 0; }
.stats.compact .stat { background: var(--bg); border-radius: 10px; padding: 12px; }

/* Analytics */
.stats.six { grid-template-columns: repeat(6, 1fr); }
.stats.six strong { font-size: 22px; }
.legend { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--muted); }
.legend.wrap { flex-wrap: wrap; margin-top: 12px; gap: 8px 18px; }
.legend a { color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--brand)); }
.sw.new { background: var(--brand); }
.sw.won { background: var(--st-won); }
.chart { display: flex; align-items: stretch; gap: 3px; height: 180px; margin-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.stack-bar { flex: 1; position: relative; }
.chart .b { position: absolute; bottom: 0; left: 10%; right: 10%; border-radius: 4px 4px 0 0; min-height: 0; }
.chart .b.new { background: color-mix(in srgb, var(--brand) 35%, transparent); }
.chart .b.won { background: var(--st-won); left: 25%; right: 25%; }
.chart small { text-align: center; color: var(--muted); font-size: 10px; margin-top: 4px; }
.chart.dense small { visibility: hidden; }
.chart.dense .col:nth-child(7n+1) small { visibility: visible; }
.stackline { display: flex; height: 18px; border-radius: 99px; overflow: hidden; gap: 2px; }
.stackline span { background: var(--c); }
.rank { font-size: 18px; width: 40px; }
.who { display: flex; align-items: center; gap: 10px; }
.meter { display: block; height: 4px; background: var(--bg); border-radius: 99px; margin-top: 4px; max-width: 160px; }
.meter span { display: block; height: 100%; background: var(--st-won); border-radius: 99px; }

/* Settings */
.srows { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.srow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.srow > input[name=label] { flex: 1 1 180px; width: auto; }
.srow > select, .srow > .fopts { width: auto; }
.srow > .fopts { flex: 2 1 200px; }
.srow input[type=color] { width: 40px; height: 36px; padding: 2px; flex-shrink: 0; }
.srow .check-label { margin: 0; }
.srow.add { padding-top: 12px; border-top: 1px dashed var(--line); }
.order { display: flex; gap: 2px; width: 58px; flex-shrink: 0; }
.del { position: relative; }
.del summary { cursor: pointer; color: var(--danger); font-weight: 600; list-style: none; padding: 8px; }
.del summary::-webkit-details-marker { display: none; }
.del[open] > div { position: absolute; right: 0; top: 100%; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.12); display: flex; flex-direction: column; gap: 8px; width: 240px; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode { border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; color: var(--text); font-weight: 400; font-size: 13px; }
.mode input { position: absolute; opacity: 0; width: 1px; }
.mode.on { border-color: var(--brand); background: var(--brand-soft); }
.mode b { font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.switch span { width: 34px; height: 20px; border-radius: 99px; background: var(--line); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { color: var(--st-won); }
.switch.on span { background: var(--st-won); }
.switch.on span::after { left: 16px; }
.add-user { margin-top: 12px; flex-wrap: wrap; }
.add-user input { flex: 1 1 160px; }

/* Demo */
.demo-bar { background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; margin-bottom: 16px; }
.hint .linkish { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--brand); cursor: pointer; text-decoration: underline; }

/* Mobile */
@media (max-width: 1000px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2, .grid-detail { grid-template-columns: 1fr; }
  .stats.six { grid-template-columns: repeat(3, 1fr); }
  .fields.three { grid-template-columns: 1fr 1fr; }
  .grid-detail > .card { margin-bottom: 0; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .side { width: 100%; height: auto; position: sticky; top: 0; z-index: 10; flex-direction: row; align-items: center; padding: 8px 12px; gap: 8px; }
  .brand { padding: 0; }
  .brand span:last-child { display: none; }
  .side nav { flex-direction: row; justify-content: center; }
  .side nav a { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 11px; }
  .me { border: 0; padding: 0; }
  .me div, .me .avatar { display: none; }
  .main { padding: 18px 16px 40px; }
  .fields { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input[name=title] { flex: 1 1 100%; }
  .inline-form select, .inline-form input[type=date] { flex: 1 1 auto; width: auto; }
  .filters select { flex: 1 1 30%; }
  .stats.six, .stats.compact, .modes { grid-template-columns: 1fr 1fr; }
  .fields.three { grid-template-columns: 1fr; }
  .side nav { overflow-x: auto; justify-content: flex-start; }
  .side nav a span { white-space: nowrap; }
  .pill { position: absolute; margin: -4px 0 0 18px; }
  .side nav a { position: relative; }
  .notify-btn { display: none; }
  .chart { height: 140px; }
}
