/* LudoCRM — feuille de style unique, thèmes clair et sombre */
:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --border: #e6e5e1;
  --text: #1b1b19;
  --muted: #7a7873;
  --accent: #2f6f4f;
  --accent-soft: #e7f0ea;
  --danger: #a33a32;
  --danger-soft: #f8eae9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,20,18,.05), 0 8px 24px rgba(20,20,18,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #141513;
  --surface: #1c1e1b;
  --surface-2: #232622;
  --border: #2f332e;
  --text: #ecebe6;
  --muted: #9b9a93;
  --accent: #76c39a;
  --accent-soft: #1f2e26;
  --danger: #e08b83;
  --danger-soft: #33211f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { font-weight: 600; letter-spacing: -.01em; margin: 0; }

/* --- Boutons et champs --- */
.btn {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn.primary { color: #10231a; }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); font-size: 22px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
input, select, textarea {
  font: inherit; font-size: 14px; width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 72px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 5px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }
/* Double saisie du mot de passe : la divergence se voit sans lire le message. */
input.mismatch, input.mismatch:focus { border-color: var(--danger); }
input.mismatch:focus { box-shadow: 0 0 0 3px var(--danger-soft); }

/* --- Connexion --- */
/* iOS : 100vh vaut la fenêtre barre d'adresse rétractée, donc plus haute que
   ce qu'on voit — d'où un bas de page inaccessible. dvh suit le visible ; vh
   reste déclaré au-dessus pour les navigateurs qui ignorent dvh. */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); padding: 30px;
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-card .btn { width: 100%; margin-top: 4px; }
.login-card p.muted { margin: 4px 0 22px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -.02em; font-size: 17px; }
/* Logo : un dé, face 3, en aplat de la couleur d'accentuation. Les pastilles
   reprennent le fond de la surface pour rester lisibles dans les deux thèmes. */
.brand .logo { width: 1.15em; height: 1.15em; flex: 0 0 auto; }
.logo-face { fill: var(--accent); }
.logo-pip { fill: var(--surface); }

/* --- Structure --- */
.app {
  display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; min-height: 100dvh;
  background-image: linear-gradient(90deg, var(--surface) 232px, var(--bg) 232px);
}
/* Panneau ouvert : le contenu se resserre au lieu d'être recouvert.
   Cantonné aux grands écrans : sans sa requête de média, ce sélecteur — plus
   spécifique que `.app` — l'emportait aussi en mobile, où le panneau est une
   surcouche. La liste derrière était alors comprimée dans une colonne de
   232 px, sa hauteur triplait, et le défilement partait ailleurs. */
@media (min-width: 1101px) {
  body.panel-open .app { grid-template-columns: 232px minmax(0, 1fr) 380px; }
}
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  text-align: left; font: inherit; font-size: 14px; padding: 8px 11px; border: 0;
  border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.user-meta strong { font-size: 14px; font-weight: 550; }
/* Numéro de version : discret, mais toujours sous les yeux pour un support. */
.app-version { margin-left: auto; font-size: 11px; opacity: .65; flex: 0 0 auto; }
.foot-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.search { flex: 1 1 260px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 500; }
.actions { display: flex; gap: 8px; margin-left: auto; }

.stats { display: flex; gap: 22px; margin-bottom: 20px; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 7px; }
.stat b { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.stat span { font-size: 13px; color: var(--muted); }

/* --- Groupes et cartes --- */
.group { margin-bottom: 26px; }
.group-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-bottom: 9px; margin-bottom: 12px; border-bottom: 1px solid var(--border);
}
.group-head h2 { font-size: 15px; overflow-wrap: anywhere; }
.group-head .spacer { flex: 1; }
.tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
  padding: 3px 8px; border-radius: 5px; background: var(--surface-2); color: var(--muted);
}
.tag.editeur { background: var(--accent-soft); color: var(--accent); }
.tag.distributeur { background: #eceaf5; color: #5a4f8d; }
[data-theme="dark"] .tag.distributeur { background: #262437; color: #a89ce0; }
/* Magenta : la seule plage de teintes encore libre entre le violet du
   distributeur (251°) et la brique de l'auteur (12°), à une soixantaine de
   degrés de chacun. Le vert reste à l'éditeur. */
.tag.agence-de-com { background: #f4e7f0; color: #8a4076; }
[data-theme="dark"] .tag.agence-de-com { background: #2c1f29; color: #d99cc6; }
.tag.illustrateur { background: #e6eef5; color: #3d6384; }
[data-theme="dark"] .tag.illustrateur { background: #1c2733; color: #8fb8d8; }
.tag.auteur { background: #f6ede0; color: #8a6425; }
[data-theme="dark"] .tag.auteur { background: #302718; color: #d4ad6a; }

/* Les colonnes s'élargissent d'elles-mêmes : une carte occupe au minimum 300px,
   ou toute la largeur disponible si l'écran est plus étroit. */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 15px; transition: border-color .15s, box-shadow .15s;
  min-width: 0; overflow-wrap: anywhere;
}
.card:hover { border-color: var(--muted); box-shadow: var(--shadow); }
.card h3 { font-size: 15px; overflow-wrap: anywhere; }
.card .role { font-size: 13px; color: var(--muted); margin: 1px 0 9px; overflow-wrap: anywhere; }
/* Une adresse longue se coupe plutôt que de déborder de la carte. */
.card .line { display: flex; gap: 7px; align-items: baseline; font-size: 13.5px; margin-top: 3px; }
.card .line > a { min-width: 0; overflow-wrap: anywhere; }
.card .line a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); }
.card .line a:hover { border-color: var(--accent); color: var(--accent); }
.card .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; }
.card .note { margin-top: 10px; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.card-actions { display: flex; gap: 6px; margin-top: 12px; }
.empty { color: var(--muted); font-size: 14px; padding: 26px 0; text-align: center; }

/* --- Listes en lignes (contacts, sociétés) --- */
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border);
        border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list-row {
  display: grid; grid-template-columns: minmax(0, 2.2fr) auto minmax(0, 1.4fr) 14px;
  align-items: center; gap: 14px; padding: 11px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background .12s;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-row.selected { background: var(--accent-soft); }
.list-row.selected .row-main strong { color: var(--accent); }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-main strong { font-size: 14.5px; font-weight: 550; overflow-wrap: anywhere; }
.row-main span { overflow-wrap: anywhere; }
.row-tags { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
/* Une adresse trop longue est tronquée plutôt que coupée en deux lignes. */
.row-side { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chevron { color: var(--muted); font-size: 18px; line-height: 1; text-align: right; }

/* --- Panneau de détail --- */
.panel {
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px 22px 40px; overflow-y: auto; position: sticky; top: 0;
  height: 100vh; height: 100dvh; width: 380px;
  /* Arrivé en bout de course, le panneau ne doit pas entraîner la page. */
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.panel-head { margin-bottom: 14px; }
.panel-head h2 { font-size: 18px; letter-spacing: -.02em; overflow-wrap: anywhere; padding-right: 28px; }
.panel-head p { margin: 3px 0 0; }
.panel-close { position: absolute; top: 16px; right: 18px; }
.panel-back { display: none; }
.panel .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 4px; }
.panel-section { margin-top: 20px; }
.panel-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin-bottom: 8px;
}
.panel-section .note { margin: 0; font-size: 13.5px; white-space: pre-wrap; }
.fields { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; margin: 0; font-size: 13.5px; }
/* Libellés plus longs sur les profils de comptes (« Dernière connexion »). */
.fields.wide { grid-template-columns: 122px 1fr; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.fields a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); }
.fields a:hover { color: var(--accent); border-color: var(--accent); }
.link-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%;
  font: inherit; font-size: 13.5px; text-align: left; cursor: pointer;
  background: transparent; border: 0; border-bottom: 1px solid var(--border);
  padding: 8px 0; color: var(--text);
}
.link-row:last-child { border-bottom: 0; }
.link-row:hover { color: var(--accent); }
.panel-actions { display: flex; gap: 8px; margin-top: 22px; }
.panel-actions .btn { flex: 1; }
.panel .timeline li { padding: 9px 0; }
.panel table.diff td { font-size: 12.5px; }

/* --- Échanges --- */
.exch-list { list-style: none; margin: 0 0 10px; padding: 0; }
.exch {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; background: var(--surface);
}
.exch:last-child { margin-bottom: 0; }
.exch.pinned { border-color: var(--accent); background: var(--accent-soft); }
.exch-head { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.exch-head strong { font-size: 14px; font-weight: 550; overflow-wrap: anywhere; }
.exch-head .spacer { flex: 1; }
.exch-dir { font-size: 13px; font-weight: 700; line-height: 1; }
.exch-dir.outgoing { color: var(--accent); }
.exch-dir.incoming { color: #5a4f8d; }
[data-theme="dark"] .exch-dir.incoming { color: #a89ce0; }
/* Une note n'a pas de sens : son pictogramme se suffit. */
.exch-dir.note { font-size: 12px; }
.exch-meta { margin-top: 3px; }
.exch-body { margin: 7px 0 0; font-size: 13.5px; white-space: pre-wrap; }
.exch-actions { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.pin { font-size: 12px; }
/* Auteur dont le compte n'existe plus : la donnée reste, le nom s'efface. */
.ghost-user { font-style: italic; opacity: .75; }

/* Pièces jointes */
.files { list-style: none; margin: 8px 0 0; padding: 0; }
.files li {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; margin-bottom: 4px;
  background: var(--surface-2); border-radius: 6px; font-size: 13px;
}
.files li:last-child { margin-bottom: 0; }
.files a { color: inherit; text-decoration: none; flex: 1; min-width: 0;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files a:hover { color: var(--accent); }
.files .icon-btn { font-size: 16px; padding: 0 2px; }
input[type="file"] { padding: 8px; background: var(--surface-2); cursor: pointer; }
.pin-tag { background: var(--accent-soft); color: var(--accent); }

/* Bandeau d'attente : qui doit jouer, et depuis quand. */
.await {
  margin-top: 7px; font-size: 12.5px; font-weight: 550; padding: 5px 9px;
  border-radius: 6px; background: var(--surface-2); color: var(--muted);
}
.await.them { background: #f6ede0; color: #8a6425; }
[data-theme="dark"] .await.them { background: #302718; color: #d4ad6a; }
.await.us { background: var(--accent-soft); color: var(--accent); }
.await.overdue { background: var(--danger-soft); color: var(--danger); }
.stat.overdue b, .stat.overdue span { color: var(--danger); }

/* Étiquette d'attente en liste : même code couleur que le bandeau du détail. */
.await-tag.them { background: #f6ede0; color: #8a6425; }
[data-theme="dark"] .await-tag.them { background: #302718; color: #d4ad6a; }
.await-tag.us { background: var(--accent-soft); color: var(--accent); }
.overdue-text { color: var(--danger); }

.panel-section h3 .add-exch { float: right; margin-top: -4px; }
.link-inline {
  font: inherit; font-size: inherit; background: transparent; border: 0; padding: 0;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}

/* Pastille du menu « À suivre » */
.nav-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: auto;
  border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
}
.nav-badge.alert { background: var(--danger-soft); color: var(--danger); }

/* --- Journal global --- */
.hist-filters { margin-bottom: 14px; }
/* Le journal s'affiche désormais en `.list-row`, comme les autres listes : son
   détail s'ouvre dans le panneau. Il ne reste ici que l'étiquette d'action. */
.hist-action {
  font-size: 12px; padding: 2px 8px; border-radius: 5px;
  background: var(--surface-2); color: var(--muted);
}
/* Préfixe act- : sans lui, « login » hériterait des styles de l'écran de connexion. */
.hist-action.act-create, .hist-action.act-login { background: var(--accent-soft); color: var(--accent); }
.hist-action.act-delete, .hist-action.act-purge, .hist-action.act-login_failed {
  background: var(--danger-soft); color: var(--danger);
}
.hist-more { margin-top: 14px; text-align: center; }

/* --- Tableaux --- */
table { width: 100%; border-collapse: collapse; background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; font-size: 14px; border-bottom: 1px solid var(--border);
         overflow-wrap: anywhere; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.right { text-align: right; white-space: nowrap; }

/* --- Modale --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,15,14,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; max-height: 88dvh; overflow: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 22px 24px 24px;
}
.modal header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal h2 { font-size: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
/* Lien sortant : la flèche signale qu'on quitte l'application. */
.ext-link { color: var(--accent); overflow-wrap: anywhere; }
.ext-link span { font-size: 11px; opacity: .7; }

/* Une note n'a pas de canal : le champ restant occupe toute la ligne. */
.row.one-col { grid-template-columns: 1fr; }
.checks { display: flex; gap: 22px; flex-wrap: wrap; }
/* Indication sous un champ : rappel de contexte, pas une erreur. */
.form-hint { margin: -6px 0 14px; }
/* Champ facultatif : sa case l'active, il reste grisé tant qu'on n'y touche pas. */
.opt-field { margin-bottom: 14px; }
.opt-field .check { margin-bottom: 6px; }
.opt-field select[disabled], .opt-field input[disabled] { opacity: .5; cursor: not-allowed; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text); margin-bottom: 14px; }
.check input { width: auto; }
.picker { border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; max-height: 158px; overflow: auto; margin-bottom: 14px; }
.picker .check { margin-bottom: 7px; font-size: 13.5px; }
.picker .check:last-child { margin-bottom: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* --- Historique --- */
.timeline { list-style: none; margin: 0 0 14px; padding: 0; }
.timeline li { padding: 11px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.tl-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.tl-head strong { font-size: 14px; font-weight: 550; }
table.diff { margin-top: 8px; border: 0; background: transparent; }
table.diff th { font-size: 11px; padding: 2px 8px 2px 0; }
table.diff td { font-size: 13px; padding: 3px 8px 3px 0; border-bottom: 0; vertical-align: top; }
table.diff th:first-child, table.diff td:first-child {
  width: 104px; min-width: 104px; overflow-wrap: normal; word-break: keep-all;
}
table.diff th:not(:first-child), table.diff td:not(:first-child) { width: 44%; }
table.diff tbody tr:hover { background: transparent; }
table.diff td.before { color: var(--muted); text-decoration: line-through; }
table.diff td.after { color: var(--accent); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 60;
}
.toast.err { background: var(--danger); color: #fff; }

/* Visible uniquement sur mobile (entrée « Compte » de la barre basse). */
.mobile-only { display: none; }

/* Fond non défilant pendant qu'une surcouche occupe l'écran. On ne fige plus la
   page en `position: fixed` : sur iOS, cela désynchronise les coordonnées de
   touche dès qu'un clavier s'ouvre par-dessus. Le geste tactile est refusé en
   JavaScript, cette règle couvrant le reste (molette, barre d'espace). */
@media (max-width: 760px) {
  body.scroll-locked { overflow: hidden; }
}
/* Libellés courts de la barre basse, utilisés seulement sur les petits écrans. */
.nav-mini { display: none; }
/* L'icône se cale sur la hauteur du texte : elle suit la taille du libellé. */
.nav-icon { flex: 0 0 auto; width: 1em; height: 1em; }

/* Fenêtre « Mon compte » (mobile) */
.account-card { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.account-card .avatar { width: 40px; height: 40px; font-size: 15px; }
.account-actions { display: flex; flex-direction: column; gap: 8px; }
.account-actions .btn { width: 100%; padding: 12px 14px; }

/* Entre 761 et 1100 px, la place manque pour trois colonnes : le panneau
   glisse par-dessus la liste. */
@media (max-width: 1100px) and (min-width: 761px) {
  body.panel-open .app { grid-template-columns: 232px minmax(0, 1fr); }
  .panel {
    position: fixed; inset: 0 0 0 auto; z-index: 45; width: min(420px, 100%);
    box-shadow: -8px 0 28px rgba(20, 20, 18, .12);
  }
  [data-theme="dark"] .panel { box-shadow: -8px 0 28px rgba(0, 0, 0, .45); }
}

/* --------------------------------------------------------------------- */
/* Mobile et petites tablettes                                            */
/* --------------------------------------------------------------------- */
@media (max-width: 760px) {
  :root { --mobile-bar-h: 46px; }
  .app, body.panel-open .app { grid-template-columns: 1fr; background-image: none; }

  /* --- Navigation : barre fixe en bas, à portée de pouce --- */
  .sidebar {
    position: fixed; inset: auto 0 0 0; z-index: 40; height: auto;
    flex-direction: row; gap: 0; padding: 0; border-right: 0;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -1px 12px rgba(20, 20, 18, .06);
  }
  [data-theme="dark"] .sidebar { box-shadow: 0 -1px 12px rgba(0, 0, 0, .35); }
  .sidebar .brand, .sidebar-foot { display: none; }
  .sidebar nav { flex-direction: row; width: 100%; gap: 0; }
  .nav-item {
    flex: 1; text-align: center; border-radius: 0; padding: 14px 2px;
    min-height: 52px; color: var(--muted);
  }
  .nav-item.active { background: transparent; color: var(--accent); font-weight: 600; }
  .nav-item { position: relative; }
  /* Au-dessus du libellé et centrée : un nombre déborderait sur l'onglet voisin. */
  .nav-badge {
    position: absolute; top: 11px; left: 50%; margin: 0; padding: 0;
    width: 7px; height: 7px; min-width: 0; border-radius: 50%;
    font-size: 0; line-height: 0; transform: translateX(10px);
    background: var(--muted);
  }
  .nav-badge.alert { background: var(--danger); }
  /* Icône seule : le titre de la page est repris par le bandeau du haut.
     Les libellés restent dans le DOM, lisibles par les lecteurs d'écran. */
  .nav-item { display: block; }
  .nav-full, .nav-mini {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .nav-icon {
    width: 24px; height: 24px; margin: 0 auto; stroke-width: 1.6; opacity: .8;
  }
  .nav-item.active .nav-icon { opacity: 1; stroke-width: 1.9; }
  .mobile-only { display: block; }

  /* Clavier ouvert : la barre de navigation, en position fixe, se poserait
     par-dessus. On l'efface le temps de la saisie, et on rend au contenu la
     place qu'elle réservait. */
  .keyboard-open .sidebar { display: none; }
  .keyboard-open .main { padding-bottom: 24px; }
  .keyboard-open #btn-add { display: none; }

  /* --- Contenu : place pour la barre basse et le bouton flottant --- */
  .main { padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0)); }

  /* --- Bandeau de titre, collé au-dessus de la barre d'outils --- */
  .mobile-bar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 31; height: var(--mobile-bar-h);
    margin: 0 -16px; padding: 0 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .mobile-bar .brand { font-size: 15px; flex: 0 0 auto; }
  .mobile-bar .mobile-title {
    flex: 1; min-width: 0; text-align: right; font-size: 14px; font-weight: 500;
    color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* --- Barre d'outils collée sous le bandeau --- */
  .topbar.bare { display: none; }
  .topbar {
    position: sticky; top: var(--mobile-bar-h); z-index: 30;
    margin: 0 -16px 12px; padding: 10px 16px 8px;
    background: var(--bg); border-bottom: 1px solid var(--border); gap: 8px;
  }
  .search { flex: 1 1 60%; }
  .actions { flex: 0 0 auto; gap: 6px; }
  /* Filtres et statistiques : une seule ligne qui défile horizontalement. */
  .filters, .stats {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none; margin: 0 -16px; padding: 0 16px; width: calc(100% + 32px);
  }
  .filters::-webkit-scrollbar, .stats::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; min-height: 36px; }
  /* Les compteurs tiennent sur la largeur plutôt que de défiler : police
     réduite, et le retour à la ligne rétabli si jamais ils débordent. */
  .stats { gap: 6px 14px; margin-bottom: 14px; flex-wrap: wrap; overflow-x: visible; }
  .stat { flex: 0 0 auto; gap: 4px; }
  .stat b { font-size: 15px; }
  .stat span { font-size: 11.5px; }

  /* Ajout : bouton flottant au-dessus de la barre de navigation. */
  #btn-add {
    position: fixed; right: 16px; z-index: 41;
    bottom: calc(66px + env(safe-area-inset-bottom, 0));
    padding: 13px 20px; font-size: 15px; border-radius: 999px;
    box-shadow: 0 6px 20px rgba(20, 20, 18, .18);
  }

  /* --- Cibles tactiles --- */
  .btn { min-height: 40px; }
  .btn.small { min-height: 38px; padding: 8px 12px; font-size: 13.5px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  /* 16px minimum : en dessous, iOS zoome à la mise au point du champ. */
  input, select, textarea { font-size: 16px; padding: 11px 12px; }

  /* --- Tableaux : une fiche empilée par ligne --- */
  table, thead, tbody, tr, td { display: block; width: 100%; }
  table { border: 0; background: transparent; }
  thead { display: none; }
  tbody tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
  }
  tbody tr:hover { background: var(--surface); }
  tbody td { border-bottom: 0; padding: 3px 0; font-size: 14px; }
  /* Le libellé de colonne devient une étiquette devant la valeur. */
  tbody td[data-label]::before {
    content: attr(data-label) ' ';
    display: inline-block; min-width: 96px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600;
  }
  tbody td[data-label]:first-child::before { display: none; }
  tbody td:first-child { font-size: 15px; padding-bottom: 8px; }
  tbody td.right {
    text-align: left; white-space: normal; display: flex; flex-wrap: wrap;
    gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  }
  tbody td.right .btn { flex: 1 1 auto; }

  /* --- Panneau de détail : plein écran, avec bouton retour ---
     Hauteur calée sur la fenêtre visuelle : à l'ouverture du clavier, iOS ne
     redimensionne que celle-ci. Sans cela le bas du panneau, boutons compris,
     se retrouve sous le clavier. --vvh est posée en JavaScript ; sans elle, on
     retombe sur la hauteur dynamique de la fenêtre. */
  .panel {
    position: fixed; left: 0; right: 0; bottom: auto; z-index: 50; width: 100%;
    top: var(--vvtop, 0px); height: var(--vvh, 100dvh);
    border-left: 0; padding: 14px 16px calc(28px + env(safe-area-inset-bottom, 0));
  }
  .panel-back { display: inline-flex; margin: 0 0 10px -10px; }
  .panel-close { display: none; }
  .panel-head h2 { padding-right: 0; }
  .panel-actions { position: sticky; bottom: 0; background: var(--surface);
                   padding: 10px 0 calc(6px + env(safe-area-inset-bottom, 0)); }

  /* --- Lignes : étiquettes sur la ligne du nom, le reste en pleine largeur.
     Les étiquettes occupaient une colonne sur toute la hauteur de la ligne :
     fonction et email se retrouvaient coupés dans ce qui restait. Elles ne
     partagent plus que la première ligne. `display: contents` fait remonter le
     nom et la fonction au niveau de la grille, pour qu'ils occupent chacun leur
     rangée sans ajouter de balise. --- */
  .list-row {
    grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 12px 14px;
    grid-template-areas: 'name tags' 'sub sub' 'side side';
  }
  .row-main { display: contents; }
  .row-main strong { grid-area: name; align-self: center; }
  .row-main > span { grid-area: sub; }
  .row-tags { grid-area: tags; align-self: center; }
  .row-side { grid-area: side; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .row-chevron { display: none; }

  /* --- Cartes et groupes --- */
  .cards { gap: 10px; }
  .group-head { position: relative; row-gap: 2px; }
  .group-head .spacer { display: none; }
  .group-head .muted.small:last-child { margin-left: auto; }

  /* --- Fenêtres : feuille ancrée en bas d'écran --- */
  .modal-backdrop {
    padding: 0; align-items: flex-end;
    bottom: auto; top: var(--vvtop, 0px); height: var(--vvh, 100dvh);
  }
  .modal {
    max-width: none; max-height: 92vh; max-height: 92dvh;
    max-height: calc(var(--vvh, 100dvh) - 16px);
    border-radius: 16px 16px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0));
  }
  .modal header { position: sticky; top: -18px; background: var(--surface); padding-top: 4px; z-index: 1; }
  /* En-tête et barre de boutons étant collés, un champ ramené à l'écran doit
     garder de la marge sous chacun d'eux. */
  .modal input, .modal select, .modal textarea { scroll-margin-block: 64px; }
  .row { grid-template-columns: 1fr; }
  .modal-actions {
    position: sticky; bottom: 0; background: var(--surface);
    margin: 0 -18px; padding: 12px 18px 0; border-top: 1px solid var(--border);
  }
  .modal-actions .btn { flex: 1; }
  .picker { max-height: 180px; }

  /* --- Connexion --- */
  .login { padding: 16px; }
  .login-card { padding: 24px 20px; box-shadow: none; }

  /* --- Historique --- */
  table.diff, table.diff tbody, table.diff tr, table.diff td { display: block; width: 100%; }
  table.diff tbody tr {
    background: transparent; border: 0; border-radius: 0;
    padding: 0 0 8px; margin: 0 0 8px; border-bottom: 1px dashed var(--border);
  }
  table.diff tbody tr:last-child { border-bottom: 0; }
  table.diff td { padding: 1px 0; font-size: 13px; }
  table.diff td:first-child {
    width: auto; min-width: 0; font-size: 11px; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); font-weight: 600; padding-bottom: 2px;
  }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0)); }
}

/* Très petits écrans (iPhone SE et assimilés) */
@media (max-width: 380px) {
  .nav-item { padding-left: 0; padding-right: 0; }
  .main { padding-left: 12px; padding-right: 12px; }
  .topbar, .mobile-bar { margin-left: -12px; margin-right: -12px;
                         padding-left: 12px; padding-right: 12px; }
  .filters, .stats { margin-left: -12px; margin-right: -12px; padding-left: 12px;
                     padding-right: 12px; width: calc(100% + 24px); }
  tbody td[data-label]::before { display: block; min-width: 0; }
}

/* Appareils tactiles, y compris les tablettes qui gardent la mise en page bureau :
   pas d'effet de survol résiduel, et des cibles confortables au doigt. */
@media (hover: none) and (pointer: coarse) {
  .card:hover { border-color: var(--border); box-shadow: none; }
  .btn:hover { background: var(--surface); }
  .btn.primary:hover { opacity: 1; }
  /* Sans souris, l'état de survol resterait « collé » après un appui. */
  .btn.danger:hover { background: transparent; }
  .nav-item:hover { background: transparent; }
  tbody tr:hover { background: var(--surface); }

  .btn { min-height: 40px; }
  .btn.small { min-height: 38px; }
  .chip { min-height: 36px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  input, select, textarea { font-size: 16px; }
}
