/* Tatbiki Devis — charte Tatbiki : jaune / gris / noir sur fond clair ; rouge = erreur ; vert = WhatsApp uniquement. */
:root {
  --jaune: #FFC107;
  --noir: #16181D;
  --gris: #55585F;
  --gris-clair: #E2E0DA;
  --fond: #F6F5F2;
  --blanc: #FFFFFF;
  --alerte: #B45309;
  --erreur: #B91C1C;
  --whatsapp: #1F7A4D;
  --rayon: 14px;
  --ombre: 0 1px 3px rgba(0, 0, 0, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fond); color: var(--noir); }
body {
  font-family: Inter, "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
[dir="rtl"] body, [lang="ar"] { font-family: "Noto Sans Arabic", Inter, system-ui, sans-serif; }
h1, h2, h3, .montant, .stat b, .chrono { font-family: "Space Grotesk", Inter, "Noto Sans Arabic", sans-serif; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { font-family: "Noto Sans Arabic", sans-serif; }
h2 { font-size: 1.25rem; margin: .2em 0 .5em; }
h3 { font-size: 1rem; margin: .8em 0 .3em; }
[hidden] { display: none !important; }
.gris { color: var(--gris); }
.petit { font-size: 15px; }
.centre { text-align: center; }
.jaune { color: var(--jaune); }

/* ---------- En-tête (charte § 3) ---------- */
.barre {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--blanc); border-bottom: 1px solid var(--gris-clair);
}
.barre-gauche { display: flex; align-items: center; gap: 6px; min-width: 0; }
.logo { height: 34px; width: auto; }
.barre h1 { margin: 0; font-size: 1.05rem; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.langues { display: flex; justify-content: flex-end; gap: 2px; background: var(--fond); border-radius: 999px; padding: 3px; justify-self: end; }
.langue { min-width: 36px; min-height: 36px; border: 0; background: transparent; border-radius: 999px; font: inherit; font-weight: 700; font-size: 14px; color: var(--gris); cursor: pointer; }
.langue.actif { background: var(--blanc); color: var(--noir); box-shadow: var(--ombre); }
.btn-icone { width: 48px; height: 48px; min-width: 48px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--noir); border-radius: 12px; cursor: pointer; }
.btn-icone svg { width: 26px; height: 26px; }
/* Flèche retour : jaune, contour noir (charte § 4) */
.fleche { background: var(--jaune) !important; color: var(--noir); border: 2px solid var(--noir) !important; border-radius: 50% !important; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
[dir="rtl"] .fleche svg { transform: scaleX(-1); }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 40px; }
.ecran { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Composants ---------- */
.carte { background: var(--blanc); border-radius: var(--rayon); padding: 16px; box-shadow: var(--ombre); border: 1px solid var(--gris-clair); }
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 15px; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--noir);
  background: var(--blanc); border: 1.5px solid var(--gris-clair); border-radius: 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid var(--noir); outline-offset: 1px; }
