/* ==========================================================================
   Design system — Notes de frais (Phase 1)
   Tokens, dark mode auto, composants : cartes, badges, toasts, sheet, skeletons
   ========================================================================== */

:root {
  /* Couleurs — mode clair */
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #eff6ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  /* Sémantique */
  --success: #059669;  --success-bg: #ecfdf5;
  --warning: #b45309;  --warning-bg: #fffbeb;
  --danger:  #dc2626;  --danger-bg:  #fef2f2;
  --info:    #0284c7;  --info-bg:    #f0f9ff;
  /* Typo */
  --font: -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
  /* Espacement (grille 4px) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-6: 24px;
  /* Rayons */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;
  /* Ombres */
  --shadow-1: 0 1px 2px rgb(15 23 42 / 0.06);
  --shadow-2: 0 4px 12px rgb(15 23 42 / 0.08);
  --shadow-3: 0 12px 32px rgb(15 23 42 / 0.18);
  /* Animation */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --t-fast: 120ms; --t-med: 220ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #3b82f6; --brand-hover: #60a5fa; --brand-soft: #1e2a4a;
    --bg: #0b1120; --surface: #131c2e; --surface-2: #1c2740;
    --border: #263350;
    --text: #f1f5f9; --text-2: #a5b4cd; --text-3: #64748b;
    --success: #34d399; --success-bg: #05291e;
    --warning: #fbbf24; --warning-bg: #2a2008;
    --danger: #f87171;  --danger-bg: #2a0e0e;
    --info: #38bdf8;    --info-bg: #082433;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 4px 12px rgb(0 0 0 / 0.5);
    --shadow-3: 0 12px 32px rgb(0 0 0 / 0.6);
  }
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* jamais de défilement horizontal (header admin, textes longs) */
}

.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* Montants : chiffres tabulaires, toujours */
.amount, .money { font-variant-numeric: tabular-nums; font-weight: 650; }

/* --- Login --- */
#login-screen, #invite-screen, #reset-screen { display: flex; align-items: center; justify-content: center; }
.login-help { font-size: 0.75rem; color: var(--text-3); margin-top: var(--sp-2); line-height: 1.5; }
.login-box { display: flex; flex-direction: column; gap: var(--sp-3); width: min(320px, 85vw); text-align: center; }
.login-box h1 { font-size: 1.5rem; margin-bottom: var(--sp-2); }

