/* ============================================================
   compta.css — module « TVA - Pièces compta » (glocauxitec.fr)
   Mobile d'abord ; n'écrase aucune règle d'admin.css ; variables :root existantes
   (--fond, --fond2, --fond3, --sep, --texte, --texte2, --texte3, --bleu, --vert, --rouge, --orange, --violet, --gris, --r, --rl).
   Toutes les classes sont préfixées compta- (ou scopées sous [data-compta] / .compta-feuille).
   ============================================================ */

/* ---------- généralités ---------- */
.compta { padding-bottom: 8px; }
.compta button, .compta-feuille button { min-height: 44px; -webkit-tap-highlight-color: transparent; }
.compta .btn-petit, .compta-feuille .btn-petit { padding: 10px 14px; min-height: 44px; font-weight: 600; white-space: nowrap; }
.compta .btn-lien, .compta-feuille .btn-lien { min-height: 44px; }
.compta .segment button { min-height: 40px; }
.compta-ok { color: var(--vert); }
.compta-attention { color: var(--orange); }
.compta-ko { color: var(--rouge); }
.compta-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; }
.compta-val-fort { color: var(--texte) !important; font-weight: 700; font-size: 20px; }
.compta-val-long { white-space: normal; line-height: 1.35; font-size: 15px; max-width: 100%; }
.compta-champs .ligne .val { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.compta-alerte { background: rgba(255,69,58,.14); border: 1px solid rgba(255,69,58,.4); color: var(--texte); border-radius: var(--r); padding: 12px 14px; margin: 10px 0; font-size: 15px; line-height: 1.4; }
.compta-lien-ext { display: block; text-align: center; padding: 10px; font-size: 15px; }

/* petit spinner (dans les boutons et cartes) */
.compta-spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; vertical-align: -2px; animation: compta-rot .8s linear infinite; }
@keyframes compta-rot { to { transform: rotate(360deg); } }

