/* Notes de frais : langage visuel iOS (titres larges, listes groupées, feuilles, verre dépoli).
   Le verre dépoli est une approximation web (backdrop-filter), pas le matériau natif d'Apple.
   Rayons : 10 (vignettes), 14 (contrôles), 20 (cartes et feuilles), pastille complète (dock, puces, toast).
   Une seule teinte d'accent, définie ici et utilisée partout. */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7; --card: #ffffff; --ink: #1c1c1e; --muted: #6c6c70;
  --line: rgb(60 60 67 / .14); --fill: rgb(120 120 128 / .12);
  --accent: #0071e3; --accent-text: #0066cc; --accent-soft: rgb(0 113 227 / .10); --on-accent: #ffffff;
  --bad: #d70015; --bad-soft: rgb(215 0 21 / .10); --warn-bg: #fff3d1; --warn-ink: #6b4a00;
  --glass: rgb(255 255 255 / .72); --glass-line: rgb(255 255 255 / .65);
  --shadow: 0 10px 36px rgb(20 40 90 / .10);
  --r-s: 10px; --r-m: 14px; --r-l: 20px;
  --ease: cubic-bezier(.16, 1, .3, 1); --sheet-ease: cubic-bezier(.32, .72, 0, 1);
  --top: env(safe-area-inset-top); --bot: env(safe-area-inset-bottom);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e; --card: #1c1c1e; --ink: #f5f5f7; --muted: #a1a1a6;
    --line: rgb(235 235 245 / .14); --fill: rgb(120 120 128 / .24);
    --accent-text: #5eb0ff; --accent-soft: rgb(41 151 255 / .16);
    --bad: #ff7b73; --bad-soft: rgb(255 69 58 / .16); --warn-bg: #3a2e0e; --warn-ink: #f2d58a;
    --glass: rgb(38 38 42 / .68); --glass-line: rgb(255 255 255 / .12);
    --shadow: 0 10px 36px rgb(0 0 0 / .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.35 var(--font); letter-spacing: -.011em;
  -webkit-font-smoothing: antialiased; font-synthesis: none;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; letter-spacing: inherit; color: inherit; }
button { cursor: pointer; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ic { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- barre du haut et titre large ---------- */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 10; height: calc(44px + var(--top)); padding-top: var(--top);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600;
  background: transparent; border-bottom: 1px solid transparent;
  transition: background .3s, border-color .3s, backdrop-filter .3s;
}
.bar span { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .35s var(--ease); }
.bar.show { background: var(--glass); border-bottom-color: var(--line); backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%); }
.bar.show span { opacity: 1; transform: none; }

main { max-width: 560px; margin: 0 auto; padding: calc(var(--top) + 52px) 16px calc(112px + var(--bot)); min-height: 100dvh; }
.large { margin: 6px 4px 18px; font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -.024em; }
.sh { margin: 24px 16px 8px; font-size: 13px; line-height: 1.3; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.muted { color: var(--muted); }
.sub { font-size: 14px; color: var(--muted); line-height: 1.3; }
.sub.bad { color: var(--bad); }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note { margin: 8px 16px 0; font-size: 13px; line-height: 1.4; color: var(--muted); }

/* ---------- groupes (listes inset) ---------- */
.group { background: var(--card); border-radius: var(--r-l); overflow: hidden; }
.row { position: relative; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 16px; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--line); }
.row > span:first-child:not(.tile):not(.thumb) { flex: none; }
.row input:not([type=checkbox]), .row select {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; text-align: right; font-size: 17px; color: var(--ink);
}
.row input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.row select { appearance: none; -webkit-appearance: none; padding-right: 22px; }
.row .caret { position: absolute; right: 16px; width: 14px; height: 14px; color: var(--muted); pointer-events: none; }
label.row:focus-within { background: var(--accent-soft); }
.grow { flex: 1; min-width: 0; }
.t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tap { cursor: pointer; transition: background .15s; }
.tap:active { background: var(--fill); }
.tile { width: 36px; height: 36px; border-radius: var(--r-s); display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-text); }
.tile .ic { width: 20px; height: 20px; }
.chev { width: 14px; height: 14px; color: var(--muted); opacity: .6; }