/* --- Header --- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 12px;
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.header-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--sp-2); }
header h1 { font-size: 1.1rem; font-weight: 700; }

/* Bouton profil = identité : avatar à initiales + « Nom · Rôle » (desktop) */
.profile-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: var(--r-full); padding: 4px 12px 4px 4px;
  white-space: nowrap;
}
.profile-chip .btn-label { font-size: 0.8rem; font-weight: 600; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface-2); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.02em;
}
/* Rôle en un coup d'œil : admin = bleu plein, approbateur = vert, employé = gris */
.avatar.role-admin { background: var(--brand); color: #fff; }
.avatar.role-approver { background: var(--success-bg); color: var(--success); border: 1.5px solid var(--success); }
.avatar.role-employee { background: var(--surface-2); color: var(--text-2); }
.summary { font-size: 0.85rem; color: var(--text-2); line-height: 1.5; }
.summary .money { color: var(--text); }
/* Avance(s) à côté du résumé, mobile et desktop */
#summary .adv-chip { margin-left: var(--sp-2); vertical-align: middle; }

/* Ligne résumé + bouton Filtres */
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.filters-toggle { flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px; }
.filters-toggle.active { color: var(--brand); border-color: var(--brand); }
.filters-wrap { display: flex; flex-direction: column; gap: var(--sp-2); }
/* Mobile : filtres repliés par défaut (la pastille indique les filtres actifs) */
.filters-wrap.collapsed { display: none; }
.filters { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.filters select { flex: 1 1 45%; min-width: 0; }
#search { width: 100%; }

/* --- Liste groupée par mois --- */
main { padding: var(--sp-3) var(--sp-3) 110px; display: flex; flex-direction: column; gap: var(--sp-2); }

.month-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: var(--sp-4) var(--sp-1) 0; gap: var(--sp-3);
}
.month-header .month-name { font-weight: 700; text-transform: capitalize; font-size: 0.95rem; }
.month-header .month-total { font-size: 0.78rem; color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; flex-shrink: 0; }
.month-header .month-left { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; flex-wrap: wrap; }

/* Chip avance sur frais dans l'en-tête de mois */
.adv-chip {
  border: none; min-height: 32px; padding: 4px 12px;
  border-radius: var(--r-full); font-size: 0.7rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.adv-chip.set { background: var(--info-bg); color: var(--info); }
/* En-tête du dernier lot d'import (tri "Par import récent") */
.month-header.latest-import .month-name { color: var(--info); }
.adv-chip.negative { background: var(--danger-bg); color: var(--danger); }

/* Conteneur swipe (façon WhatsApp) : les actions sont derrière la carte */
.receipt-wrap { position: relative; border-radius: var(--r-md); overflow: hidden; }
.swipe-actions {
  position: absolute; top: 0; right: 0; bottom: 0;
  display: flex; z-index: 0;
  /* Invisibles tant qu'on ne glisse pas : plus de liseré rouge derrière les coins arrondis */
  opacity: 0; transition: opacity var(--t-fast) var(--ease); pointer-events: none;
}
.receipt-wrap.swipe-reveal .swipe-actions { opacity: 1; pointer-events: auto; }
.swipe-btn {
  width: 76px; min-height: 100%; border: none; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 1.05rem; color: #fff; cursor: pointer; padding: 0;
}
.swipe-btn small { font-size: 0.6rem; font-weight: 600; }
.swipe-btn.status { background: var(--success); }
.swipe-btn.delete { background: var(--danger); }
.swipe-content { position: relative; z-index: 1; transition: transform var(--t-med) var(--ease); }

/* Sur desktop (souris) : les actions apparaissent au survol, à droite,
   et le contenu se décale pour laisser les montants visibles */
@media (hover: hover) {
  .swipe-actions { opacity: 0; z-index: 2; transition: opacity var(--t-fast); pointer-events: none; }
  .swipe-actions .swipe-btn { border-radius: var(--r-sm); margin: 6px 6px 6px 0; min-height: auto; width: 60px; }
  .receipt { transition: padding-right var(--t-med) var(--ease); }
  .receipt-wrap:hover .swipe-actions { opacity: 0.96; pointer-events: auto; }
  .receipt-wrap:hover .receipt { border-color: var(--border); box-shadow: var(--shadow-2); padding-right: 80px; }
}

.receipt {
  background: var(--surface); border-radius: var(--r-md);
  padding: 10px 12px; display: flex; align-items: center; gap: var(--sp-3);
  box-shadow: var(--shadow-1); cursor: pointer;
  border: 1px solid transparent;
}

.receipt .thumb {
  width: 46px; height: 46px; border-radius: var(--r-sm); object-fit: cover;
  background: var(--surface-2); flex-shrink: 0;
}
/* Indicateur pull-to-refresh (mobile) */
.ptr {
  position: fixed; top: calc(env(safe-area-inset-top) + 8px); left: 50%;
  transform: translateX(-50%); z-index: 7;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: var(--text-3); transition: transform var(--t-fast);
}
.ptr.ready { color: var(--brand); border-color: var(--brand); }
.ptr.spin { animation: ptr-spin 0.8s linear infinite; }
@keyframes ptr-spin { to { rotate: 360deg; } }

/* Vignette absente (dépense déclarée sans justificatif, corbeille) */
.thumb-none { display: flex; align-items: center; justify-content: center; font-size: 1.15rem; color: var(--text-3); }
.vd-photo-none {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-3); font-size: 0.8rem;
  min-height: 90px; border-radius: var(--r-sm); cursor: default;
}
.receipt .info { flex: 1; min-width: 0; }
.receipt .merchant { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt .meta { font-size: 0.76rem; color: var(--text-3); margin-top: 2px; }
.receipt .right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.receipt .amount { font-size: 0.95rem; white-space: nowrap; }
.receipt .approx { font-size: 0.72rem; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Carte "analyse en cours" (OCR en arrière-plan) */
.receipt.processing { pointer-events: none; border: 1px dashed var(--border); box-shadow: none; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.68rem; font-weight: 600;
  border-radius: var(--r-full); padding: 2px 8px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* --- Empty states --- */
.empty { text-align: center; color: var(--text-2); margin-top: 16vh; line-height: 1.7; display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.empty .big { font-size: 2.2rem; }
.empty button, .empty .cta { margin-top: var(--sp-1); }

/* --- Skeletons --- */
.skeleton {
  border-radius: var(--r-md); height: 66px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- FAB : un DOCK unique (flex), plus aucun positionnement individuel --- */
/* --- Tab bar basse (mobile) : navigation principale au pouce --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; align-items: stretch;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(58px + env(safe-area-inset-bottom));
}
.tabbar .tab-slot { display: flex; }
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: none; border-radius: 0; box-shadow: none;
  font-size: 1.25rem; color: var(--text-2); padding: 6px 2px; min-height: 0;
}
.tabbar button .tab-label, .tabbar button .btn-label {
  display: block; font-size: 0.62rem; font-weight: 600; letter-spacing: 0.01em; line-height: 1;
}
.tabbar #profile-id { display: none; }         /* le nom complet reste au header desktop */
.tabbar .avatar { width: 24px; height: 24px; font-size: 0.7rem; }
.tabbar .count-pill { position: absolute; transform: translate(14px, -16px); }
.tabbar button { position: relative; }
.tabbar .tab-notes[aria-current="page"], .tabbar button.active { color: var(--brand); }
.tab-fab-gap { pointer-events: none; }

.fab-dock {
  position: fixed; bottom: calc(env(safe-area-inset-bottom) + 22px);
  left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  pointer-events: none; /* seuls les boutons sont cliquables */
}
.fab-dock > * { pointer-events: auto; }

.fab {
  width: 68px; height: 68px; border-radius: var(--r-full);
  background: var(--brand); color: #fff; font-size: 1.8rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgb(37 99 235 / 0.4); cursor: pointer;
  transition: transform var(--t-fast) var(--ease);
}
.fab:active { transform: scale(0.92); }

@media (max-width: 899px) {
  .fab-dock {
    bottom: calc(env(safe-area-inset-bottom) + 74px);
    gap: 10px;
    z-index: 60; /* contexte d'empilement : le FAB doit passer devant la tab bar */
  }
  .fab { /* posé à cheval sur la tab bar, au centre */
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom) + 14px);
    width: 62px; height: 62px; border: 4px solid var(--bg);
    z-index: 60; /* au-dessus de la tab bar */
  }
  .fab:active { transform: translateX(-50%) scale(0.92); }
  .header-actions #admin-btn, .header-actions #export-btn { display: none; } /* -> Profil */
  main { padding-bottom: 168px; }
}

/* Boutons pellicule, instruction et saisie manuelle : satellites du FAB */
.fab-gallery, .fab-hint, .fab-manual {
  width: 48px; height: 48px; border-radius: var(--r-full);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; box-shadow: var(--shadow-2); cursor: pointer;
  padding: 0; min-height: 48px;
}
.fab-hint, .fab-manual { order: -1; } /* à gauche du FAB : ✍️ 📝 📷 🖼️ */
.fab-hint.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Libellés : masqués sur mobile (cercles), affichés sur desktop (pilules) */
.fab-label { display: none; }

/* Champs du guide d'analyse */
.field-label { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-2); }
.field-label .row > input, .field-label .row > select { flex: 1; min-width: 0; }
.clear-x { flex: 0 0 auto; width: 44px; padding: 0; font-size: 1rem; }
#hint-preview { min-height: 1.2em; font-style: italic; }

/* En-tête : groupe de boutons */
/* La rangée d'actions ne se coupe JAMAIS en interne : si elle ne tient pas à côté
   du titre, elle passe ENTIÈRE à la ligne (via le wrap de .header-top). */
.header-actions { display: flex; gap: var(--sp-2); flex-wrap: nowrap; justify-content: flex-end; }

/* Petit écran : boutons icône seuls (les libellés partent, les title/aria restent) */
@media (max-width: 560px) {
  .header-actions .btn-label { display: none; }
  .header-actions button.small { padding: 6px 10px; font-size: 1.05rem; }
  .header-actions .profile-chip { padding: 4px; } /* avatar seul, bouton rond */
}

/* Sheet des taux */
.sheet-desc { font-size: 0.78rem; color: var(--text-2); line-height: 1.45; }
.override-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2);
  font-size: 0.82rem;
}
.override-row .money { font-variant-numeric: tabular-nums; }
.override-row button { min-height: 30px; padding: 2px 8px; background: none; color: var(--danger); font-weight: 700; }

/* --- Bandeau note de frais du mois (sticky sous le header) --- */
.report-banner {
  position: sticky; top: 0; z-index: 4;
  width: calc(100% - 24px); margin: 10px 12px 0;
  display: flex; align-items: center; gap: var(--sp-3);
  text-align: left; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-1);
  cursor: pointer; color: var(--text);
}
.report-banner:active { transform: scale(0.99); }
.report-banner .rb-icon { font-size: 1.3rem; flex-shrink: 0; }
.report-banner .rb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.report-banner .rb-title { font-weight: 700; font-size: 0.9rem; }
.report-banner .rb-sub { font-size: 0.78rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.report-banner .rb-cta {
  flex-shrink: 0; font-size: 0.8rem; font-weight: 700; color: var(--brand);
}
.report-banner.ready { border-color: var(--brand); background: var(--brand-soft); }
.report-banner.ready .rb-cta { color: var(--brand); }
.report-banner.submitted { border-color: var(--info); background: var(--info-bg); }
.report-banner.submitted .rb-cta { color: var(--info); }
.report-banner.todo { border-color: var(--warning); background: var(--warning-bg); }
.report-banner.todo .rb-cta { color: var(--warning); }

/* Badge de statut de note dans l'en-tête de mois */
.month-header .note-badge {
  font-size: 0.66rem; font-weight: 700; padding: 1px 8px;
  border-radius: var(--r-full); display: inline-flex; align-items: center; gap: 4px;
}
.month-header .note-badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.note-badge.submitted { background: var(--info-bg); color: var(--info); }
.note-badge.approved, .note-badge.reimbursed { background: var(--success-bg); color: var(--success); }

/* --- Écran récap : ma note du mois --- */
.report-card { width: min(460px, 94vw); max-height: 92vh; overflow-y: auto; }
.report-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.report-head h2 { font-size: 1rem; }
#report-lines { display: flex; flex-direction: column; gap: 6px; margin: var(--sp-1) 0; }
.report-line {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 8px 10px; border-radius: var(--r-sm);
  background: var(--surface-2); font-size: 0.84rem;
}
.report-line.excluded { opacity: 0.5; }
.report-line.incomplete { background: var(--warning-bg); }
.report-line .rl-info { flex: 1; min-width: 0; }
.report-line .rl-merchant { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-line .rl-meta { font-size: 0.72rem; color: var(--text-3); }
.rl-cap-tag { color: var(--info); font-weight: 600; }
.report-line .rl-amount { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.report-line .rl-fix { flex-shrink: 0; background: var(--warning); color: #fff; min-height: 32px; padding: 4px 10px; font-size: 0.76rem; font-weight: 600; }
/* Interrupteur d'exclusion (switch) */
.rl-switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; cursor: pointer; }
.rl-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.rl-switch .track { position: absolute; inset: 0; background: var(--border); border-radius: var(--r-full); transition: background var(--t-fast); }
.rl-switch .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--t-fast); }
.rl-switch input:checked ~ .track { background: var(--brand); }
.rl-switch input:checked ~ .knob { transform: translateX(16px); }
.report-totals {
  border-top: 1px solid var(--border); padding-top: var(--sp-2);
  font-size: 0.84rem; color: var(--text-2); display: flex; flex-direction: column; gap: 3px;
}
.report-totals .rt-row { display: flex; justify-content: space-between; gap: var(--sp-3); }
.report-totals .rt-total { color: var(--text); font-weight: 700; }
.report-totals .money { font-variant-numeric: tabular-nums; }
.report-totals .rt-neg { color: var(--danger); }
#report-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Éditeur : verrou d'une dépense soumise */
.editor-card input:disabled, .editor-card select:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- Règles de dépense (policy) --- */
.policy-card { width: min(460px, 94vw); max-height: 90vh; overflow-y: auto; }
#policy-list { display: flex; flex-direction: column; gap: 6px; }
.policy-row {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 0.82rem;
}
.policy-row.off { opacity: 0.55; }
.policy-row .p-text { flex: 1; min-width: 0; }
.policy-row .p-text b { font-variant-numeric: tabular-nums; }
.policy-row .p-del { min-height: 30px; padding: 2px 8px; background: none; color: var(--danger); font-weight: 700; flex: 0 0 auto; }
.policy-row .p-mode {
  min-height: 26px; padding: 2px 8px; flex: 0 0 auto; font-size: 0.68rem; font-weight: 700;
  border-radius: var(--r-full); background: var(--surface-2); color: var(--text-2);
}
.policy-row .p-mode.cap { background: var(--info-bg); color: var(--info); }
.policy-check { display: flex; align-items: center; gap: var(--sp-2); font-size: 0.82rem; color: var(--text-2); }
.policy-check input { min-height: 0; width: 18px; height: 18px; flex: 0 0 auto; }
.policy-empty { font-size: 0.8rem; color: var(--text-3); font-style: italic; }
/* Interrupteur actif/inactif (réutilise le style du switch récap) */
.p-switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; }
.p-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.p-switch .track { position: absolute; inset: 0; background: var(--border); border-radius: var(--r-full); transition: background var(--t-fast); }
.p-switch .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--t-fast); }
.p-switch input:checked ~ .track { background: var(--brand); }
.p-switch input:checked ~ .knob { transform: translateX(16px); }
/* Champ notes surligné quand un motif est requis par une règle */
input.policy-required { border: 1px solid var(--warning) !important; background: var(--warning-bg) !important; }
/* Ligne récap hors-policy et badge manager */
.report-line.policy { background: var(--warning-bg); }
.report-line .rl-motif { flex-shrink: 0; background: var(--warning); color: #fff; min-height: 32px; padding: 4px 10px; font-size: 0.76rem; font-weight: 600; }
.inbox-policy { font-size: 0.74rem; color: var(--warning); background: var(--warning-bg); border-radius: var(--r-sm); padding: 4px 8px; }

/* --- Timeline / historique (audit trail) --- */
.timeline-wrap { display: flex; flex-direction: column; gap: var(--sp-2); }
.history-toggle { align-self: flex-start; padding: 6px 4px; color: var(--text-2); }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-event {
  position: relative; padding: 0 0 12px 20px; font-size: 0.8rem; color: var(--text-2);
}
.tl-event::before { /* pastille */
  content: ''; position: absolute; left: 3px; top: 4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--brand); z-index: 1;
}
.tl-event::after { /* trait vertical reliant les pastilles */
  content: ''; position: absolute; left: 6.5px; top: 4px; bottom: -4px; width: 1px; background: var(--border);
}
.tl-event:last-child { padding-bottom: 0; }
.tl-event:last-child::after { display: none; }
.tl-event.approved::before, .tl-event.reimbursed::before { background: var(--success); }
.tl-event.rejected::before, .tl-event.deleted::before { background: var(--danger); }
.tl-event.submitted::before { background: var(--info); }
.tl-event.auto_correction::before { background: var(--warning); }
.tl-title { color: var(--text); font-weight: 600; }
.tl-meta { color: var(--text-3); font-size: 0.72rem; }
.tl-change { color: var(--text-2); }
.tl-change .old { text-decoration: line-through; color: var(--text-3); }
.tl-change .new { color: var(--text); font-weight: 600; }
.tl-empty { color: var(--text-3); font-size: 0.8rem; font-style: italic; }

