:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #17171a; --muted: #6b6b73; --line: #e6e4de;
  --accent: #1f5eff; --accent-ink: #fff; --good: #138a4a; --warn: #b26b00; --bad: #c0392b;
  --chip: #f0efea; --chip-on: #17171a; --chip-on-ink: #fff; --row-hover: #faf9f6;
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --panel: #18181b; --ink: #ececef; --muted: #9a9aa3; --line: #2a2a2f;
    --accent: #5b8cff; --chip: #232327; --chip-on: #ececef; --chip-on-ink: #111; --row-hover: #1e1e22;
    --good: #3ccf7f; --warn: #f0a83a; --bad: #ff6b5b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); display: grid; grid-template-columns: 320px 1fr; font-size: 14px; }

.panel { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 18px; overflow-y: auto; height: 100vh; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }

.block { display: flex; flex-direction: column; gap: 8px; }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.lbl b { color: var(--ink); text-transform: none; letter-spacing: 0; }
.lbl-row { display: flex; justify-content: space-between; align-items: center; }
.hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.hint.err { color: var(--bad); }
.row { display: flex; gap: 6px; }
input[type=search], select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.row input { flex: 1; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: transparent; }
.btn-big { padding: 12px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: progress; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }

.geo-list { list-style: none; margin: 0; padding: 0; border-radius: 8px; overflow: hidden; }
.geo-list li { padding: 7px 10px; font-size: 12px; cursor: pointer; border: 1px solid var(--line); border-top: 0; background: var(--bg); }
.geo-list li:first-child { border-top: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.geo-list li:last-child { border-radius: 0 0 8px 8px; }
.geo-list li:hover { background: var(--row-hover); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 12px; border: 0; background: var(--chip); color: var(--ink); border-radius: 999px; padding: 6px 10px; cursor: pointer; }
.chip.on { background: var(--chip-on); color: var(--chip-on-ink); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check small { color: var(--muted); }
.check.sub { justify-content: space-between; color: var(--muted); font-size: 12px; padding-left: 24px; }
.check.inline { font-size: 12px; white-space: nowrap; }

.main { display: grid; grid-template-rows: 42vh 1fr; height: 100vh; min-width: 0; }
#map { width: 100%; height: 100%; }
.results { display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { font: inherit; border: 0; background: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.tab.active { background: var(--chip); color: var(--ink); }
.tab span { font-weight: 500; font-variant-numeric: tabular-nums; margin-left: 4px; opacity: .8; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; background: var(--bg); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); z-index: 1; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: var(--row-hover); }
tr.focus td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.score { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; font-weight: 700; font-variant-numeric: tabular-nums; color: #fff; }
.name { font-weight: 600; cursor: pointer; }
.meta { color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); margin-right: 4px; }
.tag.none { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.tag.social { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.tag.site { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }
.actions { display: flex; flex-direction: column; gap: 4px; font-size: 12px; white-space: nowrap; }
.follow select { font-size: 12px; padding: 5px 6px; width: 120px; }
.follow textarea { display: block; margin-top: 4px; width: 160px; font: inherit; font-size: 12px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; resize: vertical; min-height: 30px; }

.brand-txt { flex: 1; min-width: 0; }
.toggle-panel { display: none; }

/* ---------- tablette / téléphone ---------- */
@media (max-width: 860px) {
  html, body { height: auto; min-height: 100%; }
  body { display: block; }
  .panel { height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; gap: 16px; position: sticky; top: 0; z-index: 1200; max-height: 100dvh; }
  .toggle-panel { display: inline-block; }
  .panel.collapsed { gap: 0; }
  .panel.collapsed > :not(.brand) { display: none; }
  .brand p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .main { display: block; height: auto; }
  #map { height: 42vh; min-height: 260px; }
  .results { border-top: 0; }
  .table-wrap { overflow: visible; }
  th { top: 0; }
  /* 16px minimum : évite le zoom automatique d'iOS sur les champs */
  input[type=search], input[type=password], select, textarea, .follow select, .follow textarea { font-size: 16px !important; }
  .btn { min-height: 42px; }
  .chip { padding: 9px 13px; font-size: 13px; }
  .check { min-height: 32px; }
}

@media (max-width: 700px) {
  .toolbar { padding: 10px 12px; gap: 8px; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 9px; }
  .filters { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters #filterQ, .filters #filterSite { grid-column: 1 / -1; width: 100%; }
  .filters .btn { width: 100%; }
  .check.inline { font-size: 13px; }

  /* le tableau devient une liste de cartes */
  table, tbody { display: block; }
  thead { display: none; }
  tbody tr {
    display: grid; grid-template-columns: 44px 1fr auto; column-gap: 12px; row-gap: 10px;
    grid-template-areas: "score name name" "score contact avis" ". web web" "follow follow follow" "actions actions actions";
    padding: 14px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
  }
  tbody tr:hover td, tr.focus td { background: none; }
  tr.focus { background: color-mix(in srgb, var(--accent) 10%, var(--panel)) !important; }
  tbody td { display: block; padding: 0; border: 0; min-width: 0; }
  tbody td:nth-child(1) { grid-area: score; }
  tbody td:nth-child(2) { grid-area: name; }
  tbody td:nth-child(3) { grid-area: contact; }
  tbody td:nth-child(4) { grid-area: avis; text-align: right; }
  tbody td:nth-child(5) { grid-area: web; }
  tbody td:nth-child(6) { grid-area: follow; display: grid; grid-template-columns: auto 1fr; gap: 8px; }
  tbody td:nth-child(7) { grid-area: actions; flex-direction: row; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; }
  tbody td.empty { grid-column: 1 / -1; padding: 32px 8px; }
  tbody tr:has(td.empty) { display: block; }
  .name { font-size: 16px; }
  .follow select { width: auto; }
  .follow textarea { width: 100%; margin-top: 0; min-height: 42px; }
  .web-tags, td:nth-child(5) .meta { display: inline-block; margin-left: 6px; }
  .actions a, .actions .link { padding: 4px 0; }
}

.login { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; }
.login-card .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); }
.login-card h2 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; color: var(--muted); font-size: 13px; }
.login-card input { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.login-card .btn { padding: 11px; }

.add-lead { font: inherit; font-size: 12px; font-weight: 600; border: 1px solid var(--accent); color: var(--accent); background: transparent; border-radius: 999px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.add-lead:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.add-lead.on { border-color: transparent; background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
@media (max-width: 700px) {
  .add-lead { order: -1; flex-basis: 100%; font-size: 15px; padding: 10px; text-align: center; }
}

/* ---------- profil ---------- */
.profile-chip { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; cursor: pointer; }
.profile-chip:hover { border-color: var(--muted); }
.avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: var(--accent); }
.profile-txt { display: flex; flex-direction: column; min-width: 0; }
.profile-txt b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-txt small { color: var(--muted); font-size: 11px; }
.panel.collapsed .profile-chip { display: none; }

/* ---------- sélection ---------- */
.selbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.selbar[hidden] { display: none; }
.selbar .btn { padding: 6px 12px; }
.sel { display: flex; align-items: center; justify-content: center; margin-top: 8px; }
.sel input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.mail-btn { font: inherit; font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--ink); background: var(--panel); border-radius: 999px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.mail-btn:hover { border-color: var(--accent); color: var(--accent); }
.who { color: var(--muted); font-size: 11px; margin-top: 4px; }
.who b { color: var(--ink); font-weight: 600; }

/* ---------- listes ---------- */
.list-row td { vertical-align: middle; }
.list-row .name { cursor: default; }
.list-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- boîtes de dialogue ---------- */
.dlg { border: 0; padding: 0; background: transparent; max-width: min(620px, calc(100vw - 24px)); width: 100%; color: var(--ink); }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100dvh - 32px); overflow-y: auto; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg label:not(.check) { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.dlg input:not([type=checkbox]):not([type=radio]), .dlg textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-weight: 400; }
.dlg textarea { resize: vertical; line-height: 1.45; }
.dlg code { font-size: 11px; background: var(--chip); padding: 1px 5px; border-radius: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.profile-list { display: flex; flex-direction: column; gap: 6px; }
.profile-list button { display: flex; align-items: center; gap: 10px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; }
.profile-list button:hover { border-color: var(--accent); }
.profile-list small { color: var(--muted); display: block; font-size: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg[hidden] { display: none; }
.seg label { flex-direction: row !important; align-items: center; gap: 8px !important; border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; color: var(--ink) !important; font-weight: 600; font-size: 13px !important; }
.seg label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.recipients { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.recipients:empty { display: none; }
.rcpt { display: grid; grid-template-columns: 1fr 1.2fr auto; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.rcpt .rname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcpt input { padding: 6px 8px !important; font-size: 13px !important; }
.rcpt .btn { padding: 6px 10px; font-size: 12px; }
.rcpt.done { opacity: .6; }
.rcpt.done .btn { border-color: var(--good); color: var(--good); }

@media (max-width: 700px) {
  .grid2, .seg { grid-template-columns: 1fr; }
  .rcpt { grid-template-columns: 1fr auto; }
  .rcpt input { grid-column: 1 / -1; grid-row: 2; }
  .dlg-card { padding: 16px; border-radius: 14px; }
  .dlg input, .dlg textarea { font-size: 16px !important; }
  .dlg-actions .btn { flex: 1; }
  .sel { margin-top: 10px; }
  .mail-btn { font-size: 14px; padding: 9px 12px; }
  .selbar { padding: 10px 12px; position: sticky; top: var(--panel-h, 0px); z-index: 1100; }
  .list-actions { justify-content: flex-start; }
}

[hidden] { display: none !important; }