/* ---------- boutons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; padding: 0 18px;
  border: 0; border-radius: var(--r-m); background: var(--card); color: var(--accent-text); font-weight: 600; font-size: 17px; text-align: center;
  transition: transform .25s var(--ease), background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.soft { background: var(--accent-soft); }
.btn.danger { color: var(--bad); }
.btn.small { width: auto; min-height: 34px; padding: 0 14px; font-size: 15px; border-radius: 99px; background: var(--accent-soft); }
.btn.small.primary { background: var(--accent); }
.btn.icon { width: 34px; min-height: 34px; padding: 0; border-radius: 50%; background: var(--fill); color: var(--muted); }
.btn:disabled { opacity: .45; }
.stack > * + * { margin-top: 10px; }
.link { border: 0; background: none; padding: 8px 4px; color: var(--accent-text); font-size: 17px; }

/* ---------- scanner ---------- */
.capture {
  position: relative; overflow: hidden; text-align: center; padding: 34px 20px 24px; border-radius: var(--r-l);
  background: linear-gradient(165deg, color-mix(in srgb, var(--accent) 14%, var(--card)), var(--card) 72%);
  box-shadow: var(--shadow);
}
.vf {
  --c: var(--accent-text); --t: 3px; --l: 24px;
  position: absolute; inset: 16px; pointer-events: none; opacity: .5; background-repeat: no-repeat;
  background-image:
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)),
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c));
  background-position: 0 0, 0 0, 100% 0, 100% 0, 0 100%, 0 100%, 100% 100%, 100% 100%;
  background-size: var(--l) var(--t), var(--t) var(--l), var(--l) var(--t), var(--t) var(--l), var(--l) var(--t), var(--t) var(--l), var(--l) var(--t), var(--t) var(--l);
}
.shutter {
  position: relative; display: grid; place-items: center; width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--card); box-shadow: 0 0 0 4px var(--accent), 0 12px 28px rgb(0 80 200 / .28);
  cursor: pointer; transition: transform .3s var(--ease), box-shadow .3s;
}
.shutter:active { transform: scale(.93); }
.shutter-core { display: grid; place-items: center; width: 70px; height: 70px; border-radius: 50%; background: var(--accent); color: var(--on-accent); }
.shutter-core .ic { width: 32px; height: 32px; }
.capture h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.capture p { margin: 0 auto 16px; max-width: 30ch; font-size: 15px; color: var(--muted); }

.thumb { position: relative; width: 56px; height: 56px; border-radius: var(--r-s); overflow: hidden; flex: none; background: var(--fill); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.scanning::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 40%;
  background: linear-gradient(to bottom, transparent, rgb(41 151 255 / .75), transparent);
  animation: sweep 1.5s ease-in-out infinite;
}
.skel { height: 11px; width: 70%; margin-top: 7px; border-radius: 6px; background: linear-gradient(90deg, var(--fill) 25%, rgb(255 255 255 / .35) 50%, var(--fill) 75%); background-size: 200% 100%; animation: shimmer 1.5s linear infinite; }

.sum { padding: 18px 20px; display: block; }
.sum-amount { font-size: 40px; line-height: 1.1; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

/* ---------- export ---------- */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: var(--r-m); background: var(--fill); }
.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 11px; background: transparent; font-weight: 600; font-size: 15px; transition: background .25s var(--ease), box-shadow .25s; }
.seg button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 4px rgb(0 0 0 / .16); }
.export { padding: 16px; display: grid; gap: 12px; }
.file-chip { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r-m); background: var(--bg); animation: pop .55s var(--ease) both; }

/* ---------- états vides ---------- */
.empty { text-align: center; padding: 56px 24px; }
.empty .halo { display: grid; place-items: center; width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }
.empty .halo .ic { width: 42px; height: 42px; }
.empty h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.empty p { margin: 0 auto 20px; max-width: 28ch; color: var(--muted); font-size: 15px; }
.empty .btn { width: auto; display: inline-flex; padding: 0 24px; }

/* ---------- réglages ---------- */
.switch { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 51px; height: 31px; border-radius: 99px; background: var(--fill); transition: background .3s var(--ease); cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgb(0 0 0 / .25); transition: transform .35s var(--ease); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- barre d'onglets flottante ---------- */
.dock {
  --i: 0; position: fixed; z-index: 20; left: 50%; bottom: calc(10px + var(--bot)); transform: translateX(-50%);
  width: min(calc(100vw - 24px), 372px); height: 66px; padding: 6px; display: grid; grid-template-columns: repeat(3, 1fr);
  border-radius: 99px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(26px) saturate(180%); -webkit-backdrop-filter: blur(26px) saturate(180%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .5), 0 14px 40px rgb(10 30 70 / .18);
}
@media (prefers-color-scheme: dark) { .dock { box-shadow: inset 0 1px 0 rgb(255 255 255 / .1), 0 14px 40px rgb(0 0 0 / .55); } }
.dock-ind { position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc((100% - 12px) / 3); border-radius: 99px; background: var(--accent-soft); transform: translateX(calc(var(--i) * 100%)); transition: transform .55s var(--ease); }
.dock button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; border-radius: 99px; background: none; color: var(--muted); font-size: 11px; font-weight: 600; transition: color .25s, transform .25s var(--ease); }
.dock button:active { transform: scale(.94); }
.dock button .ic { width: 24px; height: 24px; }
.dock button .on { display: none; }
.dock button[aria-current="true"] { color: var(--accent-text); }
.dock button[aria-current="true"] .on { display: block; }
.dock button[aria-current="true"] .off { display: none; }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: var(--on-accent); font-size: 11px; line-height: 18px; text-align: center; animation: pop .5s var(--ease) both; }