/* --- Espace Validation (approbateur / admin) --- */
#validation-sheet .validation-card { width: min(560px, 95vw); max-height: 92vh; overflow-y: auto; }
.val-filters { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin: var(--sp-1) 0 var(--sp-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-full); overflow: hidden; }
.seg button { min-height: 32px; padding: 5px 12px; font-size: 0.78rem; background: transparent; color: var(--text-2); border: none; border-radius: 0; }
.seg button.active { background: var(--brand); color: #fff; }
#val-person { min-height: 34px; padding: 4px 8px; font-size: 0.8rem; flex: 0 0 auto; max-width: 45%; }
#val-list { display: flex; flex-direction: column; gap: 6px; }
.val-note {
  display: flex; align-items: center; gap: var(--sp-2); text-align: left; width: 100%;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); cursor: pointer;
}
.val-note:hover { border-color: var(--brand); background: var(--brand-soft); }
.vn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vn-who { font-weight: 600; font-size: 0.88rem; }
.vn-orphan { font-size: 0.66rem; font-weight: 700; color: var(--warning); background: var(--warning-bg); padding: 1px 6px; border-radius: var(--r-full); }
.vn-sub { font-size: 0.74rem; color: var(--text-3); }
.vn-right { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }
.vn-total { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 0.86rem; }
.vn-flags { font-size: 0.72rem; font-weight: 700; color: var(--warning); }
.vn-ok { color: var(--success); font-weight: 700; }
#val-approve-clean { margin-top: var(--sp-1); }
.val-empty { text-align: center; color: var(--text-2); padding: var(--sp-6) 0; font-size: 0.95rem; line-height: 1.6; }

