/* Charte commune des applications de mjacquot.fr, servie sur https://mjacquot.fr/charte.css.
 * Style : thème « Sandstone » de Bootswatch (choix de Max, 2026-10-17), reproduit sans Bootstrap :
 * police Roboto, fond crème, bords beige, boutons pleins en petites majuscules, messages et pastilles
 * en couleurs pleines. Valeurs reprises de bootswatch@5.3.3 (dist/sandstone/_variables.scss).
 *
 * Chaque application la charge AVANT sa propre feuille de style :
 *   <link rel="stylesheet" href="https://mjacquot.fr/charte.css">
 *   <link rel="stylesheet" href="/style.css">
 * et pose sa couleur : :root { --accent: #1d6f42; }  (celle de src/outils.js).
 *
 * Tout est rangé dans la couche « charte » (@layer) : le style propre à une application gagne toujours,
 * même avec un sélecteur plus faible. On peut donc brancher la charte sans rien casser, puis retirer
 * petit à petit de l'application ce que la charte fait déjà.
 *
 * Briques : .entete, .page, .carte, button / .bouton (.principal, .danger, .clair, .discret, .petit), .actions,
 * .alerte, .pastille, .etiquette, .champ, .tableau, dialog.fenetre, .notification, .roue, .aide.
 * Page de démonstration : https://mjacquot.fr/charte
 * Mode sombre : seulement si l'application le demande (<html data-theme="auto"> ou "dark").
 */

/* Roboto servie par le portail (licence OFL, polices/LICENCE-roboto.txt) : pas d'appel à Google. */
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 400; font-display: swap; src: url("/polices/roboto-400.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 500; font-display: swap; src: url("/polices/roboto-500.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 700; font-display: swap; src: url("/polices/roboto-700.woff2") format("woff2"); }

