:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #16191f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --up: #047857;
  --down: #c2410c;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; }
h3:first-child { margin-top: 0; }
p { margin: .3rem 0; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Barre du haut */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink); }
.brand svg { color: var(--brand); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.topbar nav a.active { color: var(--ink); background: var(--bg); }

/* En-têtes de page */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumb { font-size: .85rem; color: var(--muted); margin-bottom: 2px; }
.crumb a { color: var(--muted); }
.actions { display: flex; gap: 8px; }

/* Boutons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.busy { opacity: .7; cursor: progress; }

/* Messages */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.flash.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* Chiffres clés */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat strong { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat strong.small { font-size: 1rem; }

/* Cartes des sites */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); color: var(--ink); display: block; }
a.card:hover { border-color: var(--brand); text-decoration: none; }
.card-head h2 { margin: 0; }
.card-head { margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.kpis div { display: flex; flex-direction: column; }
.kpis strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpis span { font-size: .78rem; color: var(--muted); }
.card-foot { display: flex; justify-content: space-between; padding-top: 10px; font-size: .85rem; }

/* Panneaux */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 20px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .panel { margin-bottom: 0; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; gap: 16px; } }
.empty { text-align: center; padding: 48px 16px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty .btn { margin-top: 12px; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line-strong); background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
table.compact td { padding: 5px 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--ink); }
th.sorted-asc::after { content: " ↑"; }
th.sorted-desc::after { content: " ↓"; }
th.comp, td.comp { background: #fafafa; }
th.comp { text-transform: none; letter-spacing: 0; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
td.url { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter { font: inherit; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 8px; width: min(320px, 100%); }

/* Positions */
.pos { display: inline-block; min-width: 34px; text-align: center; padding: 2px 7px; border-radius: 6px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pos-top3 { background: #d1fae5; color: #065f46; }
.pos-top10 { background: #e0f2fe; color: #075985; }
.pos-top20 { background: #fef3c7; color: #92400e; }
.pos-far { background: #f3f4f6; color: #374151; }
.pos-out { background: transparent; color: var(--muted); font-weight: 500; }
.pos-none { color: var(--line-strong); }
.delta { font-size: .85rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.muted { font-weight: 400; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 999px; background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; margin: 1px 0; }
.tag.good { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }

/* Graphiques */
.spark { width: 110px; height: 24px; display: block; }
.spark path { fill: none; stroke: #94a3b8; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.spark.up path { stroke: var(--up); }
.spark.down path { stroke: var(--down); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .85rem; margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg a { padding: 5px 12px; color: var(--muted); font-size: .85rem; }
.seg a + a { border-left: 1px solid var(--line-strong); }
.seg a.active { background: var(--ink); color: #fff; }
.seg a:hover { text-decoration: none; }

/* Top 10 */
.serp { list-style: none; padding: 0; margin: 0 0 12px; }
.serp li { display: flex; gap: 12px; padding: 8px 10px; border-radius: 8px; align-items: baseline; }
.serp li div { display: flex; flex-direction: column; min-width: 0; }
.serp li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.serp li.mine { background: #eff6ff; outline: 1px solid #bfdbfe; }
.serp li.comp { background: #fff7ed; }
.serp .rank { font-weight: 650; color: var(--muted); width: 20px; text-align: right; flex: none; font-variant-numeric: tabular-nums; }

/* Formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 550; color: #374151; }
input:not([type=checkbox]), select, textarea { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
textarea { resize: vertical; width: 100%; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.chips { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { display: inline-flex; align-items: center; gap: 4px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 999px; padding: 2px 4px 2px 10px; font-size: .85rem; }
.chips form { display: inline; }
.chips button { border: 0; background: none; cursor: pointer; color: #9a3412; font-size: 1rem; line-height: 1; padding: 0 4px; }

/* Connexion */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { font-size: 1.3rem; }

/* Moteur, priorité, estimation */
.engine { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px; font-size: .7rem; font-weight: 700; color: #fff; margin-right: 6px; vertical-align: 1px; }
.engine-google { background: #2563eb; }
.engine-bing { background: #0d9488; }
.star { color: #d97706; margin-right: 4px; }
.estimate { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.estimate .label { display: block; color: var(--muted); font-size: .82rem; }
.estimate strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.estimate small { font-size: .85rem; font-weight: 400; color: var(--muted); }
.estimate p { flex: 1; min-width: 260px; margin: 0; }
.bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.pending-note { color: #92400e; }

/* Téléphone */
.mobile-only { display: none; }
@media (max-width: 700px) {
  :root { font-size: 14px; }
  .wrap { padding: 0 14px; }
  main.wrap { padding-top: 16px; }
  .topbar .wrap { height: auto; min-height: 52px; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; gap: 6px; }
  .topbar nav { width: 100%; overflow-x: auto; }
  .topbar nav a { padding: 6px 10px; white-space: nowrap; }
  .page-head { align-items: stretch; margin-bottom: 14px; }
  .page-head > form, .page-head .actions, .page-head .btn { width: 100%; justify-content: center; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
  .stat { padding: 10px 12px; }
  .stat strong { font-size: 1.25rem; }
  .cards { grid-template-columns: 1fr; }
  .panel { padding: 14px 12px; margin-bottom: 14px; }
  .opt { display: none; }
  .mobile-only { display: block; margin-top: 2px; font-size: .75rem; }
  .sticky { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 130px; max-width: 170px; box-shadow: 1px 0 0 var(--line); }
  th.sticky { z-index: 2; }
  td, th { padding: 7px 8px; }
  .filter { width: 100%; }
  .toolbar .muted.small { display: none; }
  .seg { width: 100%; }
  .seg a { flex: 1; text-align: center; padding: 6px 4px; }
  .serp li a { white-space: normal; }
  .inline-form > *, .inline-form input { width: 100%; }
  .row label { flex: 1 1 45%; }
  .chart .axis { font-size: 26px; }
  .chart .grid { stroke-width: 2; }
}

/* Connexion : case « Rester connecté » et titre avec logo */
.login-box .brand { font-size: 1.4rem; }
.login-box label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); }
.login-box label.check input { width: auto; margin: 0; }
/* Encoche des téléphones en mode application */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
