/* ==========================================================================
   Mise en page et composants communs (barre d'application, boutons,
   fenêtres, messages). Ce fichier ne contient aucune couleur : il utilise
   les variables définies dans themes.css. Il est pensé pour être réutilisé
   par les autres applications de la suite (tableur, aide à l'écriture…).
   ========================================================================== */

:root {
  --police-interface: "Oxanium", "Trebuchet MS", system-ui, sans-serif;
  --police-document: "Literata", Georgia, serif;
  --police-chiffres: "JetBrains Mono", ui-monospace, monospace;
  --rayon-bouton: 10px;
  --rayon-carte: 14px;
  --cible: 44px;            /* taille minimale d'une zone tactile */
  --duree: 150ms;           /* durée maximale des transitions */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police-interface);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.4;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--halo);
  text-underline-offset: 3px;
}

/* Focus clavier : toujours visible, même style partout. */
:focus-visible {
  outline: 2px solid var(--halo);
  outline-offset: 3px;
}

/* Un élément masqué (attribut hidden) l'est toujours, même un bouton. */
[hidden] {
  display: none !important;
}

.visuellement-cache {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.etiquette {
  font-family: var(--police-interface);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--discret);
}

.chiffres {
  font-family: var(--police-chiffres);
  font-variant-numeric: tabular-nums;
}

/* Lien d'évitement : invisible tant qu'il n'a pas le focus clavier. */
.lien-evitement {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: var(--rayon-bouton);
  background: var(--accent);
  color: var(--accent-texte);
  font-weight: 700;
  transform: translateY(-200%);
}

.lien-evitement:focus {
  transform: none;
}

.sprite {
  display: none;
}

/* --- Ossature de l'application ------------------------------------------ */
/* La hauteur suit la zone réellement visible (clavier virtuel compris). */
.application {
  position: fixed;
  left: 0;
  top: var(--decalage-visible, 0px);
  width: 100%;
  height: var(--hauteur-visible, 100dvh);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "entete" "outils" "recherche" "contenu" "etat";
}

/* Chaque partie a sa place, même quand l'une d'elles est masquée. */
.application > header {
  grid-area: entete;
}

.application > main {
  grid-area: contenu;
}

.application > footer {
  grid-area: etat;
}

/* Champ de saisie d'une ligne. */
.champ {
  min-width: 0;
  min-height: var(--cible);
  padding: 0 12px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-bouton);
  background: var(--page);
  color: var(--texte);
  font: inherit;
  font-weight: 500;
}

.champ::placeholder {
  color: var(--discret);
  opacity: 1;
}

/* --- Barre d'application (haut de l'écran) ------------------------------ */
.barre-app {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--trait);
}

.zone-titre {
  flex: 1;
  min-width: 0;
  display: grid;
}

.champ-titre {
  width: 100%;
  min-height: var(--cible);
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: var(--rayon-bouton);
  background: transparent;
  color: var(--texte);
  font-family: var(--police-interface);
  font-weight: 700;
  font-size: 1.08rem;
  text-overflow: ellipsis;
  transition: border-color var(--duree);
}

.champ-titre::placeholder {
  color: var(--discret);
  opacity: 1;
}

.champ-titre:hover {
  border-color: var(--trait);
}

.etat-enregistrement {
  min-height: 1.2em;
  padding: 0 11px;
  font-size: 0.78rem;
  color: var(--discret);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.etat-enregistrement[data-etat="erreur"] {
  color: var(--danger);
  font-weight: 700;
}

/* --- Boutons ------------------------------------------------------------- */
.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: var(--cible);
  min-height: var(--cible);
  padding: 0 14px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-bouton);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background-color var(--duree), border-color var(--duree);
}

.bouton:hover {
  background: var(--survol);
}

.bouton:disabled {
  opacity: 0.45;
  cursor: default;
}

.bouton:disabled:hover {
  background: var(--surface);
}