@layer charte {
  :root {
    /* Couleur de l'application (Sandstone : bleu #325d88). Les teintes dérivées suivent. */
    --accent: #325d88;
    --accent-fonce: color-mix(in srgb, var(--accent) 85%, black);
    --accent-clair: color-mix(in srgb, var(--accent) 10%, white);
    --accent-texte: var(--accent);
    --sur-accent: #ffffff;

    /* Palette Sandstone */
    --fond: #f8f5f0;      /* gray-200 « light » */
    --carte: #ffffff;
    --gris: #f8f5f0;
    --texte: #3e3f3a;     /* gray-800 « dark » */
    --doux: #6e6f6b;      /* texte secondaire (Bootstrap : body-color à 75 %) */
    --bord: #dfd7ca;      /* gray-300 */
    --secondaire: #8e8c84;/* gray-600 */

    --succes: #93c54b;
    --info: #29abe0;
    --attention: #f47c3c;
    --danger: #d9534f;
    --sur-couleur: #ffffff;

    --police: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --taille: 16px; /* 18px pour les applications de la mère de Max (plus lisible) */
    --rayon: 0.375rem;
    --rayon-grand: 0.5rem;
    --ombre-forte: 0 0.5rem 1rem rgb(0 0 0 / 0.15);
    --largeur-page: 1200px;
    --marge: 16px;

    /* Mouvement : valeurs d'IBM Carbon (@carbon/motion v11, courbes « expressive »). Rapide à l'aller, plus vif au départ. */
    --duree-rapide: 110ms;   /* fast-02 */
    --duree-moyenne: 240ms;  /* moderate-02 : fenêtres, volet */
    --courbe-entree: cubic-bezier(0, 0, 0.3, 1);       /* entrance expressive : arrive vite, se pose en douceur */
    --courbe-sortie: cubic-bezier(0.4, 0.14, 1, 1);    /* exit expressive : part doucement, file vite */
    --courbe-standard: cubic-bezier(0.4, 0.14, 0.3, 1);
    color-scheme: light;
  }

  /* Mode sombre (celui de Bootstrap 5.3), sur demande de l'application seulement. */
  @media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
      --fond: #212529; --carte: #2b3035; --gris: #343a40; --texte: #dee2e6; --doux: #adb5bd; --bord: #495057;
      --accent-clair: color-mix(in srgb, var(--accent) 25%, #2b3035);
      --accent-texte: color-mix(in srgb, var(--accent) 55%, white);
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --fond: #212529; --carte: #2b3035; --gris: #343a40; --texte: #dee2e6; --doux: #adb5bd; --bord: #495057;
    --accent-clair: color-mix(in srgb, var(--accent) 25%, #2b3035);
    --accent-texte: color-mix(in srgb, var(--accent) 55%, white);
    color-scheme: dark;
  }

  /* --- Base --- */
  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body {
    margin: 0;
    font: 400 var(--taille)/1.5 var(--police);
    background: var(--fond);
    color: var(--texte);
  }
  h1, h2, h3, h4 { margin: 0 0 0.5em; font-weight: 400; line-height: 1.2; text-wrap: balance; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.4rem; }
  h3 { font-size: 1.15rem; }
  h4 { font-size: 1rem; font-weight: 500; }
  p { margin: 0 0 1em; }
  b, strong { font-weight: 700; }
  a { color: var(--accent-texte); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* --- En-tête (barre de navigation Sandstone, à la couleur de l'application) --- */
  .entete {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 12px 24px;
    background: var(--accent);
    color: var(--sur-accent);
  }
  .entete h1 { margin: 0; font-size: 1.35rem; font-weight: 400; }
  .entete .titre { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .entete a, .entete .lien { color: rgb(255 255 255 / 0.8); font-size: 13px; font-weight: 500; text-transform: uppercase; text-decoration: none; }
  .entete a:hover { color: #fff; }
  #volet-outils:empty { display: none; } /* portail injoignable (ex. en local) : pas de bouton, pas de décalage */
  @media (max-width: 600px) { .entete { padding: 10px var(--marge); } .entete h1 { font-size: 1.2rem; } }

  /* --- Contenu de la page --- */
  .page { max-width: var(--largeur-page); margin: 0 auto; padding: 24px var(--marge) 64px; }
  .page.etroite { --largeur-page: 760px; }

  /* --- Carte (card Sandstone : bord beige, coins peu arrondis) --- */
  .carte {
    background: var(--carte);
    border: 1px solid color-mix(in srgb, var(--bord) 75%, transparent);
    border-radius: var(--rayon);
    padding: 20px;
    margin-bottom: 16px;
  }
  .carte > :last-child { margin-bottom: 0; }
  .carte.active { border: 2px solid var(--accent); }
  .carte-tete { margin: -20px -20px 16px; padding: 10px 20px; background: color-mix(in srgb, var(--gris) 60%, transparent); border-bottom: 1px solid var(--bord); border-radius: var(--rayon) var(--rayon) 0 0; }

  /* --- Boutons (button ou lien a.bouton) : pleins, petites majuscules.
     Règle de Max (2026-10-18) : un bouton utilisable est plein à la couleur de l'application (Sandstone les met
     en gris « secondary ») ; le gris est réservé aux boutons qu'on ne peut pas utiliser (désactivés). --- */
  button, .bouton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: calc(var(--taille) * 0.8125); /* 13 px pour un texte de 16 px */
    font-weight: 500;
    line-height: 22px;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: var(--rayon);
    background: var(--accent);
    color: var(--sur-couleur);
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  }
  button:hover:not(:disabled), .bouton:hover { background: var(--accent-fonce); border-color: var(--accent-fonce); }
  button.principal, .bouton.principal { font-weight: 700; } /* même couleur : le bouton principal se distingue par le gras */
  button.danger, .bouton.danger { background: var(--danger); border-color: var(--danger); }
  button.danger:hover:not(:disabled), .bouton.danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }
  button.succes, .bouton.succes { background: var(--succes); border-color: var(--succes); }
  button.succes:hover:not(:disabled), .bouton.succes:hover { background: color-mix(in srgb, var(--succes) 85%, black); }
  /* Action secondaire : teinte pâle de la couleur de l'application (jamais grise) */
  button.clair, .bouton.clair { background: var(--accent-clair); border-color: color-mix(in srgb, var(--accent) 35%, white); color: var(--accent-texte); }
  button.clair:hover:not(:disabled), .bouton.clair:hover { background: color-mix(in srgb, var(--accent) 22%, white); border-color: color-mix(in srgb, var(--accent) 35%, white); }
  button.discret, .bouton.discret { background: transparent; border-color: transparent; color: var(--accent-texte); }
  button.discret:hover:not(:disabled), .bouton.discret:hover { background: transparent; text-decoration: underline; }
  button.petit, .bouton.petit { font-size: calc(var(--taille) * 0.7); line-height: 18px; padding: 0.25rem 0.5rem; }
  button.grand, .bouton.grand { font-size: var(--taille); padding: 0.5rem 1rem; }
  button:focus-visible, .bouton:focus-visible { outline: none; box-shadow: 0 0 0 0.25rem color-mix(in srgb, var(--accent) 40%, transparent); }
  /* Désactivé : gris, quelle que soit la variante (placé après elles pour gagner) */
  button:disabled, .bouton[aria-disabled="true"] { background: var(--bord); border-color: var(--bord); color: var(--doux); cursor: not-allowed; }
  button.discret:disabled, .bouton.discret[aria-disabled="true"] { background: transparent; border-color: transparent; }
  .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
  .actions.droite { justify-content: flex-end; }
  .actions.centre { justify-content: center; }

  /* --- Messages dans la page (alert Sandstone : couleur pleine, texte blanc) --- */
  .alerte {
    padding: 1rem;
    border-radius: var(--rayon);
    background: var(--info);
    color: var(--sur-couleur);
    margin-bottom: 1rem;
  }
  .alerte > :last-child { margin-bottom: 0; }
  .alerte a { color: inherit; text-decoration: underline; }
  .alerte.succes { background: var(--succes); }
  .alerte.attention { background: var(--attention); }
  .alerte.erreur { background: var(--danger); }
  .alerte.claire { background: var(--gris); color: var(--texte); border: 1px solid var(--bord); }

  /* --- Pastille (badge Sandstone : état court, « ✓ Identique ») et étiquette (mot-clé) --- */
  .pastille {
    display: inline-block;
    padding: 0.35em 0.65em;
    border-radius: var(--rayon);
    font-size: 0.75em;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    vertical-align: baseline;
    background: var(--secondaire);
    color: var(--sur-couleur);
  }
  .pastille.ok { background: var(--succes); }
  .pastille.attention { background: var(--attention); }
  .pastille.erreur { background: var(--danger); }
  .pastille.info { background: var(--info); }
  .pastille.accent { background: var(--accent); }
  .pastille.claire { background: var(--gris); color: var(--texte); }
  .etiquette {
    display: inline-block;
    padding: 0.2em 0.6em;
    border: 1px solid var(--bord);
    border-radius: var(--rayon);
    font-size: 0.75em;
    font-weight: 500;
    text-transform: uppercase;
    color: var(--doux);
  }

  /* --- Champs de formulaire (form-control Sandstone : pas d'ombre) --- */
  .champ { display: flex; flex-direction: column; gap: 6px; margin-bottom: 1rem; }
  .champ > label { font-weight: 500; }
  input:not([type=checkbox], [type=radio], [type=file], [type=range]), select, textarea {
    font: inherit;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--bord);
    border-radius: var(--rayon);
    background: var(--carte);
    color: var(--texte);
    max-width: 100%;
    transition: border-color 0.15s ease-in-out;
  }
  input:focus, select:focus, textarea:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 50%, white); }
  input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.1em; height: 1.1em; }
  .aide { color: var(--doux); font-size: 0.875em; }

  /* --- Tableau (dans un bloc .tableau, qui défile en largeur si besoin) --- */
  .tableau { overflow-x: auto; border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--carte); }
  .tableau table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  .tableau th, .tableau td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: top; }
  .tableau thead th { background: var(--gris); font-weight: 700; position: sticky; top: 0; }
  .tableau tbody tr:last-child td { border-bottom: none; }
  .tableau tbody tr:hover td { background: color-mix(in srgb, var(--texte) 4%, transparent); }
  .tableau tfoot td { font-weight: 700; border-top: 2px solid var(--bord); border-bottom: none; }
  .tableau .nombre { text-align: right; white-space: nowrap; }
  .tableau thead.fonce th { background: var(--texte); color: var(--carte); }

  /* --- Fenêtre (<dialog class="fenetre">, ouverte par showModal()) : modal Sandstone --- */
  dialog.fenetre {
    width: min(500px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--bord);
    border-radius: var(--rayon-grand);
    background: var(--carte);
    color: var(--texte);
    box-shadow: var(--ombre-forte);
  }
  dialog.fenetre::backdrop { background: rgb(0 0 0 / 0.5); }
  .fenetre-contenu { padding: 1rem; }
  .fenetre-contenu h2 { margin: -1rem -1rem 1rem; padding: 1rem; border-bottom: 1px solid var(--bord); font-size: 1.25rem; }
  .fenetre-contenu .actions { justify-content: flex-end; margin: 1rem -1rem -1rem; padding: 0.75rem 1rem; border-top: 1px solid var(--bord); }

  /* --- Notification en bas de l'écran (toast) --- */
  .notification {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 50;
    max-width: calc(100vw - 32px);
    padding: 0.75rem 1rem;
    border-radius: var(--rayon);
    background: var(--texte);
    color: var(--carte);
    box-shadow: var(--ombre-forte);
  }

  /* --- Chargement --- */
  .roue {
    display: inline-block;
    width: 1.2em;
    height: 1.2em;
    border: 0.2em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    color: var(--accent);
    animation: charte-tourne 0.75s linear infinite;
    vertical-align: middle;
  }
  @keyframes charte-tourne { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .roue { animation-duration: 2.25s; } }

  /* --- Mouvement (comme la fenêtre d'IBM Carbon), seulement si l'appareil ne demande pas de réduire les animations --- */
  @media (prefers-reduced-motion: no-preference) {
    /* Arrivée sur une page (y compris en passant d'une application à l'autre) : fondu, et le contenu monte un peu. */
    body { animation: charte-fondu var(--duree-rapide) var(--courbe-entree); }
    main { animation: charte-monte var(--duree-moyenne) var(--courbe-entree); }

    /* Fenêtre : descend de 24 px en apparaissant, remonte en disparaissant ; le fond sombre suit en fondu.
       Pour la fermeture, le navigateur doit savoir garder la fenêtre affichée le temps du fondu (overlay) :
       sinon (Firefox), elle se ferme d'un coup, comme avant. */
    dialog.fenetre[open] { animation: charte-fenetre var(--duree-moyenne) var(--courbe-entree); }
    dialog.fenetre[open]::backdrop { animation: charte-fondu var(--duree-moyenne) var(--courbe-entree); }
    @supports (overlay: auto) {
      dialog.fenetre, dialog.fenetre::backdrop {
        transition: opacity var(--duree-moyenne) var(--courbe-sortie), transform var(--duree-moyenne) var(--courbe-sortie),
          overlay var(--duree-moyenne) allow-discrete, display var(--duree-moyenne) allow-discrete;
      }
      dialog.fenetre:not([open]) { opacity: 0; transform: translateY(-24px); }
      dialog.fenetre:not([open])::backdrop { opacity: 0; }
    }
  }
  @keyframes charte-fondu { from { opacity: 0; } }
  @keyframes charte-monte { from { opacity: 0; transform: translateY(8px); } }
  @keyframes charte-fenetre { from { opacity: 0; transform: translateY(-24px); } }
}
