:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16191d;
  --muted: #666e79;
  --line: #dcdfe4;
  --accent: #b4232a;      /* rouge canadien, discret */
  --accent-ink: #ffffff;
  --ok: #1f7a4d;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --radius: 14px;
  --pad: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #171b20;
    --surface-2: #21262d;
    --text: #e9ecf0;
    --muted: #99a1ac;
    --line: #2c333b;
    --accent: #e05561;
    --accent-ink: #16191d;
    --ok: #4bbd85;
    --warn: #e0b25e;
    --warn-bg: #33291479;
  }
}

* { box-sizing: border-box; }

/* L'attribut `hidden` ne masque que via le `display: none` de la feuille de
   style du navigateur : n'importe quelle règle `display` de la page le bat.
   Ce reset rend l'attribut fiable quel que soit le style de l'élément. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- barre de titre --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) var(--pad) 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.grand-total { text-align: right; line-height: 1.15; }
.grand-total span { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.grand-total small { display: block; font-size: 11px; color: var(--muted); }

main { padding: var(--pad); display: grid; gap: 14px; max-width: 720px; margin: 0 auto; }

/* --- cartes --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-body { padding: 0 var(--pad) var(--pad); display: grid; gap: 12px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px var(--pad) 6px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.count {
  background: var(--surface-2); color: var(--muted);
  border-radius: 99px; padding: 2px 9px; font-size: 12px; font-variant-numeric: tabular-nums;
}

/* --- formulaire --- */
label { display: grid; gap: 6px; font-size: 13px; font-weight: 550; color: var(--muted); }
.opt { font-weight: 400; opacity: .7; }
input[type=text], input[type=date] {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; width: 100%;
  min-height: 44px;  /* cible tactile iOS */
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.amount-hint { margin-top: -4px; }
.amount-hint.manual { color: var(--ok); font-weight: 550; }
.amount-hint.alert { color: var(--warn); font-weight: 600; }
.tag {
  display: inline-block; margin-left: 6px; padding: 0 5px;
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}

/* --- boutons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; text-decoration: none;
  border: 1px solid transparent; border-radius: 12px;
  padding: 12px 16px; min-height: 48px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.big { width: 100%; font-size: 16px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.ico { font-size: 18px; }

.capture { display: grid; gap: 10px; }
.export { display: grid; gap: 10px; margin-bottom: 24px; }

/* --- chips de catégorie --- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 14px; font-weight: 550;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 99px;
  padding: 9px 14px; min-height: 40px; cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

/* --- file d'attente --- */
.queue { display: grid; gap: 8px; }
.queue-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- revue --- */
.review { border-color: var(--accent); }
.review-head { display: flex; gap: 12px; padding: var(--pad); align-items: center; }
.thumb-btn {
  position: relative; flex: none; padding: 0; border: none; background: none;
  cursor: zoom-in; line-height: 0; -webkit-tap-highlight-color: transparent;
}
.review-head img {
  width: 64px; height: 64px; object-fit: cover; display: block;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
}
.zoom-hint {
  position: absolute; right: -4px; bottom: -4px;
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--text); color: var(--bg);
  font-size: 10px; line-height: 20px; text-align: center;
}

/* --- case de confirmation du montant --- */
.confirm-check {
  display: flex; align-items: center; gap: 10px; width: 100%;
  font: inherit; font-size: 14px; font-weight: 600; text-align: left;
  color: var(--text); background: var(--warn-bg);
  border: 1px solid var(--warn); border-radius: 12px;
  padding: 12px 14px; min-height: 52px; cursor: pointer;
}
.confirm-check .box {
  width: 22px; height: 22px; flex: none; border-radius: 6px;
  border: 2px solid var(--warn); background: transparent;
  color: transparent; font-size: 14px; line-height: 19px; text-align: center;
}
.confirm-check[aria-pressed="true"] {
  background: transparent; border-color: var(--ok); color: var(--ok);
}
.confirm-check[aria-pressed="true"] .box {
  background: var(--ok); border-color: var(--ok); color: var(--surface);
}

/* --- visionneuse plein écran --- */
.viewer {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .92);
  padding: env(safe-area-inset-top) 8px calc(env(safe-area-inset-bottom) + 8px);
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close {
  position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 12px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, .15); color: #fff;
  border: none; font-size: 20px; cursor: pointer;
}
.review-head h2 { margin: 0; font-size: 16px; }
.badge {
  display: inline-block; background: var(--surface-2); color: var(--muted);
  border-radius: 5px; padding: 1px 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}
.warn {
  margin: 0 var(--pad) 12px; padding: 10px 12px;
  background: var(--warn-bg); color: var(--warn);
  border-radius: 10px; font-size: 13px;
}
.warn ul { margin: 0; padding-left: 18px; }
.actions {
  display: flex; gap: 10px; padding: 0 var(--pad) var(--pad);
}
.actions .btn { flex: 1; }
.raw summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.raw pre {
  max-height: 220px; overflow: auto; margin: 8px 0 0;
  background: var(--surface-2); border-radius: 10px; padding: 10px;
  font-size: 11px; line-height: 1.35; white-space: pre-wrap; word-break: break-word;
}

/* --- récapitulatif + liste --- */
.recap { display: grid; gap: 6px; padding: 8px var(--pad) 4px; }
.recap-line {
  display: flex; justify-content: space-between; font-size: 13px; color: var(--muted);
}
.recap-line b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px var(--pad); border-top: 1px solid var(--line);
}
.list .thumb {
  width: 40px; height: 40px; flex: none; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--line); background: var(--surface-2);
}
.list .info { flex: 1; min-width: 0; }
.list .info strong { display: block; font-size: 14px; font-weight: 600; }
.list .info small { color: var(--muted); font-size: 12px; }
.list .amount { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.list .del {
  background: none; border: none; color: var(--muted);
  font-size: 20px; line-height: 1; padding: 6px 2px; cursor: pointer;
}
.empty { padding: 12px var(--pad) var(--pad); color: var(--muted); font-size: 13px; margin: 0; }

/* --- toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 550;
  z-index: 50; max-width: 90vw; text-align: center;
}
.toast.error { background: var(--accent); color: var(--accent-ink); }
