/* ==========================================================================
   Espace lecteur (/mon-compte/) — chargé seulement par layout-espace.hbs.
   Une application à part : barre latérale, une vue à la fois.
   La pièce maîtresse est la jauge d’accès, lue comme un crédit prépayé :
   verte tant qu’il reste du temps, orange à l’approche de la fin.
   ========================================================================== */

.espace {
    --fond-app: #f3f4f2;
    --carte: #ffffff;
    --ligne: #e3e4e0;
    --ambre: #b45309;
    --ambre-fond: #fff4d6;
    --rayon-carte: 12px;
    --rayon-champ: 8px;
    background: var(--fond-app);
    min-height: 100vh;
    font-size: 16px;
}
.espace .drapeau { position: relative; z-index: 2; }

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

.espace-app { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: calc(100vh - 5px); }

.espace-barre {
    position: sticky; top: 0; z-index: 1;
    display: flex; flex-direction: column; gap: 4px;
    padding: 12px var(--gouttiere) 0;
    background: var(--carte);
    border-bottom: 1px solid var(--ligne);
}
.espace-logo { display: inline-flex; width: fit-content; color: var(--encre); }
.espace-logo:hover { color: var(--encre); }
.espace-logo img { max-height: 32px; width: auto; }
.espace-logo .logo-texte { font-size: 28px; }

.espace-nav { display: flex; gap: 4px; margin: 0 calc(var(--gouttiere) * -1); padding: 0 var(--gouttiere); overflow-x: auto; scrollbar-width: none; }
.espace-nav::-webkit-scrollbar { display: none; }
.espace-nav a {
    flex: none; position: relative;
    padding: 12px 10px 14px;
    font-size: 15px; font-weight: 600; color: var(--gris);
}
.espace-nav a[hidden] { display: none; }
.espace-nav a:hover { color: var(--encre); }
.espace-nav a[aria-current="page"] { color: var(--encre); }
.espace-nav a[aria-current="page"]::after {
    content: ""; position: absolute; left: 10px; right: 10px; bottom: 0;
    height: 3px; border-radius: 3px 3px 0 0; background: var(--orange);
}

.espace-moi { display: none; }

.espace-contenu { width: 100%; max-width: 940px; padding: 20px var(--gouttiere) 64px; }
.espace-haut { display: flex; justify-content: flex-end; margin-bottom: 20px; }

.espace-retour { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--gris); }
.espace-retour svg { width: 16px; height: 16px; transform: scaleX(-1); }
.espace-retour:hover { color: var(--orange-fonce); }

/* ---------- Typographie ---------- */

