/* Socle commun (repris du carnet d'entretien) : couleurs (thème clair/sombre automatique), typographie, en-tête,
   cartes, boutons, formulaires, dialogues, badges, notifications à l'écran. Styles des vues : css/app.css. */
:root {
  --fond: #f4f5f7;
  --carte: #ffffff;
  --texte: #1c1e22;
  --discret: #646a73;
  --bord: #e2e4e8;
  --accent: #b8325a;
  --accent-doux: #fbe9ef;
  --accent-texte: #ffffff;
  --bon: #1d7a46;
  --bon-doux: #e4f4ea;
  --moyen: #9a6a00;
  --moyen-doux: #fdf3dc;
  --faible: #b4322a;
  --faible-doux: #fbe7e5;
  --badge: #eef1f6;
  --ombre: 0 1px 2px rgba(16, 24, 40, .06);
  --rayon: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #15171a;
    --carte: #1f2226;
    --texte: #e7e9ec;
    --discret: #9aa1ab;
    --bord: #33373d;
    --accent: #ff86a6;
    --accent-doux: #3a1d27;
    --accent-texte: #2a0c16;
    --bon: #4cc785;
    --bon-doux: #17301f;
    --moyen: #e2b54a;
    --moyen-doux: #352a12;
    --faible: #ff7b70;
    --faible-doux: #3a1c1a;
    --badge: #2a2e34;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
h3 { font-size: .95rem; margin: 1.1rem 0 .5rem; }
p { margin: .4rem 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.discret { color: var(--discret); font-size: .88rem; }
.erreur { color: var(--faible); min-height: 1.2em; margin: .5rem 0 0; white-space: pre-line; }
.pre { white-space: pre-line; }
.nb { font-variant-numeric: tabular-nums; }
.icone { flex: none; vertical-align: -3px; }

/* ─── Boutons ─── */
button, input, select, textarea { font: inherit; color: inherit; }
button, .bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 0;
  border-radius: 8px;
  padding: .55rem .95rem;
  background: var(--accent);
  color: var(--accent-texte);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  min-height: 40px;
}
button.secondaire, .bouton.secondaire { background: var(--badge); color: var(--texte); }
button.discret-btn { background: transparent; color: var(--accent); padding: .3rem .5rem; min-height: 0; }
button.danger { background: var(--badge); color: var(--faible); }
button.danger-plein { background: var(--faible); color: #fff; }
button.icone-seule { padding: .45rem; min-height: 36px; min-width: 36px; }
button.petit, .bouton.petit { padding: .3rem .6rem; font-size: .85rem; min-height: 32px; }
button:disabled { opacity: .55; cursor: wait; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .9rem; }
.actions.droite { justify-content: flex-end; }
.bouton-fichiers { display: inline-flex; }

/* ─── Formulaires ─── */
input, select, textarea {
  width: 100%;
  padding: .55rem .65rem;
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--carte);
  min-height: 40px;
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); }
.champ { margin-top: .7rem; min-width: 0; }
.champ label { display: block; margin-bottom: .25rem; color: var(--discret); font-size: .88rem; }
.champ .aide { display: block; margin-top: .2rem; color: var(--discret); font-size: .8rem; }
.requis { color: var(--faible); }
label.case { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; cursor: pointer; }
.champs-ligne { display: grid; gap: 0 .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); }
fieldset { border: 1px solid var(--bord); border-radius: 10px; padding: .5rem .9rem .9rem; margin: .9rem 0 0; min-width: 0; }
legend { color: var(--discret); font-size: .88rem; padding: 0 .3rem; }
.choix-segments { display: flex; flex-wrap: wrap; gap: .35rem; }
.choix-segments label {
  display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .75rem; border-radius: 999px;
  background: var(--badge); cursor: pointer; font-size: .9rem; color: var(--texte); margin: 0;
}
.choix-segments input { position: absolute; opacity: 0; pointer-events: none; }
.choix-segments label:has(input:checked) { background: var(--accent); color: var(--accent-texte); }
.choix-segments label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Connexion ─── */
.connexion { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.connexion form { width: min(360px, 100%); }
.connexion h1 { margin-bottom: .5rem; }
.connexion label { display: block; margin: .75rem 0 .25rem; color: var(--discret); font-size: .9rem; }
.connexion button { width: 100%; margin-top: 1.1rem; }

/* ─── En-tête et navigation ─── */
.entete {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--carte); border-bottom: 1px solid var(--bord);
}
.logo { display: flex; align-items: center; gap: .5rem; color: var(--texte); text-decoration: none; font-weight: 650; }
.menu { display: flex; gap: .15rem; overflow-x: auto; }
.menu a { padding: .45rem .7rem; border-radius: 8px; color: var(--discret); text-decoration: none; white-space: nowrap; font-size: .93rem; }
.menu a.actif { background: var(--accent-doux); color: var(--accent); font-weight: 600; }
@media (max-width: 520px) { .logo span { display: none; } }

.vue { max-width: 1180px; margin: 0 auto; padding: 14px 16px 40px; outline: none; }
.chargement { color: var(--discret); text-align: center; padding: 2rem 0; }
.titre-page { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin: .25rem 0 1rem; }
.titre-page h1 { flex: 1; min-width: 12rem; }
.fil { font-size: .88rem; margin-bottom: .35rem; }
.fil a { text-decoration: none; }

