/* ===========================================================================
   PEA Screener — feuille de style
   Palette de visualisation validée (bande de clarté, plancher de chroma,
   séparation daltonisme, contraste sur surface). Mode sombre choisi pas à pas,
   pas obtenu par inversion automatique.
   Aucune police distante : pile système uniquement.
   =========================================================================== */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --surface-2:       #f2f2ee;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, .10);
  --border-strong:   rgba(11, 11, 11, .18);

  --series-1:        #2a78d6;   /* bleu   — score, cours */
  --series-2:        #eb6834;   /* orange — MM200 */

  /* Rampe séquentielle bleue : magnitude du score */
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5;
  --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;

  --good:      #0ca30c;
  --warning:   #fab219;
  --serious:   #ec835a;
  --critical:  #d03b3b;
  --delta-up:  #006300;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 1px 2px rgba(11,11,11,.05), 0 8px 24px rgba(11,11,11,.06);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255,255,255,.10);
    --border-strong:  rgba(255,255,255,.18);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --delta-up:       #0ca30c;
    --shadow:         0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255,255,255,.10);
  --border-strong:  rgba(255,255,255,.18);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --delta-up:       #0ca30c;
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 640; letter-spacing: -.011em; }
p { margin: 0; }
button { font: inherit; color: inherit; }

/* --------------------------------------------------------------------- */
/* Barre supérieure                                                       */
/* --------------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-main {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px 8px;
  max-width: 1280px; margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }   /* sans quoi le sous-titre déborde sous le sélecteur */
.brand-mark { width: 26px; height: 26px; color: var(--series-1); flex: none; }
.brand h1 { font-size: 17px; white-space: nowrap; }
.brand-sub {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.control {
  appearance: none;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 11px; font-size: 13px; font-variant-numeric: tabular-nums;
  max-width: 150px;
}

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-2); }

/* Onglets — défilement horizontal sur petit écran */
.tabs {
  display: flex; gap: 2px; padding: 0 12px 8px;
  max-width: 1280px; margin: 0 auto;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none; background: none; border: 0; cursor: pointer;
  padding: 7px 13px; border-radius: 999px;
  font-size: 13.5px; font-weight: 550; color: var(--text-secondary);
  white-space: nowrap;
}
.tab:hover { background: var(--surface-2); }
.tab.is-active { background: var(--text-primary); color: var(--page); }