input[type="radio"], input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--noir); margin: 0; }
.option { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 500; margin: 0; }
fieldset.choix { border: 1.5px solid var(--gris-clair); border-radius: 10px; margin: 12px 0 0; padding: 4px 12px; }
legend { font-weight: 600; padding: 0 4px; font-size: 15px; }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; width: 100%; min-height: 52px; padding: 10px 16px;
  font: inherit; font-weight: 700; font-size: 16px; border-radius: 12px; border: 2px solid var(--noir); cursor: pointer; text-align: center;
  background: var(--blanc); color: var(--noir); text-decoration: none; margin-top: 8px;
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-principal { background: var(--jaune); color: var(--noir); }
.btn-secondaire { background: var(--blanc); }
.btn-grand { min-height: 60px; font-size: 17px; }
.btn-petit { width: auto; min-height: 44px; padding: 6px 14px; margin: 0; }
.btn-lien { border: 0; background: transparent; text-decoration: underline; font-weight: 600; min-height: 48px; }
.btn-lien.danger { color: var(--erreur); }
.btn-whatsapp { background: var(--whatsapp); color: #fff; border-color: var(--whatsapp); }
.btn small, .sous-ar { display: block; width: 100%; font-weight: 500; font-size: 15px; opacity: .85; font-family: "Noto Sans Arabic", sans-serif; }
[dir="rtl"] .sous-ar { display: none; } /* déjà en arabe */
.sous-ar:not(small) { margin: 0; color: var(--gris); text-align: center; }
.erreur { color: var(--erreur); font-weight: 600; margin: 8px 0 0; }
.succes { color: var(--noir); background: var(--fond); border-left: 4px solid var(--jaune); padding: 10px; border-radius: 8px; font-weight: 600; }
[dir="rtl"] .succes { border-left: 0; border-right: 4px solid var(--jaune); }
.pastille { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--fond); border: 1px solid var(--gris-clair); font-weight: 700; font-size: 15px; margin: 0; }
.pastille.doute { background: #FEF3C7; border-color: var(--alerte); color: var(--alerte); }
.titre-section { font-size: 1.05rem; margin: 10px 0 0; }
.vide { color: var(--gris); text-align: center; padding: 16px; }
.actions { display: flex; flex-direction: column; gap: 2px; }
.champ-code { text-align: center; font-size: 28px; letter-spacing: 10px; font-family: "Space Grotesk", sans-serif; }

/* ---------- Accueil ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--blanc); border: 1px solid var(--gris-clair); border-radius: var(--rayon); padding: 12px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--ombre); }
.stat b { font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--gris); font-size: 15px; }
.stat-large { grid-column: 1 / -1; background: var(--noir); color: #fff; border-color: var(--noir); }
.stat-large span { color: var(--gris-clair); }
.zone-micro { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; }
.micro {
  width: 168px; height: 168px; border-radius: 50%; border: 4px solid var(--noir); background: var(--jaune); color: var(--noir);
  display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: transform .12s;
}
.micro-moyen { width: 104px; height: 104px; }
.micro.enregistre { transform: scale(1.08); box-shadow: 0 0 0 14px rgba(255, 193, 7, .35), 0 8px 24px rgba(0, 0, 0, .2); }
.micro-label { font-weight: 800; font-size: 1.15rem; margin: 4px 0 0; }
.bascule { display: inline-flex; background: var(--blanc); border: 1.5px solid var(--gris-clair); border-radius: 999px; padding: 3px; margin-top: 8px; }
.bascule button { min-height: 44px; padding: 6px 14px; border: 0; border-radius: 999px; background: transparent; font: inherit; font-weight: 700; font-size: 15px; color: var(--gris); cursor: pointer; }
.bascule button[aria-checked="true"] { background: var(--noir); color: #fff; }
.raccourcis .btn { margin: 0; flex-wrap: nowrap; }
.attente { display: flex; align-items: center; gap: 10px; border-color: var(--alerte); }
.attente span { flex: 1; font-weight: 600; color: var(--alerte); }

/* ---------- Listes ---------- */
.liste-docs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.doc {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: start; padding: 12px 14px; min-height: 64px;
  background: var(--blanc); border: 1px solid var(--gris-clair); border-radius: 12px; font: inherit; color: inherit; cursor: pointer;
}
.doc b { font-family: "Space Grotesk", Inter, sans-serif; }
.doc .doc-montant { text-align: end; font-weight: 700; }
.doc small { color: var(--gris); font-size: 15px; }
.statut { justify-self: end; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--fond); border: 1px solid var(--gris-clair); }
.statut.brouillon { background: #fff; border-style: dashed; }
.statut.paye { background: var(--noir); color: #fff; border-color: var(--noir); }
.statut.paye_partiel, .statut.accepte { background: var(--jaune); border-color: var(--noir); }
.statut.refuse, .statut.annule { color: var(--erreur); }
.filtres { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.filtre { flex: none; min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--gris-clair); background: var(--blanc); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; }
.filtre.actif { background: var(--noir); color: #fff; border-color: var(--noir); }
.liste-simple { list-style: none; padding: 0; margin: 8px 0; }
.liste-simple li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--gris-clair); }

/* ---------- Dictée ---------- */
.chrono { font-size: 2rem; font-weight: 700; margin: 0; }
.etat-dictee { color: var(--gris); font-weight: 600; min-height: 1.4em; margin: 0; text-align: center; }
.ecoute { display: flex; gap: 6px; height: 48px; align-items: center; }
.ecoute span { width: 8px; height: 12px; background: var(--gris-clair); border-radius: 4px; }
.ecoute.actif span { background: var(--jaune); animation: onde 0.9s ease-in-out infinite; }
.ecoute.actif span:nth-child(2) { animation-delay: .1s; } .ecoute.actif span:nth-child(3) { animation-delay: .2s; }
.ecoute.actif span:nth-child(4) { animation-delay: .3s; } .ecoute.actif span:nth-child(5) { animation-delay: .4s; }
@keyframes onde { 0%, 100% { height: 12px; } 50% { height: 46px; } }
@media (prefers-reduced-motion: reduce) { .ecoute.actif span { animation: none; height: 30px; } .micro { transition: none; } }
.citation { background: var(--fond); border-radius: 8px; padding: 10px; margin: 0; font-style: italic; }
.questions { margin: 8px 0 0; padding-inline-start: 20px; color: var(--alerte); font-weight: 600; }

/* ---------- Vérification ---------- */
.type-doc { font-weight: 800; margin: 0; font-family: "Space Grotesk", sans-serif; }
.lignes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ligne { background: var(--blanc); border: 1.5px solid var(--gris-clair); border-radius: var(--rayon); padding: 12px; }
.ligne.doute { border-color: var(--alerte); background: #FFFBEB; }
.ligne-tete { display: flex; gap: 8px; align-items: center; }
.ligne-tete input { font-weight: 700; }
.ligne-chiffres { display: grid; grid-template-columns: 1fr .9fr 1.2fr; gap: 8px; margin-top: 8px; }
.ligne-chiffres label { font-size: 14px; margin: 0 0 2px; color: var(--gris); font-weight: 600; }
.ligne-total { text-align: end; font-weight: 800; margin-top: 8px; font-family: "Space Grotesk", sans-serif; }
.doute-zone { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #FEF3C7; color: var(--alerte); font-weight: 700; }
.doute-zone .grille-2 .btn { margin-top: 6px; min-height: 48px; }
.totaux > div { display: flex; justify-content: space-between; padding: 6px 0; }
.totaux .ttc { background: var(--jaune); margin: 6px -16px 0; padding: 10px 16px; font-size: 1.15rem; border-radius: 0 0 var(--rayon) var(--rayon); }
.totaux .reste b { color: var(--alerte); }
.montant { font-size: 1.8rem; font-weight: 700; margin: 4px 0 0; }

/* ---------- Document prêt ---------- */
.apercu iframe { width: 100%; height: 70vh; border: 1px solid var(--gris-clair); border-radius: var(--rayon); background: #fff; }
.progression { height: 14px; background: var(--gris-clair); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progression div { height: 100%; width: 0; background: var(--noir); transition: width .3s; }

/* ---------- Assistance ---------- */
.fil { display: flex; flex-direction: column; gap: 8px; min-height: 40vh; }
.bulle { max-width: 85%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; }
.bulle.moi { align-self: flex-end; background: var(--jaune); }
.bulle.ia { align-self: flex-start; background: var(--gris-clair); }
.saisie-bas { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 8px 0; background: var(--fond); }
.saisie-bas .btn { min-width: 52px; }

/* ---------- Menu (charte § 5 et § 16 : côté du ☰) ---------- */
.panneau { position: fixed; inset: 0; z-index: 50; }
.panneau-fond { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.panneau-contenu {
  position: absolute; top: 0; bottom: 0; width: min(340px, 88vw); background: var(--blanc); overflow-y: auto; padding: 12px 14px 30px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: 8px 0 30px rgba(0, 0, 0, .15);
}
[dir="ltr"] .panneau-contenu { left: 0; border-radius: 0 20px 20px 0; }
[dir="rtl"] .panneau-contenu { right: 0; border-radius: 20px 0 0 20px; }
.panneau-tete { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.panneau-tete h2 { margin: 0; }
.menu-lien { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 8px 10px; border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 16px; color: var(--noir); border-radius: 10px; cursor: pointer; text-align: start; }
.menu-lien:hover { background: var(--fond); }
.menu-lien svg { width: 22px; height: 22px; flex: none; }
.chevron { margin-inline-start: auto; }
.compte-details { padding: 4px 12px 8px; font-size: 15px; }
.compte-details p { margin: 6px 0; }
.menu-titre-apps { font-weight: 800; margin: 16px 0 4px; font-size: 15px; color: var(--gris); }
.m-apps { display: flex; flex-direction: column; gap: 4px; }
.m-app { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 10px; border-radius: 10px; color: var(--noir); text-decoration: none; font-weight: 600; background: var(--fond); }
.m-app svg { width: 20px; height: 20px; }
.m-app small { margin-inline-start: auto; color: var(--gris); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.m-app.cours { opacity: .6; }
.m-app.ici { border: 2px solid var(--jaune); opacity: 1; }
hr { border: 0; border-top: 1px solid var(--gris-clair); margin: 8px 0; width: 100%; }

/* ---------- Divers ---------- */
.bandeau { background: var(--alerte); color: #fff; text-align: center; padding: 8px 12px; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--noir); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.toast.erreur-toast { background: var(--erreur); }
.attente-plein { position: fixed; inset: 0; z-index: 70; background: rgba(246, 245, 242, .85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-weight: 700; }
.roue { width: 48px; height: 48px; border: 5px solid var(--gris-clair); border-top-color: var(--noir); border-radius: 50%; animation: tourne 1s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }
.dialogue { border: 0; border-radius: var(--rayon); padding: 18px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.dialogue::backdrop { background: rgba(0, 0, 0, .45); }
.image-champ { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.image-champ img { max-height: 80px; max-width: 100%; object-fit: contain; border: 1px solid var(--gris-clair); border-radius: 8px; background: #fff; }

@media (max-width: 380px) {
  .barre h1 { font-size: .95rem; }
  .logo { height: 28px; }
  .langue { min-width: 32px; }
  .micro { width: 148px; height: 148px; }
  .ligne-chiffres { grid-template-columns: 1fr 1fr; }
  .ligne-chiffres > div:last-child { grid-column: 1 / -1; }
}
