:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1c2333;
  --muted: #6b7489;
  --line: #e3e7ef;
  --brand: #2f5bea;
  --brand-soft: #e8eefe;
  --ok: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
  /* stage colours: 0 = not contacted … 7 = paid */
  --s0: #9aa3b5; --s1: #3b82f6; --s2: #06b6d4; --s3: #f59e0b;
  --s4: #f97316; --s5: #8b5cf6; --s6: #10b981; --s7: #15803d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131c; --panel: #171c27; --text: #e6e9f0; --muted: #9099ad; --line: #283041;
    --brand: #6f8dff; --brand-soft: #1f2a4a; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
small.muted { font-weight: normal; }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.link.small { font-size: 12px; }
.danger { color: var(--danger) !important; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; font-weight: normal; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--bg); }

.alert { background: #fde8e8; color: #9b1c1c; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.alert.ok { background: #e3f7ea; color: #14632e; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.badge.admin { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; font-weight: 600; }
.pill.ok { background: #e3f7ea; color: #14632e; }
.pill.off { background: #f1f2f5; color: #6b7489; }

/* ---------- auth pages ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-box { background: var(--panel); padding: 32px 28px; border-radius: 16px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: left; }
.auth-box h1 { margin: 12px 0 2px; }
.auth-box p { margin: 0 0 18px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 800; }
.logo.big { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topbar nav a.active, .topbar nav a:hover { background: var(--brand-soft); color: var(--brand); }
.me { display: flex; gap: 14px; align-items: center; font-size: 14px; }
.me a { color: var(--muted); }

/* ---------- dashboard layout ---------- */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; padding: 20px; align-items: start; }
.filters { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow-y: auto; background: var(--panel); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.filter-group + .filter-group { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.filter-group h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.chips-col { display: flex; flex-direction: column; gap: 2px; }
.chips-col.scroll { max-height: 230px; overflow-y: auto; }
.mini-search { padding: 5px 8px; font-size: 13px; margin-bottom: 6px; }
.chip { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 7px; cursor: pointer; color: var(--text); font: inherit; font-size: 14px; }
.chip:hover { background: var(--bg); }
.chip.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .count { font-size: 12px; min-width: 24px; text-align: center; padding: 1px 6px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.chip.active .count { background: var(--brand); color: #fff; }

.content { min-width: 0; }
.toolbar { display: flex; gap: 10px; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1; }
.toolbar select { width: auto; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; min-height: 4px; }
.tag { background: var(--brand-soft); color: var(--brand); border: 0; border-radius: 99px; padding: 3px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.only-mobile { display: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; align-items: start; }
.result-count { grid-column: 1 / -1; margin: 0; font-size: 13px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 50px 20px; background: var(--panel); border-radius: var(--radius); color: var(--muted); }

/* ---------- card ---------- */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 12px; border-top: 4px solid var(--sc, var(--s0)); display: flex; flex-direction: column; gap: 10px; }
.card.s0 { --sc: var(--s0); } .card.s1 { --sc: var(--s1); } .card.s2 { --sc: var(--s2); } .card.s3 { --sc: var(--s3); }
.card.s4 { --sc: var(--s4); } .card.s5 { --sc: var(--s5); } .card.s6 { --sc: var(--s6); } .card.s7 { --sc: var(--s7); }
.card-head { display: flex; justify-content: space-between; gap: 8px; }
.card h3 { margin: 0; font-size: 17px; line-height: 1.3; }
.loc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-actions { display: flex; flex-shrink: 0; align-self: flex-start; }
.contact { display: flex; align-items: center; gap: 8px; }
.contact .wa { font-weight: 600; color: #128c4a; background: #e6f7ec; padding: 4px 10px; border-radius: 8px; }
.contact .wa:hover { background: #d3f1de; }
.contact .call { padding: 4px 8px; border-radius: 8px; background: var(--bg); }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.plat { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.plat:hover { border-color: currentColor; }
.plat.whatsapp { color: #128c4a; } .plat.facebook { color: #1877f2; } .plat.instagram { color: #c13584; }
.plat.tiktok { color: #111; } .plat.youtube { color: #e00; } .plat.linkedin { color: #0a66c2; }
.plat.telegram { color: #229ed9; } .plat.x { color: #333; }
@media (prefers-color-scheme: dark) { .plat.tiktok, .plat.x { color: #ddd; } .contact .wa { background: #12301f; color: #4ade80; } }

.status { display: flex; flex-direction: column; gap: 6px; }
.steps { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.step { height: 7px; border: 0; padding: 0; border-radius: 4px; background: var(--line); cursor: pointer; }
.step.on { background: var(--sc); }
.step:hover { outline: 2px solid var(--sc, var(--brand)); outline-offset: 1px; }
.status-select { padding: 5px 8px; font-size: 13px; font-weight: 600; color: var(--sc); border-color: var(--line); }

.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.by { color: var(--muted); }
.by b { color: var(--text); font-weight: 600; }
.conv-btn { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; font: inherit; font-size: 13px; color: var(--text); white-space: nowrap; }
.conv-btn.open, .conv-btn:hover { border-color: var(--brand); color: var(--brand); }

.convs { display: flex; flex-direction: column; gap: 10px; background: var(--bg); border-radius: 10px; padding: 10px; }
.convs p { margin: 4px 0; font-size: 13px; }
.conv { background: var(--panel); border-radius: 8px; padding: 8px 10px; border-left: 3px solid var(--line); }
.conv.mine { border-left-color: var(--brand); }
.conv-head { font-size: 13px; margin-bottom: 4px; }
.msg { padding: 5px 0; border-top: 1px dashed var(--line); }
.msg:first-of-type { border-top: 0; }
.msg-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg-meta { display: flex; gap: 10px; font-size: 11px; color: var(--muted); }
.compose { display: flex; gap: 8px; align-items: flex-end; }
.compose textarea { resize: vertical; font-size: 14px; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 16px; padding: 22px; width: min(520px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 35, .45); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.links-field { margin-bottom: 12px; }
.links-field .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.link-row { display: flex; gap: 6px; margin-bottom: 6px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- generic pages ---------- */
.page { padding: 24px 20px; max-width: 1300px; margin: 0 auto; }
.page.narrow { max-width: 460px; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form h2 { width: 100%; margin: 0; }
.inline-form label { margin: 0; flex: 1 1 160px; }
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--brand); }
.table tr.inactive td { opacity: .55; }
.table td.c { text-align: center; }
.table th.c { text-align: center; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions form { display: flex; gap: 6px; }
.reset-form input { width: 130px; padding: 4px 8px; font-size: 13px; }
.table input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--ok); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.analysis-tools { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.analysis-tools input { flex: 1 1 220px; }
.analysis-tools select { width: auto; }
.stage-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ---------- toast ---------- */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; }
.toast { background: #1c2333; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .filters { display: none; position: static; max-height: none; }
  .filters.show { display: block; }
  .only-mobile { display: inline-block; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input[type=search] { flex-basis: 100%; order: -1; }
  .topbar { flex-wrap: wrap; gap: 8px 14px; padding: 10px 16px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .me { margin-left: auto; }
  .grid { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  .page { padding: 16px; }
}