.espace-titre { font-size: clamp(30px, 6vw, 44px); font-weight: 900; letter-spacing: -.035em; line-height: 1.05; }
.espace-intro { max-width: 60ch; margin: 10px 0 28px; color: var(--gris); font-size: 17px; line-height: 1.5; }
.espace-note { max-width: 62ch; margin-top: 16px; font-size: 14px; line-height: 1.5; color: var(--gris); }
.espace-vide { padding: 28px 24px; border: 1px dashed #cfd1cb; border-radius: var(--rayon-carte); color: var(--gris); text-align: center; }
.espace-vide[hidden] { display: none; }
.espace-lien { padding: 0; border: 0; background: none; color: var(--orange-fonce); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.espace-lien:hover { color: var(--encre); }
.espace-statut { margin: 12px 0 0; font-size: 14px; font-weight: 600; color: var(--vert-fonce); }
.espace-statut:empty { display: none; }
.espace-statut-erreur { color: #b3261e; }

.espace-vue[hidden] { display: none; }

.pastille { display: inline-block; padding: 3px 10px; border-radius: 99px; background: #ececea; color: var(--texte); font-size: 13px; font-weight: 700; white-space: nowrap; }
.pastille-ok { background: #e2f5e6; color: var(--vert-fonce); }
.pastille-attente, .pastille-alerte { background: var(--ambre-fond); color: var(--ambre); }
.pastille-erreur { background: #fde7e5; color: #b3261e; }

/* ---------- Carte d’accès et jauge ---------- */

.acces {
    position: relative; overflow: hidden;
    padding: 30px 24px 24px;
    background: var(--carte);
    border: 1px solid var(--ligne);
    border-radius: var(--rayon-carte);
}
/* Les trois bandes du drapeau en tête de carte : la carte d’abonné du journal */
.acces::before {
    content: ""; position: absolute; inset: 0 0 auto 0; height: 6px;
    background: linear-gradient(90deg, var(--orange) 0 33.33%, #fff 33.33% 66.66%, var(--vert) 66.66%);
    border-bottom: 1px solid var(--ligne);
}
.acces + .acces { margin-top: 16px; }
.acces-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.acces-formule { font-size: clamp(34px, 7vw, 52px); font-weight: 900; letter-spacing: -.04em; line-height: 1; }
.acces-reste { margin-top: 14px; font-size: 19px; color: var(--texte); }
.acces-reste strong { color: var(--encre); font-weight: 800; }

.jauge { margin-top: 18px; }
.jauge[hidden] { display: none; }
.jauge-piste { height: 12px; border-radius: 99px; background: #ecedea; overflow: hidden; }
.jauge-niveau { display: block; height: 100%; min-width: 12px; border-radius: inherit; background: var(--vert); transition: width .8s cubic-bezier(.2, .7, .2, 1); }
.acces-fin-proche .jauge-niveau { background: var(--orange); }
.jauge-dates { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--gris); }
.jauge-dates span:last-child { text-align: right; }

.acces-alerte { margin-top: 18px; padding: 12px 14px; border-radius: var(--rayon-champ); background: var(--ambre-fond); color: #6b3a00; font-size: 15px; line-height: 1.5; }
.acces-alerte[hidden] { display: none; }
.acces-alerte .espace-lien { color: inherit; }
.acces-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 24px; }
.acces-actions .bouton { padding: 12px 20px; font-size: 15px; border-radius: var(--rayon-champ); }
.acces-actions .espace-note { margin: 0; }

.acces-comparaison { display: grid; gap: 20px; margin-top: 22px; }
.acces-comparaison h3 { margin-bottom: 8px; font-size: 15px; font-weight: 800; }
.acces-comparaison ul { margin: 0; padding: 0; list-style: none; }
.acces-comparaison li { position: relative; padding: 5px 0 5px 26px; line-height: 1.45; }
.acces-comparaison li::before { position: absolute; left: 0; top: 5px; font-weight: 900; }
.liste-oui li::before { content: "✓"; color: var(--vert-fonce); }
.liste-plus li::before { content: "+"; color: var(--orange); font-size: 19px; line-height: 1.1; }
@media (min-width: 640px) { .acces-comparaison { grid-template-columns: 1fr 1fr; } }

/* ---------- Paiements ---------- */

.paiements { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon-carte); overflow: hidden; }
.paiements[hidden] { display: none; }
.paiements table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.paiements th { padding: 12px 16px; background: #fafaf8; border-bottom: 1px solid var(--ligne); font-size: 13px; font-weight: 700; color: var(--gris); text-align: left; }
.paiements td { padding: 14px 16px; border-bottom: 1px solid var(--ligne); vertical-align: top; }
.paiements tr:last-child td { border-bottom: 0; }
.paiements .nombre { text-align: right; white-space: nowrap; }
.paiements td small { display: block; margin-top: 2px; font-size: 13px; font-weight: 400; color: var(--gris); }
.paiements .reference { color: var(--gris); font-size: 14px; letter-spacing: .04em; }

@media (max-width: 699px) {
    .paiements thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .paiements tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 16px; border-bottom: 1px solid var(--ligne); }
    .paiements tr:last-child { border-bottom: 0; }
    .paiements td { padding: 0; border: 0; }
    /* Fiche : date et montant en tête, le reste en dessous */
    .paiements td:nth-child(1) { font-weight: 700; color: var(--encre); }
    .paiements td:nth-child(3) { grid-row: 1 / 3; grid-column: 2; font-weight: 700; color: var(--encre); }
    .paiements td:nth-child(2) { grid-column: 1; color: var(--gris); }
    .paiements td:nth-child(4) { grid-column: 1 / -1; margin-top: 6px; }
    .paiements td:nth-child(5), .paiements td:nth-child(6) { grid-column: 1 / -1; font-size: 14px; color: var(--gris); }
    .paiements td:nth-child(5)::before, .paiements td:nth-child(6)::before { content: attr(data-libelle) " : "; }
}

/* ---------- Newsletters ---------- */

.reglages { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon-carte); }
.reglage { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--ligne); cursor: pointer; }
.reglages > :last-child, .reglages [data-newsletters]:last-child .reglage:last-child { border-bottom: 0; }
.reglage-texte { display: grid; gap: 3px; }
.reglage-texte strong { color: var(--encre); font-size: 16px; }
.reglage-texte small { color: var(--gris); font-size: 14px; line-height: 1.4; }

.interrupteur {
    -webkit-appearance: none; appearance: none;
    flex: none; position: relative;
    width: 46px; height: 28px; margin: 0;
    border-radius: 99px; background: #cfd1cb;
    cursor: pointer; transition: background .2s;
}
.interrupteur::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 2px rgba(20, 20, 20, .25);
    transition: transform .2s;
}
.interrupteur:checked { background: var(--vert-fonce); }
.interrupteur:checked::after { transform: translateX(18px); }
.interrupteur:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---------- Profil ---------- */

.profil { display: grid; gap: 20px; max-width: 520px; padding: 24px; background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon-carte); }
.profil .champ input { border-radius: var(--rayon-champ); }
.profil .champ input[readonly] { background: var(--fond-app); color: var(--gris); }
.profil .champ small { line-height: 1.5; }
.profil-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.profil-actions .bouton { padding: 12px 20px; font-size: 15px; border-radius: var(--rayon-champ); }
.profil-actions .espace-statut { margin: 0; }

/* ---------- Aide ---------- */

.aide { display: grid; gap: 0; margin: 28px 0 0; background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon-carte); }
.aide > div { padding: 20px 22px; border-bottom: 1px solid var(--ligne); }
.aide > div:last-child { border-bottom: 0; }
.aide dt { font-weight: 800; color: var(--encre); }
.aide dd { max-width: 64ch; margin: 6px 0 0; color: var(--texte); line-height: 1.6; }

/* ---------- Invité (non connecté) ---------- */

.espace-invite { display: flex; flex-direction: column; align-items: flex-start; gap: 0; max-width: 560px; margin: 0 auto; padding: 12vh var(--gouttiere) 48px; }
.espace-invite .espace-logo { margin-bottom: 40px; }
.espace-invite .espace-logo .logo-texte { font-size: 40px; }
.espace-invite .acces-actions { margin: 0 0 40px; }

/* ---------- Grand écran : barre latérale ---------- */

@media (min-width: 900px) {
    .espace-app { grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: auto; }
    .espace-barre {
        position: sticky; top: 0; height: 100vh;
        padding: 28px 16px 20px;
        border-bottom: 0; border-right: 1px solid var(--ligne);
    }
    .espace-logo { margin: 0 12px 28px; }
    .espace-nav { flex-direction: column; gap: 2px; margin: 0; padding: 0; overflow: visible; }
    .espace-nav a { padding: 10px 12px; border-radius: var(--rayon-champ); }
    .espace-nav a:hover { background: var(--fond-app); }
    .espace-nav a[aria-current="page"] { background: var(--fond-app); }
    .espace-nav a[aria-current="page"]::after { left: 0; right: auto; top: 9px; bottom: 9px; width: 3px; height: auto; border-radius: 0 3px 3px 0; }

    .espace-moi {
        display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 4px 12px;
        margin-top: auto; padding: 16px 12px 0; border-top: 1px solid var(--ligne);
    }
    .espace-avatar { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; overflow: hidden; border-radius: 50%; background: var(--encre); color: #fff; font-weight: 800; }
    .espace-avatar img { width: 100%; height: 100%; object-fit: cover; }
    .espace-moi-texte { display: grid; min-width: 0; font-size: 14px; line-height: 1.3; }
    .espace-moi-texte strong { color: var(--encre); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .espace-moi-texte span { color: var(--gris); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .espace-deconnexion { grid-column: 1 / -1; margin-top: 12px; font-size: 14px; font-weight: 600; color: var(--gris); }
    .espace-deconnexion:hover { color: #b3261e; }

    .espace-contenu { padding: 28px 48px 80px; }
    .espace-haut { margin-bottom: 36px; }
    .acces { padding: 38px 36px 32px; }
}

/* Petit écran : la barre latérale n’a pas de place pour la déconnexion, l’onglet Aide la porte */
.espace-deconnexion-mobile { margin-top: 24px; border-radius: var(--rayon-champ); }
@media (min-width: 900px) { .espace-deconnexion-mobile { display: none; } }
@media (max-width: 899px) { .espace-haut { justify-content: flex-start; } }

@media (prefers-reduced-motion: reduce) {
    .jauge-niveau, .interrupteur, .interrupteur::after { transition: none; }
}
