:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --text: #15181e;
  --muted: #5d6573;
  --border: #dfe3ea;
  --accent: #0b5cab;
  --accent-ink: #ffffff;
  --warn: #b42318;
  --good: #137333;
  --focus: #1a73e8;
  --st-new: #6b7280;
  --st-attempted: #a15c07;
  --st-contacted: #0b5cab;
  --st-follow-up: #7c3aed;
  --st-quoted: #c2410c;
  --st-won: #15803d;
  --st-not-interested: #9f1239;
  --st-bad-lead: #3f3f46;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --surface: #1a1d24; --surface-2: #232731; --text: #e8eaee; --muted: #9aa2b1; --border: #2e333e;
    --accent: #5aa2f0; --accent-ink: #0b1220; --warn: #ff8a80; --good: #6fcf8f; --focus: #8ab4f8;
    --st-new: #9ca3af; --st-attempted: #e0a33a; --st-contacted: #5aa2f0; --st-follow-up: #b48cff; --st-quoted: #fb8c4b;
    --st-won: #4ade80; --st-not-interested: #fb7185; --st-bad-lead: #a1a1aa;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --surface: #1a1d24; --surface-2: #232731; --text: #e8eaee; --muted: #9aa2b1; --border: #2e333e;
  --accent: #5aa2f0; --accent-ink: #0b1220; --warn: #ff8a80; --good: #6fcf8f; --focus: #8ab4f8;
  --st-new: #9ca3af; --st-attempted: #e0a33a; --st-contacted: #5aa2f0; --st-follow-up: #b48cff; --st-quoted: #fb8c4b;
  --st-won: #4ade80; --st-not-interested: #fb7185; --st-bad-lead: #a1a1aa;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.45rem; margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.error { color: var(--warn); }