.bouton-icone {
  width: var(--cible);
  padding: 0;
}

.bouton-principal {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-texte);
}

.bouton-principal:hover {
  background: var(--accent);
  border-color: var(--halo);
}

.bouton-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-texte);
}

.bouton-danger:hover {
  background: var(--danger);
  border-color: var(--texte);
}

/* Bouton discret : sans bordure, utilisé dans les barres d'outils. */
.bouton-discret {
  border-color: transparent;
  background: transparent;
}

.bouton-discret:disabled:hover {
  background: transparent;
}

/* Bouton activé (gras actif, alignement choisi…). */
.bouton[aria-pressed="true"] {
  background: var(--accent-doux);
  border-color: var(--accent);
}

.icone {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sur un écran étroit, certains boutons n'affichent que leur icône. */
@media (max-width: 700px) {
  .libelle-large {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .barre-app .bouton:has(.libelle-large) {
    width: var(--cible);
    padding: 0;
  }
}

/* --- Listes déroulantes -------------------------------------------------- */
.liste {
  position: relative;
  display: inline-flex;
}

.liste select {
  min-height: var(--cible);
  padding: 0 30px 0 10px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-bouton);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-weight: 600;
  appearance: none;
  cursor: pointer;
  transition: background-color var(--duree);
}

.liste select:hover {
  background: var(--survol);
}

/* Petite flèche dessinée en CSS (pas d'image). */
.liste::after {
  content: "";
  position: absolute;
  right: 13px;
  top: calc(50% - 6px);
  width: 7px;
  height: 7px;
  border: solid var(--discret);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

/* --- Fenêtres (élément <dialog>) ----------------------------------------- */
dialog {
  width: min(520px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-carte);
  background: var(--surface);
  color: var(--texte);
  box-shadow: var(--ombre);
  overflow: auto;
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: var(--voile);
}

dialog[open] {
  animation: apparition var(--duree) ease-out;
}

@keyframes apparition {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.fenetre-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 6px 20px;
}

.fenetre-entete h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

.fenetre-corps {
  display: grid;
  gap: 12px;
  padding: 8px 20px 12px;
  line-height: 1.5;
}

.fenetre-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 20px 20px;
}

.texte-discret {
  color: var(--discret);
  font-size: 0.92rem;
}

.case-a-cocher {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--cible);
  cursor: pointer;
}

.case-a-cocher input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

/* --- Fenêtre « Exporter » : une grande carte par format ------------------- */
.choix-export {
  display: grid;
  gap: 8px;
}

.option-export {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 14px;
  row-gap: 2px;
  min-height: var(--cible);
  padding: 12px 14px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-carte);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--duree), border-color var(--duree);
}

.option-export:hover {
  background: var(--survol);
  border-color: var(--accent);
}

.option-export .icone {
  grid-row: span 2;
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.option-nom {
  font-weight: 700;
}

.option-detail {
  color: var(--discret);
  font-size: 0.9rem;
}

/* --- Menu principal ------------------------------------------------------ */
dialog.menu {
  margin: 0;
  width: min(360px, calc(100vw - 24px));
}

.menu-section {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px 16px 14px;
  border: 0;
  border-top: 1px solid var(--trait);
}

.menu-section:first-of-type {
  border-top: 0;
}

.menu-section > legend,
.menu-section > .etiquette {
  float: left;
  width: 100%;
  margin-bottom: 4px;
  padding: 0;
}

.menu-section .bouton {
  justify-content: flex-start;
  width: 100%;
  text-align: left;
}

.choix-theme {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--cible);
  padding: 6px 12px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-bouton);
  cursor: pointer;
  font-weight: 700;
  transition: background-color var(--duree), border-color var(--duree);
}

.choix-theme:hover {
  background: var(--survol);
}

.choix-theme:has(input:checked) {
  background: var(--accent-doux);
  border-color: var(--accent);
}

.choix-theme:has(input:focus-visible) {
  outline: 2px solid var(--halo);
  outline-offset: 3px;
}

