/* FormiAgent : mobile d'abord, menu latéral à partir de 900 px (cf. maquettes) */
:root {
  --bg: #F4F5F2; --surface: #FFFFFF; --text: #17201C; --muted: #55625C; --border: #E1E5E1;
  --line: #EEF1EE; --field: #C9D3CE; --accent: #1F6F5C; --accent-dark: #15513f;
  --accent-soft: #E3EFEA; --ai-bg: #FBEFD9; --ai-text: #7A4F00; --warn: #8A4B00;
  --danger: #A3271D; --radius: 16px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100dvh; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { margin: 0; }
h1 { font-family: "Space Grotesk", Inter, sans-serif; font-size: 28px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Mise en page */
.shell { display: flex; min-height: 100dvh; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; padding: 20px 16px 96px; max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head .back { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; margin-left: -10px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar a { min-height: 56px; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--muted); text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; flex: 0 0 230px; background: var(--surface); border-right: 1px solid var(--border); padding: 24px 16px; position: sticky; top: 0; height: 100dvh; }
  .sidebar .brand { font-family: "Space Grotesk", Inter, sans-serif; font-size: 20px; font-weight: 700; padding: 0 12px 20px; }
  .sidebar a { min-height: 44px; padding: 0 12px; border-radius: 10px; display: flex; align-items: center; color: #3F4B45; text-decoration: none; }
  .sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .sidebar form { margin-top: auto; }
  .main { padding: 32px 40px; }
  h1 { font-size: 32px; }
}

/* Blocs */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.accent { border: 2px solid var(--accent); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: start; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .value { font-size: 20px; font-weight: 700; }
.stat .value small { font-size: 13px; font-weight: 500; }
.bar { height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { min-height: 96px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; justify-content: space-between; }
.tile:hover { border-color: var(--accent); color: var(--text); }
.tile span { font-size: 16px; font-weight: 600; }
.list { display: flex; flex-direction: column; }
.list .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; border-bottom: 1px solid var(--line); font-size: 15px; }
.list .row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 8px; background: var(--accent-soft); color: var(--accent-dark); }
.badge.ai { background: var(--ai-bg); color: var(--ai-text); }
.totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; }
.totals strong { display: block; font-size: 16px; color: var(--text); }
.flash { border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600; background: var(--accent-soft); color: var(--accent-dark); }
.flash.error { background: #FBE4E1; color: var(--danger); }
.code { background: var(--bg); border-radius: 10px; padding: 10px 12px; font: 12px/1.5 ui-monospace, monospace; color: #3F4B45; white-space: pre-wrap; max-height: 180px; overflow: auto; }
.photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; }
details { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
summary { cursor: pointer; font-weight: 500; min-height: 24px; }
details[open] summary { margin-bottom: 12px; }

/* Formulaires */
.btn { min-height: 48px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: 600 16px Inter, sans-serif; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--accent-dark); color: #fff; }
.btn.block { width: 100%; }
.btn.outline { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--field); font-weight: 500; font-size: 15px; justify-content: space-between; }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 12px; }
.btn.round { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 22px; background: var(--accent-soft); color: var(--accent); font-size: 22px; }
.btn.danger { background: transparent; color: var(--danger); border: 0; min-height: 40px; padding: 0 8px; font-size: 14px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns > * { flex: 1 1 140px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field > span { color: var(--muted); font-size: 13px; }
input[type=text], input[type=number], input[type=search], input[type=date], input[type=time], input[type=password], input:not([type]), select, textarea {
  min-height: 44px; border: 1px solid var(--field); border-radius: 10px; padding: 0 12px; font: 400 16px Inter, sans-serif; color: var(--text); background: var(--surface); width: 100%;
}
textarea { padding: 10px 12px; min-height: 96px; resize: vertical; font-size: 13px; }
textarea.mono { font-family: ui-monospace, monospace; font-size: 12px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, .chips label:focus-within { outline: 3px solid #7FB8A8; outline-offset: 2px; }
.qty { width: 80px !important; text-align: center; }
.big-number { font: 700 48px "Space Grotesk", sans-serif !important; text-align: center; border: 0 !important; width: 170px !important; background: transparent !important; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
/* Pastilles de choix : radio cachés stylés */
.chips { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0; }
.chips legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; inset: 0; }
.chips label span { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--field); background: var(--surface); display: inline-flex; align-items: center; font-size: 14px; cursor: pointer; }
.chips input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.chips.grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.chips.grid-5 span, .chips.grid-3 span { justify-content: center; width: 100%; border-radius: 10px; }
.chips.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chips a.chip { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--field); background: var(--surface); display: inline-flex; align-items: center; font-size: 14px; color: var(--text); text-decoration: none; }
.chips a.chip[aria-current="true"] { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.inline { display: inline; }
.login { max-width: 380px; margin: 12vh auto 0; }

/* Confirmation d'une analyse photo (lot 3) */
.confirm { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.confirm h3 { margin: 0 0 4px; font-size: 16px; }
.confirm-item { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.confirm-item legend { font-weight: 600; padding: 0 4px; }
.confirm-item .qty-field { max-width: 140px; }
.choice { display: flex; gap: 8px; align-items: flex-start; min-height: 32px; }
.choice input { margin-top: 3px; }
.choice > span { display: flex; flex-direction: column; }
.choice .badge { align-self: flex-start; }
.scan-dialog { width: min(480px, calc(100vw - 32px)); border: 0; display: none; flex-direction: column; gap: 10px; }
.scan-dialog[open] { display: flex; }
.scan-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.scan-dialog video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; background: #000; }
