/* Aperçus de l'espace organisateur : panneau commun (apercu.js, TDApercu.panneau). Préfixe tda-.
   ≥ 1200 px : colonne collante à droite du formulaire (modèle .jo-apercu de pro-journees.css) ; en dessous, bouton fixe
   « Aperçu » qui ouvre le même panneau en plein écran (<dialog> modal). Tailles et échelle du cadre posées par CSSOM. */

/* Mise en page conseillée d'un écran avec aperçu : formulaire à gauche, panneau à droite (ancre = second enfant) */
.tda-colonnes { display: grid; gap: 24px; align-items: start; min-width: 0; }
@media (min-width: 1200px) {
  .tda-colonnes { grid-template-columns: minmax(0, 1fr) minmax(420px, 40%); }
  .tda-colonnes > .tda-ancre, .tda-colonnes > .tda-hote { align-self: stretch; min-width: 0; }
}

.tda-hote { min-width: 0; height: 100%; }
html.tda-bloque { overflow: hidden; }

/* ---------------------------------------------------------------- bouton fixe (écrans < 1200 px) */
.tda-ouvrir { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 40; box-shadow: 0 8px 28px rgba(22, 26, 29, .22); }
.tda-ouvrir .ico { width: 18px; height: 18px; }
.tda-point { width: 9px; height: 9px; margin-left: 2px; border: 2px solid #fff; border-radius: 50%; background: var(--yellow); }
.tda-point[hidden] { display: none; }
.tda-hote.tda-large .tda-ouvrir { display: none; }
.tda-hote:not(.tda-large) .tda-plein { display: none; }   /* écran étroit : le panneau est déjà en plein écran */

/* ---------------------------------------------------------------- dialog : colonne (non modal) ou plein écran (modal) */
.tda-dlg { margin: 0; padding: 0; border: 0; background: none; color: var(--ink); }
.tda-dlg:not(.tda-modale) { position: sticky; top: calc(var(--hdp-h, 72px) + 18px); inset: auto; width: 100%; max-width: none;
  height: calc(100vh - var(--hdp-h, 72px) - 36px); height: calc(100dvh - var(--hdp-h, 72px) - 36px); min-height: 560px; max-height: none; }
.tda-dlg.tda-modale { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; }
.tda-dlg::backdrop { background: rgba(22, 26, 29, .38); }
.tda-dlg[open] { display: block; }

.tda { display: flex; flex-direction: column; gap: 10px; height: 100%; min-width: 0; padding: 14px 16px 12px; border: 1px solid var(--rule);
  border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-2); box-sizing: border-box; }
