/*
 * Fleetsy — système visuel.
 * Principe : encre sur papier. Une seule couleur forte (l'encre) pour l'action principale,
 * le rouge réservé aux alertes, tout le reste en gris. Les chiffres sont alignés (tabular-nums).
 */
:root {
  --bg: #f5f4f1;
  --card: #ffffff;
  --sunken: #f1efeb;
  --text: #17181c;
  --muted: #6d6f76;
  --line: #e4e1db;
  --accent: #17181c;       /* action principale */
  --accent-text: #ffffff;
  --focus: #2f5fd0;
  --ok: #17713c;
  --err: #b3261e;
  --err-soft: #fbeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 24, 28, 0.04), 0 1px 1px rgba(23, 24, 28, 0.03);
  --sidebar: 244px;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1); /* départ vif, arrivée douce */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f12;
    --card: #16181d;
    --sunken: #1c1f25;
    --text: #eceef2;
    --muted: #9a9ea8;
    --line: #272a31;
    --accent: #eceef2;
    --accent-text: #121317;
    --focus: #7ea2ff;
    --ok: #4cc27a;
    --err: #ff8a80;
    --err-soft: #2a1716;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #0e0f12;
  --card: #16181d;
  --sunken: #1c1f25;
  --text: #eceef2;
  --muted: #9a9ea8;
  --line: #272a31;
  --accent: #eceef2;
  --accent-text: #121317;
  --focus: #7ea2ff;
  --ok: #4cc27a;
  --err: #ff8a80;
  --err-soft: #2a1716;
  --shadow: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.012em; margin: 0; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.02rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 10px; }
small { font-size: 0.8rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
code { background: var(--sunken); padding: 1px 5px; border-radius: 4px; font-size: 0.86em; }

/* ------------------------------------------------------------------ structure */
#topbar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 14px 16px;
  background: var(--card);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 8;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent); color: var(--accent-text);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}
#nav { display: flex; flex-direction: column; gap: 16px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-title {
  /* Titre de rubrique (Suivi, Parc…) : léger soulignement pour ne pas le confondre avec un bouton du menu. */
  margin: 0 10px 6px; padding: 0 0 5px;
  border-bottom: 1px solid var(--line);
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.nav-item {
  all: unset;
  box-sizing: border-box;
  display: block; width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.93rem;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.nav-item:active { transform: scale(0.98); }
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item.active { background: var(--sunken); color: var(--text); font-weight: 600; }
.nav-item:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.who {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 8px 0;
  border-top: 1px solid var(--line);
}
#who { display: flex; flex-direction: column; line-height: 1.3; }
#who strong { font-weight: 600; font-size: 0.9rem; }
#who small { color: var(--muted); }

#mobilebar { display: none; }
#scrim { display: none; }

main { max-width: 1180px; margin: 0 auto; padding: 34px 28px 64px; }
body.authed main { margin-left: var(--sidebar); max-width: none; padding: 34px 40px 64px; }
body.authed main > * { max-width: 1180px; }

/* ------------------------------------------------------------------ éléments */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-bottom: 14px; }
.card.auth { max-width: 380px; margin: 9vh auto 0; padding: 28px; }
.card.auth h1 { margin-bottom: 6px; }
.card.auth form { margin-top: 18px; }

.bar {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  gap: 14px; margin-bottom: 22px;
}
.bar h1 + p { margin: 6px 0 0; }
.bar label { flex-direction: row; align-items: center; gap: 8px; }
.bar-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { width: 280px; }
.section-title { margin: 28px 0 12px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 0;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
/* Filets entre les cases : tracés par chaque case, pour qu'une ligne incomplète reste propre. */
.kpi { background: var(--card); padding: 14px 16px; min-width: 0; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.kpi span {
  display: block;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted);
}
.kpi strong { display: block; margin-top: 6px; font-size: 1.12rem; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.kpis.small { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); box-shadow: none; }
.kpis.small .kpi strong { font-size: 1rem; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit; font-weight: 400;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%; min-width: 0;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.84rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.grid .wide { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack button { align-self: flex-start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text);
  border-radius: 8px;
  padding: 8px 14px;
  white-space: nowrap;
  transition: opacity 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}
button:active:not(:disabled) { transform: scale(0.97); } /* retour tactile à l'appui */
button:hover { opacity: 0.88; }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button.ghost { background: var(--card); color: var(--text); border-color: var(--line); font-weight: 500; }
button.ghost:hover { background: var(--sunken); opacity: 1; }
button.danger { background: transparent; color: var(--err); border-color: transparent; font-weight: 500; padding: 5px 8px; }
button.danger:hover { background: var(--err-soft); opacity: 1; }
button.small { padding: 5px 10px; font-size: 0.82rem; }
button:disabled { opacity: 0.45; cursor: default; }

.seg { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 14px; background: var(--sunken); border-radius: 10px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; color: var(--muted); font-weight: 500; padding: 6px 12px; border-radius: 7px; }
.seg button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* Ombres sur les bords quand le tableau dépasse : elles signalent qu'on peut faire défiler
   horizontalement, et disparaissent une fois le bord atteint. */
.table-wrap {
  overflow-x: auto; margin: 0 -4px; -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, var(--card) 30%, transparent),
    linear-gradient(to left, var(--card) 30%, transparent) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.28), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.28), transparent) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); padding-top: 4px; white-space: normal; line-height: 1.3; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td select { padding: 5px 8px; min-width: 150px; }
