/* ───────────────────────────────────────────────────────────────────────────
   3DLib — feuille de style unique, sans build.
   Ordre : variables, base, mise en page, composants, écrans, impression.
   Le thème sombre suit le système et peut être forcé par [data-theme].
   ─────────────────────────────────────────────────────────────────────────── */

:root {
  --brand: #4f46e5;
  --brand-strong: #3730a3;
  --brand-soft: #eef2ff;
  --accent: #f59e0b;
  --accent-soft: #fef3c7;
  /* Encre ambre pour le texte et les graphiques porteurs de sens : l'ambre de
     remplissage tombe à 2,15:1 sur blanc, donc illisible. Mesuré, pas estimé. */
  --accent-ink: #b45309;
  --success: #047857;
  --success-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --muted: #5c6b7e;
  --border: #e2e8f0;
  /* Bordure des composants interactifs : WCAG 1.4.11 exige 3:1 pour ce qui
     permet d'identifier un champ ou un bouton. La bordure décorative des cartes
     et des séparateurs reste claire, elle ne porte aucune information. */
  --border-strong: #8293a9;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 8px 24px -12px rgb(15 23 42 / 18%);
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 8%);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --header-height: 60px;
  --nav-height: 62px;
  --sidebar-width: 232px;
  --max-width: 1240px;
  --gutter: clamp(.75rem, 2vw, 1.5rem);

  /* Zones sûres des écrans à encoche. Avec viewport-fit=cover et une barre
     d'état translucide, le contenu commence sous l'horloge et sous la barre
     de gestes : sans ces marges, l'en-tête passe derrière l'heure et le bas
     de page devient inatteignable au défilement. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #a5b4fc;
    --brand-strong: #c7d2fe;
    --brand-soft: #1e1b45;
    --accent: #fbbf24;
    --accent-soft: #3a2c0c;
    /* En thème sombre l'ambre atteint 10:1 : aucune encre distincte nécessaire. */
    --accent-ink: #fbbf24;
    --success: #34d399;
    --success-soft: #0d2f24;
    --danger: #f87171;
    --danger-soft: #3a1717;

    --bg: #0b1020;
    --surface: #141a2e;
    --surface-2: #101527;
    --text: #e6ebf4;
    --muted: #94a3b8;
    --border: #262f4a;
    --border-strong: #526891;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 10px 30px -14px rgb(0 0 0 / 70%);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 45%);
  }
}

:root[data-theme="dark"] {
  --brand: #a5b4fc;
  --brand-strong: #c7d2fe;
  --brand-soft: #1e1b45;
  --accent: #fbbf24;
  --accent-soft: #3a2c0c;
  --accent-ink: #fbbf24;
  --success: #34d399;
  --success-soft: #0d2f24;
  --danger: #f87171;
  --danger-soft: #3a1717;

  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #101527;
  --text: #e6ebf4;
  --muted: #94a3b8;
  --border: #262f4a;
  --border-strong: #526891;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 10px 30px -14px rgb(0 0 0 / 70%);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 45%);
}

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

/* L'attribut `hidden` doit gagner contre toute règle de composant : la règle
   `[hidden] { display: none }` du navigateur est moins spécifique qu'un
   `.btn { display: inline-flex }`, et le bouton restait visible. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* `contain` et non `none` : le rebond élastique est conservé — c'est lui qui
     rend la fin de défilement douce — mais l'enchaînement vers le document
     parent est bloqué. La barre du bas ne s'en trouve plus décollée depuis
     qu'elle appartient au flux : le rebond l'emmène avec le contenu. */
  overscroll-behavior-y: contain;
}

body {
  margin: 0;
  /* Coquille d'application : une colonne qui occupe au moins tout l'écran. La
     mise en page s'étire, ce qui pousse la barre du bas contre le bord même
     quand la page est presque vide — un élément `fixed` n'offrait pas cette
     garantie et pouvait sembler flotter. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* manipulation : supprime le double-tap pour zoomer, et avec lui le délai de
     300 ms qu'il impose à chaque appui. Le défilement et le pincement système
     ne sont pas affectés par cette règle. */
  touch-action: manipulation;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: .82rem; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

.sprite { display: none; }

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -.18em;
}
.icon--lg { width: 1.5em; height: 1.5em; }
.icon--xl { width: 2em; height: 2em; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 100;
  padding: .6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ── Mise en page ───────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: .75rem;
  /* La hauteur inclut la barre d'état, et le remplissage haut y descend le
     contenu : l'en-tête peint donc lui-même la zone de l'horloge, dans la
     couleur du thème, au lieu de passer dessous. */
  height: calc(var(--header-height) + var(--safe-top));
  padding: var(--safe-top) calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text);
  letter-spacing: -.02em;
}
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
/* La recherche ayant quitté l'en-tête sur mobile, le nom peut s'afficher : il
   remplit un vide et ancre l'identité, ce qu'un logo seul ne fait pas. */
.brand span { display: inline; }

/* Sur mobile, ce champ n'affichait qu'un texte tronqué — « Aire, commune, » —
   pour un doublon de la recherche de la page Aires, atteignable en un appui par
   la barre du bas. Il ne s'affiche donc que là où il y a la place. */
.header-search { display: none; flex: 1; max-width: 460px; }
@media (min-width: 900px) { .header-search { display: block; } }
.header-actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }

.layout {
  display: flex;
  flex: 1 1 auto;
  gap: clamp(1rem, 2vw, 2rem);
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  /* La barre du bas étant dans le flux, plus besoin de réserver sa hauteur :
     arrivé en bas de page, le contenu est intégralement lisible et la barre le
     suit. Elle ne le recouvre qu'en cours de défilement. */
  padding:
    clamp(1rem, 2vw, 1.75rem)
    calc(var(--gutter) + var(--safe-right))
    1.5rem
    calc(var(--gutter) + var(--safe-left));
}
@media (min-width: 900px) {
  .layout { padding-bottom: 3rem; }
}