.badge {
  display: inline-grid; place-items: center; min-width: 17px; height: 17px;
  margin-left: 6px; padding: 0 5px; border-radius: 999px;
  background: var(--series-1); color: #fff;
  font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.tab.is-active .badge { background: var(--page); color: var(--text-primary); }

/* --------------------------------------------------------------------- */
/* Structure                                                              */
/* --------------------------------------------------------------------- */

main {
  max-width: 1280px; margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 26px 0 11px;
}
.section-title:first-child { margin-top: 4px; }
.section-title h2 { font-size: 15px; }
.section-title .hint { font-size: 12.5px; color: var(--text-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.prose { font-size: 14px; color: var(--text-secondary); max-width: 68ch; }
.prose p + p { margin-top: 11px; }
.prose strong { color: var(--text-primary); font-weight: 600; }

/* --------------------------------------------------------------------- */
/* Tuiles de synthèse                                                     */
/* --------------------------------------------------------------------- */

.tiles {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
}
.tile { padding: 13px 15px; }
.tile-label {
  font-size: 11.5px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .045em; font-weight: 600;
}
.tile-value {
  font-size: 25px; font-weight: 650; letter-spacing: -.02em;
  margin-top: 3px; line-height: 1.15;
}
.tile-note { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* --------------------------------------------------------------------- */
/* Tableau du classement                                                  */
/* --------------------------------------------------------------------- */

.rank-list { display: flex; flex-direction: column; }

.rank-row {
  display: grid;
  grid-template-columns: 42px minmax(0,1fr) 92px 180px;
  align-items: center; gap: 12px;
  padding: 11px 15px; border-bottom: 1px solid var(--border);
  cursor: pointer; text-align: left; width: 100%;
  background: none; border-left: 0; border-right: 0; border-top: 0;
}
.rank-row:last-child { border-bottom: 0; }
.rank-row:hover { background: var(--surface-2); }

.rank-head {
  display: grid;
  grid-template-columns: 42px minmax(0,1fr) 92px 180px;
  gap: 12px; padding: 9px 15px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}

/* Clé de lecture des 7 barres : l'identité des axes ne repose pas
   sur la couleur, qui encode uniquement la magnitude de la note. */
.axes-key { display: flex; gap: 3px; margin-top: 4px; }
.axes-key span {
  flex: 1; min-width: 4px; text-align: center;
  font-size: 9px; font-weight: 600; letter-spacing: 0;
  color: var(--text-muted); text-transform: none;
  overflow: hidden; white-space: nowrap;
}

.rank-num {
  font-variant-numeric: tabular-nums; font-weight: 640; font-size: 15px;
  display: flex; align-items: baseline; gap: 4px;
}
.rank-delta { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-delta.up { color: var(--delta-up); }
.rank-delta.down { color: var(--critical); }
.rank-delta.flat { color: var(--text-muted); }

.rank-name { min-width: 0; }
.rank-name strong {
  display: block; font-size: 14.5px; font-weight: 580;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rank-meta {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.rank-score { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 620; }
.rank-score small { display: block; font-size: 11px; font-weight: 500; color: var(--text-muted); }

/* Barres de sous-scores : 7 axes, hauteur = note */
.axes { display: flex; align-items: flex-end; gap: 3px; height: 30px; }
.axis-bar {
  flex: 1; min-width: 4px; border-radius: 2px 2px 0 0;
  background: var(--seq-400); position: relative;
}
.axis-bar[data-null="1"] {
  background: repeating-linear-gradient(45deg,
    var(--grid) 0 3px, transparent 3px 6px);
  height: 100% !important;
}

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.tag.new { background: color-mix(in srgb, var(--series-1) 16%, transparent);
           color: var(--series-1); border-color: transparent; }

/* --------------------------------------------------------------------- */
/* Recherche et filtres du classement                                     */
/* --------------------------------------------------------------------- */

.search-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 15px; border-bottom: 1px solid var(--border);
}

.search-field { position: relative; flex: 1 1 200px; min-width: 0; }
.search-field svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-muted); pointer-events: none;
}
.search-field input {
  width: 100%; appearance: none;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 32px 9px 32px; font: inherit; font-size: 14px;
}
.search-field input::placeholder { color: var(--text-muted); }
.search-field input:focus {
  outline: 2px solid var(--series-1); outline-offset: -1px;
  background: var(--surface);
}
.search-clear {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: none; cursor: pointer; display: grid; place-items: center;
  color: var(--text-muted);
}
.search-clear svg { position: static; transform: none; width: 13px; height: 13px; }
.search-clear:hover { background: var(--surface-2); color: var(--text-primary); }
/* L'attribut hidden pose display:none, mais la règle de classe ci-dessus
   impose display:grid et l'emporte : sans cette ligne, la croix reste
   visible alors que le champ est vide. */
.search-clear[hidden] { display: none; }

/* Masque la croix native de type="search" : on en fournit une, deux
   feraient doublon. */
.search-field input::-webkit-search-cancel-button { display: none; }

.filter-select {
  appearance: none; flex: 0 1 auto; max-width: 46%;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 13.5px;
}

.result-line {
  padding: 9px 15px; font-size: 12.5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.result-line button {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--series-1);
}

.more-row { padding: 14px 15px; text-align: center; }

/* Repère visuel : la valeur fait-elle partie de la sélection du jour ? */
.rank-row.is-selected .rank-num > span:first-child { color: var(--series-1); }

/* --------------------------------------------------------------------- */
/* Insights                                                               */
/* --------------------------------------------------------------------- */

.insight {
  display: flex; gap: 12px; padding: 13px 15px;
  border-bottom: 1px solid var(--border);
}
.insight:last-child { border-bottom: 0; }
.insight-icon {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--surface-2); color: var(--text-secondary);
}
.insight-icon svg { width: 15px; height: 15px; }
.insight[data-sev="5"] .insight-icon { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.insight[data-sev="4"] .insight-icon { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--series-1); }
.insight[data-sev="2"] .insight-icon { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--serious); }

.insight-body { min-width: 0; }
.insight-kind {
  font-size: 11px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .045em; color: var(--text-muted); margin-bottom: 1px;
}
.insight-msg { font-size: 14px; color: var(--text-primary); }
.insight-link {
  background: none; border: 0; padding: 0; margin-top: 4px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--series-1);
}

/* --------------------------------------------------------------------- */
/* Graphiques                                                             */
/* --------------------------------------------------------------------- */

.chart-wrap { padding: 14px 15px 10px; position: relative; }
.chart-title { font-size: 13.5px; font-weight: 620; margin-bottom: 2px; }
.chart-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 9px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
}
.legend-swatch { width: 11px; height: 3px; border-radius: 2px; flex: none; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 12px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transform: translate(-50%, -100%); opacity: 0; transition: opacity .1s;
}
.tooltip.on { opacity: 1; }
.tooltip-title { font-weight: 640; margin-bottom: 2px; }
.tooltip-row { display: flex; align-items: center; gap: 6px; }
.tooltip-dot { width: 7px; height: 7px; border-radius: 2px; flex: none; }