/* Détail d'une note */
#validation-detail-view { display: flex; flex-direction: column; gap: var(--sp-2); }
#val-back-btn { align-self: flex-start; }
.vd-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.vd-title { font-weight: 700; font-size: 0.98rem; }
.vd-sub { font-size: 0.78rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.val-hint { font-size: 0.76rem; color: var(--warning); background: var(--warning-bg); border-radius: var(--r-sm); padding: 7px 10px; }
.vd-lines { display: flex; flex-direction: column; gap: 6px; margin: var(--sp-1) 0; }
.vd-line { border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.vd-line-row { display: flex; align-items: center; gap: var(--sp-2); padding: 7px 9px; cursor: pointer; }
.vd-line-row:hover { background: var(--surface-2); }
.vd-thumb { width: 34px; height: 34px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.vd-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.vd-merchant { font-weight: 600; font-size: 0.84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vd-meta { font-size: 0.72rem; color: var(--text-3); }
.vd-amount { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 0.84rem; white-space: nowrap; }
.vd-amount-comp { color: var(--text-3); font-weight: 550; } /* carte entreprise : non remboursé */
.vd-comp-tag { color: var(--text-3); }
.vd-chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 9px 7px 51px; }
.vd-chip { font-size: 0.68rem; color: var(--warning); background: var(--warning-bg); border-radius: var(--r-full); padding: 2px 8px; }
.vd-chip-cap { color: var(--info); background: var(--info-bg); }
.vd-expand { padding: 0 9px; }
.vd-expand-inner { display: flex; flex-wrap: wrap; gap: 10px; padding: 9px 0 11px; border-top: 1px solid var(--border); }
.vd-uncap-zone { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
.vd-uncap-zone:empty { display: none; }
.vd-photo { width: 110px; max-height: 150px; object-fit: contain; border-radius: var(--r-sm); background: var(--surface-2); cursor: zoom-in; flex-shrink: 0; }
.vd-fields { flex: 1; font-size: 0.8rem; }
.vd-fields > div { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 3px 0; border-top: 1px solid var(--border); }
.vd-fields > div:first-child { border-top: none; }
.vd-fields span:first-child { color: var(--text-2); }
.vd-fields span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.vd-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding-top: var(--sp-2); border-top: 1px solid var(--border); }
.vd-actions .approve { background: var(--success); color: #fff; }
.vd-actions .assign { background: var(--surface-2); }
.vd-noaction { font-size: 0.8rem; color: var(--text-3); font-style: italic; }
.assign-sel { flex: 1; min-width: 0; min-height: 40px; }
.val-note.active { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.val-placeholder { color: var(--text-3); text-align: center; padding: 20vh var(--sp-4) 0; font-size: 0.95rem; }

/* Desktop (>= 900px) : espace Validation en pleine largeur, deux panneaux côte à côte */
@media (min-width: 900px) {
  .tabbar { display: none; }
  /* Desktop : Gestion et Exporter existent déjà au header — seules les notifications restent */
  .profile-nav #profile-admin-btn, .profile-nav #profile-export-btn { display: none; }
  /* Validation : un ESPACE plein écran (inbox), pas une fenêtre flottante */
  #validation-sheet { align-items: stretch; justify-content: stretch; padding: 0; }
  #validation-sheet .validation-card {
    width: 100%; max-width: none; height: 100vh; max-height: 100vh; border-radius: 0;
    display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 0;
    padding: 0; overflow: hidden;
  }
  #validation-list-view {
    display: flex; flex-direction: column; gap: var(--sp-2);
    border-right: 1px solid var(--border); padding: var(--sp-4); overflow-y: auto; min-height: 0;
  }
  #validation-list-view h2 { margin-bottom: var(--sp-1); }
  #val-list { flex: 1; }
  #validation-detail-view { padding: var(--sp-4) var(--sp-6); overflow-y: auto; min-height: 0; }
  /* En deux panneaux, le reçu déplié peut s'afficher plus grand */
  /* Reçu déplié : directement lisible (l'espace plein écran est fait pour ça) */
  #validation-detail-view .vd-expand-inner {
    display: grid; grid-template-columns: minmax(420px, 1fr) minmax(240px, 320px);
    gap: var(--sp-4); align-items: start;
  }
  #validation-detail-view .vd-photo {
    width: 100%; max-height: 82vh; object-fit: contain;
    border: 1px solid var(--border); box-shadow: var(--shadow-1);
  }
  #validation-detail-view .vd-photo-none { width: 100%; min-height: 120px; }
  #validation-detail-view .vd-fields { font-size: 0.95rem; }
}

/* Menu ⋯ (actions secondaires du détail de note) */
.vd-more-wrap { position: relative; display: inline-flex; }
.vd-menu {
  position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 20;
  display: flex; flex-direction: column; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: 4px;
}
.vd-menu button {
  background: none; border: none; box-shadow: none; text-align: left;
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 0.9rem;
}
.vd-menu button:hover { background: var(--bg); }

/* --- Boîte de validation (inbox manager) --- */

/* --- Boîte de validation (inbox manager) --- */
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 5px;
  border-radius: var(--r-full); background: var(--danger); color: #fff;
  font-size: 0.66rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.inbox-card { width: min(480px, 95vw); max-height: 90vh; overflow-y: auto; }
#inbox-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.inbox-item {
  position: relative; overflow: hidden;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-1);
  padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2);
  transition: transform var(--t-med) var(--ease);
}
.inbox-item .ii-approve-hint {
  position: absolute; inset: 0; display: flex; align-items: center; padding-left: 18px;
  background: var(--success); color: #fff; font-weight: 700; opacity: 0; z-index: 0;
}
.inbox-item .ii-body { position: relative; z-index: 1; display: flex; flex-direction: column; gap: var(--sp-2); background: var(--surface); }
.inbox-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); }
.inbox-head .ii-who { font-weight: 700; font-size: 0.92rem; }
.inbox-head .ii-month { font-size: 0.76rem; color: var(--text-3); }
.inbox-total { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 0.95rem; }
.inbox-meta { font-size: 0.76rem; color: var(--text-2); }
.inbox-thumbs { display: flex; gap: 5px; flex-wrap: wrap; }
.inbox-thumbs img { width: 42px; height: 42px; object-fit: cover; border-radius: var(--r-sm); background: var(--surface-2); }
.inbox-thumbs .more { width: 42px; height: 42px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-3); display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; }
.inbox-anoms { display: flex; flex-direction: column; gap: 4px; }
.inbox-anom { font-size: 0.74rem; color: var(--warning); background: var(--warning-bg); border-radius: var(--r-sm); padding: 4px 8px; }
.inbox-anom.doublon { color: var(--danger); background: var(--danger-bg); }
.inbox-actions { display: flex; gap: var(--sp-2); }
.inbox-actions button { flex: 1; }
.inbox-empty { text-align: center; color: var(--text-2); padding: var(--sp-6) 0; font-size: 1rem; line-height: 1.6; }