.tda-modale .tda { border: 0; border-radius: 0; box-shadow: none; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
@media (prefers-reduced-motion: no-preference) {
  .tda-modale[open] .tda { animation: tda-entre .22s var(--ease); }
}
@keyframes tda-entre { from { transform: translateY(16px); opacity: .5; } to { transform: none; opacity: 1; } }

/* tête : titre, pastille « Non enregistré », état (aria-live), fermer */
.tda-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.tda-h { display: flex; align-items: center; margin: 0; margin-right: auto; font: 800 17px/1.2 var(--f-display); letter-spacing: -.02em; overflow-wrap: anywhere; }
.tda-h::before { content: ""; flex: none; width: 5px; height: .8em; margin-right: 9px; background: var(--red-deep); transform: skew(-15deg); }
.tda-pastille { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 99px; background: var(--warn-bg); color: var(--yellow-ink);
  font: 700 12px/1 var(--f-text); white-space: nowrap; }
.tda-pastille[hidden] { display: none; }
.tda-etat { display: inline-flex; align-items: center; gap: 6px; margin: 0; font: 600 12.5px/1.2 var(--f-text); color: var(--ink-3); white-space: nowrap; }
.tda-etat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.tda-etat[data-etat="ok"]::before { background: var(--green); }
.tda-etat[data-etat="corriger"] { color: var(--danger); }
.tda-etat[data-etat="corriger"]::before, .tda-etat[data-etat="erreur"]::before { background: var(--danger); }
.tda-etat[data-etat="erreur"] { color: var(--danger); white-space: normal; }
.tda-fermer { display: none; place-items: center; width: 44px; height: 44px; margin: -6px -8px -6px 0; border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer; }
.tda-fermer:hover { background: var(--paper-2); }
.tda-fermer .ico { width: 22px; height: 22px; }
.tda-modale .tda-fermer { display: grid; }

/* commandes : une ligne compacte (taille, « Options de l'aperçu », plein écran, imprimer) ; options secondaires repliées */
.tda-vues, .tda-barre .td2-seg { flex-wrap: wrap; }
.tda .td2-seg button { min-height: 36px; padding: 0 11px; font-size: 13.5px; }
.tda-barre { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tda-barre > .td2-seg { flex: none; }
.tda-version-z[hidden], .tda-barre [hidden] { display: none; }
.tda-reglages { display: inline-flex; align-items: center; gap: 7px; flex: 1 1 auto; min-width: 0; min-height: 36px; padding: 2px 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink); text-align: left; cursor: pointer; }
.tda-reglages:hover { border-color: var(--ink); }
.tda-reglages[aria-expanded="true"] { border-color: var(--ink); background: var(--paper); }
.tda-reglages .ico { flex: none; width: 16px; height: 16px; }
.tda-reglages-t { display: grid; min-width: 0; line-height: 1.2; }
.tda-reglages-t b { font: 600 13px/1.25 var(--f-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tda-resume { font: 500 11.5px/1.25 var(--f-text); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tda-resume:empty { display: none; }
.tda-actions { display: inline-flex; flex: none; gap: 6px; margin-left: auto; }
.tda-actions .btn.small { width: 36px; height: 36px; padding: 0; justify-content: center; }
.tda-actions .ico { width: 16px; height: 16px; }
.tda-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 10px; align-items: end;
  padding: 10px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--paper); }
.tda-options > .tda-version-z { grid-column: 1 / -1; }

.tda-options[hidden], .tda-options [hidden] { display: none; }
.tda-champ { display: grid; gap: 4px; min-width: 0; }
.tda-champ > span { font: 600 12px/1.2 var(--f-text); color: var(--ink-3); }
.tda-champ select { width: 100%; min-width: 0; height: 38px; padding: 0 28px 0 10px; border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background-color: #fff;
  color: var(--ink); font: 500 14px var(--f-text); }
.tda-case { display: flex; align-items: center; gap: 8px; min-height: 38px; font: 500 13.5px/1.25 var(--f-text); color: var(--ink-2); cursor: pointer; }
.tda-case input { width: 18px; height: 18px; margin: 0; accent-color: var(--red-deep); }
.tda button:focus-visible, .tda select:focus-visible, .tda input:focus-visible, .tda-ouvrir:focus-visible { outline: 2px solid var(--red-deep); outline-offset: 2px; box-shadow: var(--focus); }

/* avertissements (200) et erreurs des champs (422) */
.tda-avert { display: grid; gap: 4px; flex: none; max-height: 6.6em; overflow-y: auto; margin: 0; padding: 7px 12px 7px 28px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--yellow-ink); font: 500 13px/1.4 var(--f-text); overscroll-behavior: contain; }
.tda-avert:focus-visible { outline: 2px solid var(--red-deep); outline-offset: 2px; }
.tda-aller { min-height: 28px; padding: 0 2px; border: 0; background: none; color: inherit; font: 700 13px/1.2 var(--f-text);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.tda-avert.tda-erreurs { background: var(--danger-bg); color: var(--danger); }
.tda-avert[hidden] { display: none; }

/* ---------------------------------------------------------------- scène et cadres alternés */
.tda-scene { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; padding: 12px; border-radius: var(--radius-sm); background: var(--paper-2); }
.tda-cadre { position: relative; width: 100%; height: 100%; transform-origin: 0 0; background: #fff; box-shadow: 0 2px 10px rgba(22, 26, 29, .08); }
.tda-cadre[data-taille="telephone"] { border-radius: 18px; overflow: hidden; outline: 6px solid #fff; outline-offset: -1px; }
.tda-cadre[data-taille="ordinateur"] { border-radius: 6px; overflow: hidden; }
.tda-cadre[hidden] { display: none; }
.tda-cadre iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; visibility: hidden; }
.tda-cadre iframe.visible { visibility: visible; }
.tda-cadre iframe:focus-visible { outline: 3px solid var(--red-deep); outline-offset: -3px; }
.tda-scene[aria-busy="true"]::after { content: ""; position: absolute; top: 0; left: 0; height: 3px; width: 40%; background: var(--red-deep); }
@media (prefers-reduced-motion: no-preference) {
  .tda-scene[aria-busy="true"]::after { animation: tda-charge 1.1s var(--ease) infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .tda-scene[aria-busy="true"]::after { width: 100%; opacity: .5; }
}
@keyframes tda-charge { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.tda-echelle { margin: -4px 0 0; min-height: 14px; font: 500 11.5px/1.2 var(--f-text); color: var(--ink-3); text-align: right; }

/* ---------------------------------------------------------------- boîte de réception (emails) */
.tda-boite-z { height: 100%; overflow-y: auto; }
.tda-boite-z[hidden] { display: none; }
.tda-boite { max-width: 680px; margin: 0 auto; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; overflow: hidden; }
.tda-boite-tete { display: grid; gap: 4px; margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--rule); background: var(--paper); }
.tda-boite-tete > div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; font-size: 13.5px; line-height: 1.4; }
.tda-boite-tete dt { color: var(--ink-3); }
.tda-boite-tete dd { margin: 0; overflow-wrap: anywhere; color: var(--ink); }
.tda-adr { color: var(--ink-3); }
.tda-boite-corps { margin: 0; padding: 16px; font: 400 14.5px/1.55 var(--f-text); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.tda-boite-mode { margin: 0; padding: 10px 16px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-2); }
.tda-boite-mode span { font-weight: 700; }
.tda-boite-alerte { margin: 0; padding: 10px 16px; background: var(--warn-bg); color: var(--yellow-ink); font: 600 13px/1.4 var(--f-text); }

@media (max-width: 520px) {
  .tda { padding: 10px 12px; gap: 8px; }
  .tda-scene { padding: 6px; }
  .tda-barre { flex-wrap: wrap; }
  .tda-reglages { order: 2; flex-basis: 100%; }   /* ligne 1 : taille + plein écran / imprimer ; ligne 2 : options */
  .tda-boite-tete > div { grid-template-columns: 1fr; gap: 0; }
}
