:root {
  color-scheme: light;
  --fond: #f5f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --bord: #e2e1dc;
  --texte: #0b0b0b;
  --texte-2: #52514e;
  --texte-3: #7d7c76;
  --grille: #e8e7e2;
  --accent: #2a78d6;
  --accent-texte: #1c5cab;
  --serie-google: #2a78d6;
  --serie-bing: #eb6834;
  --serie-prec: #a3a29b;
  --bon: #0c7a0c;
  --critique: #c0302f;
  --alerte: #a86c00;
  --serieux: #c45a2f;
  --bon-fond: #e3f4e3;
  --critique-fond: #fbe5e5;
  --alerte-fond: #fdf1d6;
  --serieux-fond: #fce9e0;
  --ombre: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --bord: #2e2e2b;
    --texte: #f0efec;
    --texte-2: #c3c2b7;
    --texte-3: #8d8c84;
    --grille: #2a2a28;
    --accent: #3987e5;
    --accent-texte: #86b6ef;
    --serie-google: #3987e5;
    --serie-bing: #d95926;
    --serie-prec: #6b6a64;
    --bon: #3fc93f;
    --critique: #f07070;
    --alerte: #fab219;
    --serieux: #ec835a;
    --bon-fond: #15301a;
    --critique-fond: #3a1818;
    --alerte-fond: #362a0d;
    --serieux-fond: #3a2216;
    --ombre: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fond: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --bord: #2e2e2b;
  --texte: #f0efec;
  --texte-2: #c3c2b7;
  --texte-3: #8d8c84;
  --grille: #2a2a28;
  --accent: #3987e5;
  --accent-texte: #86b6ef;
  --serie-google: #3987e5;
  --serie-bing: #d95926;
  --serie-prec: #6b6a64;
  --bon: #3fc93f;
  --critique: #f07070;
  --alerte: #fab219;
  --serieux: #ec835a;
  --bon-fond: #15301a;
  --critique-fond: #3a1818;
  --alerte-fond: #362a0d;
  --serieux-fond: #3a2216;
  --ombre: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent-texte); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.cache { display: none !important; }
.muet { color: var(--texte-3); }
.petit { font-size: 12px; }

/* ---------- Barre du haut */
.entete {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--fond) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--bord);
}
.entete-in { max-width: 1480px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; color: var(--texte); }
.logo svg { width: 22px; height: 22px; }
.nav { display: flex; gap: 2px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--texte-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.actif { background: var(--surface-2); color: var(--texte); }
.espace { flex: 1; }
.synchro-pastille { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--texte-2); }
.synchro-pastille .point { width: 8px; height: 8px; border-radius: 50%; background: var(--bon); }
.synchro-pastille .point.encours { background: var(--accent); animation: pulse 1s infinite alternate; }
.synchro-pastille .point.erreur { background: var(--critique); }
@keyframes pulse { to { opacity: .3; } }

.btn {
  border: 1px solid var(--bord); background: var(--surface); padding: 6px 12px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.principal:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critique); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-icone { border: 0; background: none; padding: 6px; border-radius: 8px; color: var(--texte-2); display: inline-flex; }
.btn-icone:hover { background: var(--surface-2); color: var(--texte); }