/* Suggestions de motif de refus */
.reject-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.reject-chips button {
  min-height: 32px; padding: 4px 12px; font-size: 0.78rem;
  background: var(--surface-2); border-radius: var(--r-full);
}
.reject-chips button.active { background: var(--brand); color: #fff; }

/* Note refusée : badge dans l'en-tête de mois */
.note-badge.rejected { background: var(--danger-bg); color: var(--danger); }
.report-banner.rejected { border-color: var(--danger); background: var(--danger-bg); }
.report-banner.rejected .rb-cta { color: var(--danger); }

/* --- Supervision (vue équipe, admin) --- */
.supervision-card { width: min(520px, 95vw); max-height: 90vh; overflow-y: auto; }
#supervision-list { display: flex; flex-direction: column; gap: var(--sp-4); }
.sup-user { display: flex; flex-direction: column; gap: 5px; }
.sup-name { font-weight: 700; font-size: 0.9rem; display: flex; align-items: baseline; gap: var(--sp-2); }
.sup-role { font-size: 0.66rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; }
.sup-empty { font-size: 0.8rem; color: var(--text-3); font-style: italic; }
.sup-note {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 0.82rem;
}
.sup-month { font-weight: 600; text-transform: capitalize; min-width: 92px; }
.sup-meta { flex: 1; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sup-meta .money { color: var(--text); }
.sup-del { min-height: 30px; padding: 2px 10px; font-size: 0.72rem; flex: 0 0 auto; }
.note-badge.open { background: var(--surface-2); color: var(--text-2); }

/* --- Profil & utilisateurs --- */
.sheet-sep { border: none; border-top: 1px solid var(--border); margin: var(--sp-2) 0; width: 100%; }
.users-card { width: min(460px, 94vw); max-height: 90vh; overflow-y: auto; }
.users-sub { font-size: 0.85rem; color: var(--text-2); }
#users-list { display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 0.82rem;
}
.user-row .u-head { display: flex; align-items: center; gap: var(--sp-2); }
.user-row .u-info { flex: 1; min-width: 0; }
.user-row .u-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row .u-email { font-size: 0.72rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row .u-head select { min-height: 34px; padding: 4px 8px; font-size: 0.78rem; flex: 0 0 auto; max-width: 42%; }
.user-row .u-reset { min-height: 34px; padding: 4px 8px; flex: 0 0 auto; background: var(--surface-2); font-size: 0.85rem; }
.user-row.user-disabled .u-info { opacity: 0.5; }
.user-row .u-me { font-size: 0.68rem; color: var(--text-3); }
.user-row .u-approver { display: flex; align-items: center; gap: var(--sp-2); }
.user-row .u-approver-label { font-size: 0.72rem; color: var(--text-2); flex: 0 0 auto; }
.user-row .u-approver select { flex: 1; min-height: 32px; padding: 4px 8px; font-size: 0.78rem; }
.invite-link { display: flex; gap: var(--sp-2); align-items: center; }
.invite-link input { flex: 1; min-width: 0; font-size: 0.76rem; }
.role-pill { font-size: 0.66rem; font-weight: 700; padding: 1px 8px; border-radius: var(--r-full); background: var(--info-bg); color: var(--info); }

/* --- Overlays / bottom-sheet --- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgb(2 6 23 / 0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; gap: var(--sp-4); padding: var(--sp-4);
  animation: fade-in var(--t-med) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }

/* Sur mobile, l'éditeur devient une bottom-sheet */
#editor { justify-content: flex-end; padding: 0; }
.editor-card {
  background: var(--surface); color: var(--text);
  border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--sp-2) var(--sp-4) calc(env(safe-area-inset-bottom) + 16px);
  width: 100%; max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-3);
  animation: slide-up var(--t-med) var(--ease);
}
@keyframes slide-up { from { transform: translateY(40px); opacity: 0.5; } }
.sheet-handle { width: 40px; height: 4px; border-radius: var(--r-full); background: var(--border); margin: 0 auto var(--sp-1); flex-shrink: 0; }

