:root {
  --navy: #0e2544;
  --ink: #101a2e;
  --muted: #63708c;
  --line: #dfe4ec;
  --bg: #f3f5f9;
  --card: #ffffff;
  --blue: #1263b4;
  --orange: #f47a2a;
  --green: #127a4b;
  --green-bg: #e3f4ea;
  --red: #c2352f;
  --red-bg: #fbe7e6;
  --amber: #a15c00;
  --amber-bg: #fdf0dc;
  --grey-bg: #eef1f5;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; color: var(--navy); }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

header.top {
  background: var(--navy); color: #fff; display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 54px; position: sticky; top: 0; z-index: 5;
}
header.top .brand { white-space: nowrap; font-weight: 700; letter-spacing: .3px; color: #fff; }
header.top .brand span { color: var(--orange); }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a { color: #c9d4e6; padding: 8px 12px; border-radius: 6px; font-weight: 600; font-size: 14px; }
header.top nav a.on, header.top nav a:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
header.top .who { font-size: 13px; color: #c9d4e6; }
header.top .who button { margin-left: 8px; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 6px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { border-color: #b9c3d3; text-decoration: none; }
button.primary, .btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.good, .btn.good { background: var(--green); border-color: var(--green); color: #fff; }
button.danger { color: var(--red); }
button.ghost { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

input, select, textarea {
  font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff; color: var(--ink);
  max-width: 100%;
}
textarea { width: 100%; min-height: 70px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 14px; }
.fields input, .fields select { width: 100%; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border-radius: 999px; padding: 6px 14px; }
.tabs button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.tabs .count { font-weight: 500; opacity: .75; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; background: #fafbfd; }
tbody tr:hover { background: #fafbfd; }
tr.click { cursor: pointer; }
.tablewrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.tablewrap table { min-width: 760px; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.badge.new { background: #e6effa; color: var(--blue); }
.badge.contacted { background: #efe8fb; color: #5b3aa8; }
.badge.working { background: var(--amber-bg); color: var(--amber); }
.badge.signed { background: var(--green-bg); color: var(--green); }
.badge.lost { background: var(--red-bg); color: var(--red); }
.badge.open { background: var(--green-bg); color: var(--green); }
.badge.taken { background: var(--red-bg); color: var(--red); }
.badge.partly { background: var(--amber-bg); color: var(--amber); }
.badge.src { background: var(--navy); color: #fff; }
.badge.unknown { background: var(--grey-bg); color: var(--muted); }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 150px; flex: 1; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.stat .v { font-size: 26px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--muted); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

.call {
  display: flex; justify-content: center; align-items: center; gap: 8px; background: var(--green); color: #fff !important;
  font-weight: 700; font-size: 17px; padding: 13px; border-radius: var(--radius); text-decoration: none !important; margin-bottom: 10px;
}
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .t-stage { color: var(--navy); font-weight: 600; }

.avail { display: flex; flex-wrap: wrap; gap: 8px; }
.avail .cell { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; min-width: 130px; }
.avail .cell .lbl { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.avail .cell.open { border-color: #bfe3cc; background: var(--green-bg); }
.avail .cell.taken { border-color: #f1c4c1; background: var(--red-bg); }

.grid-map td.open { background: var(--green-bg); color: var(--green); font-weight: 600; }
.grid-map td.taken { background: var(--red-bg); color: var(--red); font-weight: 600; }
.grid-map td.inactive { opacity: .5; }

.notice { padding: 10px 14px; border-radius: 6px; font-size: 14px; margin-bottom: 12px; }
.notice.bad { background: var(--red-bg); color: var(--red); }
.notice.warn { background: var(--amber-bg); color: var(--amber); }
.notice.ok { background: var(--green-bg); color: var(--green); }

dialog { border: 0; border-radius: 10px; padding: 0; width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(14,37,68,.3); }
dialog::backdrop { background: rgba(14,37,68,.45); }
dialog form { padding: 20px 22px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 6px; font-size: 14px; display: none; z-index: 20; max-width: calc(100vw - 32px); }
#toast.bad { background: var(--red); }

.login { max-width: 360px; margin: 12vh auto; }
.login input { width: 100%; }

@media (max-width: 760px) {
  header.top { padding: 0 12px; gap: 8px; }
  header.top .who span { display: none; }
  header.top nav a { padding: 6px 7px; font-size: 13px; white-space: nowrap; }
  header.top .brand { font-size: 14px; }
  header.top .brand span { display: none; }
  header.top nav { gap: 0; }
  header.top .who button { margin-left: 0; }
  main { padding: 16px 12px 60px; }
  .kv { grid-template-columns: 110px 1fr; }
  /* The leads table becomes cards: Mike is mostly on his phone. */
  .cards-on-mobile table { min-width: 0; }
  .cards-on-mobile thead { display: none; }
  .cards-on-mobile tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .cards-on-mobile td { display: inline-block; border: 0; padding: 2px 8px 2px 0; }
  .cards-on-mobile td.hide-m { display: none; }
  .cards-on-mobile td.first { display: block; font-size: 16px; }
}

/* Maps */
.mapbox { height: 380px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #eef1f5; }
.mapbox.small-map { height: 260px; margin-top: 10px; }
.mapbox.big-map { height: min(68vh, 640px); }
.leaflet-container { font: inherit; }
dialog.wide { width: min(860px, calc(100vw - 24px)); }
.picker .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #e6effa; color: var(--blue); border: 1px solid #c6daf2; border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.sel { background: #fdeee3; color: #b5530f; border-color: #f6c9a6; }
.chip button { border: 0; background: transparent; padding: 0 6px; font-size: 16px; line-height: 1; color: inherit; }
.searchbox { position: relative; flex: 1; min-width: 180px; }
.searchbox input { width: 100%; }
.searchbox .results { position: absolute; z-index: 1000; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(14,37,68,.15); margin-top: 2px; }
.searchbox .results button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; padding: 8px 10px; font-weight: 500; }
.searchbox .results button:hover { background: var(--grey-bg); }
.radius { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 0; color: var(--ink); }
.small-btn { padding: 2px 8px; font-size: 12px; margin-left: 6px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dealer-list li { cursor: pointer; }
.dealer-list li.on { background: #f4f8fd; }

[hidden] { display: none !important; }
dialog { max-height: calc(100vh - 32px); overflow: auto; }

.paybox { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; background: #fafbfd; }
.progress { height: 8px; background: var(--grey-bg); border-radius: 999px; position: relative; overflow: visible; margin: 8px 0 4px; }
.progress .bar { height: 100%; border-radius: 999px; background: var(--blue); max-width: 100%; }
.progress .bar.good { background: var(--green); }
.progress .bar.bad { background: var(--orange); }
.progress .pace { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--navy); opacity: .55; }
.targets { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.pnl { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pnl .stat .v.neg { color: var(--red); }
.sectionhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 28px 0 12px; }
.sectionhead h2 { margin: 0; font-size: 18px; }