/* --------------------------------------------------------------------- */
/* Fiche détail                                                           */
/* --------------------------------------------------------------------- */

.detail-sheet { position: fixed; inset: 0; z-index: 50; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); }

.detail-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--page); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slide-in .22s cubic-bezier(.32,.72,0,1);
  padding-top: env(safe-area-inset-top);
}
@keyframes slide-in { from { transform: translateX(22px); opacity: .4; } }

.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 15px 16px 12px; border-bottom: 1px solid var(--border);
}
.detail-head h2 { font-size: 17px; }
.detail-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.detail-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

/* Tableaux de valeurs brutes */
.kv { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.kv th, .kv td { padding: 8px 0; border-bottom: 1px solid var(--border); text-align: left; }
.kv th { font-weight: 500; color: var(--text-secondary); }
.kv td { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
.kv .na { color: var(--text-muted); font-weight: 450; }

/* Barre de note d'un axe */
.axis-row {
  display: grid; grid-template-columns: 74px 1fr 46px;
  align-items: center; gap: 10px; padding: 6px 0;
}
.axis-label { font-size: 13px; color: var(--text-secondary); }
.axis-track { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.axis-fill { height: 100%; border-radius: 4px; background: var(--seq-400); }
.axis-value {
  font-size: 13px; font-variant-numeric: tabular-nums;
  text-align: right; font-weight: 580; white-space: nowrap;
}
.axis-value.na { color: var(--text-muted); font-weight: 450; }

/* --------------------------------------------------------------------- */
/* Réglages                                                               */
/* --------------------------------------------------------------------- */

.slider-row {
  display: grid; grid-template-columns: 96px 1fr 62px;
  align-items: center; gap: 12px; padding: 9px 15px;
  border-bottom: 1px solid var(--border);
}
.slider-row:last-of-type { border-bottom: 0; }
.slider-row label { font-size: 13.5px; }
.slider-row input[type=range] { width: 100%; accent-color: var(--series-1); }
.slider-out {
  font-size: 13px; font-variant-numeric: tabular-nums;
  text-align: right; font-weight: 600; color: var(--text-secondary);
}

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 13px 15px; }
.btn {
  padding: 8px 15px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 13.5px; font-weight: 580;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--text-primary); color: var(--page); border-color: transparent;
}

.split-bar {
  display: flex; height: 9px; border-radius: 5px; overflow: hidden;
  margin: 10px 15px; gap: 2px;
}
.split-bar div { height: 100%; }

/* Encart code (adresse pour le téléphone) */
.code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; user-select: all; word-break: break-all;
}

.callout {
  border-left: 3px solid var(--warning);
  background: color-mix(in srgb, var(--warning) 8%, transparent);
  padding: 11px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px; color: var(--text-secondary);
}

/* --------------------------------------------------------------------- */
/* Divers                                                                 */
/* --------------------------------------------------------------------- */

.loading { display: grid; place-items: center; gap: 12px; padding: 70px 0; color: var(--text-muted); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--grid); border-top-color: var(--series-1);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { padding: 40px 18px; text-align: center; color: var(--text-muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 80;
  background: var(--text-primary); color: var(--page);
  padding: 9px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 550;
  box-shadow: var(--shadow);
}

.disclaimer {
  margin-top: 26px; padding: 13px 15px;
  font-size: 12.5px; color: var(--text-muted); line-height: 1.55;
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------- */
/* Téléphone                                                              */
/* --------------------------------------------------------------------- */

@media (max-width: 720px) {
  .rank-head { display: none; }
  .axes-key { display: none; }
  .control { max-width: 112px; padding: 6px 8px; font-size: 12.5px; }
  .topbar-main { gap: 8px; }

  .rank-row {
    grid-template-columns: 38px minmax(0,1fr) auto;
    grid-template-areas: "num name score" ". axes axes";
    row-gap: 8px; padding: 12px 14px;
  }
  .rank-num { grid-area: num; }
  .rank-name { grid-area: name; }
  .rank-score { grid-area: score; text-align: right; }
  .axes { grid-area: axes; height: 22px; }

  .tile-value { font-size: 22px; }
  .detail-panel { animation: slide-up .24s cubic-bezier(.32,.72,0,1); border-left: 0; }
  @keyframes slide-up { from { transform: translateY(26px); opacity: .4; } }
  .axis-row { grid-template-columns: 62px 1fr 52px; }
  .slider-row { grid-template-columns: 78px 1fr 54px; gap: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Impression / contraste forcé : la texture prend le relais de la couleur */
@media (forced-colors: active) {
  .axis-bar, .axis-fill { forced-color-adjust: none; background: CanvasText; }
  .card { border: 1px solid CanvasText; }
}