@media (min-width: 640px) {
  #editor { justify-content: center; padding: var(--sp-4); }
  .editor-card { width: min(440px, 94vw); border-radius: var(--r-lg); }
  .sheet-handle { display: none; }
}

.editor-card img { width: 100%; max-height: 150px; object-fit: contain; border-radius: var(--r-sm); background: var(--surface-2); cursor: zoom-in; }
.editor-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-2); flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row select { text-overflow: ellipsis; }
.editor-status { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }

/* --- Visionneuse --- */
.viewer { background: rgb(0 0 0 / 0.93); cursor: zoom-out; }
.viewer img { max-width: 100vw; max-height: 88vh; object-fit: contain; }
.viewer p { font-size: 0.85rem; opacity: 0.7; }

/* --- Bannières / alertes inline --- */
.banner {
  border-radius: var(--r-sm); padding: 10px 12px;
  font-size: 0.83rem; line-height: 1.45;
}
.banner.warn { background: var(--warning-bg); color: var(--warning); }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner.info { background: var(--info-bg); color: var(--info); }
.hint { color: var(--warning); font-size: 0.72rem; }
.learned-hint { color: var(--text-3); font-size: 0.7rem; margin-top: 2px; }
input.missing, select.missing { border: 1px solid var(--warning) !important; background: var(--warning-bg) !important; }

/* --- Toasts --- */
#toasts {
  position: fixed; bottom: calc(env(safe-area-inset-bottom) + 104px);
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 20; width: min(400px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  border-radius: var(--r-md); padding: 11px 14px;
  font-size: 0.86rem; box-shadow: var(--shadow-3);
  display: flex; align-items: center; gap: var(--sp-3);
  pointer-events: auto;
  animation: toast-in var(--t-med) var(--ease);
}
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
.toast .msg { flex: 1; min-width: 0; }
.toast button {
  background: none; border: none; color: inherit;
  font-weight: 700; font-size: 0.86rem; padding: 4px 6px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; flex-shrink: 0;
}
.toast.success { background: var(--success); color: #fff; }
.toast.warn { background: var(--warning); color: #fff; }
.toast.danger { background: var(--danger); color: #fff; }

/* Onglets des outils de gestion (navigation directe entre sheets) */
.mgmt-tabs {
  display: flex; gap: 6px; margin-bottom: var(--sp-1);
  flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* rangée défilante, jamais de retour à la ligne */
}
.mgmt-tabs::-webkit-scrollbar { display: none; }
.mgmt-tab { flex-shrink: 0; white-space: nowrap; }
.mgmt-tab {
  min-height: 30px; padding: 4px 10px; font-size: 0.72rem; font-weight: 600;
  border-radius: var(--r-full); background: var(--surface-2); color: var(--text-2);
  text-align: center;
}
.mgmt-tab.active { background: var(--brand); color: #fff; cursor: default; }

/* Tableau de bord */
.dash-card { width: min(560px, 94vw); max-height: 88vh; overflow-y: auto; }
.dash-card h2 { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); }
.dash-card h2 select { min-height: 32px; padding: 4px 8px; font-size: 0.75rem; flex: 0 0 auto; max-width: 170px; font-weight: 400; }
.dash-row { display: flex; align-items: center; gap: var(--sp-2); margin: 5px 0; }
.dash-label { flex: 0 0 44%; font-size: 0.78rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-label small { color: var(--text-3); }
.dash-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; }
.dash-fill { display: block; height: 100%; background: var(--brand); border-radius: var(--r-full); }
.dash-val { flex: 0 0 auto; font-size: 0.75rem; font-variant-numeric: tabular-nums; font-weight: 650; min-width: 72px; text-align: right; }

/* Aide raccourcis clavier */
.help-keys { display: flex; flex-direction: column; gap: 8px; font-size: 0.85rem; }
.help-keys > div { display: flex; align-items: center; gap: 8px; }
.help-keys span { color: var(--text-2); margin-left: auto; }
kbd {
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 7px; font-size: 0.75rem; font-family: var(--font);
}

/* --- Sheet d'export --- */
.action-sheet {
  background: var(--surface); color: var(--text);
  border-radius: var(--r-lg); padding: var(--sp-4);
  width: min(340px, 92vw); display: flex; flex-direction: column; gap: var(--sp-2);
  box-shadow: var(--shadow-3);
}
.action-sheet h2 { font-size: 0.95rem; margin-bottom: var(--sp-1); }
.action-sheet button { text-align: left; }
/* Les boutons de sortie sont des actions, pas des entrées de liste : centrés */
.action-sheet button[id$="-close-btn"], .action-sheet button[id$="-cancel-btn"] { text-align: center; }
@media (min-width: 700px) {
  .action-sheet { width: min(430px, 92vw); }
}

/* Entrées de la sheet ⚙️ Gestion : libellé + description */
.admin-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 10px 12px; font-weight: 600; font-size: 0.9rem;
}
.admin-item small { font-weight: 400; font-size: 0.72rem; color: var(--text-3); }

/* --- Vérification des cadres détectés --- */
.review-card {
  background: var(--surface); color: var(--text);
  border-radius: var(--r-lg); padding: var(--sp-4);
  width: min(440px, 94vw); max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--sp-2);
  box-shadow: var(--shadow-3);
}
.review-card h2 { font-size: 1rem; }
/* La photo doit TOUJOURS être visible en entier : elle se réduit pour tenir
   dans l'écran (boutons compris) au lieu d'être coupée par la carte. */
.review-stage {
  position: relative; border-radius: var(--r-sm); background: #000;
  flex: 0 0 auto; align-self: center; max-width: 100%;
}
.review-stage img {
  display: block; max-width: 100%; max-height: 52vh;
  width: auto; height: auto;
}
.review-box {
  position: absolute; border: 3px solid var(--brand);
  background: rgb(37 99 235 / 0.12); border-radius: 4px;
  cursor: move; touch-action: none;
}
.review-box .num {
  position: absolute; top: -2px; left: -2px;
  background: var(--brand); color: #fff; font-size: 0.78rem; font-weight: 700;
  padding: 2px 9px; border: none; border-radius: 4px 0 8px 0;
  min-height: 26px; cursor: pointer;
}
.review-box .handle {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand); border: 2px solid #fff;
  touch-action: none; box-shadow: var(--shadow-1);
}
.review-box .handle.tl { left: -12px; top: -12px; cursor: nwse-resize; }
.review-box .handle.tr { right: -12px; top: -12px; cursor: nesw-resize; }
.review-box .handle.bl { left: -12px; bottom: -12px; cursor: nesw-resize; }
.review-box .handle.br { right: -12px; bottom: -12px; cursor: nwse-resize; }
.review-box.off { border-color: #9ca3af; border-style: dashed; background: rgb(0 0 0 / 0.35); cursor: default; }
.review-box.off .num { background: #9ca3af; text-decoration: line-through; }
.review-box.off .handle { display: none; }

/* --- Panneau anomalies --- */
.anomalies-card { max-height: 88vh; overflow-y: auto; width: min(440px, 94vw); }
#anomalies-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.anomaly {
  border-radius: var(--r-sm); padding: 10px 12px;
  background: var(--warning-bg);
  display: flex; flex-direction: column; gap: 6px;
}
.anomaly.doublon { background: var(--danger-bg); }
.anomaly .a-title { font-weight: 700; font-size: 0.82rem; }
.anomaly.doublon .a-title { color: var(--danger); }
.anomaly:not(.doublon) .a-title { color: var(--warning); }
.anomaly .a-msg { font-size: 0.8rem; color: var(--text-2); line-height: 1.4; }
.anomaly .a-receipt {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface); border-radius: var(--r-sm);
  padding: 6px 10px; cursor: pointer; font-size: 0.82rem;
  border: 1px solid var(--border);
}
.anomaly .a-receipt .money { margin-left: auto; white-space: nowrap; }
.anomalies-empty { text-align: center; color: var(--text-2); padding: var(--sp-6) 0; font-size: 0.95rem; }