/* ─── Cartes, grilles ─── */
.carte {
  background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 1rem; min-width: 0; box-shadow: var(--ombre);
}
.carte + .carte { margin-top: 12px; }
.grille > .carte + .carte { margin-top: 0; }
.grille { display: grid; gap: 12px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 860px) {
  .grille.deux { grid-template-columns: 1fr 1fr; }
  .grille .large { grid-column: 1 / -1; }
}
.grille.cartes { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.titre-carte { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.titre-carte h2 { margin: 0; }
.cliquable { cursor: pointer; transition: border-color .15s, transform .15s; }
.cliquable:hover { border-color: var(--accent); }
.vide { text-align: center; color: var(--discret); padding: 1.5rem 1rem; border: 1px dashed var(--bord); border-radius: var(--rayon); }
.vide .actions { justify-content: center; }
.erreur-vue { border-color: var(--faible); }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .75rem; }
.chiffre { padding: .6rem .75rem; border-radius: 10px; background: var(--badge); }
.chiffre b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.chiffre small { color: var(--discret); font-size: .8rem; }

/* ─── Badges et tons ─── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .75rem; padding: .1rem .5rem; border-radius: 999px;
  background: var(--badge); color: var(--discret); white-space: nowrap; vertical-align: 1px;
}
.badge.ok { background: var(--bon-doux); color: var(--bon); }
.badge.attention { background: var(--moyen-doux); color: var(--moyen); }
.badge.ko { background: var(--faible-doux); color: var(--faible); }
.badge.info { background: var(--accent-doux); color: var(--accent); }
.ton-ok { color: var(--bon); }
.ton-attention { color: var(--moyen); }
.ton-ko { color: var(--faible); }

/* ─── Onglets ─── */
.onglets { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--bord); margin-bottom: 14px; scrollbar-width: none; }
.onglets a, .onglets button {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .6rem .8rem; border-radius: 0; background: transparent; color: var(--discret);
  border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; min-height: 0;
}
.onglets [aria-current="page"], .onglets [aria-selected="true"] { color: var(--texte); border-bottom-color: var(--accent); font-weight: 600; }

/* ─── Tableaux et listes ─── */
.tableau-defilant { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--bord); vertical-align: top; }
th { color: var(--discret); font-weight: 500; font-size: .82rem; }
td.nb, th.nb { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.cliquable:hover td { background: var(--badge); }
.liste { list-style: none; margin: 0; padding: 0; }
.liste > li { padding: .6rem 0; border-top: 1px solid var(--bord); }
.liste > li:first-child { border-top: 0; }
.ligne-info { display: grid; grid-template-columns: minmax(7rem, 38%) 1fr; gap: .5rem; padding: .35rem 0; border-top: 1px solid var(--bord); font-size: .93rem; }
.ligne-info:first-child { border-top: 0; }
.ligne-info > :first-child { color: var(--discret); }

/* ─── Dialogues ───
   Le dialogue défile lui-même (titre collé en haut, boutons collés en bas) : pas de mise en page flexible, que
   Safari ne recalcule pas toujours quand un bloc réapparaît (fenêtre coupée après Garage → Fait soi-même → Garage). */
dialog.dialogue {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--bord);
  border-radius: 16px;
  background: var(--carte);
  color: var(--texte);
  overflow-y: auto;
  overscroll-behavior: contain;
}
dialog.dialogue.large { width: min(860px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialogue-entete {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .8rem 1rem; border-bottom: 1px solid var(--bord); background: var(--carte);
}
.dialogue-entete h2 { margin: 0; font-size: 1.05rem; }
.dialogue-corps { padding: .25rem 1rem 1rem; }
.dialogue-corps > form > .actions:last-child, .dialogue-corps > .actions:last-child {
  position: sticky; bottom: 0; z-index: 3; justify-content: flex-end;
  margin: .75rem -1rem -1rem; padding: .75rem 1rem; background: var(--carte); border-top: 1px solid var(--bord);
}
@media (max-width: 600px) {
  dialog.dialogue, dialog.dialogue.large { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}
.visionneuse-image { display: block; max-width: 100%; max-height: 70dvh; margin: .75rem auto; border-radius: 8px; object-fit: contain; }

/* ─── Vignettes de fichiers ─── */
.fichiers { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.vignette {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 88px; height: 88px; border-radius: 10px; overflow: hidden; background: var(--badge);
  border: 1px solid var(--bord); color: var(--texte); text-decoration: none; font-size: .72rem; text-align: center; padding: 0;
}
.vignette img { width: 100%; height: 100%; object-fit: cover; }
.vignette .nom { padding: 0 .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.vignette .supprimer-fichier {
  position: absolute; top: 3px; right: 3px; min-height: 0; padding: .15rem; border-radius: 6px;
  background: rgba(0, 0, 0, .55); color: #fff;
}

/* ─── Notifications à l'écran ─── */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 1000; display: grid; gap: .5rem; width: min(420px, calc(100vw - 32px)); }
.toast { padding: .7rem 1rem; border-radius: 10px; background: var(--texte); color: var(--carte); box-shadow: 0 6px 20px rgba(0, 0, 0, .2); transition: opacity .4s, transform .4s; }
.toast.ko { background: var(--faible); color: #fff; }
.toast.attention { background: var(--moyen); color: #fff; }
.toast.sortie { opacity: 0; transform: translateY(8px); }

/* ─── Listes de liens ─── */
.liens { list-style: none; margin: .25rem 0 0; padding: 0; }
.liens li { display: flex; align-items: center; gap: .4rem; padding: .25rem 0; min-width: 0; }
.liens a { overflow-wrap: anywhere; }

/* ─── Petits utilitaires partagés ─── */
.bloc { display: block; }
.titre-simple { margin: .25rem 0 1rem; }
.boutons-ligne { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.puces { margin: .25rem 0; padding-left: 1.1rem; }
.puces li { margin: .15rem 0; }
