/* ==========================================================================
   SondePrix — Design system
   Thème clair par défaut, thème sombre automatique, mobile-first responsive
   ========================================================================== */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --ok: #059669;
  --warn: #b45309;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 28px -14px rgba(15, 23, 42, .16);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);
  --r: 14px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a111e;
    --surface: #111b2d;
    --surface2: #0d1626;
    --ink: #e8edf6;
    --muted: #8a99b0;
    --line: #1e2b43;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px -16px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
small { font-size: 12.5px; }
h1, h2, h3 { margin: 0; }

/* ---------- Animations ---------- */
@keyframes rise   { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade   { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop    { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes sheet  { from { transform: translateY(100%); } to { transform: none; } }
@keyframes drop   { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes shake  { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes pulse  { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dot, var(--ok)) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }
@keyframes draw   { to { stroke-dashoffset: 0; } }
@keyframes grow   { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes slide  { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Apparition en cascade des blocs (désactivée lors des actualisations automatiques) */
#view:not(.still) > *,
#view:not(.still) .kpi,
#view:not(.still) .pcard,
#view:not(.still) .store,
#view:not(.still) .grid-2 > .card {
  animation: rise .55s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}
#view:not(.still) .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.3s .15s var(--ease) forwards; }
#view:not(.still) .fadein { animation: fade 1s .5s both; }
#view:not(.still) .bar i { transform-origin: left; animation: grow 1s .3s var(--ease) both; }

/* ---------- En-tête ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 28px;
  padding: 12px 32px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; letter-spacing: -.02em; text-decoration: none; }
.logo { width: 32px; height: 32px; flex: none; }
.top nav { display: flex; gap: 4px; }
.top nav a {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none;
  transition: background .2s, color .2s;
}
.top nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: none; }
.top nav a:hover { color: var(--ink); background: var(--surface2); }
.top nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 11%, transparent); }
.actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.live { --dot: var(--ok); display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface2); white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); animation: pulse 2s infinite; }
.live.busy { --dot: var(--accent); color: var(--accent); }
.live.bad { --dot: var(--bad); color: var(--bad); }
.live.bad i { animation: none; }
.user { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 3px 4px 3px 3px; border-radius: 999px; transition: background .2s; }
.user:hover { background: var(--surface2); }
.uinfo { display: grid; line-height: 1.2; }
.uinfo b { font-size: 13px; }
.uinfo small { color: var(--muted); font-size: 12px; }
.av { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.av.lg { width: 54px; height: 54px; font-size: 18px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform .18s var(--ease), box-shadow .2s, background .2s, border-color .2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn.danger { color: var(--bad); }
.btn.google { width: 100%; padding: 11px 15px; }
.btn.google svg { width: 18px; height: 18px; }
#refreshBtn:disabled .ic { animation: spin .8s linear infinite; }
.ic { display: inline-block; }

/* ---------- Contenu ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 32px 32px 40px; }
.page-title { font-size: 30px; font-weight: 750; letter-spacing: -.025em; line-height: 1.15; }
.page-sub { margin: 8px 0 26px; color: var(--muted); max-width: 66ch; }
.foot { max-width: 1240px; margin: 0 auto; padding: 8px 32px 40px; display: flex; gap: 12px 24px; flex-wrap: wrap; justify-content: space-between; color: var(--muted); font-size: 13px; }
.foot nav { display: flex; gap: 18px; }
.foot a { text-decoration: none; }
.foot a:hover { color: var(--ink); }

/* Bannières */
.err-note, .scrape-note {
  position: relative; overflow: hidden;
  margin: 0 0 20px; padding: 14px 18px; border-radius: 12px;
  display: flex; align-items: center; gap: 14px; justify-content: space-between;
  animation: drop .45s var(--ease) both;
}
.err-note { border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); color: var(--bad); font-weight: 600; animation: drop .45s var(--ease) both, shake .5s .3s; }
.err-note::before { content: "!"; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--bad); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.err-note span { flex: 1; }
.scrape-note { justify-content: flex-start; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.scrape-note .spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.scrape-note p { margin: 0; font-size: 14px; }
.scrape-note::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 30%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: slide 1.6s linear infinite; }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head p { margin: 4px 0 0; font-size: 13.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.kpis { display: grid; gap: 16px; margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpis.five { grid-template-columns: repeat(5, 1fr); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); display: grid; gap: 4px; align-content: start; transition: transform .25s var(--ease), box-shadow .25s; }
.kpi:hover { transform: translateY(-3px); }
.kpi span { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi strong { font-size: 28px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.kpi strong.sm { font-size: 18px; padding-top: 6px; }
.kpi small { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; margin: 0; }
.empty p { margin: 0 0 8px; }
.empty .ico { width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-size: 26px; font-weight: 800; animation: floaty 3s ease-in-out infinite; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar p { margin: 0; }

/* Variations */
.up { color: var(--bad); font-weight: 600; }
.down { color: var(--ok); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--surface2); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.badge.err { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.badge.wait { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.run { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.badge.run::before { width: 10px; height: 10px; background: none; border: 2px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; }
.sd { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.tag { margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }

/* ---------- Contrôles ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; max-width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[readonly] { background: var(--surface2); color: var(--muted); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; margin-bottom: 14px; }
label input, label select { width: 100%; font-weight: 400; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .2s, color .2s; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s; }
.chip:hover { color: var(--ink); border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#sw { display: none; }
.chk { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; margin: 0; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-weight: 600; transition: all .2s; }
.chk input { width: auto; accent-color: var(--accent); }
.chk:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }

/* ---------- Graphique ---------- */
.lg-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.lgb { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .2s; }
span.lgb { cursor: default; }
.lgb i { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.lgb.best i { background: var(--accent); }
.lgb.band i { opacity: .3; border-radius: 3px; }
.lgb.off { opacity: .45; text-decoration: line-through; }
.lgb.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lgb small { color: var(--muted); font-weight: 500; }
.cnt { font-style: normal; font-size: 11px; font-weight: 700; color: var(--muted); }
.chart { position: relative; height: 320px; width: 100%; }
.chart svg { width: 100%; height: 100%; display: block; touch-action: pan-y; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .guide { stroke: var(--muted); stroke-dasharray: 3 3; opacity: .6; }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; opacity: 0; transition: opacity .15s, r .15s; }
.chart .pt.on { opacity: 1; r: 6; }
.pop { position: absolute; width: 290px; max-width: calc(100% - 8px); padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); z-index: 3; }
.pp-top { display: flex; gap: 12px; }
.pp-top small { color: var(--muted); display: block; }
.pp-top b { display: block; font-size: 22px; letter-spacing: -.02em; }
.pp-top a { color: var(--accent); font-weight: 600; font-size: 13px; text-decoration: none; }
.ps { display: flex; align-items: center; font-size: 12.5px; color: var(--muted); }
.ps i { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

div.best { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 18px; margin-top: 18px; padding: 16px 18px; border-radius: 12px; background: color-mix(in srgb, var(--ok) 8%, var(--surface2)); border: 1px solid color-mix(in srgb, var(--ok) 25%, var(--line)); }
div.best b { font-size: 22px; letter-spacing: -.02em; }
div.best .others { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
div.best .others span { padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-weight: 600; }
div.best .others span.muted { background: none; border: 0; color: var(--muted); font-weight: 500; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 14px 16px 10px; color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td { padding: 13px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface2); }
td a { text-decoration: none; }
td a:hover strong { color: var(--accent); }
.lnk { color: var(--accent); font-weight: 600; text-decoration: none; white-space: nowrap; }
.log-row { cursor: pointer; }
.car { display: inline-block; width: 14px; color: var(--muted); }
table .empty { padding: 30px; }
.table-wrap td:first-child { min-width: 150px; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 13px 0; border-top: 1px solid var(--line); text-decoration: none; transition: padding .2s; }
.row:first-of-type { border-top: 0; }
a.row:hover { padding-left: 6px; }
.row small { display: block; color: var(--muted); }

/* ---------- Produits ---------- */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 20px; }
.pcard { display: flex; flex-direction: column; gap: 14px; padding: 20px; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); transition: transform .3s var(--ease), box-shadow .3s, border-color .3s; }
.pcard:hover { transform: translateY(-5px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: var(--shadow-lg); }
.pc-head { display: flex; gap: 14px; align-items: center; }
.pc-head h3 { font-size: 15.5px; font-weight: 700; margin-top: 5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pc-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cat { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pc-price { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pc-price b { font-size: 28px; font-weight: 750; letter-spacing: -.03em; }
.spark { width: 100%; height: 34px; display: block; }
.ocs { display: flex; flex-wrap: wrap; gap: 6px; }
.oc { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface2); font-size: 12.5px; gap: 2px; }
.oc b { margin-left: 6px; }
.oc.low { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.oc .cnt { margin-left: 4px; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.pc-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); padding-top: 12px; border-top: 1px dashed var(--line); }
.pc-foot b { color: var(--ink); font-weight: 600; }
.pimg { width: 48px; height: 48px; border-radius: 12px; flex: none; object-fit: contain; background: #fff; border: 1px solid var(--line); display: inline-grid; place-items: center; font-size: 22px; }
span.pimg { background: hsl(var(--h, 220) 70% 93%); }
.pimg.sm { width: 46px; height: 46px; }
.pimg.lg { width: 58px; height: 58px; }
.pimg.xl { width: 88px; height: 88px; border-radius: 16px; }

.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; transition: color .2s, transform .2s; }
.back:hover { color: var(--accent); transform: translateX(-3px); }
.hero { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; padding: 22px; border-radius: var(--r); border: 1px solid var(--line); background: linear-gradient(120deg, color-mix(in srgb, var(--accent) 9%, var(--surface)), var(--surface) 60%); box-shadow: var(--shadow); }
.hero h2 { font-size: 24px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 6px; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }
.of-bar { display: flex; gap: 10px; padding: 16px 20px 12px; flex-wrap: wrap; }
.of-bar input { flex: 1; min-width: 200px; }
.of-stores { padding: 0 20px 14px; margin: 0; }
.of-pager { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; font-size: 14px; }

/* ---------- Enseignes ---------- */
.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.store { display: grid; gap: 14px; align-content: start; transition: transform .3s var(--ease); }
.store:hover { transform: translateY(-3px); }
.store header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.store h3 { font-size: 17px; }
.url { color: var(--accent); font-size: 13px; word-break: break-all; text-decoration: none; }
.store dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 13.5px; }
.store dt { color: var(--muted); } .store dd { margin: 0; font-weight: 600; text-align: right; }
.sel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sel > div { min-width: 0; padding: 8px 10px; border-radius: 9px; background: var(--surface2); border: 1px solid var(--line); }
.sel span { display: block; font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.sel code { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg { margin: 0; padding: 9px 12px; border-radius: 9px; font-size: 13px; border-left: 3px solid var(--muted); background: var(--surface2); }
.msg.ok { border-color: var(--ok); } .msg.err { border-color: var(--bad); } .msg.wait { border-color: var(--warn); }

/* ---------- Réglages ---------- */
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.set-grid .card { margin: 0; display: grid; gap: 4px; }
.set-grid .card > h2 { margin-bottom: 12px; }
.set-grid .card .btn { justify-self: start; margin-top: 6px; }
.set-grid p.muted { margin: 0 0 12px; font-size: 13.5px; }
.profile { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile b { display: block; } .profile small { color: var(--muted); }
.sw-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 13px 0; border-top: 1px solid var(--line); }
.sw-row .muted { font-size: 13px; }
.sw-row input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 999px; padding: 0; border: 0; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .25s; }
.sw-row input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .25s var(--ease); }
.sw-row input[type=checkbox]:checked { background: var(--accent); }
.sw-row input[type=checkbox]:checked::after { transform: translateX(18px); }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
button.sw { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface); cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s; }
button.sw:hover { transform: scale(1.12); }
button.sw.on { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- Fenêtres modales ---------- */
dialog.modal { padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); width: min(500px, calc(100vw - 24px)); max-height: 92vh; overflow: auto; box-shadow: var(--shadow-lg); }
dialog.modal.wide { width: min(740px, calc(100vw - 24px)); }
dialog.modal[open] { animation: pop .3s var(--ease); }
dialog.modal::backdrop { background: rgba(10, 17, 30, .55); backdrop-filter: blur(4px); animation: fade .3s; }
dialog.modal form { padding: 26px; }
dialog.modal h2 { font-size: 20px; letter-spacing: -.02em; margin-bottom: 4px; }
dialog.modal form > p.muted { margin: 0 0 18px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Notification (toast) ---------- */
.toast { position: fixed; z-index: 100; left: 50%; bottom: 28px; transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
  max-width: min(460px, calc(100vw - 28px)); padding: 13px 18px; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); border-left: 4px solid var(--muted);
  transition: opacity .3s, transform .4s var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--bad); }
.toast.err.show { animation: shake .45s .15s; }

/* ---------- Connexion ---------- */
#auth { position: fixed; inset: 0; z-index: 999; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--bg); overflow: auto; }
.auth-side { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; padding: 48px 56px; color: #fff;
  background: radial-gradient(900px 500px at 10% -10%, color-mix(in srgb, var(--accent) 80%, #fff 0%), transparent 60%), linear-gradient(160deg, #0b1b3f, #0a1226 70%); }
.auth-side::before, .auth-side::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .06); animation: floaty 7s ease-in-out infinite; }
.auth-side::before { width: 380px; height: 380px; right: -120px; bottom: -100px; }
.auth-side::after { width: 200px; height: 200px; right: 160px; top: 90px; animation-delay: -3s; }
.auth-side > * { position: relative; z-index: 1; }
.auth-side .brand { color: #fff; }
.auth-side h2 { font-size: 40px; line-height: 1.1; letter-spacing: -.03em; max-width: 14ch; font-weight: 750; }
.auth-side > div > p { margin: 16px 0 0; color: rgba(255, 255, 255, .78); max-width: 46ch; font-size: 16px; }
.auth-feats { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 14px; }
.auth-feats li { display: flex; align-items: center; gap: 12px; font-weight: 550; animation: rise .6s var(--ease) both; }
.auth-feats li:nth-child(2) { animation-delay: .12s; } .auth-feats li:nth-child(3) { animation-delay: .24s; }
.auth-feats li::before { content: "✓"; flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .16); font-size: 13px; }
.auth-side small { color: rgba(255, 255, 255, .55); }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
#auth form { display: grid; gap: 14px; width: min(390px, 100%); animation: rise .6s var(--ease) both; }
#auth .brand.mobile { display: none; }
#auth h2.t { font-size: 28px; letter-spacing: -.025em; }
#auth .lead { margin: -6px 0 6px; color: var(--muted); }
#auth input { width: 100%; padding: 12px 14px; }
#auth a { color: var(--accent); font-weight: 600; cursor: pointer; font-size: 14px; }
#authMsg { margin: 0; font-size: 14px; }
#authMsg:not(:empty) { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 10%, transparent); color: var(--bad); animation: drop .35s var(--ease), shake .45s .1s; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .uinfo, .live { display: none; }
  .kpis.five { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
  .grid-2, .set-grid { grid-template-columns: 1fr; }
  #auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  #auth .brand.mobile { display: inline-flex; margin-bottom: 8px; }
}
@media (max-width: 820px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .top { padding: 10px 16px; gap: 12px; }
  .brand { font-size: 17px; }
  .logo { width: 30px; height: 30px; }
  .actions { gap: 8px; }
  .actions .lbl, #logoutBtn, .actions .hide-m { display: none; }
  #refreshBtn { padding: 9px 12px; }
  /* Navigation : barre d'onglets en bas de l'écran */
  .top nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -12px rgba(15, 23, 42, .18);
  }
  .top nav a { flex-direction: column; gap: 3px; padding: 8px 4px; font-size: 11.5px; text-align: center; border-radius: 12px; }
  .top nav a svg { display: block; width: 22px; height: 22px; }
  main { padding: 20px 16px 24px; }
  .page-title { font-size: 25px; }
  .page-sub { margin-bottom: 20px; font-size: 14px; }
  .foot { padding: 0 16px 24px; flex-direction: column; }
  .card { padding: 16px; margin-bottom: 16px; }
  .kpis, .kpis.five { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpis.five .kpi:last-child:nth-child(odd) { grid-column: span 2; }
  .kpi { padding: 14px 16px; }
  .kpi strong { font-size: 23px; }
  .chart { height: 250px; }
  .chips { display: none; }
  #sw { display: block; width: 100%; }
  .card-head > div:last-child { width: 100%; }
  .seg { width: 100%; justify-content: space-between; }
  .seg button { flex: 1; padding: 7px 4px; }
  .pgrid, .store-grid { grid-template-columns: 1fr; gap: 16px; }
  .hero { flex-direction: column; align-items: flex-start; padding: 18px; }
  .hero h2 { font-size: 21px; }
  .pimg.xl { width: 68px; height: 68px; }
  .grid2 { grid-template-columns: 1fr; }
  th, td { padding-left: 12px; padding-right: 12px; }
  table { font-size: 13.5px; min-width: 620px; }
  .table-wrap tr > :first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; box-shadow: 1px 0 0 var(--line); }
  .of-bar { padding: 14px 16px 10px; } .of-stores { padding: 0 16px 12px; } .of-pager { padding: 12px 16px; }
  .err-note, .scrape-note { padding: 12px 14px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .auth-main { align-items: start; padding-top: 56px; }
  /* Fenêtres : feuille qui monte depuis le bas */
  dialog.modal, dialog.modal.wide { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; border-bottom: 0; max-height: 94vh; }
  dialog.modal[open] { animation: sheet .35s var(--ease); }
  dialog.modal form { padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); }
  .modal-actions .btn { flex: 1; }
  .modal-actions #epDelete { flex-basis: 100%; margin-right: 0 !important; order: 3; }
  /* évite le zoom automatique d'iOS */
  input, select, textarea { font-size: 16px; }
}
@media (hover: none) {
  .pcard:hover, .kpi:hover, .store:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}


/* ==========================================================================
   Catalogue d'enseignes (fenêtre « Ajouter une enseigne »)
   ========================================================================== */
.store-list { border: 1px solid var(--line, #e5e7eb); border-radius: 10px; overflow: hidden; margin: 0 0 12px; }
.store-opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line, #e5e7eb); background: transparent; text-align: left; cursor: pointer; font: inherit; color: inherit; transition: background .2s; }
.store-opt:last-child { border-bottom: 0; }
.store-opt:hover:not(:disabled) { background: rgba(127, 127, 127, .08); }
.store-opt.on { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.store-opt:disabled { opacity: .55; cursor: default; }
.store-opt .sd { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.store-opt b { display: block; font-size: 14px; }
.store-opt small { display: block; font-size: 12px; opacity: .7; }
.store-opt .rt { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; opacity: .8; white-space: nowrap; }
.store-opt.on .rt { color: var(--accent); opacity: 1; }
/* Enseigne en cours d'ajout : reste bien visible malgré l'état désactivé */
.store-opt.is-busy:disabled { opacity: 1; background: color-mix(in srgb, var(--accent) 9%, transparent); cursor: progress; }
.store-opt.is-busy .rt { color: var(--accent); opacity: 1; font-weight: 600; }
.adv-toggle { display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px 2px; border: 0; background: transparent; font: inherit; font-size: 14px; color: inherit; opacity: .75; cursor: pointer; text-align: left; }
.adv-toggle:hover { opacity: 1; }
#advBox { margin: 4px 0 8px; }

/* Garantit que l'attribut hidden masque bien les éléments stylés par .btn / .store-opt */
#storeSubmit[hidden], #advBox[hidden] { display: none !important; }

/* ---------- Logo d'enseigne (cartes Enseignes, tableau de bord, fenêtre d'ajout) ---------- */
.store-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.store-id h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-logo {
  width: 44px; height: 44px; flex: none;
  border-radius: 12px; object-fit: contain;
  background: transparent; border: none; padding: 0;
}
.store-logo.sm { width: 32px; height: 32px; border-radius: 9px; padding: 3px; }
.store-logo.ph {
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: 18px; line-height: 1; color: #fff;
  background: var(--c, #2563eb); border: 0; padding: 0;
}
.store-logo.sm.ph { font-size: 14px; }

/* Champs d'authentification masqués (pseudo / confirmation) */
#authForm input[hidden] { display: none; }

/* ==========================================================================
   Retours dans les fenêtres : erreur, traitement en cours, bouton animé
   ========================================================================== */

/* Message d'erreur affiché dans la fenêtre */
.form-err {
  margin: 14px 0 0; padding: 12px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--bad) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  border-left: 4px solid var(--bad);
  color: var(--ink); font-size: 14px; line-height: 1.45;
  animation: drop .3s var(--ease);
}
.form-err b { display: block; margin-bottom: 2px; color: var(--bad); font-weight: 700; }
.form-err p { margin: 0; }
.form-err small { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; word-break: break-word; }
dialog.shake { animation: shake .4s; }

/* Bandeau « traitement en cours » avec barre de progression indéterminée */
.form-busy {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px;
  margin: 14px 0 0; padding: 14px 16px 16px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  animation: drop .3s var(--ease);
}
.form-busy b { display: block; font-size: 14px; }
.form-busy small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.form-busy::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 30%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: slide 1.4s linear infinite;
}
.fb-spin, .mini-spin {
  display: inline-block; flex: none; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.fb-spin { width: 24px; height: 24px; }
.mini-spin { width: 13px; height: 13px; border-width: 2px; }

/* Pendant le traitement, le contenu de la fenêtre est figé */
form.is-busy .store-list,
form.is-busy .adv-toggle,
form.is-busy #advBox,
form.is-busy label,
form.is-busy fieldset { opacity: .55; pointer-events: none; }
form.is-busy .store-list .store-opt.is-busy { opacity: 1; }

/* Bouton en cours d'enregistrement (spinner) puis confirmation (coche verte) */
.btn.loading, .btn.loading:disabled { opacity: .92; cursor: progress; transform: none; box-shadow: none; }
.btn.loading::before {
  content: ""; display: inline-block; flex: none; width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.btn.done, .btn.done:disabled { opacity: 1; }
.btn.done::before { content: "✓"; font-weight: 800; }
.btn.primary.done { background: var(--ok); border-color: var(--ok); }

/* Mouvement réduit : on garde un retour visuel (rotation lente) plutôt que de le supprimer */
@media (prefers-reduced-motion: reduce) {
  .btn.loading::before, .fb-spin, .mini-spin { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
  .form-busy::after { animation: none !important; width: 100%; opacity: .35; }
}