/* --- Spinner --- */
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 0.3); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Champs & boutons --- */
input, select, button {
  font: inherit; padding: 11px 12px;
  border-radius: var(--r-sm); border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  min-height: 44px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: var(--text-3); }
button { cursor: pointer; }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button.primary { background: var(--brand); color: #fff; font-weight: 600; }
button.primary:active { background: var(--brand-hover); }
button.danger { background: var(--danger-bg); color: var(--danger); }
button.ghost { background: transparent; color: var(--text-2); }
button.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   Desktop premium (>= 900px) : table dense + drawer + sélection + raccourcis.
   Le mobile (< 900px) n'est PAS affecté par ce bloc.
   ========================================================================== */
@media (min-width: 900px) {
  main#list { padding: var(--sp-3) var(--sp-4) 96px; gap: 0; }

  .rx-table {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden;
    box-shadow: var(--shadow-1);
  }
  .rx-table thead th {
    position: sticky; top: 0; z-index: 2; background: var(--surface-2);
    text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em;
    color: var(--text-3); font-weight: 700; padding: 9px 12px; cursor: pointer;
    user-select: none; white-space: nowrap; border-bottom: 1px solid var(--border);
  }
  .rx-table thead th.rx-num { text-align: right; }
  .rx-table thead th:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

  /* Séparateurs de lots d'import (tri "Par import récent") */
  .rx-table .rx-group td {
    background: var(--surface-2); color: var(--text-2); font-size: 0.75rem; font-weight: 700;
    padding: 6px 12px; border-top: 1px solid var(--border); max-width: none;
  }
  .rx-table .rx-group.latest td { background: var(--info-bg); color: var(--info); }

  .filters-toggle { display: none; }
  .filters-wrap.collapsed { display: flex; } /* desktop : jamais repliés */
  /* Filtres sur UNE ligne : la table remonte d'un étage */
  .filters-wrap { flex-direction: row; align-items: center; }
  .filters-wrap #search { flex: 1.6; min-width: 220px; }
  .filters { flex: 2.4; flex-wrap: nowrap; }
  .filters select { flex: 1; min-width: 0; }
  .rx-covered { color: var(--text-2); font-size: 0.8rem; }

  .rx-row { height: 44px; border-top: 1px solid var(--border); cursor: pointer; }
  .rx-row:first-child { border-top: none; }
  .rx-row:hover { background: var(--brand-soft); }
  .rx-row.active { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
  .rx-row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
  .rx-table td {
    padding: 4px 12px; font-size: 0.85rem; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 280px;
  }
  .rx-table td.rx-num { text-align: right; font-variant-numeric: tabular-nums; }
  .rx-table td.rx-num .amount { font-weight: 650; }
  .rx-table td.rx-merchant { font-weight: 600; }
  .rx-eur { color: var(--text-3); font-size: 0.72rem; margin-left: 6px; }
  .rx-warn { font-size: 0.8rem; }

  .rx-check { width: 40px; text-align: center; }
  .rx-check input { width: 16px; height: 16px; min-height: 0; opacity: 0; cursor: pointer; vertical-align: middle; }
  .rx-row:hover .rx-check input, .rx-check input:checked, .rx-check input:focus-visible { opacity: 1; }
  .rx-table thead .rx-check input { opacity: 0.55; }

  /* Éditeur en drawer droit — la liste reste visible ET cliquable */
  #editor { justify-content: flex-end; align-items: stretch; padding: 0; background: transparent; pointer-events: none; animation: none; }
  #editor .editor-card {
    pointer-events: auto; width: 480px; max-width: 92vw; height: 100vh; max-height: 100vh;
    border-radius: 0; box-shadow: var(--shadow-3); overflow-y: auto; animation: slide-left var(--t-med) var(--ease);
  }
  @keyframes slide-left { from { transform: translateX(40px); opacity: 0.6; } }
  #editor .sheet-handle { display: none; }

  /* Dock à droite (le centre reste à la barre de sélection), boutons en pilules libellées */
  .fab-dock { left: auto; right: 24px; justify-content: flex-end; gap: 10px; }
  .fab-label { display: inline; font-size: 0.88rem; font-weight: 600; }
  .fab {
    width: auto; height: 46px; padding: 0 18px; gap: 8px;
    font-size: 1.05rem; box-shadow: var(--shadow-2);
  }
  .fab-gallery, .fab-hint, .fab-manual {
    width: auto; height: 42px; min-height: 42px; padding: 0 14px; gap: 6px;
    font-size: 1rem; color: var(--text-2);
  }
  /* Ordre desktop : [Guider] [Sans justificatif] [Galerie] [Scanner] — l'action principale à droite */
  .fab-hint { order: 0; }
  .fab-manual { order: 1; }
  .fab-gallery { order: 2; }
  .fab { order: 3; }
}

/* Barre d'action bulk (affichée uniquement en desktop via JS) */
.bulk-bar select { min-height: 34px; padding: 4px 8px; font-size: 0.8rem; max-width: 160px; }
.bulk-bar {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 15;
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--text); color: var(--bg);
  padding: 8px 10px 8px 14px; border-radius: var(--r-full); box-shadow: var(--shadow-3);
}
.bulk-bar .bulk-count { font-weight: 700; font-size: 0.82rem; padding-right: var(--sp-1); white-space: nowrap; }
.bulk-bar button {
  min-height: 36px; padding: 6px 12px; font-size: 0.82rem; white-space: nowrap;
  background: rgb(255 255 255 / 0.14); color: inherit; border-radius: var(--r-sm);
}
.bulk-bar button:hover { background: rgb(255 255 255 / 0.24); }
.bulk-bar button.danger { background: var(--danger); color: #fff; }
.bulk-bar button.ghost { background: transparent; }
.bulk-bar button:focus-visible { outline: 2px solid var(--bg); outline-offset: 2px; }

/* --- Éditeur : cadre photo vide (vrai point d'entrée) et destructive isolée --- */
.photo-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 100%; min-height: 110px; margin-bottom: var(--sp-3);
  border: 2px dashed var(--border); border-radius: var(--r-md);
  background: var(--bg); color: var(--text-2); cursor: pointer;
}
.photo-empty .pe-icon { font-size: 1.6rem; }
.photo-empty .pe-title { font-weight: 650; color: var(--text); }
.photo-empty small { color: var(--text-3); }
.editor-save { width: 100%; }
.danger-text {
  background: none; border: none; box-shadow: none; width: 100%;
  color: var(--danger); font-weight: 600; padding: 10px;
}