td small { display: block; color: var(--muted); }
td:first-child { white-space: normal; min-width: 150px; }
td .wrap { display: block; white-space: normal; min-width: 150px; max-width: 190px; }
.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.row-actions button { margin: 0; }
td button + button { margin-left: 4px; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--sunken); }
tr.row-link:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
ul.plain, ol.plain { margin: 0 0 10px; padding-left: 20px; }
ul.plain li, ol.plain li { margin: 5px 0; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block;
  font-size: 0.76rem; font-weight: 500;
  padding: 2px 9px; border-radius: 999px;
  background: var(--sunken); color: var(--text);
  white-space: nowrap;
}
.badge.alert { background: var(--err-soft); color: var(--err); }
.badge.muted-badge { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; flex-direction: column; padding: 5px 10px; border-radius: 8px; background: var(--sunken); font-weight: 600; font-size: 0.86rem; }
.chip small { font-weight: 400; color: var(--muted); font-size: 0.74rem; }

/* ------------------------------------------------------------------ flottes */
.fleet { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.fleet-head {
  all: unset; box-sizing: border-box;
  display: grid; grid-template-columns: minmax(200px, 1.2fr) 3fr auto 18px; align-items: center; gap: 20px;
  width: 100%; padding: 18px 20px; cursor: pointer;
}
.fleet-head:hover { background: var(--sunken); }
.fleet-head:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.fleet-title p { margin: 3px 0 0; }
.fleet-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 0; }
.fleet-stats dt { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.fleet-stats dd { margin: 3px 0 0; font-weight: 600; }
.chevron { width: 8px; height: 8px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s; }
.fleet.open .chevron { transform: rotate(45deg); }
.fleet-body { border-top: 1px solid var(--line); padding: 8px 20px 18px; }
.fleet-body h3 { margin: 18px 0 8px; font-size: 0.68rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.free-vehicle { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.free-vehicle:last-child { border-bottom: none; }
.free-vehicle select { width: 220px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.group-head p { margin: 0; }

/* Anciennes cartes conducteur (encore utilisées pour les listes simples) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.driver-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.driver-card:hover, .driver-card:focus-visible { border-color: var(--text); outline: none; }
.driver-card header { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.driver-card header p { margin: 2px 0 0; }

/* ------------------------------------------------------------------ panneau latéral */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 11, 14, 0.38); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(680px, 100vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(10, 11, 14, 0.12);
  z-index: 11;
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 22px 12px; background: var(--card); }
.drawer-head p { margin: 3px 0 0; }
.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 10px; font-weight: 500; }
.tabs button:hover { color: var(--text); opacity: 1; }
.tabs button.active { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
.drawer-body { padding: 18px 22px; overflow-y: auto; flex: 1; }

/* ------------------------------------------------------------------ relevés, dépenses */
.report[hidden] { display: none; }
.report-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 14px; }
.report-head p { margin: 3px 0 0; }
#synthese h3 { margin: 22px 0 8px; font-size: 0.68rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.pending-card { border-color: var(--text); }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 12px; }
.bookmarklet { display: inline-block; padding: 4px 12px; border-radius: 999px; border: 1px dashed var(--text); color: var(--text); font-weight: 600; text-decoration: none; cursor: grab; }

/* ------------------------------------------------------------------ messagerie */
.msg-layout { display: grid; grid-template-columns: 1fr; gap: 14px; }
.msg-layout.with-list { grid-template-columns: minmax(200px, 270px) minmax(0, 1fr); }
.msg-layout > * { min-width: 0; } /* le fil ne déborde plus de l'écran */
.conv-list { display: flex; flex-direction: column; gap: 2px; max-height: 72vh; overflow-y: auto; padding: 8px; }
.conv { text-align: left; display: flex; flex-direction: column; gap: 1px; background: transparent; color: var(--text); border: none; font-weight: 400; padding: 9px 10px; white-space: normal; }
.conv strong { font-weight: 600; }
.conv span { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv:hover { background: var(--sunken); opacity: 1; }
.conv.active { background: var(--sunken); }
.thread-card { display: flex; flex-direction: column; gap: 14px; min-height: 380px; }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; padding-right: 4px; flex: 1; }
.bubble { align-self: flex-start; max-width: 76%; background: var(--sunken); border-radius: 14px 14px 14px 4px; padding: 8px 12px; }
.bubble.mine { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--accent); color: var(--accent-text); }
.bubble .meta { font-size: 0.72rem; opacity: 0.7; margin-bottom: 2px; }
.bubble .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: grid; grid-template-columns: 210px 1fr auto; gap: 8px; align-items: end; padding-top: 12px; border-top: 1px solid var(--line); }
.composer textarea { font-family: inherit; font-size: inherit; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-weight: 500; font-size: 0.9rem;
  box-shadow: 0 8px 28px rgba(10, 11, 14, 0.22);
  z-index: 30;
}
.toast.err { background: var(--err); color: #fff; }

/* ------------------------------------------------------------------ impression */
@media print {
  :root { --bg: #fff; --card: #fff; --sunken: #f4f4f4; --text: #000; --muted: #444; --line: #bbb; --shadow: none; }
  #topbar, #mobilebar, #scrim, .no-print, .toast { display: none !important; }
  body.authed main { margin-left: 0; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
  .table-wrap { overflow: visible; }
  th, td { white-space: normal; font-size: 11px; padding: 4px 5px; }
}

/* ------------------------------------------------------------------ écrans étroits */
@media (max-width: 1100px) {
  .fleet-head { grid-template-columns: 1fr auto 18px; }
  .fleet-stats { grid-column: 1 / -1; grid-row: 2; }
  /* Fenêtre moyenne (tablette, petit portable) : la zone de saisie passe sur plusieurs lignes
     pour que le bouton Envoyer reste visible. */
  .composer { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  #mobilebar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 7;
    padding: 10px 14px;
    background: var(--card); border-bottom: 1px solid var(--line);
    font-weight: 600;
  }
  /* Le menu glisse depuis la gauche. Fermé, il est masqué (visibility) : ni lisible ni atteignable
     au clavier. Si l'animation est désactivée, il s'ouvre et se ferme instantanément. */
  #topbar {
    width: min(280px, 84vw); z-index: 9;
    transform: translateX(-104%); visibility: hidden;
    transition: transform 0.28s var(--ease-out), visibility 0s linear 0.28s;
  }
  body.nav-open #topbar {
    transform: none; visibility: visible; box-shadow: 16px 0 40px rgba(10, 11, 14, 0.18);
    transition: transform 0.28s var(--ease-out), visibility 0s;
  }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 8;
    background: rgba(10, 11, 14, 0.38); opacity: 0; pointer-events: none;
    transition: opacity 0.28s ease;
  }
  body.nav-open #scrim { opacity: 1; pointer-events: auto; }
  body.authed main { margin-left: 0; padding: 20px 14px 48px; }
  main { padding: 20px 14px 48px; }
  h1 { font-size: 1.3rem; }
  .bar { flex-direction: column; align-items: stretch; }
  .bar-tools, .search { width: 100%; }
  .bar-tools label { justify-content: space-between; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .msg-layout.with-list { grid-template-columns: 1fr; }
  .conv-list { max-height: 210px; }
  .composer { grid-template-columns: 1fr; }
  .fleet-head { padding: 16px; gap: 12px; }
  .fleet-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
  .fleet-body { padding: 6px 16px 16px; }
  .free-vehicle select { width: 100%; }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
  .card.auth { margin-top: 4vh; }
}

/* ------------------------------------------------------------------ droits de l'équipe */
.perm-group { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 12px; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 18px; }
.perm-group legend { padding: 0 6px; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.perm-group .check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; font-weight: 400; padding: 3px 0; }
.perm-group .check input { width: auto; accent-color: var(--text); }
.preset-row { margin-bottom: 2px; }
.member .group-head { margin-bottom: 14px; }
[inert] { opacity: 0.45; pointer-events: none; }

/* ------------------------------------------------------------------ transitions d'écran */
/* Pendant le chargement d'un écran, l'ancien contenu s'estompe : l'appui est pris en compte
   tout de suite, même si le serveur met un instant à répondre. */
main { transition: opacity 0.2s ease; }
main.view-loading { opacity: 0.5; pointer-events: none; }

/* Le nouvel écran apparaît en glissant légèrement, bloc par bloc. */
@keyframes view-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
main.view-enter > * { animation: view-in 0.34s var(--ease-out) both; }
main.view-enter > *:nth-child(2) { animation-delay: 0.04s; }
main.view-enter > *:nth-child(3) { animation-delay: 0.08s; }
main.view-enter > *:nth-child(n + 4) { animation-delay: 0.12s; }

/* Barre de progression fine en haut, seulement si le chargement dure. */
@keyframes busy-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
body.view-busy::after {
  content: ""; position: fixed; top: 0; left: 0; z-index: 30;
  width: 40%; height: 3px; border-radius: 0 3px 3px 0;
  background: var(--focus);
  animation: busy-slide 1s ease-in-out infinite;
}

/* Messages éphémères : entrée douce plutôt qu'apparition sèche. */
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast { animation: toast-in 0.25s var(--ease-out) both; }

/* Réglage « Réduire les animations » du téléphone ou de l'ordinateur : tout est instantané. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  body.view-busy::after { display: none; }
}

/* ------------------------------------------------------------------ accès, invitations, relevé à confirmer */
.access { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 4px 0 10px; }
details.inline > summary { cursor: pointer; color: var(--text); font-size: 0.86rem; font-weight: 500; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.inline-form input { width: auto; flex: 1 1 160px; }
.small-note { font-size: 0.8rem; margin: 4px 0 0; }
.invite { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.nav-item .badge { margin-left: 4px; }

/* ------------------------------------------------------------------ confort au doigt (téléphone) */
@media (max-width: 860px) {
  /* 16 px minimum : en dessous, Safari (iPhone) zoome sur le champ à chaque saisie. */
  input, select, textarea { font-size: 16px; }
  /* Cibles tactiles d'au moins 44 px (recommandation Apple ; 48 px chez Android pour les principales). */
  button, button.small, .nav-item, details.inline > summary { min-height: 44px; }
  .nav-item { display: flex; align-items: center; padding: 10px 12px; }
  details.inline > summary { display: flex; align-items: center; }
  input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  .error-card .actions button { width: 100%; }
}

/* ------------------------------------------------------------------ formules, consultation, inscription */
.badge.ok { background: rgba(23, 113, 60, 0.12); background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.plan-strip { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; padding-top: 12px; padding-bottom: 12px; }
.plan-strip p { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.plan-strip.pro { border-color: var(--ok); }
.plan-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; }
.plan-card h2 { margin: 8px 0 4px; }
.plan-card p { margin: 0; }
.plan-card > div:first-child { flex: 1 1 320px; }
.plan-card.pro { border-color: var(--ok); }
.plan-upsell {
  flex: 0 1 300px; display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px; border-radius: 10px; background: var(--sunken);
}
#consult-banner {
  position: sticky; top: 0; z-index: 7;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px;
  margin-left: var(--sidebar); padding: 10px 40px;
  background: #fff4d6; color: #5a4300; border-bottom: 1px solid #ecd48a;
  font-size: 0.9rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #consult-banner { background: #3a2f0e; color: #ffe39a; border-color: #5a4a1a; }
}
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--muted); }
button.link {
  all: unset; cursor: pointer; color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
button.link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.small-print { font-size: 0.78rem; margin: 14px 0 0; text-align: center; }
.small-print a { color: inherit; }

/* Relevé mensuel : mise en page de document. */
.statement { padding: 28px; }
.statement-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 2px solid var(--text); }
.statement-head .brand { padding: 0; font-size: 1.1rem; }
.statement-head > div:last-child { text-align: right; }
.statement-head h2 { font-size: 1.25rem; margin-bottom: 4px; }
.statement-head p { margin: 0; }
.statement h3 { margin: 22px 0 10px; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.statement-foot { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.78rem; }

@media print {
  #consult-banner { display: none !important; }
  .statement { border: none; padding: 0; }
  .statement .kpis { box-shadow: none; }
  .statement-head > div:last-child { text-align: right; }
  @page { margin: 14mm; }
}

/* ------------------------------------------------------------------ adaptation à chaque appareil */
/* Grands écrans (moniteur large) : plus de place pour les tableaux. */
@media (min-width: 1600px) {
  :root { --sidebar: 264px; }
  body.authed main > * { max-width: 1440px; }
  body { font-size: 15px; }
}

/* Tablettes et petits portables : barre latérale plus étroite, marges réduites. */
@media (min-width: 861px) and (max-width: 1100px) {
  :root { --sidebar: 212px; }
  body.authed main { padding: 28px 24px 56px; }
  #consult-banner { padding: 10px 24px; }
}

/* Téléphones et tablettes en mode portrait. */
@media (max-width: 860px) {
  #consult-banner { margin-left: 0; padding: 10px 14px; top: 0; }
  body.consulting #mobilebar { position: static; }
  #mobilebar { padding-top: max(10px, env(safe-area-inset-top)); }
  #mobile-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .plan-upsell { flex-basis: 100%; }
  .statement { padding: 16px; }
  .statement-head > div:last-child { text-align: left; }
}

/* Encoche et barre d'accueil de l'iPhone (application installée sur l'écran d'accueil). */
@supports (padding: max(0px)) {
  body.authed main { padding-bottom: max(64px, calc(env(safe-area-inset-bottom) + 32px)); }
  #topbar { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .toast { bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); }
}

/* Téléphones et tablettes en portrait : chaque ligne de tableau devient une fiche, chaque valeur
   précédée du nom de sa colonne. Plus besoin de faire défiler de gauche à droite. */
@media screen and (max-width: 860px) {
  .table-wrap { overflow: visible; margin: 0; background: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr { display: block; width: 100%; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-wrap tr {
    margin-bottom: 10px; padding: 4px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .card .table-wrap tr { background: var(--bg); }
  .table-wrap td {
    display: grid; grid-template-columns: minmax(96px, 40%) minmax(0, 1fr); gap: 12px; align-items: baseline;
    padding: 8px 0; border-bottom: 1px solid var(--line); white-space: normal; text-align: right; min-width: 0;
  }
  .table-wrap td::before {
    content: attr(data-label); text-align: left;
    font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  }
  .table-wrap td:last-child, .table-wrap tbody tr:last-child td:last-child { border-bottom: none; }
  /* Première colonne : titre de la fiche (plaque, nom…). */
  .table-wrap td:first-child { display: block; text-align: left; font-size: 1rem; padding: 10px 0 8px; }
  .table-wrap td:first-child::before { display: none; }
  .table-wrap td[data-label=""] { display: block; text-align: left; }
  .table-wrap td[data-label=""]::before { display: none; }
  .table-wrap td .cell { min-width: 0; overflow-wrap: anywhere; }
  .table-wrap td .wrap { max-width: none; min-width: 0; }
  .table-wrap td select { min-width: 0; width: 100%; }
  .table-wrap .row-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
  .table-wrap td[data-label=""] .row-actions { justify-content: flex-start; }
  .table-wrap .badges { justify-content: flex-end; }
  .table-wrap .inline-form { justify-content: flex-end; }
  .table-wrap tr.row-link:hover td { background: transparent; }
  .table-wrap tr.row-link:active { border-color: var(--text); }
  .kpi { padding: 12px 14px; }
  .kpi strong { font-size: 1.02rem; }
  .plan-card { gap: 12px; }
}

/* Tablette en portrait : deux fiches côte à côte. */
@media screen and (min-width: 641px) and (max-width: 860px) {
  .table-wrap tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: start; }
  .table-wrap tr { margin-bottom: 0; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Appareils tactiles : pas d'effet de survol « collant » après un appui. */
@media (hover: none) {
  button:hover { opacity: 1; }
  .nav-item:hover:not(.active) { background: transparent; color: var(--muted); }
}

.help-link { color: var(--muted); font-size: 0.85rem; text-underline-offset: 3px; }
.help-link:hover { color: var(--text); }

/* Abonnement Pro : offres de paiement */
.offer-list { display: grid; gap: 10px; margin: 12px 0; }
.offer { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--sunken); }
.offer small { display: block; color: var(--muted); }
.offer-price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 640px) {
  .offer { grid-template-columns: 1fr auto; }
  .offer button { grid-column: 1 / -1; }
}

/* 0.6 : code d'invitation, changements programmés, messages automatiques, double vérification */
.invite-code { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 20px; border-color: var(--accent); }
.invite-code h2 { margin: 0 0 4px; }
.code-big { font-size: 2rem; font-weight: 700; letter-spacing: 0.12em; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
form.invite { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; }
form.invite input[name="code"] { width: 9.5em; }
small.scheduled { display: block; color: var(--muted); margin-top: 2px; }
.terms-box { margin-top: 14px; padding: 14px 16px; border-radius: 10px; background: var(--sunken); }
.terms-box h3 { margin: 0 0 10px; }
.terms-box p { margin: 10px 0 0; }
.bubble.system { background: var(--sunken); border-style: dashed; }
code.secret { font-size: 1rem; letter-spacing: 0.06em; padding: 2px 6px; border-radius: 6px; background: var(--sunken); word-break: break-all; }
ol.steps { padding-left: 1.2em; display: grid; gap: 6px; }
.plan-opening .actions { margin-top: 12px; }