/* ---------- Page */
main { max-width: 1480px; margin: 0 auto; padding: 18px 20px 60px; }
.barre-filtres { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.segments { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.segments button { white-space: nowrap; flex: none; border: 0; background: none; padding: 5px 11px; border-radius: 7px; color: var(--texte-2); font-weight: 500; font-size: 13px; }
.segments button.actif { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }
:root[data-theme="dark"] .segments button.actif { background: #34342f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .segments button.actif { background: #34342f; } }
.recherche { position: relative; flex: 1 1 200px; max-width: 320px; }
.recherche input[type=text] { width: 100%; padding: 7px 10px 7px 32px; border-radius: 9px; border: 1px solid var(--bord); background: var(--surface); }
.recherche svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--texte-3); }
select.choix { padding: 6px 8px; border-radius: 9px; border: 1px solid var(--bord); background: var(--surface); }
input[type=text], input[type=password], textarea { border: 1px solid var(--bord); background: var(--surface); border-radius: 8px; padding: 7px 10px; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.puces { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.puce {
  border: 1px solid var(--bord); background: var(--surface); padding: 4px 10px; border-radius: 99px;
  font-size: 12.5px; color: var(--texte-2); display: inline-flex; gap: 6px; align-items: center;
}
.puce b { color: var(--texte); font-weight: 600; }
.puce.actif { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--texte); }
.puce .pastille { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Chiffres clés */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: 12px 14px; text-align: left;
  box-shadow: var(--ombre);
}
button.kpi { cursor: pointer; }
button.kpi.actif { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.kpi .lib { font-size: 12.5px; color: var(--texte-2); font-weight: 500; }
.kpi .val { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.kpi .cmp { font-size: 12px; color: var(--texte-3); margin-top: 2px; }
.delta { font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.delta.haut { color: var(--bon); }
.delta.bas { color: var(--critique); }
.delta.neutre { color: var(--texte-3); }

.carte-graphe { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: 14px 16px 8px; margin-bottom: 18px; box-shadow: var(--ombre); }
.carte-graphe .tete { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.carte-graphe h2 { font-size: 14px; }
.legende { display: flex; gap: 14px; font-size: 12.5px; color: var(--texte-2); flex-wrap: wrap; }
.legende span { display: inline-flex; align-items: center; gap: 6px; }
.legende i { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.legende i.pointille { border-top-style: dashed; }
.graphe { position: relative; height: 240px; }
.graphe svg { display: block; width: 100%; height: 100%; overflow: visible; }
.graphe .axe { fill: var(--texte-3); font-size: 11px; }
.graphe .grille { stroke: var(--grille); stroke-width: 1; }
.info-bulle {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--texte);
  border: 1px solid var(--bord); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  min-width: 130px;
}
.info-bulle .d { color: var(--texte-2); margin-bottom: 3px; font-weight: 500; }
.info-bulle .l { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.info-bulle .l span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--texte-2); }
.info-bulle .l i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- Grille de sites */
.liste-tete { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.liste-tete h2 { font-size: 15px; }
.grille-sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.site {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: 12px 14px 10px;
  cursor: pointer; box-shadow: var(--ombre); display: flex; flex-direction: column; gap: 8px; min-width: 0;
  transition: border-color .12s;
}
.site:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--bord)); }
.site.etat-pete { border-left: 3px solid var(--critique); }
.site.etat-chute { border-left: 3px solid var(--serieux); }
.site-tete { display: flex; align-items: center; gap: 8px; min-width: 0; }
.site-tete img { width: 16px; height: 16px; border-radius: 3px; flex: none; }
.site-tete .nom { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.etoile { border: 0; background: none; padding: 0 2px; color: var(--texte-3); font-size: 15px; line-height: 1; }
.etoile.on { color: #e3a008; }
.site-chiffres { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.site-chiffres .c { display: flex; flex-direction: column; }
.site-chiffres .c .v { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.site-chiffres .c .l { font-size: 11px; color: var(--texte-3); text-transform: uppercase; letter-spacing: .04em; }
.spark { height: 46px; position: relative; }
.spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.site-pied { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; min-height: 20px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--texte-2); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.tag i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.etat { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.etat.pete { background: var(--critique-fond); color: var(--critique); }
.etat.chute { background: var(--serieux-fond); color: var(--serieux); }
.etat.hausse { background: var(--bon-fond); color: var(--bon); }
.etat.inactif { background: var(--surface-2); color: var(--texte-3); }
.src { font-size: 10.5px; font-weight: 700; color: var(--texte-3); border: 1px solid var(--bord); border-radius: 4px; padding: 0 4px; }

/* ---------- Tableau */
.tableau-conteneur { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; overflow-x: auto; box-shadow: var(--ombre); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--texte-2); font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--bord); white-space: nowrap; position: sticky; top: 0; background: var(--surface); user-select: none; }
table.t th.triable { cursor: pointer; }
table.t th.triable:hover { color: var(--texte); }
table.t th.num, table.t td.num { text-align: right; }
table.t td { padding: 7px 10px; border-bottom: 1px solid var(--grille); white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t tbody tr.cliquable { cursor: pointer; }
table.t td.nom { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.t td.nom img { width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px; border-radius: 2px; }
table.t .mini-spark { width: 110px; height: 26px; display: block; }
.barre-selection {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 30; background: var(--surface);
  border: 1px solid var(--bord); border-radius: 12px; padding: 8px 12px; display: flex; gap: 8px; align-items: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); flex-wrap: wrap; max-width: calc(100vw - 32px);
}

/* ---------- Détail d'un site */
.fil { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.fil h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; min-width: 0; overflow-wrap: anywhere; }
.fil h1 img { width: 22px; height: 22px; border-radius: 4px; }
.onglets { display: flex; gap: 2px; border-bottom: 1px solid var(--bord); margin-bottom: 10px; flex-wrap: wrap; }
.onglets button { border: 0; background: none; padding: 8px 12px; color: var(--texte-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.onglets button.actif { color: var(--texte); border-bottom-color: var(--accent); }
.deux-col { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.panneau { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: 14px 16px; box-shadow: var(--ombre); margin-bottom: 16px; }
.panneau h3 { font-size: 13.5px; margin-bottom: 10px; }
.barre-ctr { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; margin-right: 6px; opacity: .55; }

/* ---------- Réglages */
.reglages { max-width: 860px; }
.reglages .panneau h2 { font-size: 16px; margin-bottom: 4px; }
.reglages .panneau > p { color: var(--texte-2); margin: 0 0 12px; }
.ligne-compte { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--grille); flex-wrap: wrap; }
.ligne-compte .qui { flex: 1; min-width: 200px; }
.ligne-compte .qui b { display: block; }
.ok-txt { color: var(--bon); }
.ko-txt { color: var(--critique); }
.etapes { margin: 0; padding-left: 20px; color: var(--texte-2); }
.etapes li { margin-bottom: 6px; }
.etapes code, .code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; overflow-wrap: anywhere; }
.form-ligne { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.form-ligne input[type=text], .form-ligne input[type=password] { flex: 1 1 220px; }
textarea { width: 100%; min-height: 90px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.message { padding: 9px 12px; border-radius: 8px; margin-top: 10px; font-size: 13px; }
.message.ok { background: var(--bon-fond); color: var(--bon); }
.message.ko { background: var(--critique-fond); color: var(--critique); }
.message.info { background: var(--surface-2); color: var(--texte-2); }
.vide { text-align: center; padding: 50px 20px; color: var(--texte-2); }
.vide h2 { color: var(--texte); margin-bottom: 8px; font-size: 18px; }
.progression { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progression div { height: 100%; background: var(--accent); transition: width .3s; }
.menu-tags { position: absolute; z-index: 40; background: var(--surface); border: 1px solid var(--bord); border-radius: 10px; padding: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.2); min-width: 200px; max-height: 320px; overflow: auto; }
.menu-tags label { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.menu-tags label:hover { background: var(--surface-2); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .deux-col { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .entete-in { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  main { padding: 14px 16px 60px; }
  .synchro-pastille .txt { display: none; }
  .kpi .val { font-size: 21px; }
  .graphe { height: 200px; }
  .recherche { max-width: none; flex-basis: 100%; }
  .grille-sites { grid-template-columns: 1fr; }
}

/* ---------- Appli téléphone (écran étroit / appli installée sur l'écran d'accueil) */
.onglets-bas { display: none; }
button, a, .puce, .segments button { touch-action: manipulation; }
.graphe { touch-action: pan-y; }
@media (max-width: 700px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
  .entete-in { padding: 8px 16px; gap: 8px; flex-wrap: nowrap; }
  .nav { display: none; }
  .logo { font-size: 16px; }
  #btn-synchro { padding: 7px 9px; font-size: 0; gap: 0; }
  #btn-synchro svg { width: 17px; height: 17px; }
  main { padding: 12px 16px 24px; }
  input[type=text], input[type=password], select, textarea { font-size: 16px; } /* évite le zoom automatique d'iOS */
  .barre-filtres { gap: 8px; margin-bottom: 10px; }
  .barre-filtres > .segments { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .barre-filtres > .segments::-webkit-scrollbar, .puces::-webkit-scrollbar { display: none; }
  .barre-filtres > .muet { flex-basis: 100%; }
  .puces { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; }
  .puce { flex: none; padding: 6px 11px; }
  .kpis { gap: 8px; margin-bottom: 10px; }
  .kpi { padding: 10px 11px; border-radius: 11px; }
  .kpi .lib { font-size: 12px; }
  .kpi .val { font-size: 20px; }
  .kpi .cmp { font-size: 11px; }
  .kpi .cmp span:last-child { display: block; }
  .carte-graphe { padding: 12px 10px 6px; margin-bottom: 14px; }
  .graphe { height: 190px; }
  .liste-tete { gap: 8px; }
  .site { padding: 11px 12px 9px; gap: 6px; }
  .site-chiffres { gap: 12px; }
  .site-chiffres .c .v { font-size: 16px; }
  .spark { height: 38px; }
  .fil { gap: 8px; }
  .fil h1 { font-size: 18px; flex-basis: 100%; order: -1; }
  .fil .espace { display: none; }
  .fil .btn { padding: 6px 10px; font-size: 13px; }
  .panneau { padding: 12px; }
  .barre-selection { bottom: calc(72px + env(safe-area-inset-bottom)); }
  .onglets-bas {
    display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--bord); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .onglets-bas a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 500; color: var(--texte-3); padding: 4px 0; text-decoration: none; }
  .onglets-bas a svg { width: 23px; height: 23px; }
  .onglets-bas a.actif { color: var(--accent-texte); }
}