/*
 * Barre latérale : tiroir sur petit écran, colonne collante au-delà de 900 px.
 * Un seul balisage sert aux deux, donc un seul endroit à corriger. Sur mobile,
 * l'aside devient le voile assombri et `.sidebar__panel` le panneau qui glisse.
 */
.sidebar {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  background: rgb(8 12 22 / 55%);
}
.sidebar--open { display: block; }
.sidebar__panel {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  width: min(300px, 84vw);
  height: 100%;
  padding: 1rem calc(.9rem + var(--safe-left)) calc(1rem + var(--safe-bottom));
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow-y: auto;
}
@media (prefers-reduced-motion: no-preference) {
  .sidebar--open .sidebar__panel { animation: drawer-in .18s ease-out; }
}
@keyframes drawer-in { from { transform: translateX(-14px); opacity: .6; } to { transform: none; opacity: 1; } }

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .6rem;
  font-weight: 700;
}
.sidebar__foot { margin: auto 0 0; padding: .7rem; color: var(--muted); }

@media (min-width: 900px) {
  /* Au-delà de 900 px le tiroir n'existe plus : c'est une colonne, toujours
     visible, et le voile comme le bouton de fermeture disparaissent. */
  .sidebar {
    position: sticky;
    inset: auto;
    display: block;
    top: calc(var(--header-height) + var(--safe-top) + 1.25rem);
    flex: 0 0 var(--sidebar-width);
    align-self: flex-start;
    background: none;
  }
  .sidebar__panel {
    width: auto;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }
  .sidebar__head { display: none; }
}