/* ---------- sous-onglets (segment défilable) ---------- */
.compta-segment { display: flex; width: 100%; margin: 0 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.compta-segment::-webkit-scrollbar { display: none; }
.compta-segment button { flex: 1 0 auto; white-space: nowrap; padding: 8px 14px; }

/* ---------- en-tête collant du mois ---------- */
.compta-entete { position: sticky; top: 0; z-index: 5; background: var(--fond); padding: 8px 0 10px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.compta-nav { display: flex; align-items: center; gap: 8px; }
.compta-nav .compta-fleche { flex: 0 0 48px; font-size: 24px; line-height: 1; padding: 6px 0; }
.compta-select-mois { flex: 1; min-width: 0; background: var(--fond3); color: var(--texte); border: none; border-radius: 9px; padding: 10px 12px; font-size: 17px; font-weight: 600; min-height: 44px; }
.compta-nav-feuille { justify-content: center; margin: 8px 0; }
.compta-nav-feuille span { font-weight: 600; min-width: 150px; text-align: center; }
.compta-synchro { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.compta-synchro small { color: var(--texte2); font-size: 13px; }

/* cartes KPI : 2 colonnes sur mobile */
.compta-cartes { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.compta-cartes .carte { padding: 12px 14px; }
.compta-cartes .carte .v { font-size: 24px; }

/* ---------- barre d'actions (fixe en bas sur mobile) ---------- */
.compta-actions { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 14px; }
.compta-actions .btn-ios { width: 100%; }
.compta-switch-tout { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--texte2); font-size: 15px; padding: 0 4px; }
.compta-switch-tout .switch { margin-left: auto; }

/* ---------- progression « Aller chercher » ---------- */
.compta-progression { background: var(--fond2); border-radius: var(--rl); padding: 14px 16px; margin: 0 0 14px; }
.compta-progression-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.compta-journal { margin-top: 10px; max-height: 220px; overflow-y: auto; font-size: 14px; line-height: 1.45; color: var(--texte2); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.compta-journal div { padding: 2px 0; border-bottom: 1px solid var(--sep); overflow-wrap: anywhere; }
.compta-journal div:last-child { border-bottom: none; }
.compta-journal-ok { color: var(--vert); }
.compta-journal-ko { color: var(--orange); }
.compta-journal-haut { max-height: 45vh; background: var(--fond3); border-radius: var(--r); padding: 8px 10px; margin: 10px 0; }

/* ---------- liste des transactions ---------- */
.compta-liste .ligne { gap: 10px; }
.compta-tx { border-top: 1px solid var(--sep); }
.compta-tx:first-child { border-top: none; }
.compta-tx-ligne { flex-wrap: wrap; padding: 10px 12px; }
.compta-tx-ligne .lib { flex: 1 1 60%; min-width: 0; }
.compta-tx-ligne .lib small { overflow-wrap: anywhere; }
.compta-tx-date { flex: 0 0 auto; color: var(--texte2); font-size: 14px; font-variant-numeric: tabular-nums; min-width: 44px; }
.compta-tx-montant { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: auto; }
.compta-tx-ligne .pastille { max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compta-tx-ligne .chev { flex: 0 0 auto; }
/* document proposé sous la ligne */
.compta-tx-doc { display: flex; align-items: center; gap: 10px; padding: 8px 12px 10px 12px; background: rgba(48,209,88,.06); }
.compta-vignette { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: #000; flex: 0 0 56px; cursor: zoom-in; }
/* PDF sans miniature (sources e-mail / connecteur : jamais rendus par Ghostscript, cf. compta_imap.php) : icône texte à la place de l'image */
.compta-vignette-pdf { width: 56px; height: 56px; flex: 0 0 56px; border-radius: 8px; background: var(--fond3); color: var(--texte2); font-size: 12px; font-weight: 700; letter-spacing: .5px; display: inline-flex; align-items: center; justify-content: center; }
.compta-tx-doc-txt { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compta-tx-doc-txt small { display: block; color: var(--texte2); font-size: 13px; white-space: normal; }
.compta-btn-valider { flex: 0 0 auto; }

/* ---------- explication d'échec (Claude) : bloc orange ---------- */
.compta-explication { margin: 0 12px 12px; padding: 12px 14px; border-radius: var(--r); background: rgba(255,159,10,.12); border-left: 4px solid var(--orange); }
.compta-explication-titre { color: var(--orange); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.compta-explication p { margin: 0 0 10px; line-height: 1.45; font-size: 15px; white-space: pre-wrap; }
.compta-explication-boutons { display: flex; flex-wrap: wrap; gap: 8px; }
.compta-explication-boutons .btn-petit { flex: 1 1 45%; white-space: normal; }

/* ---------- « Tout est à jour » : bloc festif ---------- */
.compta-ajour { margin: 18px 0; padding: 34px 22px; text-align: center; border-radius: 20px;
  background: radial-gradient(500px 260px at 50% 0%, rgba(48,209,88,.28), transparent 70%), var(--fond2); border: 1px solid rgba(48,209,88,.35);
  animation: compta-apparition .5s ease-out; }
.compta-ajour-ic { font-size: 52px; line-height: 1; margin-bottom: 10px; animation: compta-saut 1.6s ease-in-out infinite; }
.compta-ajour h2 { margin: 0 0 10px; font-size: 22px; line-height: 1.3; color: var(--vert); }
.compta-ajour p { margin: 0; color: var(--texte2); }
@keyframes compta-saut { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes compta-apparition { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Scanner ---------- */
.compta-scan-boutons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.compta-scan-boutons .btn-ios { width: 100%; font-size: 17px; }
.compta-drop { border: 2px dashed var(--sep); border-radius: var(--rl); padding: 26px 16px; text-align: center; color: var(--texte2); cursor: pointer; margin-bottom: 12px; transition: border-color .15s, background .15s; }
.compta-drop small { display: block; margin-top: 6px; font-size: 13px; color: var(--texte3); }
.compta-drop-ic { font-size: 30px; margin-bottom: 4px; }
.compta-drop.on { border-color: var(--bleu); background: rgba(10,132,255,.08); color: var(--texte); }
.compta-compteurs { color: var(--texte2); font-size: 14px; min-height: 18px; margin: 4px 2px; }
.compta-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.compta-grille .compta-grille-vide { grid-column: 1 / -1; }
.compta-carte { background: var(--fond2); border-radius: var(--rl); overflow: hidden; display: flex; flex-direction: column; }
.compta-carte-nouvelle { animation: compta-apparition .45s ease-out; }
.compta-carte-locale { opacity: .85; }
.compta-carte-img { background: #000; height: 96px; display: grid; place-items: center; overflow: hidden; cursor: zoom-in; }
.compta-carte-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.compta-carte-vide { color: var(--texte3); font-size: 34px; }
.compta-carte-corps { padding: 8px 10px 4px; font-size: 14px; flex: 1; }
.compta-carte-nom { color: var(--texte2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compta-carte-statut { display: block; font-weight: 700; margin-top: 3px; }
.compta-carte-detail { display: block; color: var(--texte2); font-size: 13px; line-height: 1.35; margin-top: 2px; overflow-wrap: anywhere; }
.compta-carte-boutons { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px 10px; }
.compta-carte-boutons .btn-petit { flex: 1 1 auto; padding: 8px 10px; font-size: 14px; min-height: 40px; }

/* barre « à la chaîne » (mobile) : fixe en bas, gros bouton, safe-area */
.compta-chaine { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: rgba(28,28,30,.97); border-top: 1px solid var(--sep);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.compta-chaine span { color: var(--texte2); font-size: 14px; text-align: center; }
.compta-chaine .btn-ios { width: 100%; font-size: 20px; padding: 18px; }

/* ---------- feuille de détail (transaction / aperçu) ---------- */
.compta-detail { display: flex; flex-direction: column; gap: 12px; }
.compta-detail-doc { order: -1; }                  /* mobile : aperçu en premier */
.compta-apercu { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: var(--r); }
.compta-iframe { display: block; width: 100%; height: 60vh; border: none; border-radius: var(--r); background: #fff; }
.compta-boutons-feuille { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.compta-boutons-feuille .btn-ios { width: 100%; }
.compta-motif-resultat { margin: 0 16px 10px; padding: 8px 10px; background: var(--fond3); border-radius: 8px; font-size: 13px; color: var(--texte2); line-height: 1.4; }

/* recadrage manuel : canvas plein largeur, tactile */
.compta-recadrage { background: #000; border-radius: var(--r); display: grid; place-items: center; overflow: hidden; margin: 8px 0; }
.compta-recadrage canvas { touch-action: none; display: block; max-width: 100%; cursor: crosshair; user-select: none; -webkit-user-select: none; }

/* apprentissage / test en direct */
.compta-apprentissage-etat { background: var(--fond3); border-radius: var(--r); padding: 12px 14px; line-height: 1.45; font-size: 15px; }
.compta-apprentissage-etat small { display: block; color: var(--texte2); }
.compta-question { margin: 10px 0; padding: 12px 14px; border-radius: var(--r); background: rgba(10,132,255,.12); border-left: 4px solid var(--bleu); }
.compta-question-txt { margin-bottom: 8px; line-height: 1.4; white-space: pre-wrap; }
.compta-question-champ { display: flex; gap: 8px; }
.compta-question-champ input { flex: 1; min-width: 0; background: var(--fond2); border: none; border-radius: 9px; padding: 10px 12px; color: var(--texte); font-size: 17px; }
.compta-question-champ .btn-ios { flex: 0 0 auto; padding: 10px 16px; }

/* ---------- safe-area iOS (sans casser l'existant) ---------- */
.compta-feuille { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(28px + env(safe-area-inset-bottom)); }

/* ============================================================
   Mobile (≤ 720 px) : lignes en cartes empilées, barre d'actions fixe, feuilles plein écran
   ============================================================ */
@media (max-width: 720px) {
  .compta { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }   /* place pour la barre d'actions fixe */
  .compta-tx-ligne { align-items: flex-start; }
  .compta-tx-ligne .lib { flex: 1 1 calc(100% - 60px); order: 1; }
  .compta-tx-ligne .compta-tx-date { order: 0; padding-top: 2px; }
  .compta-tx-ligne .compta-tx-montant { order: 2; margin-left: auto; font-size: 18px; }
  .compta-tx-ligne .pastille { order: 3; max-width: 100%; }
  .compta-tx-ligne .chev { order: 4; margin-left: auto; align-self: center; }
  .compta-tx-doc { flex-wrap: wrap; }
  .compta-btn-valider { flex: 1 1 100%; }
  .compta-vignette, .compta-vignette-pdf { width: 96px; height: 96px; flex-basis: 96px; }
  .compta-tx-doc-txt { flex: 1 1 calc(100% - 110px); white-space: normal; }
  .compta-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(28,28,30,.97); border-top: 1px solid var(--sep); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
  .compta-actions .btn-ios { padding: 13px; font-size: 16px; }
  .compta-switch-tout { min-height: 36px; }
  .compta-grille { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .compta-carte-img { height: 96px; }
  .compta-entete { top: -1px; }
  /* feuilles plein écran (seulement celles du module, via la classe posée par compta.js) */
  .feuille.compta-feuille { width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; padding-top: calc(8px + env(safe-area-inset-top)); }
  .compta-feuille .feuille-tete { position: sticky; top: 0; background: var(--fond2); z-index: 2; padding-top: 4px; }
  .compta-feuille .ligne .lib { flex-basis: 110px; }
  .compta-apercu { max-height: 48vh; }
  .compta-iframe { height: 55vh; }
  .compta-question-champ { flex-direction: column; }
}

/* ============================================================
   Écrans larges (> 720 px) : deux colonnes dans la feuille, actions en ligne, vignettes plus grandes
   ============================================================ */
@media (min-width: 721px) {
  .compta-segment { width: auto; margin-left: 0; }
  .compta-segment button { flex: 0 0 auto; }
  .compta-entete { flex-direction: row; align-items: center; justify-content: space-between; }
  .compta-nav { flex: 0 1 420px; }
  .compta-cartes { grid-template-columns: repeat(4, 1fr); }
  .compta-actions { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .compta-actions .btn-ios { width: auto; flex: 1 1 auto; }
  .compta-switch-tout { flex: 0 0 auto; margin-left: auto; }
  .compta-detail { flex-direction: row; align-items: flex-start; }
  .compta-detail-tx { flex: 1 1 50%; min-width: 0; }
  .compta-detail-doc { flex: 1 1 50%; min-width: 0; order: 0; position: sticky; top: 0; }
  .compta-boutons-feuille { flex-direction: row; flex-wrap: wrap; }
  .compta-boutons-feuille .btn-ios { width: auto; flex: 1 1 calc(50% - 8px); }
  .compta-scan-boutons { flex-direction: row; }
  .compta-scan-boutons .btn-ios { width: auto; flex: 0 1 auto; }
  .compta-explication-boutons .btn-petit { flex: 0 1 auto; }
  .compta-chaine { display: none; }
  .feuille.compta-feuille { width: min(980px, 100%); }
}
