/* ============================================================
   LIBRE — Styles spécifiques à l'application (app.html)
   onboarding · éditeur · stats
   ============================================================ */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1.2rem;
  background: rgba(255,255,255,.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand {
  font-weight: 800; letter-spacing: -.02em; font-size: 1.1rem;
  display: flex; align-items: center; gap: .4rem;
}
.topbar .brand .em { color: var(--etat-libre); }
.topbar .spacer { flex: 1; }
.topbar .meta { font-size: .82rem; color: var(--sub); }

/* Pastille de sauvegarde (topbar) */
.save-pill {
  font-size: .76rem; font-weight: 600; line-height: 1;
  color: #2f7d3a; background: #eaf6ec;
  border: 1px solid #cfe9d3; border-radius: 999px;
  padding: .32rem .6rem; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .32rem;
  transition: background .2s, color .2s;
}
.save-pill.is-saving { color: #8a6d1f; background: #fdf6e3; border-color: #f0e3b8; }
.save-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
@media (max-width: 640px) {
  .save-pill .lbl-long { display: none; }   /* on garde juste « Enregistré » */
}

/* Bandeau de rappel sauvegarde */
.backup-banner {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem 1.2rem;
  background: #fff8e8; border-bottom: 1px solid #f0e3b8;
  color: #6b531a; font-size: .86rem;
}
.backup-banner.urgent { background: #fdeee6; border-bottom-color: #f3cdb6; color: #8a4b22; }
.backup-banner.hidden { display: none; }
.backup-banner .bb-ico { font-size: 1.05rem; flex: 0 0 auto; }
.backup-banner .bb-text { flex: 1; min-width: 0; }
.backup-banner .bb-text b { color: inherit; font-weight: 700; }
.backup-banner .bb-actions { display: flex; align-items: center; gap: .4rem; flex: 0 0 auto; }
.backup-banner .bb-save {
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--ink); color: #fff; border: none;
  border-radius: 8px; padding: .4rem .7rem; white-space: nowrap;
}
.backup-banner .bb-save:hover { background: #000; }
.backup-banner .bb-dismiss {
  font: inherit; cursor: pointer; background: transparent; border: none;
  color: inherit; opacity: .55; padding: .2rem .35rem; line-height: 1;
}
.backup-banner .bb-dismiss:hover { opacity: 1; }
@media (max-width: 640px) {
  .backup-banner { flex-wrap: wrap; }
  .backup-banner .bb-text { flex: 1 1 100%; }
}

/* État de sauvegarde (onglet Sauvegarde) */
.save-state {
  font-size: .84rem; font-weight: 600;
  border-radius: 10px; padding: .6rem .75rem; margin-bottom: 1rem;
  display: flex; align-items: center; gap: .5rem;
}
.save-state.ok   { color: #2f7d3a; background: #eaf6ec; border: 1px solid #cfe9d3; }
.save-state.warn { color: #8a4b22; background: #fdeee6; border: 1px solid #f3cdb6; }
.muted-note { color: var(--sub); font-size: .78rem; margin-top: -.2rem; }

/* ============================================================
   ONBOARDING
   ============================================================ */
.onb {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 2rem 1.2rem;
}
.onb-card {
  width: 100%; max-width: 460px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 2.2rem; box-shadow: var(--shadow-l);
}
.onb-card h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.onb-card .sub { color: var(--sub); margin: .3rem 0 1.6rem; }
.field { margin-bottom: 1.2rem; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .4rem; }
.field .hint { font-size: .76rem; color: var(--sub); font-weight: 400; }
.field input, .field select {
  width: 100%; font-family: inherit; font-size: 1rem;
  padding: .7rem .85rem; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,125,214,.15);
}

/* ============================================================
   ÉDITEUR
   ============================================================ */
.editor { flex: 1; display: flex; min-height: 0; }

/* --- Colonne principale : la grille --- */
.grid-col {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 1.2rem 1.4rem;
}
.grid-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: .6rem 1rem;
  margin-bottom: .9rem;
}
.grid-head h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; }
.grid-head .you-are {
  font-size: .8rem; color: var(--sub);
}
.grid-scroll {
  flex: 1; overflow: auto; border: 1px solid var(--line);
  border-radius: 14px; background: #fff; padding: 14px;
}

/* En-tête des mois — même gabarit de colonnes que la grille */
#months {
  display: grid;
  grid-template-columns: 28px repeat(var(--cols, 52), 1fr);
  gap: 2px;
  position: sticky; top: -14px; z-index: 4;
  background: #fff;
  padding: 4px 0 6px;
  margin-bottom: 4px;
  margin-right: 88px; /* marge réservée aux étiquettes des repères (alignée sur #weeks) */
  border-bottom: 1px solid var(--line);
}
.month-lbl {
  font-size: 9px; color: var(--sub); text-align: center;
  line-height: 1; align-self: end; letter-spacing: .02em;
  overflow: hidden; white-space: nowrap;
}

/* La grille des semaines — DOM optimisé, event delegation */
#weeks {
  display: grid;
  /* colonnes définies dynamiquement en JS via --cols */
  grid-template-columns: 28px repeat(var(--cols, 52), 1fr);
  gap: 2px;
  align-content: start;
  position: relative; /* repère pour les lignes retraite / espérance */
  margin-right: 88px; /* marge réservée aux étiquettes des repères */
}

