:root {
  --bg: #f6f7f4; --surface: #ffffff; --surface-2: #eef1ec; --text: #1d2420; --muted: #5d6862;
  --border: #d7ddd8; --accent: #2f6b4f; --accent-text: #ffffff; --danger: #a33a2a;
  --hi: #1f7a4d; --mid: #c98a12; --lo: #7d8a84; --demo-bg: #fff1c7; --demo-text: #6b4b00;
  --snap-bg: #e3edf7; --snap-text: #1f4466;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --surface: #1a201d; --surface-2: #232b27; --text: #e4ebe6; --muted: #9aa8a0;
    --border: #2f3a34; --accent: #5fae86; --accent-text: #0d1310; --danger: #e07a68;
    --hi: #4fbf86; --mid: #e0a93b; --lo: #8a9790; --demo-bg: #3d3216; --demo-text: #f3d68a;
    --snap-bg: #1c2c3c; --snap-text: #b9d4ee; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --surface: #1a201d; --surface-2: #232b27; --text: #e4ebe6; --muted: #9aa8a0;
  --border: #2f3a34; --accent: #5fae86; --accent-text: #0d1310; --danger: #e07a68;
  --hi: #4fbf86; --mid: #e0a93b; --lo: #8a9790; --demo-bg: #3d3216; --demo-text: #f3d68a;
  --snap-bg: #1c2c3c; --snap-text: #b9d4ee; color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); }
.top { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: 10px; align-items: center; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.ok { color: var(--hi); } .pill.bad { color: var(--danger); }
.api { display: flex; gap: 8px; align-items: end; }
.api label { display: flex; gap: 6px; align-items: center; margin: 0; }
.api input { width: 220px; }
.banner { padding: 8px 16px; font-weight: 600; }
.banner.demo { background: var(--demo-bg); color: var(--demo-text); }
.banner.snap { background: var(--snap-bg); color: var(--snap-text); }
main { display: grid; grid-template-columns: 300px 1fr; gap: 0; min-height: calc(100vh - 120px); }
.panel { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.panel section + section { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
label { display: block; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); }
input, select { width: 100%; margin-top: 3px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; }
input[type=checkbox] { width: auto; margin-top: 2px; }
input[type=range] { padding: 0; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 10px; padding: 6px 10px; }
legend { font-size: 12px; color: var(--muted); }
fieldset label { margin: 4px 0; }
.hint { font-size: 11px; color: var(--muted); display: block; margin-left: 22px; }
button { padding: 7px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer; }
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 6px 0 0; }
.progress .bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.progress p { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.scans { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.scans li { padding: 6px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.scans li .st { float: right; color: var(--muted); }
.scans li .st.failed { color: var(--danger); } .scans li .st.done { color: var(--hi); }
.content { display: flex; flex-direction: column; min-width: 0; }
#map { height: 42vh; min-height: 260px; border-bottom: 1px solid var(--border); }
.tablebar { display: flex; gap: 16px; align-items: center; padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tablebar button { margin-left: auto; }
.legend { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; }
.dot.hi { background: var(--hi); } .dot.mid { background: var(--mid); } .dot.lo { background: var(--lo); }
.tablewrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); cursor: pointer; user-select: none; white-space: nowrap; }
th.sorted::after { content: " ▾"; } th.sorted.asc::after { content: " ▴"; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; } tbody tr:hover { background: var(--surface-2); }
td a { color: var(--accent); }
.score { font-weight: 700; } .score.hi { color: var(--hi); } .score.mid { color: var(--mid); } .score.lo { color: var(--lo); }
.tag { font-size: 11px; color: var(--muted); }
.demo-tag { font-size: 10px; font-weight: 700; background: var(--demo-bg); color: var(--demo-text); padding: 1px 5px; border-radius: 4px; }
dialog { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  max-width: 640px; width: calc(100% - 32px); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog dl { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 13px; }
dialog dt { color: var(--muted); } dialog dd { margin: 0; word-break: break-word; }
footer { padding: 12px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); background: var(--surface); }
.empty { padding: 24px 16px; color: var(--muted); }
@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .api input { width: 160px; }
}
dialog.wide { max-width: 860px; }
.pair { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0 0 14px; }
.pair-head { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.pair-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair-cols > div { background: var(--surface-2); border-radius: 6px; padding: 10px; min-width: 0; }
.pair-cols h4 { margin: 0 0 6px; font-size: 14px; }
.pair-cols dl { grid-template-columns: 70px 1fr; font-size: 12px; margin: 0; }
.pair .btns { margin-top: 10px; }
@media (max-width: 640px) { .pair-cols { grid-template-columns: 1fr; } }

/* ---------- CRM shell ---------- */
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 13px; }
.nav a.on { background: var(--accent); color: var(--accent-text); }
.nav a .badge { background: var(--danger); color: #fff; border-radius: 99px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.who { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.who label { margin: 0; display: flex; gap: 6px; align-items: center; color: var(--text); }
.page { padding: 16px; max-width: 1400px; margin: 0 auto; }
.page h2 { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 12px; }
.bars div { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; font-size: 13px; margin: 5px 0; }
.bars i { display: block; height: 10px; border-radius: 99px; background: var(--accent); min-width: 2px; }
.bars .track { background: var(--surface-2); border-radius: 99px; }
.list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.list li:last-child { border-bottom: 0; }
.list a, .linkish { color: var(--accent); cursor: pointer; text-decoration: none; }
.overdue { color: var(--danger); font-weight: 600; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar label { margin: 0; min-width: 130px; flex: 1 1 130px; max-width: 220px; }
.toolbar .spacer { flex: 1 1 auto; }
.toolbar button, .toolbar a.btn { flex: 0 0 auto; }
a.btn { display: inline-block; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); font-weight: 600; text-decoration: none; }
button.small, a.btn.small { padding: 3px 8px; font-size: 12px; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.pagemap { height: 320px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 14px; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.dnc { background: var(--danger); color: #fff; }
.chip.ok { background: var(--hi); color: #fff; }
.chip.warn { background: var(--demo-bg); color: var(--demo-text); }
/* ---------- board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: 10px; padding: 8px; min-height: 300px; }
.col.over { outline: 2px dashed var(--accent); }
.col h3 { margin: 2px 4px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: grab; font-size: 13px; }
.kcard b { display: block; }
.kcard .meta { color: var(--muted); font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0; }
.kcard select { padding: 2px 4px; font-size: 11px; margin-top: 4px; }
/* ---------- lead detail ---------- */
.lead-head { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.lead-head h2 { margin: 0; flex: 1 1 260px; }
.lead-head label { margin: 0; min-width: 150px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }
textarea { width: 100%; min-height: 70px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; margin-top: 3px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12px; max-height: 360px; overflow: auto; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.timeline time { color: var(--muted); }
.note { background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin: 6px 0; font-size: 13px; white-space: pre-wrap; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-top: 8px; }
.inline-form label { margin: 0; flex: 1 1 140px; }
/* ---------- login / dialogs / toast ---------- */
.login { max-width: 420px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 24px; }
.login h1 { font-size: 22px; margin-bottom: 6px; }
.devbox { margin-top: 18px; padding: 12px; border: 2px dashed var(--mid); border-radius: 8px; }
.devbox strong { color: var(--mid); }
#dlg h2 { text-transform: none; letter-spacing: 0; font-size: 17px; color: var(--text); }
#dlg pre { background: var(--surface-2); padding: 10px; border-radius: 6px; white-space: pre-wrap; word-break: break-word; font-size: 12px; max-height: 300px; overflow: auto; }
#dlg .btns { margin-top: 14px; justify-content: flex-end; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 2000; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }
.status-line { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
@media (max-width: 820px) {
  .bars div { grid-template-columns: 90px 1fr 30px; }
  .kv { grid-template-columns: 100px 1fr; }
  table.leads th:nth-child(4), table.leads td:nth-child(4), table.leads th:nth-child(8), table.leads td:nth-child(8) { display: none; }
}