/* --- Sheet Règles : grille propre pour les comptes comptables --- */
#account-codes-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2) var(--sp-4);
  margin-bottom: var(--sp-3);
}
.account-code-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  font-size: 0.88rem; color: var(--text-2);
}
.account-code-row input { width: 118px; min-height: 38px; padding: 6px 10px; text-align: right; }
@media (max-width: 480px) { #account-codes-list { grid-template-columns: 1fr; } }

/* Une sheet ouverte prend toute la scène : tab bar et FAB s effacent (pattern iOS) */
body:has(.overlay:not(.hidden)) .tabbar,
body:has(.overlay:not(.hidden)) .fab-dock { display: none; }

/* --- Visionneuse : zoom au doigt --- */
#viewer-img { transform-origin: center; transition: transform 80ms linear; will-change: transform; }
.viewer-close {
  position: fixed; top: calc(env(safe-area-inset-top) + 12px); right: 14px; z-index: 5;
  width: 40px; height: 40px; border-radius: var(--r-full);
  background: rgb(0 0 0 / 0.55); color: #fff; font-size: 1.1rem; border: none;
}
/* Décision : ⋯ reste sur la ligne des boutons */
.vd-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.vd-actions .approve { flex: 1 1 190px; }
.vd-actions .vd-more-wrap { margin-left: auto; }
/* Bandeau « hors périmètre » : informatif, pas criard */
.val-hint { font-size: 0.76rem; padding: 6px 10px; opacity: 0.85; }

/* Mini-sheet motif */
.reason-card { width: min(440px, 94vw); }
#reason-input { width: 100%; resize: none; font: inherit; padding: 11px 12px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
#reason-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* --- Résumé d'en-tête : UNE ligne (compte · total · chip avance · filtres) --- */
.summary-row { flex-wrap: nowrap; }
.summary { display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; min-width: 0; }
.summary .adv-chip { flex-shrink: 0; }
@media (max-width: 899px) {
  .ft-label { display: none; }               /* 🔍 seul : la pastille indique les filtres actifs */
  .filters-toggle { padding: 6px 10px; flex-shrink: 0; }
}

/* --- Profil : groupe de raccourcis homogène, séparé du formulaire de compte --- */
.profile-nav { display: flex; flex-direction: column; gap: 8px; margin: var(--sp-2) 0; }
.profile-nav .admin-item { width: 100%; }
.profile-nav #push-test-btn { align-self: center; margin-top: -2px; }

/* Onglets de gestion : sur mobile, les emojis sautent pour que les 4 libellés tiennent */
@media (max-width: 480px) { .mgmt-tab .mt-icon { display: none; } }

/* --- Sheets mobiles : toujours contenues DANS l'écran, au-dessus de l'indicateur home.
   Une sheet plus haute que l'écran défile à l'intérieur — « Fermer » reste tapable. --- */
@media (max-width: 899px) {
  .overlay:not(#editor) { padding: 12px 12px calc(env(safe-area-inset-bottom) + 12px); }
  .overlay:not(#editor) .action-sheet {
    max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
}