/* --- Lignes-repères tracées en travers de la grille (retraite, espérance) --- */
/* Trait fin plein logé pile dans l'espace de 2px entre deux lignes d'années. */
.grid-repere {
  position: absolute;
  left: 30px;   /* après la colonne des âges (28px + gap) */
  right: 0;
  height: 2px;
  background: var(--rc, var(--accent));
  z-index: 5;
  pointer-events: none;
}
/* Étiquette posée dans la marge de droite (jamais par-dessus la grille). */
.grid-repere .rep-tag {
  position: absolute;
  left: 100%;
  margin-left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--rc, var(--accent));
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1;
  white-space: nowrap;
}
/* étiquette « décrochée » de sa ligne (calée au bord pendant le scroll) */
.grid-repere.pinned .rep-tag { opacity: .9; }
.rep-caret { font-weight: 700; }
.row-label {
  font-size: 9px; color: var(--sub); text-align: right;
  padding-right: 4px; line-height: 1; align-self: center;
  font-variant-numeric: tabular-nums;
}
.wk {
  aspect-ratio: 1 / 1;
  border-radius: 2px;
  background: var(--etat-avenir);
  cursor: pointer;
  position: relative;
  transition: transform .08s ease;
}
.wk:hover { transform: scale(1.45); z-index: 2; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.wk.now { box-shadow: 0 0 0 2px var(--accent); z-index: 3; }
.wk.range-start { box-shadow: 0 0 0 2px var(--ink); z-index: 3; }

/* --- Panneau latéral : palette, modes, assistant --- */
.side {
  width: 320px; flex: none; border-left: 1px solid var(--line);
  background: var(--card);
  padding: 1.2rem 1.2rem 2rem;
  /* Barre latérale « collante » : elle t'accompagne quand tu scrolles la grille,
     et son propre contenu défile en interne s'il dépasse la hauteur de l'écran. */
  position: sticky;
  top: var(--topbar-h, 52px);
  align-self: flex-start;
  max-height: calc(100vh - var(--topbar-h, 52px));
  overflow-y: auto;
}
@media (max-width: 880px) {
  .editor { flex-direction: column; }
  .side {
    width: 100%; border-left: none; border-top: 1px solid var(--line);
    /* en colonne (mobile), le menu repasse dans le flux normal de la page */
    position: static; max-height: none; top: auto;
  }
}
.side h3 {
  font-size: .74rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--sub); margin: 1.4rem 0 .6rem;
}
.side h3:first-child { margin-top: 0; }

/* Onglets du panneau latéral */
.side-tabs {
  display: flex; background: var(--bg); border-radius: 12px;
  padding: 3px; gap: 3px; margin-bottom: 1.4rem;
  position: sticky; top: -1.2rem; z-index: 5;
}
.side-tabs button {
  flex: 1; font-family: inherit; font-size: .78rem; font-weight: 600;
  padding: .5rem .25rem; border: none; border-radius: 9px;
  background: transparent; color: var(--sub); cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.side-tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.tab-panel h3:first-child { margin-top: 0; }
.stats-title { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; margin: .15rem 0 0; }
#tab-stats .stat-big { margin-top: .9rem; }
#tab-stats .compare { margin-top: 1.2rem; }
#tab-stats .compare .line .who { width: 70px; }

/* Sélecteur de mode (segmented control) */
.modes { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.modes button {
  flex: 1; font-family: inherit; font-size: .8rem; font-weight: 600;
  padding: .5rem; border: none; border-radius: 9px; background: transparent;
  color: var(--sub); cursor: pointer; transition: all .15s;
}
.modes button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* Palette */
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.swatch {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .55rem; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; background: #fff;
  transition: all .12s; font-size: .82rem; font-weight: 600;
}
.swatch:hover { border-color: var(--sub); }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.swatch .dot { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.12); flex: none; }

/* Assistant de complétion */
.assist p { font-size: .85rem; color: var(--ink); }
.assist ul { margin: .4rem 0 .4rem 1.1rem; }
.assist li { font-size: .82rem; color: var(--sub); margin: .35rem 0; }

.tip {
  font-size: .8rem; color: var(--sub);
  background: var(--bg); border-radius: 10px; padding: .7rem .8rem;
  margin-top: .5rem;
}
.tip b { color: var(--ink); }

.side-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.side-actions .btn { width: 100%; }

/* Toggle calque moyen */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; font-size: .84rem; font-weight: 600;
}
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--line);
  border-radius: 999px; transition: .2s; cursor: pointer;
}
.switch .slider::before {
  content: ''; position: absolute; height: 20px; width: 20px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ============================================================
   STATS (overlay panneau)
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.modal {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 22px; padding: 2rem;
  box-shadow: var(--shadow-l);
}
.modal h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.modal .close {
  float: right; border: none; background: var(--bg); width: 34px; height: 34px;
  border-radius: 50%; font-size: 1.1rem; cursor: pointer; color: var(--sub);
}
.modal .close:hover { background: var(--line); }

.stat-big {
  display: flex; align-items: baseline; gap: .5rem; margin: 1.2rem 0 .3rem;
}
.stat-big .num { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; color: var(--etat-libre); }
.stat-big .lbl { color: var(--sub); font-size: .9rem; }

.bar { height: 22px; border-radius: 6px; overflow: hidden; display: flex; background: var(--bg); margin: .2rem 0; }
.bar span { height: 100%; }

.stat-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .6rem; }
.stat-legend .item { display: flex; align-items: center; gap: .35rem; font-size: .8rem; }