.choix-theme input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

/* Pastille d'aperçu : elle porte son propre data-theme, donc ses variables
   sont celles du thème qu'elle représente. */
.pastille-theme {
  position: relative;
  flex: none;
  width: 30px;
  height: 30px;
  border: 2px solid var(--trait);
  border-radius: 50%;
  background: var(--fond);
}

.pastille-theme::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* --- Tiroir « Mes documents » -------------------------------------------- */
dialog.tiroir {
  margin: 0;
  inset: 0 auto 0 0;
  width: min(400px, 92vw);
  height: 100dvh;
  max-height: 100dvh;
  border-width: 0 1px 0 0;
  border-radius: 0 var(--rayon-carte) var(--rayon-carte) 0;
  display: none;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

dialog.tiroir[open] {
  display: grid;
  animation: glissement var(--duree) ease-out;
}

@keyframes glissement {
  from {
    transform: translateX(-24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.tiroir-actions {
  display: grid;
  gap: 8px;
  padding: 4px 16px 12px;
}

.tiroir-actions .bouton {
  width: 100%;
}

/* Annonce dans un panneau (« … est dans la corbeille. » + « Annuler »).
   Vide, elle ne prend pas de place mais reste lue par les lecteurs d'écran. */
.annonce {
  display: flex;
  align-items: center;
  gap: 10px;
}

.annonce:has(.annonce-texte:not(:empty)) {
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--rayon-carte);
  background: var(--accent-doux);
}

.annonce-texte {
  flex: 1;
}

.tiroir-actions .annonce .bouton {
  width: auto;
  flex: none;
}

/* Bas du panneau : accès à la corbeille, ou « Vider la corbeille ». */
.tiroir-pied {
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--trait);
}

.tiroir-pied .bouton {
  width: 100%;
  justify-content: flex-start;
}

.liste-documents {
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 0;
  padding: 4px 16px 16px;
  list-style: none;
  overflow-y: auto;
}

/* Document dans la corbeille : informations, puis deux boutons. */
.document-jete {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-carte);
}

.document-jete .document-infos {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.document-jete .document-actions {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  padding: 0;
}

.document {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-carte);
  background: var(--surface);
}

.document[aria-current="true"] {
  border-color: var(--accent);
}

.document-ouvrir {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--rayon-carte) 0 0 var(--rayon-carte);
  background: transparent;
  color: var(--texte);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duree);
}

.document-ouvrir:hover {
  background: var(--survol);
}

.document-titre {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-date {
  font-size: 0.8rem;
  color: var(--discret);
}

.document-extrait {
  font-family: var(--police-document);
  font-size: 0.88rem;
  color: var(--discret);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.document-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px;
}

.document-etiquette-ouvert {
  font-size: 0.72rem;
  color: var(--halo);
  font-weight: 700;
}

.liste-vide {
  color: var(--discret);
  padding: 8px 4px;
}

/* --- Messages temporaires (en bas de l'écran) ---------------------------- */
.zone-messages {
  position: fixed;
  left: 50%;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(480px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

.message {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon-carte);
  background: var(--surface);
  color: var(--texte);
  box-shadow: var(--ombre);
  pointer-events: auto;
  animation: apparition var(--duree) ease-out;
}

.message p {
  flex: 1;
  min-height: 24px;
  display: flex;
  align-items: center;
}

/* --- Fenêtre « À propos » ------------------------------------------------ */
.a-propos {
  justify-items: center;
  padding-top: 28px;
  text-align: center;
}

.a-propos img {
  width: 104px;
  height: 104px;
  border-radius: var(--rayon-carte);
}

.a-propos .nom-application {
  font-size: 1.5rem;
  font-weight: 800;
}

.a-propos .version {
  color: var(--discret);
  font-size: 0.9rem;
}

.a-propos p {
  max-width: 40ch;
}

/* --- Animations : réduites au strict minimum ----------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