/* ---------- feuille (bottom sheet) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgb(0 0 0 / .4); opacity: 0; transition: opacity .4s var(--ease); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.sheet.open .scrim, .dialog.open .scrim { opacity: 1; }
.panel {
  position: relative; width: 100%; max-width: 560px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: var(--r-l) var(--r-l) 0 0; padding-bottom: calc(24px + var(--bot));
  transform: translateY(100%); transition: transform .55s var(--sheet-ease);
}
.sheet.open .panel { transform: none; }
.sheet-head { position: sticky; top: 0; z-index: 2; padding: 8px 8px 4px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); touch-action: none; }
.grabber { display: block; width: 38px; height: 5px; margin: 0 auto 4px; border-radius: 99px; background: var(--fill); }
.sheet-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 40px; }
.sheet-title { font-weight: 600; }
.sheet-bar .link { justify-self: start; }
.sheet-body { padding: 4px 16px 0; }
.preview { height: 168px; margin: 4px 0 6px; border-radius: var(--r-l); overflow: hidden; background: #111; }
.preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 10px 0 4px; }
.amount input { min-width: 4ch; max-width: 70vw; border: 0; background: transparent; outline: none; text-align: center; font-size: 52px; line-height: 1.1; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.amount input::placeholder { color: var(--fill); }
.amount span { font-size: 30px; font-weight: 600; color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 6px -16px 14px; padding: 4px 16px; scroll-snap-type: x proximity; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 14px; border: 0; border-radius: 99px; background: var(--card); font-size: 15px; font-weight: 500; scroll-snap-align: start; transition: background .25s var(--ease), color .25s, transform .25s var(--ease); }
.chip:active { transform: scale(.95); }
.chip .ic { width: 18px; height: 18px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.stepper { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.stepper button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--fill); }
.stepper button:active { transform: scale(.9); }
.stepper output { min-width: 1.5ch; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
textarea { display: block; width: 100%; min-height: 84px; padding: 13px 16px; border: 0; background: transparent; outline: none; resize: none; font-size: 17px; line-height: 1.35; }
.group:has(textarea:focus) { box-shadow: 0 0 0 2px var(--accent-text); }
.notice { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; padding: 12px 14px; border-radius: var(--r-m); background: var(--warn-bg); color: var(--warn-ink); font-size: 14px; line-height: 1.35; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice .ic { margin-top: 1px; }
.flash { animation: flash 1.6s var(--ease) both; }

/* ---------- dialogue, toast ---------- */
.dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; }
.alert { position: relative; width: min(100%, 290px); border-radius: var(--r-l); background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(30px) saturate(180%); -webkit-backdrop-filter: blur(30px) saturate(180%); text-align: center; overflow: hidden; transform: scale(1.08); opacity: 0; transition: transform .35s var(--ease), opacity .25s; }
.dialog.open .alert { transform: none; opacity: 1; }
.alert h3 { margin: 0; padding: 20px 20px 4px; font-size: 17px; }
.alert p { margin: 0; padding: 0 20px 18px; font-size: 14px; color: var(--muted); }
.alert-actions { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.alert-actions button { min-height: 48px; border: 0; background: none; font-size: 17px; color: var(--accent-text); }
.alert-actions button + button { border-left: 1px solid var(--line); font-weight: 600; }
.alert-actions .danger { color: var(--bad); }
.toast { position: fixed; z-index: 70; left: 50%; bottom: calc(94px + var(--bot)); max-width: min(90vw, 420px); padding: 11px 18px; border-radius: 99px; background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%); box-shadow: var(--shadow); font-size: 15px; font-weight: 500; text-align: center; pointer-events: none; opacity: 0; transform: translate(-50%, 16px) scale(.96); transition: opacity .3s, transform .5s var(--ease); }
.toast.on { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- mouvement ---------- */
.anim .rise { animation: rise .7s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes pop { from { opacity: 0; transform: scale(.88); } }
@keyframes sweep { 0% { transform: translateY(-100%); } 100% { transform: translateY(260%); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes flash { 0%, 35% { background: var(--accent-soft); } 100% { background: transparent; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .thumb.scanning::after { animation: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .bar.show, .dock, .toast, .alert, .sheet-head { background: var(--card); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .bar.show, .dock, .toast, .alert, .sheet-head { background: var(--card); }
}
@media (min-width: 700px) { .large { font-size: 40px; } }
