:root {
  --blue: #5200ff;
  --blue-dark: #3d00bf;
  --blue-tint: #efe8ff;
  --teal: #54ffd6;
  --teal-tint: #dcfff6;
  --red: #f22222;
  --red-tint: #ffe4e4;
  --yellow: #ffc36a;
  --yellow-tint: #fff2dc;
  --grey: #eeeeee;
  --ink: #141414;
  --ink-2: #3c3c3c;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bg: #f5f5f6;
  --card: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 1px rgba(0, 0, 0, 0.03);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 {
  text-transform: uppercase;
  letter-spacing: -0.03em;
  line-height: 0.95;
  font-weight: 800;
  margin: 0;
}
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ── Shell ─────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--blue);
  color: #fff;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { padding: 4px 10px 8px; }
.brand .word { font-size: 28px; font-weight: 900; letter-spacing: -0.04em; line-height: 0.9; }
.brand .sub { color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #fff;
  padding: 9px 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
}
.nav a:hover { background: rgba(255, 255, 255, 0.1); }
.nav a.active { background: rgba(0, 0, 0, 0.22); color: var(--teal); }
.nav .count {
  background: var(--teal);
  color: var(--ink);
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  font-weight: 800;
}
.nav-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.6; padding: 10px 10px 4px; font-weight: 700; }
.side .me { margin-top: auto; padding: 10px; font-size: 12px; border-top: 1px solid rgba(255, 255, 255, 0.18); }
.side .me b { display: block; font-size: 13px; }
.side .me button { color: var(--teal); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; margin-right: 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 40;
}
.search-results a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; color: var(--ink); border-bottom: 1px solid var(--grey); }
.search-results a:hover, .search-results a.focus { background: var(--blue-tint); text-decoration: none; }
.search-results .group { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); padding: 8px 12px 4px; font-weight: 700; }
.content { padding: 24px; max-width: 1400px; width: 100%; }
.hs-find { position: relative; }
.hs-find .search-results { top: calc(100% + 2px); }
.hs-find .hs-hit { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--grey); padding: 9px 12px; color: var(--ink); font: inherit; cursor: pointer; }
.hs-find .hs-hit:hover, .hs-find .hs-hit:focus { background: var(--blue-tint); outline: none; }
.hs-find .hs-hit small { display: block; color: var(--muted); }
.hs-find .hs-none { padding: 10px 12px; color: var(--muted); }
.hs-linked { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.crumb { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; display: inline-block; }

/* ── Cards, grids ──────────────────────────────────── */

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: var(--ink); }
a.kpi:hover { border-color: var(--blue); text-decoration: none; }
.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 30px; font-weight: 900; letter-spacing: -0.04em; line-height: 1.1; margin-top: 4px; }
.kpi.hero { background: var(--blue); border-color: var(--blue); color: #fff; }
.kpi.hero .label { color: var(--teal); }
.kpi.attn { background: var(--yellow-tint); border-color: #f4d39c; }
.kpi.attn .value { color: var(--red); }

.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; padding-top: 1px; }
.dl dd { margin: 0; word-break: break-word; }
td b { white-space: nowrap; }

/* ── Tables ────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--grey); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #faf8ff; }
tr.selected td { background: var(--blue-tint) !important; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

.matrix td.num { font-weight: 700; }
.matrix td.zero { color: #c4c4c4; font-weight: 400; }
/* number headers wrap so all columns fit without sideways scrolling */
.matrix th.num { white-space: normal; vertical-align: bottom; padding-left: 8px; padding-right: 8px; }
.matrix td.num { padding-left: 8px; padding-right: 8px; }

/* ── Forms ─────────────────────────────────────────── */

input, select, textarea {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid #cfcfcf;
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-height: 36px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
input[type='checkbox'], input[type='radio'] { width: 16px; height: 16px; min-height: 0; padding: 0; flex: none; accent-color: var(--blue); cursor: pointer; }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
label.field > span em { font-style: normal; color: var(--muted); font-weight: 400; }
.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-start; }
.filters > * { width: auto; }
.filters input[type='search'] { min-width: 240px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid #cfcfcf;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.teal { background: var(--teal); border-color: var(--teal); color: var(--ink); }
.btn.danger { color: var(--red); border-color: #f3b4b4; }
.btn.danger:hover { background: var(--red-tint); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--grey); }
.btn.sm { padding: 4px 10px; min-height: 28px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Badges, chips ─────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: var(--grey);
  color: var(--ink-2);
}
.b-available, .b-in_stock, .b-delivered, .b-collected, .b-arrived, .b-completed { background: var(--teal-tint); color: #00684f; }
.b-reserved, .b-low, .b-requested, .b-draft { background: var(--yellow-tint); color: #8a5300; }
.b-demo, .b-confirmed, .b-sent, .b-in_transit, .b-on_the_way, .b-transit, .b-dispatched { background: var(--blue-tint); color: var(--blue); }
.b-service { background: #ffe9d6; color: #a14b00; }
.b-rental { background: #e3f1ff; color: #0b4f8a; }
.b-consignment { background: var(--yellow-tint); color: #6b4300; }
.b-written_off, .b-out, .b-cancelled { background: var(--red-tint); color: #b00e0e; }
.b-sold { background: #ececec; color: #555; }
.b-new { background: var(--yellow-tint); color: #8a5300; }
.b-called, .b-test_ride { background: var(--blue-tint); color: var(--blue); }
.b-no_answer { background: #ffe9d6; color: #a14b00; }
.b-not_interested { background: var(--red-tint); color: #b00e0e; }
.chip { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.2); flex: none; display: inline-block; }

.alert { padding: 10px 14px; border-radius: 8px; background: var(--yellow-tint); border: 1px solid #f4d39c; color: #6b4300; }
.alert.err { background: var(--red-tint); border-color: #f2b6b6; color: #8c0b0b; }
.alert.ok { background: var(--teal-tint); border-color: #9cf0db; color: #00553f; }
.alert.info { background: var(--blue-tint); border-color: #d2c2ff; color: #2e0090; }

/* ── Bulk bar ──────────────────────────────────────── */

.bulkbar {
  position: sticky;
  bottom: 16px;
  margin-top: 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 15;
}
.bulkbar b { color: var(--teal); }
.bulkbar .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.bulkbar .btn:hover { border-color: var(--teal); }
.bulkbar .btn.teal { background: var(--teal); color: var(--ink); border-color: var(--teal); }

/* ── Timeline ──────────────────────────────────────── */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.timeline li::after { content: ''; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }

/* ── Modal, toast ──────────────────────────────────── */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 50, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 860px; }
.modal-head { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 0 20px 18px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; width: min(560px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28); max-width: 100%; pointer-events: auto; }
.toast.err { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.toast-x { margin-left: auto; background: none; border: 0; color: #fff; font: inherit; cursor: pointer; padding: 0 2px; opacity: 0.85; }
.modal-err { margin-bottom: 12px; }
.toast.err { background: var(--red); }
.toast.ok::before { content: '✓  '; color: var(--teal); }

pre.email {
  font: 13px/1.5 var(--mono);
  white-space: pre-wrap;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 0;
  max-height: 60vh;
  overflow: auto;
}

/* ── Auth pages ────────────────────────────────────── */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--blue); padding: 24px 16px; }
.auth-card { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.auth-card .brand { padding: 0 0 20px; color: var(--blue); }
.auth-card .brand .sub { color: var(--ink); }
.auth-card form > * + * { margin-top: 12px; }
.auth-card .btn { width: 100%; }

/* ── Dealer board ──────────────────────────────────── */

.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.board-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

.line-row { display: grid; grid-template-columns: 1.3fr 1.3fr 90px 36px; gap: 8px; align-items: end; }
.line-row.part { grid-template-columns: 2.6fr 90px 36px; }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.drop {
  border: 2px dashed #c9b8ff;
  border-radius: 12px;
  padding: 34px 16px;
  text-align: center;
  background: #fbf9ff;
  cursor: pointer;
}
.drop.over { background: var(--blue-tint); border-color: var(--blue); }
.drop b { display: block; font-size: 15px; margin-bottom: 4px; }
tr.err td { background: var(--red-tint); }
tr.warn td { background: var(--yellow-tint); }

/* ── Responsive ────────────────────────────────────── */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed;
    inset: 0 auto 0 0;
    width: 250px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.4); }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
  .g2, .g3, .g-side { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 110px 1fr; }
  .filters input[type='search'] { min-width: 0; flex: 1 1 100%; }
  .filters > select { flex: 1 1 45%; }
  h1 { font-size: 22px; }
  .hide-sm { display: none; }
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-row.part { grid-template-columns: 1fr 80px 36px; }
}

@media print {
  .side, .topbar, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}

/* ── Progress steps ────────────────────────────────── */

.steps { list-style: none; display: flex; gap: 0; margin: 14px 0 18px; padding: 0; counter-reset: s; flex-wrap: wrap; }
.steps li { position: relative; flex: 1 1 0; min-width: 110px; padding: 0 8px 0 0; counter-increment: s; }
.steps li span { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.steps li span::before {
  content: counter(s);
  display: inline-grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 2px solid #d4d4d4; color: var(--muted); font-size: 12px;
}
.steps li::after { content: ''; position: absolute; left: 30px; right: 10px; top: 11px; height: 2px; background: #e2e2e2; z-index: -1; }
.steps li:last-child::after { display: none; }
.steps li span { background: var(--bg); padding-right: 8px; width: max-content; }
.steps li.done span { color: var(--ink); }
.steps li.done span::before { content: '✓'; background: var(--blue); border-color: var(--blue); color: #fff; }
.steps li.done::after { background: var(--blue); }
.steps li.now span { color: var(--blue); }
.steps li.now span::before { border-color: var(--blue); color: var(--blue); background: var(--blue-tint); }
.steps.cancelled li span { color: #b5b5b5; }
.steps.cancelled li span::before { background: #f1f1f1; border-color: #ddd; color: #bbb; }

/* ── Pick stops ────────────────────────────────────── */

.stop { border-top: 1px solid var(--line); }
.stop:first-child { border-top: 0; }
.stop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 16px 8px; flex-wrap: wrap; }
.stop-head .addr { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.stop.done .stop-head h3 { color: #00684f; }
.stop table td { padding-top: 6px; padding-bottom: 6px; }
.dest-select { min-width: 190px; font-size: 13px; padding: 5px 8px; min-height: 32px; }

/* ── Log table ─────────────────────────────────────── */

.log td { vertical-align: top; }
.log .ev { font-weight: 700; }
.log .route { white-space: nowrap; }
.log .who { color: var(--muted); font-size: 12px; white-space: nowrap; }
.journey { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.journey .hop { background: var(--grey); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.journey .hop.transit { background: var(--blue-tint); color: var(--blue); }
.journey .hop.now { background: var(--blue); color: #fff; }
.journey .arr { color: var(--muted); }
.changes { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ac-entity { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 800; color: var(--muted); }

@media (max-width: 900px) {
  .steps li { min-width: 50%; margin-bottom: 8px; }
  .steps li::after { display: none; }
}

/* key–value table (lead details) */
table.kv { width: auto; }
table.kv th, table.kv td { border: 0; padding: 4px 12px 4px 0; vertical-align: top; background: none; }
table.kv th { color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0; font-size: 13px; white-space: nowrap; }