.compare {
  background: var(--bg); border-radius: 14px; padding: 1.1rem 1.2rem; margin-top: 1.4rem;
}
.compare .line { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; font-size: .88rem; }
.compare .line .who { width: 90px; flex: none; font-weight: 600; }
.compare .line .track { flex: 1; height: 14px; background: #fff; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.compare .line .fill { height: 100%; border-radius: 999px; }
.compare .verdict { margin-top: .8rem; font-size: .9rem; }

/* En-tête « Comparer avec » + select */
.compare-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .9rem; }
.compare-head > span { font-weight: 700; font-size: .9rem; }
.compare-head select {
  font-family: inherit; font-size: .85rem; font-weight: 600; color: var(--ink);
  padding: .35rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer;
}
.compare-head select:hover { border-color: var(--accent); }

/* Faits du pays comparé */
.pays-facts { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }
.pays-facts .fact {
  flex: 1 1 30%; min-width: 90px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: .5rem .6rem; display: flex; flex-direction: column; gap: .15rem;
}
.pays-facts .fk { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--sub); }
.pays-facts .fv { font-size: .9rem; font-weight: 700; }

.compare-btn { width: 100%; margin-top: 1rem; }

/* ============================================================
   Modale de comparaison des grilles
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(20,20,25,.45);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 2rem 1rem;
}
.modal {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow-l);
  width: min(880px, 100%); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 1.1rem; font-weight: 800; }
.modal-close {
  border: none; background: transparent; font-size: 1.05rem; color: var(--sub);
  cursor: pointer; padding: .3rem .5rem; border-radius: 8px; line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem;
  padding: 1.3rem 1.4rem; overflow: auto;
}
.cmp-col { min-width: 0; }
.cmp-col-head { display: flex; flex-direction: column; gap: .1rem; margin-bottom: .6rem; }
.cmp-col-head b { font-size: .95rem; }
.cmp-col-head span { font-size: .78rem; color: var(--sub); }
.cmp-grid { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .5rem; }
.mini-svg { width: 100%; height: auto; display: block; }
.modal-legend {
  display: flex; flex-wrap: wrap; gap: .35rem .9rem;
  padding: .9rem 1.4rem 1.2rem; border-top: 1px solid var(--line);
}
.modal-legend .item { display: flex; align-items: center; gap: .35rem; font-size: .76rem; color: var(--sub); }

@media (max-width: 600px) {
  .modal-body { grid-template-columns: 1fr; gap: 1rem; }
  .pays-facts .fact { flex-basis: 45%; }
}

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: .7rem 1.2rem; border-radius: 999px;
  font-size: .86rem; font-weight: 500; opacity: 0; transition: all .25s; z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Compteur "liberté collective" (onglet Stats) ---- */
.collectif {
  margin-top: 1.4rem; padding: 1.1rem 1.2rem;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  text-align: center;
}
.collectif-nums {
  display: flex; gap: 1rem; justify-content: center; margin-top: .5rem;
}
.collectif-nums > div {
  flex: 1; display: flex; flex-direction: column; gap: .15rem;
}
.collectif-nums .cn {
  font-size: 1.6rem; font-weight: 800; line-height: 1; color: var(--etat-libre);
}
.collectif-nums .cl { font-size: .76rem; color: var(--sub); }
#btnPlusLibre:disabled { opacity: .65; cursor: default; }