.good { color: var(--good); }
.loading, .empty { padding: 24px 4px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
nav { display: flex; gap: 2px; margin-left: auto; }
nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
nav a:hover { text-decoration: none; background: var(--surface-2); }
nav a.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
@media (max-width: 420px) { .brand { display: none; } nav { margin: 0 auto; } }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
body.full main { max-width: none; padding: 0; }
body.locked main, body.locked .top { visibility: hidden; }

/* cards and layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.wide { width: 100%; margin-top: 4px; }
.link { background: none; border: 0; padding: 4px 2px; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 10px; min-height: 40px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; font-size: .875rem; color: var(--muted); }
label > input, label > select { margin-top: 4px; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: 8px; }
label.inline input { width: auto; margin: 0; }
label.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 1rem; }
label.check input { width: 20px; min-height: 20px; margin: 0; }
label.file { margin-bottom: 10px; }
#imp-text { margin-bottom: 10px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

/* status chips */
.st-new { --c: var(--st-new); }
.st-attempted { --c: var(--st-attempted); }
.st-contacted { --c: var(--st-contacted); }
.st-follow-up { --c: var(--st-follow-up); }
.st-quoted { --c: var(--st-quoted); }
.st-won { --c: var(--st-won); }
.st-not-interested { --c: var(--st-not-interested); }
.st-bad-lead { --c: var(--st-bad-lead); }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.status-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  font: inherit; font-size: .9rem; font-weight: 600; padding: 8px 14px; min-height: 40px; border-radius: 999px; cursor: pointer;
  color: var(--c); background: transparent; border: 1.5px solid color-mix(in srgb, var(--c) 45%, transparent);
}
.chip-btn:hover { background: color-mix(in srgb, var(--c) 10%, transparent); }
.chip-btn.on { background: var(--c); color: var(--surface); border-color: var(--c); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 5px; vertical-align: -1px; }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; color: var(--text); }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile b { display: block; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .875rem; }
.tile.warn b { color: var(--warn); }
.tile.good b { color: var(--good); }
.bar { display: grid; grid-template-columns: 112px 1fr 48px; gap: 10px; align-items: center; padding: 4px 0; color: var(--text); }
.bar:hover { text-decoration: none; }
.bar:hover .bar-l { color: var(--accent); }
.bar-l { font-size: .9rem; }
.bar-t { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-f { display: block; height: 100%; background: var(--c); border-radius: 5px; min-width: 2px; }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; }
.t { width: 100%; border-collapse: collapse; font-size: .95rem; }
.t th, .t td { padding: 7px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.t th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.t .num { text-align: right; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li a { display: flex; align-items: center; gap: 10px; padding: 9px 0; color: var(--text); }
.list li a:hover { text-decoration: none; }
.list li a:hover b { color: var(--accent); }
.li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.li-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { font-size: .8rem; font-weight: 600; color: var(--muted); white-space: nowrap; min-width: 64px; }
.when.due { color: var(--st-quoted); }
.when.overdue { color: var(--warn); }
.act-type { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; min-width: 64px; }
.act-type.a-visit, .act-type.a-call, .act-type.a-email { color: var(--st-contacted); }
.act-type.a-status { color: var(--st-follow-up); }

/* leads list */
.filters { display: flex; flex-direction: column; gap: 10px; }
.frow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.frow select { flex: 1 1 170px; width: auto; }
.frow.between { justify-content: space-between; }
details summary { cursor: pointer; color: var(--accent); font-size: .9rem; padding: 2px 0; }
details .frow { margin-top: 8px; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.lead-row {
  display: flex; gap: 12px; justify-content: space-between; padding: 12px 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.lead-row:hover { text-decoration: none; border-color: var(--accent); }
.lr-main { min-width: 0; }
.lr-name { font-weight: 600; }
.lr-sub { color: var(--muted); font-size: .9rem; }
.lr-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: .75rem; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.fiber { color: var(--st-won); background: color-mix(in srgb, var(--st-won) 12%, transparent); }
.lr-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.star { color: #e3a008; }

/* one lead */
.lead-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.pager { display: flex; gap: 12px; align-items: center; }
.lead-head { display: flex; gap: 10px; align-items: flex-start; }
.lead-head h1 { margin-bottom: 2px; }
.lead-head p { margin: 0 0 12px; }
.star-btn {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  font-size: 1.3rem; color: var(--border); cursor: pointer; line-height: 1;
}
.star-btn.on { color: #e3a008; border-color: #e3a008; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.followup { gap: 4px 12px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline p { margin: 4px 0 0; white-space: pre-wrap; }
.timeline .del { float: right; font-size: .8rem; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: .95rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
@media (max-width: 480px) { .facts { grid-template-columns: 1fr; gap: 0; } .facts dd { margin-bottom: 8px; } }

/* map */
.map-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.map-bar select { width: auto; flex: 0 1 200px; }
#map { height: calc(100dvh - 52px - 61px - 36px); min-height: 320px; background: var(--surface-2); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 16px; font-size: .8rem; color: var(--muted); background: var(--surface); }
.pop ul { list-style: none; padding: 0; margin: 6px 0; }
.pop li { padding: 2px 0; }
.pop .chip { font-size: .7rem; padding: 0 6px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* toast + login */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 2000; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--warn); color: #fff; }
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 3000; }
#login[hidden] { display: none; }
#login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
#login h1 { margin: 0; }

/* where info came from */
.src { display: inline-block; vertical-align: 2px; margin-left: 4px; padding: 1px 7px; border-radius: 5px; font-size: .7rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; border: 1px solid; }
.legend-src .src { margin: 0 2px; }
.src-rsi { color: var(--muted); border-color: var(--border); background: var(--surface-2); }
.src-found { --c: #b45309; color: var(--c); border-color: color-mix(in srgb, var(--c) 40%, transparent); background: color-mix(in srgb, var(--c) 10%, transparent); }
.src-you { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .src-found { --c: #f59e0b; } }
:root[data-theme="dark"] .src-found { --c: #f59e0b; }
.found-card { border-color: color-mix(in srgb, #b45309 35%, var(--border)); }
.found { padding: 10px 0; border-top: 1px solid var(--border); }
.found:first-of-type { border-top: 0; }
.found-head { display: flex; gap: 8px; align-items: center; }
.found p { margin: 4px 0; }
.found .facts { margin: 8px 0; }
.conf { font-size: .75rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.conf-high { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.pre { white-space: pre-line; }
.banner { padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }
.banner.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.legend-src { margin: 0 0 12px; line-height: 1.9; }
.tag.found { color: #b45309; background: color-mix(in srgb, #b45309 10%, transparent); }
.tag.closed { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