/* Le corps ne défile pas derrière le tiroir ouvert. */
body.is-locked { overflow: hidden; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .58rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 550;
}
.sidebar-nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.sidebar-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.sidebar-group {
  margin: 1.1rem 0 .3rem;
  padding: 0 .7rem;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.content { flex: 1 1 auto; min-width: 0; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.page-head p { margin: .15rem 0 0; color: var(--muted); }

/* Barre de navigation basse, propre aux petits écrans. */
.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: flex;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
@media (min-width: 900px) { .bottom-nav { display: none; } }
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: .66rem;
  font-weight: 600;
  color: var(--muted);
}
/* Le contenu qui défile sous la barre s'estompe au lieu d'être coupé net. */
.bottom-nav::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 22px;
  pointer-events: none;
  background: linear-gradient(to top, color-mix(in srgb, var(--bg) 92%, transparent), transparent);
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a[aria-current="page"] { color: var(--brand); }
.bottom-nav .icon { width: 1.35em; height: 1.35em; }

/* ── Composants ─────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card--pad { padding: clamp(.9rem, 2vw, 1.25rem); }
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.card__head h2 { margin: 0; font-size: 1rem; }
.card__body { padding: 1.1rem; }
.card__foot {
  padding: .75rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

.grid { display: grid; gap: clamp(.7rem, 1.5vw, 1rem); }

/*
 * Piège de CSS Grid : une piste `1fr` vaut `minmax(auto, 1fr)`, et ce minimum
 * `auto` est la largeur **min-content** de son contenu. Un tableau large ou une
 * ligne en `white-space: nowrap` remontait donc sa largeur intrinsèque jusqu'à
 * la grille, qui débordait de l'écran : « Mon compte » réclamait 612 px pour un
 * écran de 393, et la page défilait horizontalement.
 *
 * `min-width: 0` autorise la piste à se réduire à la place disponible ; les
 * conteneurs à défilement interne (`.table-scroll`) reprennent alors leur rôle.
 * Même règle pour les colonnes flex, soumises au même minimum automatique.
 */
.grid > *,
.stack > *,
.card { min-width: 0; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.grid--two { grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid--two { grid-template-columns: 1.4fr 1fr; } }

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.spacer { flex: 1 1 auto; }

/*
 * Bouton secondaire : un aplat teinté plutôt qu'un contour marqué.
 *
 * Le contour à 3:1 exigé par WCAG 1.4.11 « cageait » chaque carte — six puces et
 * deux boutons cerclés de gris sur un même bloc. Le remplissage distingue
 * désormais le bouton de la carte blanche, le libellé porte l'information, et le
 * contour s'affirme au survol comme au focus, là où l'intention est manifeste.
 * Les champs de saisie, eux, gardent leur contour à 3:1 : c'est leur seule
 * affordance, et un champ sans bord est réellement inutilisable.
 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .52rem .9rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, transform .14s ease;
}
.btn:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn--primary {
  color: #fff;
  background: var(--brand);
  border-color: transparent;
}
/* En thème sombre, --brand devient une teinte claire : le texte du bouton doit
   alors être foncé pour rester lisible. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn--primary { color: #0b1020; }
}
:root[data-theme="dark"] .btn--primary { color: #0b1020; }
.btn--primary:hover { background: color-mix(in srgb, var(--brand) 88%, black); }
.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand);
}
.btn--ghost:hover { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--sm { padding: .34rem .6rem; font-size: .84rem; }
.btn--icon { padding: .45rem; }
.btn--block { width: 100%; }
.btn--active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .28rem .6rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.chip--on { color: var(--brand); background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 40%, transparent); }
.chip--road { color: #fff; background: var(--brand); border-color: transparent; letter-spacing: .02em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip--road { color: #0b1020; } }
:root[data-theme="dark"] .chip--road { color: #0b1020; }
.chip--visited { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.chip--accent { color: color-mix(in srgb, var(--accent) 78%, var(--text)); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.chip--muted { opacity: .8; }
a.chip:hover { text-decoration: none; border-color: var(--brand); color: var(--brand); }

.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.stat {
  padding: .9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat__label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.stat__value {
  margin-top: .3rem;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat__hint { font-size: .82rem; color: var(--muted); }

.progress {
  height: 8px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--accent)));
  border-radius: var(--radius-pill);
  transition: width .4s ease;
}

.bars { display: flex; align-items: flex-end; gap: 4px; height: 78px; }
.bars__item { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; text-align: center; }
.bars__bar {
  background: color-mix(in srgb, var(--brand) 75%, transparent);
  border-radius: 5px 5px 2px 2px;
  min-height: 3px;
}
.bars__label { font-size: .62rem; color: var(--muted); }

.list { display: flex; flex-direction: column; }
.list__item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.list__item:last-child { border-bottom: 0; }
.list__item:hover { background: var(--surface-2); }
.list__main { flex: 1; min-width: 0; }
.list__title { font-weight: 600; }
.list__sub { font-size: .84rem; color: var(--muted); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Formulaires ────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label { font-size: .85rem; font-weight: 600; }
.field small { color: var(--muted); }
.field--inline { flex-direction: row; align-items: center; gap: .55rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], textarea {
  /* Safari peint ses propres décorations à l'intérieur des champs — loupe,
     bouton d'effacement, ombre interne. Elles se superposaient à l'icône du
     gabarit et laissaient des traits dans le champ de recherche. */
  -webkit-appearance: none;
  appearance: none;
  background-image: none;
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  font: inherit;
  /* 16 px est un seuil, pas une préférence : en dessous, iOS agrandit toute la
     page dès la mise au point du champ, et n'en revient pas seul. La règle vaut
     même viewport verrouillé, certaines versions ignorant maximum-scale. */
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
textarea { min-height: 88px; resize: vertical; }

/* Safari applique à `type="search"` ses propres décorations — loupe interne et
   bouton d'effacement — qui se superposaient à l'icône du gabarit. */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  display: none;
}

/* opacity: 1 est nécessaire : Firefox rend le texte indicatif translucide par
   défaut, ce qui le rendait presque illisible sur fond clair. */
::placeholder {
  color: var(--muted);
  opacity: 1;
}
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search .icon { position: absolute; left: .65rem; color: var(--muted); pointer-events: none; }
.search input { padding-left: 2.1rem; border-radius: var(--radius-pill); background: var(--surface-2); }

.form-grid { display: grid; gap: .9rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid--two { grid-template-columns: 1fr 1fr; } }

/* ── Cibles tactiles ────────────────────────────────────────────────────── */

/*
 * `pointer: coarse` cible le doigt, pas la largeur d'écran : une tablette au
 * clavier garde donc l'interface dense, et un petit écran tactile obtient des
 * cibles confortables.
 *
 * Calibrage assumé : 44 px pour tout ce qu'on vise (Apple HIG), 36 px pour les
 * puces de filtre — elles forment une liste dense où 44 px doublerait la hauteur
 * du panneau, et restent très au-dessus du plancher de 24 px du critère WCAG
 * 2.5.8.
 */
@media (pointer: coarse) {
  .btn,
  .btn--sm,
  .pagination a,
  .pagination span {
    min-height: 44px;
  }

  .btn--icon {
    min-width: 44px;
  }

  label.chip {
    min-height: 36px;
  }

  /* Les liens d'une liste occupent toute la hauteur de leur rangée, ce qui donne
     une cible large sans agrandir la rangée. */
  .list__item { min-height: 52px; }
}

/* ── Messages ───────────────────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .7rem .9rem;
  margin-bottom: 1rem;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: .92rem;
}
.alert--ok { color: color-mix(in srgb, var(--success) 80%, var(--text)); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.alert--error { color: color-mix(in srgb, var(--danger) 80%, var(--text)); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert--info { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

.empty {
  padding: 2.6rem 1.5rem;
  text-align: center;
  color: var(--muted);
}
.empty .icon { color: var(--border); }
.empty h3 { margin: .7rem 0 .3rem; color: var(--text); }

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 1rem + var(--safe-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transform: translateX(-50%);
  width: min(92vw, 420px);
}
@media (min-width: 900px) { .toast-stack { bottom: 1.25rem; } }
.toast {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .65rem .9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast .btn { margin-left: auto; flex: none; }
.toast span { flex: 1; }

/* Message actionnable : toute sa surface répond, et le chevron dit qu'il mène
   quelque part — un bloc qu'on devine cliquable n'est pas une affordance. */
.toast--actionable {
  cursor: pointer;
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
}
.toast--actionable:hover { background: var(--surface-2); }
.toast__cta {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  flex: none;
  margin-left: auto;
  padding: .2rem .1rem .2rem .4rem;
  font: inherit;
  font-size: .86rem;
  font-weight: 650;
  color: var(--brand);
  background: none;
  border: 0;
  cursor: pointer;
}
.toast__cta .icon { width: 1em; height: 1em; }
.toast--ok { border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.toast--error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.offline-banner {
  display: none;
  position: sticky;
  top: calc(var(--header-height) + var(--safe-top));
  z-index: 29;
  align-items: center;
  gap: .5rem;
  padding: .5rem .9rem;
  font-size: .86rem;
  font-weight: 600;
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
  background: var(--accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
body.is-offline .offline-banner { display: flex; }

/* ── Filtres ─────────────────────────────────────────────────────────────── */

.filters { margin-bottom: 1.25rem; }

/* La recherche est l'action la plus fréquente : elle reste toujours visible. */
.filters__bar { display: flex; gap: .5rem; align-items: stretch; }
.filters__bar .search { flex: 1; }
.filters__bar .btn { flex: none; }

/* Une rangée unique pour tous les réglages secondaires : le panneau replié n'a
   pas besoin de toute la largeur, et trois pastilles côte à côte économisent
   environ 70 px de hauteur avant les résultats. */
.filters__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: .4rem;
  margin-top: .6rem;
}

.filters__panel {
  width: fit-content;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
/* Ouvert, il reprend toute la largeur : un formulaire à cinq listes ne tient pas
   dans une pastille. */
.filters__panel[open] {
  flex-basis: 100%;
  width: 100%;
  border-radius: var(--radius);
}
.filters__panel > summary {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .42rem .8rem;
  font-size: .84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.filters__panel:not([open]) > summary:hover { color: var(--text); }
.filters__panel > summary::-webkit-details-marker { display: none; }
.filters__panel > summary::after {
  content: "";
  width: .42rem;
  height: .42rem;
  margin-left: .15rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .15s ease;
}
.filters__panel[open] > summary {
  padding: .7rem .9rem;
  font-size: .9rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.filters__panel[open] > summary::after { margin-left: auto; }
.filters__panel[open] > summary::after { transform: rotate(-135deg); }
@media (pointer: coarse) {
  .filters__panel > summary { min-height: 44px; }
}

.filters__count {
  display: grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 .35rem;
  font-size: .78rem;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border-radius: var(--radius-pill);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .filters__count { color: #0b1020; }
}
:root[data-theme="dark"] .filters__count { color: #0b1020; }

.filters__grid {
  display: grid;
  gap: .8rem;
  grid-template-columns: 1fr;
  padding: .9rem;
}
@media (min-width: 560px) { .filters__grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .filters__grid { grid-template-columns: repeat(3, 1fr); } }
.filters__grid .field { margin-bottom: 0; }

.filters__services {
  margin: 0;
  padding: 0 .9rem .9rem;
  border: 0;
}
.filters__services legend {
  padding: 0 0 .5rem;
  font-size: .85rem;
  font-weight: 600;
}
.filters__hint { margin: .6rem 0 0; font-size: .82rem; color: var(--muted); }
.filters__panel .row { padding: 0 .9rem .9rem; }

/* État des filtres : visible sans ouvrir le panneau, et chaque puce se retire
   individuellement. */
.filters__active {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin: -.5rem 0 1rem;
}
.filters__active .chip .icon { opacity: .7; }
.filters__active a.chip--on:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.filters__row .chip { font: inherit; font-size: .84rem; cursor: pointer; }
@media (pointer: coarse) {
  .filters__row .chip,
  .filters__panel > summary { min-height: 38px; }
}

/* ── Chargement progressif de la liste ──────────────────────────────────── */

.load-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: 1.4rem 0 .4rem;
}
/* Squelettes : ils donnent la forme de ce qui arrive, là où un mot
   « Chargement… » ne dit rien de la quantité ni de la durée. */
.skeleton {
  padding: .95rem 1rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.skeleton__line {
  height: .8rem;
  margin-bottom: .55rem;
  background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2));
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton 1.4s ease-in-out infinite;
}
.skeleton__line:nth-child(1) { width: 62%; height: 1rem; }
.skeleton__line:nth-child(2) { width: 38%; }
.skeleton__line:nth-child(3) { width: 82%; margin-bottom: 0; }

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Une animation qui pulse en continu est exactement ce que ce réglage demande
   de supprimer. */
@media (prefers-reduced-motion: reduce) {
  .skeleton__line { animation: none; background: var(--surface-2); }
}

.load-more__status {
  margin: 0;
  min-height: 1.2em;
  font-size: .84rem;
  color: var(--muted);
  text-align: center;
}

/* ── Boîte de confirmation ───────────────────────────────────────────────── */

.modal {
  width: min(100% - 1.6rem, 27rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -20px rgb(15 23 42 / 45%);
}
.modal::backdrop {
  background: rgb(9 14 26 / 55%);
  backdrop-filter: blur(2px);
}

.modal__form { padding: 1.25rem; }
.modal__title { margin: 0 0 .45rem; font-size: 1.12rem; }
.modal__text { margin: 0 0 1.2rem; color: var(--muted); }

.modal__actions { display: flex; gap: .5rem; }
.modal__actions .btn { flex: 1 1 auto; }

/*
 * Dans la boîte, l'action destructrice est remplie et non cerclée : c'est le
 * point de non-retour, il doit se distinguer sans hésitation de l'annulation.
 * Ailleurs — le bouton qui ouvre cette boîte — le rouge reste discret, parce
 * qu'il ne fait encore rien d'irréversible.
 */
.modal .btn--danger {
  color: #fff;
  background: var(--danger);
  border-color: transparent;
}
.modal .btn--danger:hover { background: color-mix(in srgb, var(--danger) 86%, black); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .modal .btn--danger { color: #111827; }
}
:root[data-theme="dark"] .modal .btn--danger { color: #111827; }
/* L'action confirmée passe en second : sur un écran, l'œil et le pouce vont à
   droite, et l'annulation doit rester le geste le plus facile. */

/* Sur téléphone, la boîte s'ancre en bas : c'est la zone atteignable au pouce,
   et le geste de fermeture y est naturel. */
@media (max-width: 599px) {
  .modal {
    width: 100%;
    margin: auto auto 0;
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: var(--safe-bottom);
  }
  .modal__actions { flex-direction: column-reverse; }
}

/* Apparition : discrète, et supprimée quand le système le demande. */
@media (prefers-reduced-motion: no-preference) {
  .modal[open] { animation: modal-in .18s ease-out; }
  @keyframes modal-in {
    from { opacity: 0; transform: translateY(12px) scale(.99); }
    to { opacity: 1; transform: none; }
  }
}

/* ── Pagination ─────────────────────────────────────────────────────────── */

.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; justify-content: center; margin-top: 1.2rem; }
.pagination a, .pagination span {
  min-width: 2.2rem;
  padding: .38rem .55rem;
  text-align: center;
  font-size: .88rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.pagination a:hover { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.pagination [aria-current="page"] { color: #fff; background: var(--brand); border-color: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pagination [aria-current="page"] { color: #0b1020; } }
:root[data-theme="dark"] .pagination [aria-current="page"] { color: #0b1020; }
.pagination .gap { border: 0; background: none; }

/* ── Guide d'installation ───────────────────────────────────────────────── */

.install__head {
  display: flex;
  align-items: flex-start;
  gap: .9rem;
  margin-bottom: 1.1rem;
}
.install__icon img {
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.install__title { margin: 0 0 .2rem; font-size: 1.05rem; }
.install__lead { margin: 0; font-size: .9rem; color: var(--muted); }
.install__note { margin: .6rem 0 0; font-size: .84rem; color: var(--muted); text-align: center; }

.install__done {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  padding: .7rem .9rem;
  font-weight: 600;
  color: color-mix(in srgb, var(--success) 80%, var(--text));
  background: var(--success-soft);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
  border-radius: var(--radius-sm);
}

.install__platform {
  margin: 1.2rem 0 .7rem;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.install__platform:first-child { margin-top: 0; }

.install__steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.install__step { display: flex; gap: .75rem; }
.install__number {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  font-size: .82rem;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border-radius: 50%;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .install__number { color: #0b1020; }
}
:root[data-theme="dark"] .install__number { color: #0b1020; }
.install__body { flex: 1; min-width: 0; }
.install__step-title { margin: .1rem 0 .15rem; font-weight: 600; }
.install__hint { margin: 0 0 .55rem; font-size: .84rem; color: var(--muted); }

/* Maquettes d'interface : uniquement du balisage et des icônes du sprite, donc
   nettes à toute densité d'écran et cohérentes avec le thème. */
.mock {
  overflow: hidden;
  font-size: .82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mock__bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: .4rem;
  padding: .5rem .7rem;
}
.mock__bar--top { justify-content: space-between; }
.mock__url {
  flex: 1;
  padding: .2rem .6rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.mock__glyph {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  color: var(--muted);
  border-radius: 8px;
}
/* La cible du geste : c'est tout l'intérêt de la maquette. */
.mock__glyph--target {
  color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 2px var(--brand);
}
.mock__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .7rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.mock__row:last-child { border-bottom: 0; }
.mock__row span { display: inline-flex; align-items: center; gap: .45rem; }
.mock__row--target {
  font-weight: 650;
  color: var(--brand);
  background: var(--brand-soft);
}
.mock__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .7rem;
  border-bottom: 1px solid var(--border);
}
.mock__cancel { color: var(--muted); }
.mock__sheet-title { font-weight: 650; }
.mock__confirm {
  font-weight: 700;
  color: var(--brand);
  padding: .1rem .45rem;
  background: var(--brand-soft);
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--brand);
}
.mock__preview {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .6rem .7rem;
  font-weight: 600;
}
.mock__preview img { border-radius: 9px; }

/* Invitation du tableau de bord : mobile seulement, et jamais si déjà installée. */
.install-invite { margin-bottom: 1.1rem; }
@media (min-width: 900px) { .install-invite { display: none; } }
:root[data-install="installed"] .install-invite { display: none; }

.install-invite summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--brand);
  list-style: none;
}
.install-invite summary::-webkit-details-marker { display: none; }
.install-invite summary::after {
  content: " ›";
  font-weight: 700;
}
.install-invite[open] summary::after { content: " ⌄"; }

/*
 * Aiguillage par plateforme du guide d'installation.
 *
 * `app.js` pose `<html data-install="installed|ready|ios|manual">` ; sans
 * JavaScript aucun attribut n'est posé, et les deux marches à suivre restent
 * visibles — le guide demeure utilisable.
 *
 * **Deux précautions, apprises d'un défaut.** Le bloc « déjà installée » restait
 * affiché en permanence : `.install__done { display: flex }` était déclaré après
 * `[data-install-when="installed"] { display: none }`, et à spécificité égale la
 * dernière règle gagne. L'aiguillage est donc placé **après** tous les composants
 * du guide, et préfixé par `:root` pour peser plus qu'une règle de classe. Les
 * deux ensemble : déplacer ce bloc ne peut plus le rendre inopérant.
 */
:root [data-install-when="installed"],
:root [data-install-when="ready"] { display: none; }
:root[data-install="installed"] [data-install-when="installed"] { display: flex; }
:root[data-install="ready"] [data-install-when="ready"] { display: block; }
:root[data-install="installed"] [data-install-when="ios"],
:root[data-install="installed"] [data-install-when="manual"],
:root[data-install="ready"] [data-install-when="ios"],
:root[data-install="ready"] [data-install-when="manual"],
:root[data-install="ios"] [data-install-when="manual"],
:root[data-install="manual"] [data-install-when="ios"] { display: none; }

/* ── Écran de connexion ─────────────────────────────────────────────────── */

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(1.5rem, var(--safe-top))
    max(1.5rem, var(--safe-right))
    max(1.5rem, var(--safe-bottom))
    max(1.5rem, var(--safe-left));
  background:
    radial-gradient(1100px 520px at 12% -8%, color-mix(in srgb, var(--brand) 22%, transparent), transparent),
    radial-gradient(900px 480px at 105% 8%, color-mix(in srgb, var(--accent) 16%, transparent), transparent),
    var(--bg);
}
.auth-card { width: min(100%, 412px); }
.auth-card .card { padding: clamp(1.3rem, 4vw, 2rem); }
.auth-logo { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.3rem; font-size: 1.2rem; font-weight: 700; }
.auth-logo /*
 * Le sigle est le fichier `logo.svg`, celui du favicon et de l'icône installée :
 * une seule définition de la marque, donc aucune dérive entre les surfaces. Il
 * porte son propre fond, ce qui le rend lisible dans les deux thèmes sans
 * dépendre des jetons de couleur.
 */
.brand__mark {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
}
.brand__mark--lg { width: 46px; height: 46px; border-radius: 13px; }

.brand__name { font-weight: 700; letter-spacing: -.01em; }

/*
 * Le dépôt est accessible en permanence depuis l'en-tête, en icône seule : les
 * pages qui permettent un dépôt affichent déjà un bouton libellé dans leur
 * titre, et deux boutons identiques côte à côte se disputaient l'attention.
 */
.header-add { flex: none; }

/*
 * Le masquage suit immédiatement la déclaration, et non plus la requête média de
 * la barre latérale : à spécificité égale la dernière règle gagne, et le bouton
 * de tiroir restait affiché sur grand écran, où la colonne est déjà là.
 */
.nav-toggle { display: inline-flex; }
@media (min-width: 900px) {
  .nav-toggle { display: none; }
}

.breadcrumb { margin: 0 0 .2rem; font-size: .85rem; }
.breadcrumb a { display: inline-flex; align-items: center; gap: .2rem; color: var(--muted); }
.breadcrumb a:hover { color: var(--brand); text-decoration: none; }

/* ── Grilles ────────────────────────────────────────────────────────────── */

.grid--models { grid-template-columns: repeat(auto-fill, minmax(clamp(240px, 30vw, 290px), 1fr)); }
.grid--split { grid-template-columns: 1fr; align-items: start; }
@media (min-width: 980px) {
  /* La visionneuse mérite la place : deux tiers contre un tiers, pas la moitié. */
  .grid--split { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
}
.stack-tight { display: flex; flex-direction: column; gap: .6rem; }
.row--tight { gap: .3rem; }
.row--center { justify-content: center; }
/*
 * Barre d'actions d'un formulaire long.
 *
 * Collante sur petit écran — le bouton d'envoi doit rester atteignable au pouce
 * sans remonter trois cartes — mais alors **opaque** : sans fond ni bordure, elle
 * survolait la carte suivante et se lisait comme un défaut d'affichage. Sur
 * grand écran, le formulaire tient dans la fenêtre et la barre redevient une
 * simple rangée.
 */
.form-actions {
  position: sticky;
  /* Décalée de la hauteur de la barre de navigation basse : celle-ci est
     collante elle aussi, et la barre d'actions se retrouvait dessous. */
  bottom: calc(var(--nav-height) + var(--safe-bottom) + .5rem);
  z-index: 30;
  gap: .5rem;
  padding: .7rem;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
@media (min-width: 900px) {
  .form-actions {
    position: static;
    padding: 0;
    background: none;
    backdrop-filter: none;
    border: 0;
    box-shadow: none;
  }
}

/* ── Carte de modèle ────────────────────────────────────────────────────── */

.model {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.model:hover {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
  box-shadow: var(--shadow);
}
@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .model:hover { transform: translateY(-2px); }
}

.model__preview {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  background:
    /* Damier discret : il signale qu'il s'agit d'un aperçu, et une vignette au
       fond transparent reste lisible dans les deux thèmes. */
    repeating-conic-gradient(
      from 45deg,
      color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 0% 25%,
      var(--surface) 0% 50%)
    0 0 / 22px 22px;
  border-bottom: 1px solid var(--border);
}
.model__preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.model__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: color-mix(in srgb, var(--muted) 45%, transparent);
}
.model__badge {
  position: absolute;
  right: .5rem;
  bottom: .5rem;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .45rem;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  background: rgb(10 14 26 / 72%);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(4px);
}
.model__badge .icon { width: .9em; height: .9em; }

.model__body { display: flex; flex-direction: column; gap: .4rem; padding: .8rem .9rem .9rem; }
.model__title { margin: 0; font-size: .98rem; font-weight: 650; line-height: 1.3; }
.model__title a { color: var(--text); }
.model__title a:hover { color: var(--brand); text-decoration: none; }
.model__summary {
  margin: 0;
  font-size: .86rem;
  color: var(--muted);
  /* Deux lignes au plus : au-delà, les cartes d'une même rangée n'ont plus la
     même hauteur et la grille devient irrégulière. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.model__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .1rem .7rem;
  margin: 0;
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.model__meta span { display: inline-flex; align-items: center; gap: .25rem; }
.model__meta .icon { width: .95em; height: .95em; opacity: .7; }
.model__tags { margin: 0; }
.model__foot { display: flex; align-items: center; gap: .4rem; margin: auto 0 0; padding-top: .2rem; }

/* ── Puces ──────────────────────────────────────────────────────────────── */

.chip--sm { padding: .12rem .45rem; font-size: .76rem; }
.chip__count {
  padding-left: .35rem;
  margin-left: .1rem;
  border-left: 1px solid currentcolor;
  opacity: .65;
  font-variant-numeric: tabular-nums;
}
/* Une provenance se reconnaît à sa couleur : le regard trie la liste sans lire. */
.chip--thingiverse {
  color: #0d6e8c;
  background: #e0f2fe;
  border-color: color-mix(in srgb, #0d6e8c 30%, transparent);
}
.chip--makerworld {
  color: #0f6b4f;
  background: #dcfce7;
  border-color: color-mix(in srgb, #0f6b4f 30%, transparent);
}
.chip--local { color: var(--muted); background: var(--surface-2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip--thingiverse { color: #7dd3fc; background: #0b2b3a; }
  :root:not([data-theme="light"]) .chip--makerworld { color: #6ee7b7; background: #0a2a20; }
}
:root[data-theme="dark"] .chip--thingiverse { color: #7dd3fc; background: #0b2b3a; }
:root[data-theme="dark"] .chip--makerworld { color: #6ee7b7; background: #0a2a20; }

/* ── Visionneuse ────────────────────────────────────────────────────────── */

.viewer { overflow: hidden; }
.viewer__stage {
  position: relative;
  /* Assez haut pour juger une pièce, jamais plus haut que l'écran : sur un
     téléphone en paysage, 70vh laisse voir les boutons sous le canevas. */
  height: clamp(300px, 52vh, 560px);
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%),
    var(--surface-2);
}
.viewer__stage:fullscreen { height: 100vh; }
/*
 * Le canevas est positionné et porte un `z-index` : sans cela, la grille de
 * plateau — un pseudo-élément absolu — se peignait **par-dessus** le modèle,
 * puisqu'un élément positionné passe devant le contenu statique. Les surcouches
 * d'interface remontent en conséquence à 2.
 */
.viewer__canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  /* touch-action: none — sans quoi le premier glissement fait défiler la page au
     lieu de tourner la pièce, et la rotation devient impossible au doigt. */
  touch-action: none;
  cursor: grab;
}
.viewer__canvas:active { cursor: grabbing; }
.viewer__canvas:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

/* Grille de plateau : purement CSS, elle donne l'échelle sans coûter un seul
   triangle au rendu. */
.viewer[data-viewer-grid="1"] .viewer__stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .5;
  background-image:
    linear-gradient(color-mix(in srgb, var(--border-strong) 40%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--border-strong) 40%, transparent) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(70% 60% at 50% 62%, #000 30%, transparent 78%);
}

.viewer__status {
  position: absolute;
  z-index: 2;
  inset: auto 0 auto 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 0 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}
.viewer__status--error { color: color-mix(in srgb, var(--danger) 80%, var(--text)); }
.viewer__spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Une animation continue s'arrête quand le système le demande : le point reste
   visible, il ne tourne plus. */
@media (prefers-reduced-motion: reduce) {
  .viewer__spinner { animation: none; border-top-color: color-mix(in srgb, var(--brand) 30%, transparent); }
}

.viewer__toolbar {
  position: absolute;
  z-index: 2;
  top: .6rem;
  right: .6rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: .25rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
}
.viewer__readout {
  position: absolute;
  z-index: 2;
  left: .7rem;
  bottom: .6rem;
  margin: 0;
  padding: .2rem .5rem;
  font-size: .76rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-radius: var(--radius-pill);
}
.viewer__pieces {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .7rem .9rem;
  border-top: 1px solid var(--border);
}
.viewer__pieces .chip { cursor: pointer; font: inherit; font-size: .78rem; }

/* ── Zone de dépôt ──────────────────────────────────────────────────────── */

.dropzone { display: flex; flex-direction: column; gap: .5rem; }
.dropzone__area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.dropzone__area:hover { border-color: var(--brand); color: var(--brand); }
.dropzone__area .icon { color: currentcolor; opacity: .8; }
.dropzone__label { font-weight: 650; color: var(--text); }
.dropzone__hint { font-size: .8rem; }
.dropzone--over .dropzone__area {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}
.dropzone--filled .dropzone__area { padding: 1rem; }

/* Le champ natif reste focalisable au clavier tout en étant invisible : le
   masquer avec `display: none` le retirerait de l'ordre de tabulation. */
.dropzone__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.dropzone__input:focus-visible + .dropzone__files,
.dropzone__area:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }

.dropzone__files { margin: 0; padding: 0; list-style: none; font-size: .84rem; }
.dropzone__files:empty { display: none; }
.dropzone__file {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .55rem;
  border-radius: var(--radius-sm);
}
.dropzone__file:nth-child(odd) { background: var(--surface-2); }
.dropzone__file .truncate { flex: 1; min-width: 0; }
.dropzone__size { color: var(--muted); font-variant-numeric: tabular-nums; }
.dropzone__file--refused { color: var(--danger); }
.dropzone__warn { font-size: .74rem; font-weight: 700; }
.dropzone__total {
  padding: .35rem .55rem;
  margin-top: .2rem;
  border-top: 1px solid var(--border);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ── Étiquettes : sélection ─────────────────────────────────────────────── */

.tag-picker { border: 0; padding: 0; margin: 0 0 .4rem; }
.tag-picker legend { padding: 0; font-size: .85rem; font-weight: 600; }
.tag-picker__list {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  /* Plafonnée puis défilante : une bibliothèque bien tenue dépasse vite
     cinquante étiquettes, et la liste ne doit pas repousser le bouton d'envoi
     hors de l'écran. */
  max-height: 190px;
  overflow-y: auto;
  padding: .55rem;
  margin: .4rem 0 .8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.tag-option { display: inline-flex; }
.tag-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.tag-option span {
  display: inline-flex;
  align-items: center;
  padding: .25rem .6rem;
  font-size: .82rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  cursor: pointer;
  user-select: none;
}
.tag-option input:checked + span {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand);
  font-weight: 600;
}
.tag-option input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.search--sm { margin-bottom: .4rem; }
.search--sm input { padding: .35rem .7rem .35rem 2rem; font-size: .85rem; }

/* ── Mesures et listes de faits ─────────────────────────────────────────── */

.meter {
  display: inline-block;
  width: 84px;
  height: 5px;
  vertical-align: middle;
  margin-right: .4rem;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.meter__bar {
  display: block;
  /* La largeur vient d'une proportion posée en variable : aucune dimension
     n'est calculée côté serveur. */
  width: var(--part, 0%);
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
}

.bars-list { display: flex; flex-direction: column; gap: .3rem; }
.bars-list__row {
  display: grid;
  grid-template-columns: 3.6rem 1fr 2.4rem;
  align-items: center;
  gap: .5rem;
  padding: .28rem .3rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .84rem;
}
.bars-list__row:hover { background: var(--surface-2); text-decoration: none; }
.bars-list__label { font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.bars-list .meter { width: 100%; height: 7px; margin: 0; }
.bars-list__value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: .35rem .8rem; margin: 0; font-size: .87rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 550; }

.notes { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .85rem; }
.notes li + li { margin-top: .35rem; }

/*
 * Texte rendu depuis du Markdown. Les marges sont serrées vers le haut et larges
 * vers le bas : une notice enchaîne titres et listes, et l'espacement doit dire
 * ce qui appartient à quoi.
 */
.prose { color: var(--text); line-height: 1.62; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
/* Un titre de notice doit se voir sans être lu : sa graisse et son interligne le
   séparent du paragraphe, sinon il passe pour une phrase en gras. */
.prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 1.5rem 0 .5rem;
  font-weight: 700;
  line-height: 1.3;
}
.prose h3 { font-size: 1.1rem; }
.prose h4 { font-size: 1rem; }
.prose h5, .prose h6 { font-size: .92rem; color: var(--muted); text-transform: none; }
.prose p { margin: 0 0 .9rem; }
.prose ul, .prose ol { margin: 0 0 .9rem; padding-left: 1.3rem; }
.prose li { margin-bottom: .25rem; }
.prose li > ul, .prose li > ol { margin: .25rem 0 0; }
.prose hr { margin: 1.2rem 0; border: 0; border-top: 1px solid var(--border); }
.prose a { text-decoration: underline; text-underline-offset: 2px; }

.prose code {
  padding: .1rem .3rem;
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
}
/* Un bloc de code déborde plutôt qu'il ne coupe : une ligne de G-code ne se
   replie pas sans devenir illisible. */
.prose pre {
  margin: 0 0 .9rem;
  padding: .8rem .9rem;
  overflow-x: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.prose pre code { padding: 0; font-size: .85rem; background: none; border: 0; }

.prose blockquote {
  margin: 0 0 .9rem;
  padding: .1rem 0 .1rem .9rem;
  color: var(--muted);
  border-left: 3px solid color-mix(in srgb, var(--brand) 55%, var(--border));
}
.prose table { margin-bottom: .9rem; }
.prose .table-scroll { margin-bottom: .9rem; }
.prose del { color: var(--muted); }

.file-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
}
.list--compact .list__item { padding: .45rem .6rem; gap: .5rem; cursor: pointer; }

/* ── Ligne de fichier, cliquable ─────────────────────────────────────────── */

/*
 * La ligne se compose de deux zones voisines, jamais imbriquées : le nom, qui
 * ouvre l'aperçu, et les actions. Un bouton dans un bouton n'est pas du HTML
 * valide.
 */
.file-row { padding: 0; gap: 0; }
.file-row:hover { background: none; }

.file-open {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: .6rem;
  padding: .6rem .75rem;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.file-open:hover { background: var(--surface-2); text-decoration: none; }
.file-open:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.file-open .list__main { display: flex; flex-direction: column; }

/* La pièce actuellement affichée dans la visionneuse est marquée : sans cela,
   sur un ensemble de trois maillages, on ne sait plus lequel on regarde. */
.file-open--active { background: var(--brand-soft); }
.file-open--active .list__title { color: var(--brand); font-weight: 650; }

/*
 * L'affordance est écrite. Elle reste discrète au repos et se révèle au survol ;
 * sur un écran tactile, où il n'y a pas de survol, elle est toujours visible.
 */
.file-open__hint {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  flex: none;
  font-size: .74rem;
  font-weight: 600;
  color: var(--muted);
  opacity: 0;
  transition: opacity .12s;
}
.file-open__hint .icon { width: .9em; height: .9em; }
.file-open:hover .file-open__hint,
.file-open:focus-visible .file-open__hint { opacity: 1; color: var(--brand); }
.file-open--active .file-open__hint { opacity: 1; color: var(--brand); }
@media (hover: none) {
  .file-open__hint { opacity: .75; }
}

.file-row__actions { flex: none; padding-right: .6rem; }

/* ── Agrandissement d'une image ──────────────────────────────────────────── */

.lightbox {
  width: min(96vw, 1200px);
  max-width: none;
  max-height: 92vh;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.lightbox::backdrop { background: rgb(6 10 20 / 78%); backdrop-filter: blur(3px); }

/* Le damier dit qu'un fond transparent l'est vraiment, comme sur les cartes. */
.lightbox__frame {
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: calc(92vh - 56px);
  background:
    repeating-conic-gradient(
      from 45deg,
      color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 0% 25%,
      var(--surface) 0% 50%)
    0 0 / 22px 22px;
}
/* L'image tient dans la boîte sans être agrandie au-delà de sa taille réelle :
   un rendu de 600 px flouté sur 1 200 px n'apprend rien de plus. */
.lightbox__image {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 56px);
  object-fit: contain;
}
.lightbox__bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .6rem;
  border-top: 1px solid var(--border);
}
.lightbox__name { margin: 0; font-size: .86rem; font-weight: 600; min-width: 0; }
.lightbox__position { font-size: .8rem; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  .lightbox[open] { animation: lightbox-in .16s ease-out; }
}
@keyframes lightbox-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.list-summary { margin: 0 0 .5rem; }

.stat--todo {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
}
.stat--todo .stat__label { color: var(--accent-ink); }
a.stat:hover { text-decoration: none; border-color: var(--brand); }

/* Édition sur place d'une étiquette : un `<details>` suffit, donc aucun état à
   synchroniser en JavaScript. */
.inline-edit { position: relative; }
.inline-edit > summary { list-style: none; cursor: pointer; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit__form {
  position: absolute;
  right: 0;
  z-index: 20;
  display: flex;
  gap: .3rem;
  width: max(220px, 60vw);
  max-width: 320px;
  margin-top: .3rem;
  padding: .5rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.inline-edit__form input { flex: 1; min-width: 0; }

.thumb-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: .5rem; }
.thumb-choice {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  width: 100%;
  padding: 0;
  font: inherit;
  font-size: .74rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
.thumb-choice:hover { color: var(--brand); border-color: var(--brand); }
.thumb-choice:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* L'image occupe la vignette ; le damier dit qu'un fond transparent l'est
   vraiment, comme sur les cartes de la bibliothèque. */
.thumb-choice img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background:
    repeating-conic-gradient(
      from 45deg,
      color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 0% 25%,
      var(--surface) 0% 50%)
    0 0 / 16px 16px;
}
.thumb-choice__name { display: block; padding: 0 .45rem .45rem; }

.source-note + .source-note { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.source-note h3 { display: flex; align-items: center; gap: .4rem; margin: 0 0 .2rem; font-size: .92rem; }
.import__title { margin: 0 0 .1rem; font-size: 1.1rem; }

.card__search { margin: 0; }
.card__search .search input { padding: .3rem .7rem .3rem 2rem; font-size: .84rem; }

.required { color: var(--danger); }
.text-danger { color: var(--danger); }
.field--color input[type="color"] {
  width: 3rem;
  height: 2.1rem;
  padding: .15rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Un bouton occupé le dit : sans cela, un envoi de 200 Mo ressemble à un clic
   qui n'a rien fait. */
.btn--busy { opacity: .8; cursor: progress; }

/* Squelette de carte : il donne la forme de ce qui arrive, vignette comprise. */
.skeleton__thumb {
  aspect-ratio: 4 / 3;
  margin-bottom: .7rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .skeleton__thumb { animation: none; }
}

/* ── Divers ─────────────────────────────────────────────────────────────── */

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.numeric { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.inline-form { display: inline; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .app-header, .bottom-nav, .sidebar, .pagination, .toast-stack,
  .viewer__toolbar, .dropzone { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .model { break-inside: avoid; box-shadow: none; }
}
