/* ===========================================================================
   Scanner de documents plein écran — composant PARTAGÉ (plateforme)
   Extrait de festivites.css. Utilisé par Festivités (factures, inventaire)
   et par la boutique du dojo (scan d'inventaire). Client :
   static/js/festivites_scanner.js + templates/_document_scanner.html.
   =========================================================================== */
.fest-scanner { position:fixed; inset:0; z-index:1000; background:#0e0a16; color:#fff;
    display:flex; flex-direction:column; }
.fest-scanner[hidden] { display:none; }
.fest-scanner__bar { display:flex; align-items:center; justify-content:space-between; padding:1rem 1.1rem;
    padding-top:max(1rem, env(safe-area-inset-top)); }
.fest-scanner__title { font-weight:700; }
.fest-scanner__btn { background:rgba(255,255,255,.12); border:none; color:#fff; width:42px; height:42px;
    border-radius:50%; font-size:1.3rem; cursor:pointer; display:flex; align-items:center; justify-content:center; }
.fest-scanner__btn[aria-pressed="true"] { background:var(--fest-orange, #ff8a3d); }
.fest-scanner__stage { flex:1; display:flex; flex-direction:column; align-items:center;
    justify-content:center; justify-content:safe center; padding:1rem; overflow:auto; gap:1rem; }
.fest-scanner__canvas { max-width:100%; max-height:70vh; border-radius:12px; background:#fff;
    box-shadow:0 10px 40px rgba(0,0,0,.5); }
.fest-scanner__canvas[width="0"] { display:none; }
.fest-scanner__hint { text-align:center; color:rgba(255,255,255,.75); max-width:22rem; }
.fest-scanner__warn { width:100%; max-width:440px; display:flex; gap:.6rem; align-items:flex-start;
    background:rgba(245,158,11,.14); border:1px solid rgba(245,158,11,.45); border-radius:10px;
    padding:.7rem .85rem; color:#fcd9a0; font-size:.9rem; }
.fest-scanner__warn i { font-size:1.15rem; line-height:1.2; flex:none; color:#fbbf24; }
.fest-scanner__warn ul { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:.3rem; }
.fest-scanner__loading { display:flex; align-items:center; gap:.6rem; color:rgba(255,255,255,.85); }
.fest-scanner__actions { display:flex; align-items:center; justify-content:center; gap:.75rem; flex-wrap:wrap;
    padding:1.1rem; padding-bottom:max(1.1rem, env(safe-area-inset-bottom)); }
.fest-scanner__capture { cursor:pointer; }
.fest-spinner { width:18px; height:18px; border-radius:50%; border:3px solid rgba(255,255,255,.3);
    border-top-color:#fff; animation:fest-spin .8s linear infinite; display:inline-block; }
@keyframes fest-spin { to { transform:rotate(360deg); } }

/* Détails du festival : panneau repliable pleine largeur */
.fest-detail-settings__foot { display:flex; align-items:center; min-height:1.2rem; }
.fest-detail-settings > form[onsubmit] { margin-top:.5rem; }

/* ===========================================================================
   Optimisations iOS / mobile (back-office Festivités)
   =========================================================================== */

/* Empêche le zoom automatique de Safari iOS au focus d'un champ (< 16px). */
@media (max-width: 768px) {
    body.is-festivites .form-control,
    body.is-festivites select.form-control,
    body.is-festivites textarea.form-control { font-size: 16px; }
}

/* Cibles tactiles ≥ 44px et suppression du délai de tap sur les contrôles. */
body.is-festivites .button,
body.is-festivites .ui-tab,
body.is-festivites .fest-chip,
body.is-festivites .fest-icon-btn,
body.is-festivites .fest-task__box,
body.is-festivites .fest-step-btn,
.fest-scanner__btn,
.fest-scanner__capture {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (pointer: coarse) {
    body.is-festivites .fest-icon-btn,
    body.is-festivites .fest-step-btn,
    .fest-scanner__btn { min-width: 44px; min-height: 44px; }
    /* Coche de tâche : zone tactile confortable SANS élargir la rangée (alignement). */
    body.is-festivites .fest-task__box { padding: .55rem; margin: -.55rem; }
    body.is-festivites .ui-tab { min-height: 44px; }
    body.is-festivites .fest-chip { min-height: 40px; }
}

/* Défilement inertiel iOS sur les zones scrollables. */
body.is-festivites .ui-tabs,
.fest-scanner__stage { -webkit-overflow-scrolling: touch; }

/* Scanner : hauteur via viewport dynamique (évite la barre d'outils Safari)
   et confinement du rebond (overscroll). */
.fest-scanner { overscroll-behavior: contain; }
.fest-scanner__stage { overscroll-behavior: contain; }
.fest-scanner__canvas { max-height: 70dvh; }

/* ===========================================================================
   Sous-onglets des listes de tâches (festival)
   =========================================================================== */
.ui-tabs.ui-tabs--sub { flex-wrap: wrap; gap: .35rem; border-bottom-width: 1px; margin-bottom: 1rem; }
.fest-subtab { display: inline-flex; align-items: center; }
.fest-subtab .ui-tab { padding-right: .4rem; }
.fest-subtab__x { margin: 0; display: inline-flex; }
.fest-subtab__x-btn { background: none; border: none; color: var(--muted, #9ca3af); cursor: pointer;
    padding: .25rem .3rem; border-radius: 6px; display: flex; align-items: center; font-size: .85rem; line-height: 1; }
.fest-subtab__x-btn:hover { color: var(--danger, #dc2626); background: rgba(0,0,0,.06); }
.fest-subtab-add { color: var(--fest-pink, #ff4d8d); font-weight: 700; }
.fest-subtab-add:hover { background: var(--accent-soft, rgba(255,77,141,.1)); }

.fest-addlist { display: flex; flex-direction: column; gap: .65rem; padding: .25rem 0 1rem; }
.fest-addlist[hidden] { display: none; }  /* le « + » révèle/masque réellement le formulaire */
.fest-preset-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.fest-preset-chips form { margin: 0; }
.fest-chip--preset { cursor: pointer; border-style: dashed; background: none; }
.fest-chip--preset:hover { background: var(--fest-grad, #ff4d8d); color: #fff; border-color: transparent; }

/* Import / export JSON des listes de tâches */
.fest-import-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
    margin-top: .25rem; padding-top: .75rem; border-top: 1px dashed var(--line, rgba(0,0,0,.12)); }
.fest-import-form { margin: 0; }
.fest-import-btn { cursor: pointer; margin: 0; }

/* Scanner : barre d'outils + badge de détection non bloquant */
.fest-scanner__bar-tools { display: inline-flex; gap: .4rem; }
.fest-scanner__badge { position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: .5rem; padding: .45rem .9rem; border-radius: 999px;
    background: rgba(0,0,0,.6); color: #fff; font-size: .85rem; backdrop-filter: blur(4px); }
.fest-scanner__stage { position: relative; }

/* L'attribut `hidden` doit l'emporter dans le scanner : .button impose
   display:inline-flex, ce qui masquerait sinon l'effet de [hidden]. La
   spécificité « .fest-scanner [hidden] » (0,2,0) dépasse « .button » (0,1,0). */
.fest-scanner [hidden] { display: none; }

/* Scanner : écran de validation (image traitée + données lues) */
.fest-scanner__result { max-width: 100%; max-height: 88dvh; border-radius: 12px; background: #fff;
    box-shadow: 0 10px 40px rgba(0,0,0,.5); object-fit: contain; }
.fest-scanner__fields { width: 100%; max-width: 440px; background: rgba(255,255,255,.08);
    border-radius: 12px; padding: .85rem 1rem; color: #fff; }
.fest-scanner__fields h3 { margin: 0 0 .25rem; font-size: .95rem; font-weight: 700; }
.fest-scanner__fields-note { margin: 0 0 .7rem; color: rgba(255,255,255,.6); font-size: .82rem; }
/* Indicateur « comment l'image a été analysée » (IA vision / OCR+IA / OCR / zones / rien). */
.fest-scanner__method { display: inline-flex; align-items: center; gap: .35rem; margin: 0 0 .6rem;
    padding: .22rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 600; line-height: 1.3;
    border: 1px solid transparent; }
.fest-scanner__method i { font-size: .95rem; }
.fest-scanner__method.is-ai { background: rgba(52, 211, 153, .16); color: #6ee7b7; border-color: rgba(52, 211, 153, .35); }
.fest-scanner__method.is-ocr { background: rgba(56, 189, 248, .16); color: #7dd3fc; border-color: rgba(56, 189, 248, .35); }
.fest-scanner__method.is-none { background: rgba(251, 191, 36, .16); color: #fcd34d; border-color: rgba(251, 191, 36, .35); }
.fest-scanner__field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .7rem; }
.fest-scanner__field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.fest-scanner__field[data-field="fournisseur"] { grid-column: 1 / -1; }
.fest-scanner__field > span { color: rgba(255,255,255,.72); font-size: .8rem; display: flex; align-items: center; gap: .4rem; }
.fest-scanner__field .form-control { width: 100%; }

/* Recadrage interactif à bords courbes (scanner) */
.fest-crop { position: relative; display: inline-block; max-width: 100%; line-height: 0; }
.fest-crop .fest-scanner__canvas { display: block; max-width: 100%; max-height: 88dvh; border-radius: 12px; }
.fest-crop__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fest-crop__poly { fill: rgba(255,77,141,.14); stroke: #ff4d8d; stroke-width: 2; vector-effect: non-scaling-stroke; }
.fest-crop__handles { position: absolute; inset: 0; pointer-events: none; }
/* Poignées semi-transparentes (anneau) avec point central : on voit le coin de
   la facture à travers, et le point marque la position exacte. */
.fest-crop__handle { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; padding: 0;
    border-radius: 50%; background: rgba(255,77,141,.18); border: 2.5px solid rgba(255,77,141,.95);
    cursor: grab; pointer-events: auto; touch-action: none;
    box-shadow: 0 0 0 1.5px rgba(255,255,255,.7), 0 2px 6px rgba(0,0,0,.45); }
.fest-crop__handle::after { content: ""; position: absolute; left: 50%; top: 50%;
    width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%;
    background: #ff4d8d; box-shadow: 0 0 0 1.5px rgba(255,255,255,.8); }
.fest-crop__handle:active { cursor: grabbing; transform: scale(1.2); background: rgba(255,77,141,.32); }
.fest-crop__handle--edge { width: 22px; height: 22px; margin: -11px 0 0 -11px; border-width: 2px;
    border-style: dashed; background: rgba(255,255,255,.12); }
@media (pointer: coarse) {
    .fest-crop__handle { width: 38px; height: 38px; margin: -19px 0 0 -19px; }
    .fest-crop__handle--edge { width: 30px; height: 30px; margin: -15px 0 0 -15px; }
}

/* Zones d'OCR ciblé : rectangles colorés tracés par champ sur la photo */
.fest-crop__regions { position: absolute; inset: 0; pointer-events: none; }
.fest-region { position: absolute; border: 2px solid #fff; border-radius: 4px; box-sizing: border-box;
    pointer-events: none; }
.fest-region__label { position: absolute; top: -1.05rem; left: -2px; font-size: .62rem; font-weight: 700;
    color: #1a1a1a; padding: 0 .3rem; border-radius: 3px 3px 0 0; white-space: nowrap; line-height: 1.45; }
/* Pendant le tracé d'une zone : viseur sur l'image, poignées de coin en retrait. */
.fest-crop.is-arming { cursor: crosshair; touch-action: none; }
.fest-crop.is-arming .fest-crop__handle { pointer-events: none; opacity: .3; }

/* Barre de zones : pied de page (hors zone scrollable) → toujours accessible
   pendant qu'on agrandit/défile la photo. */
.fest-region-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem 1rem .15rem; border-top: 1px solid rgba(255,255,255,.1); }
.fest-region-bar__label { width: 100%; text-align: center; color: rgba(255,255,255,.6); font-size: .78rem; }
.fest-region-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .7rem;
    border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08);
    color: #fff; font: inherit; font-size: .85rem; line-height: 1.2; cursor: pointer; min-height: 38px; }
.fest-region-chip__dot { width: .8rem; height: .8rem; border-radius: 50%; background: var(--rc, #fff); flex: none; }
.fest-region-chip.has-region { border-color: var(--rc); }
.fest-region-chip.is-armed { border-color: var(--rc); box-shadow: 0 0 0 2px var(--rc); background: rgba(255,255,255,.16); }
.fest-region-chip--clear { color: rgba(255,255,255,.7); }
.fest-region-hint { margin: 0; padding: .5rem 1rem 0; text-align: center;
    color: rgba(255,255,255,.9); font-size: .88rem; }

/* ─────────────────────────────────────────────────────────────────────
   Feuille de rapprochement des lignes de facture ↔ inventaire
   (festivites_expense_lines.js). Ouverte APRÈS la fermeture du scanner :
   modale centrée sur grand écran, feuille de bas de page sur mobile.
   ───────────────────────────────────────────────────────────────────── */
.fest-recon { position: fixed; inset: 0; z-index: 1100; display: flex;
    align-items: center; justify-content: center; padding: 1rem; }
.fest-recon[hidden] { display: none; }
.fest-recon__backdrop { position: absolute; inset: 0; background: rgba(14, 10, 22, .55);
    backdrop-filter: blur(2px); }
.fest-recon__panel { position: relative; z-index: 1; display: flex; flex-direction: column;
    width: 100%; max-width: 660px; max-height: 90vh; background: #fff; color: #1a1a2e;
    border-radius: 18px; box-shadow: 0 24px 60px rgba(14, 10, 22, .4); overflow: hidden; }
.fest-recon__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: 1rem 1.15rem .6rem; }
.fest-recon__title { margin: 0; font-size: 1.12rem; font-weight: 700; display: flex; align-items: center; gap: .45rem; }
.fest-recon__x { border: 0; background: transparent; color: #666; font-size: 1.3rem; line-height: 1;
    cursor: pointer; padding: .25rem; border-radius: 8px; }
.fest-recon__x:hover { background: rgba(0, 0, 0, .06); color: #1a1a2e; }
.fest-recon__intro { margin: 0; padding: 0 1.15rem .5rem; color: #5a5a72; font-size: .88rem; line-height: 1.4; }
.fest-recon__body { flex: 1 1 auto; overflow-y: auto; padding: .5rem 1.15rem 1rem;
    display: flex; flex-direction: column; gap: .75rem; -webkit-overflow-scrolling: touch; }
.fest-recon__loading { color: #5a5a72; text-align: center; padding: 1.5rem 0; }
.fest-recon__row { border: 1px solid #e6e6ef; border-radius: 12px; padding: .75rem .8rem;
    display: flex; flex-direction: column; gap: .55rem; background: #fbfbfe; }
.fest-recon__row > label > span,
.fest-recon__nums label > span,
.fest-recon__pack > span { display: block; font-size: .74rem; font-weight: 600; color: #5a5a72;
    margin-bottom: .2rem; }
.fest-recon__nums { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .5rem; }
.fest-recon__nums input { width: 100%; }
.fest-recon__match select,
.fest-recon__pack select { width: 100%; }
.fest-recon__pack { margin-top: .1rem; }
.fest-recon__foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: .75rem 1.15rem; border-top: 1px solid #ececf4; background: #fff; flex-wrap: wrap; }
.fest-recon__status { margin: 0; color: #5a5a72; font-size: .85rem; flex: 1 1 auto; min-width: 120px; }
.fest-recon__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

@media (max-width: 560px) {
    .fest-recon { align-items: flex-end; padding: 0; }
    .fest-recon__panel { max-width: none; max-height: 92vh; border-radius: 18px 18px 0 0; }
    .fest-recon__nums { grid-template-columns: 1fr 1fr; }
    .fest-recon__actions { width: 100%; }
    .fest-recon__actions .button { flex: 1 1 auto; }
}
