:root {
  --bg: #f5efe7;
  --surface: #fffdfa;
  --surface-2: #f0e8dd;
  --line: #e6dccf;
  --ink: #241a14;
  --ink-2: #6f6158;
  --ink-3: #a3958a;
  --accent: #b5643a;
  --accent-ink: #fff;
  --accent-soft: #f6e3d6;
  --hero-1: #2a1d16;
  --hero-2: #4a2f20;
  --in: #2e7d57;
  --in-soft: #dff1e6;
  --out: #c2452d;
  --out-soft: #f9e1db;
  --neutral-soft: #ece4f6;
  --neutral: #6b4fa0;
  --shadow: 0 1px 2px rgba(60, 35, 20, .06), 0 8px 24px rgba(60, 35, 20, .07);
  --radius: 18px;
  --tabs-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14100d;
    --surface: #1e1814;
    --surface-2: #2a221c;
    --line: #342a23;
    --ink: #f3ebe3;
    --ink-2: #b9aa9e;
    --ink-3: #7d6f65;
    --accent: #e08a5a;
    --accent-ink: #1a110c;
    --accent-soft: #3a261b;
    --hero-1: #2b1e16;
    --hero-2: #47301f;
    --in: #5cc28f;
    --in-soft: #183327;
    --out: #f07a62;
    --out-soft: #3a1c16;
    --neutral-soft: #2a2238;
    --neutral: #b9a2e6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Rubik", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
svg { width: 20px; height: 20px; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
.muted { color: var(--ink-2); }
.error { color: var(--out); min-height: 1.4em; margin: 10px 0 0; font-weight: 600; font-size: 14px; }

/* ---------- Champs & boutons ---------- */
input, select, textarea {
  width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 16px; /* évite le zoom iOS */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 18px; border-radius: 14px;
  font-weight: 700; white-space: nowrap;
  transition: transform .1s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { color: var(--ink-2); }
.btn-danger { background: var(--out-soft); color: var(--out); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 12px; border-radius: 11px; font-size: 14px; }
.btn-sm svg { width: 16px; height: 16px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  color: var(--ink-2); background: var(--surface-2);
}
.row { display: flex; gap: 8px; }
.row .btn { flex: none; width: 50px; padding: 0; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(600px 400px at 80% -10%, rgba(181, 100, 58, .25), transparent 60%),
    radial-gradient(500px 400px at -10% 110%, rgba(181, 100, 58, .18), transparent 60%),
    var(--bg);
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo {
  width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 26px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--hero-2), var(--hero-1)); color: #f2c9a8;
  box-shadow: 0 18px 40px rgba(60, 30, 15, .3);
}
.logo svg { width: 48px; height: 48px; }
.login h1 { font-size: 32px; font-weight: 800; }
.login p.muted { margin: 6px 0 26px; }
#code { text-align: center; font-size: 26px; letter-spacing: .35em; padding: 16px; margin-bottom: 12px; font-weight: 700; }
#code::placeholder { letter-spacing: .3em; color: var(--ink-3); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- App ---------- */
.app {
  max-width: 560px; margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--hero-1); color: #f2c9a8; }
.brand-mark svg { width: 22px; height: 22px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding-inline: 5px 12px; border-radius: 99px;
  background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; max-width: 55%;
}
.chip .av { width: 24px; height: 24px; font-size: 11px; }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Hero solde */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(150deg, var(--hero-2), var(--hero-1));
  color: #fbeee3; border-radius: 26px; padding: 22px 18px 18px;
  box-shadow: 0 20px 40px -18px rgba(50, 25, 10, .55);
}
.hero::after {
  content: ""; position: absolute; inset-inline-end: -60px; top: -70px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(242, 180, 130, .35), transparent 70%);
}
.hero-label { font-size: 13px; font-weight: 600; opacity: .7; text-transform: uppercase; letter-spacing: .08em; }
.hero-amount { direction: ltr; text-align: right; font-size: clamp(38px, 12vw, 50px); font-weight: 800; letter-spacing: -.04em; line-height: 1.1; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.hero-amount.neg { color: #ffb3a3; }
.hero-sub { font-size: 13px; opacity: .7; min-height: 1.4em; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 2px 9px;
  border-radius: 16px; background: rgba(255, 255, 255, .08); color: #fbeee3; font-size: 12.5px; font-weight: 600;
  transition: background .15s, transform .1s;
}
.action:active { transform: scale(.95); background: rgba(255, 255, 255, .14); }
.ai { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, .12); }
.ai-in { background: #3f9a6c; color: #fff; }
.ai-out { background: #d0573d; color: #fff; }

/* Vues */
.views { margin-top: 22px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 12px; min-height: 36px; }
.view-head h2 { font-size: 20px; font-weight: 800; }
.month { font-size: 12.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; margin: 20px 4px 8px; display: flex; justify-content: space-between; }
.month:first-child { margin-top: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 12px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; width: 100%; text-align: start; }
.list .item + .item { border-top: 1px solid var(--line); }
button.item:active { background: var(--surface-2); }
.item-ic { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; flex: none; }
.k-deposit .item-ic { background: var(--in-soft); color: var(--in); }
.k-withdrawal .item-ic { background: var(--out-soft); color: var(--out); }
.k-adjust .item-ic { background: var(--neutral-soft); color: var(--neutral); }
.k-invoice .item-ic { background: var(--accent-soft); color: var(--accent); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; overflow: hidden; white-space: nowrap; }
.item-meta svg { width: 13px; height: 13px; }
.amt, .num { direction: ltr; unicode-bidi: isolate; }
.amt { font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.in { color: var(--in); }
.amt.out { color: var(--out); }
.amt.na { color: var(--ink-3); font-weight: 600; }

.av {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 800; font-size: 14px; color: #fff;
}

.empty { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty-ic { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-3); }
.empty-ic svg { width: 28px; height: 28px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 2px; }

/* Factures */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.inv { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; text-align: start; display: flex; flex-direction: column; }
.inv-thumb { aspect-ratio: 3 / 4; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); overflow: hidden; }
.inv-thumb img { width: 100%; height: 100%; object-fit: cover; }
.inv-thumb svg { width: 44px; height: 44px; }
.inv-cap { padding: 9px 11px 11px; }
.inv-cap .t { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-cap .m { font-size: 12.5px; color: var(--ink-2); display: flex; justify-content: space-between; gap: 6px; }

/* Suggestions */
.sugg-form { display: grid; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 10px; font-weight: 650; font-size: 14px; color: var(--ink-2); cursor: pointer; transition: all .15s; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.sugg .check {
  width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line); display: grid; place-items: center; flex: none; color: transparent;
}
.sugg.done .check { background: var(--in); border-color: var(--in); color: #fff; }
.sugg.done .item-title { text-decoration: line-through; color: var(--ink-3); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; }
.tag-missing { background: var(--out-soft); color: var(--out); }
.tag-idea { background: var(--neutral-soft); color: var(--neutral); }
.vote {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 46px; height: 46px; border-radius: 13px;
  background: var(--surface-2); font-weight: 800; font-size: 14px; line-height: 1;
}
.vote svg { width: 16px; height: 16px; margin-bottom: 1px; }
.vote:active { transform: scale(.94); background: var(--accent-soft); color: var(--accent); }
.vote.voted { background: var(--accent-soft); color: var(--accent); }
.mini { color: var(--ink-3); width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; flex: none; }
.mini:active { background: var(--surface-2); }
.mini svg { width: 18px; height: 18px; }
.section-label { font-size: 12.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; margin: 18px 4px 8px; }

#members { margin-bottom: 18px; }
.member-total { text-align: end; }
.member-total small { display: block; font-size: 12px; color: var(--ink-3); font-weight: 500; }

/* Barre d'onglets */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid var(--line);
}
@media (min-width: 600px) {
  .tabs { left: 50%; right: auto; width: 520px; transform: translateX(-50%); bottom: 16px; border-radius: 22px; border: 1px solid var(--line); box-shadow: var(--shadow); height: var(--tabs-h); padding: 0; }
}
.tabs button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-3); font-size: 11.5px; font-weight: 650; }
.tabs button svg { width: 23px; height: 23px; }
.tabs button.active { color: var(--accent); }
.badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--out); color: #fff; font-size: 11px; display: grid; place-items: center; }

/* ---------- Feuille modale ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 12, 8, .45); animation: fade .2s; }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .28s cubic-bezier(.2, .9, .3, 1.1);
}
@media (min-width: 600px) {
  .sheet { align-items: center; padding: 20px; }
  .sheet-panel { border-radius: 26px; }
  .sheet-grip { display: none; }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 21px; font-weight: 800; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.form { display: grid; gap: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 0 0 6px 2px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin: 6px 2px 0; }
.amount-input { position: relative; }
.amount-input input { font-size: 30px; font-weight: 800; padding: 14px 16px; padding-inline-end: 44px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.amount-input span { position: absolute; inset-inline-end: 16px; top: 50%; transform: translateY(-50%); font-size: 24px; font-weight: 700; color: var(--ink-3); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.drop {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; border: 1.5px dashed var(--line);
  background: var(--surface); color: var(--ink-2); font-weight: 600; cursor: pointer;
}
.drop .ai { background: var(--accent-soft); color: var(--accent); }
.drop input { display: none; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 3px; inset-inline-end: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; display: grid; place-items: center; }
.thumb button svg { width: 12px; height: 12px; }
.thumb.loading::after { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .5); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .2; } }

.diff { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.diff b { font-variant-numeric: tabular-nums; }

/* Détail */
.detail-amt { text-align: right; font-size: 38px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 14px 0; font-size: 14.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; text-align: end; word-break: break-word; }
.attach { display: grid; gap: 10px; margin: 14px 0; }
.attach a { display: block; border-radius: 16px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); color: inherit; text-decoration: none; }
.attach img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--surface-2); }
.attach .pdf { display: flex; align-items: center; gap: 12px; padding: 14px; font-weight: 650; }
.attach .pdf svg { width: 34px; height: 34px; color: var(--out); }

.people { display: flex; gap: 8px; flex-wrap: wrap; }
.people button { padding: 9px 14px; border-radius: 99px; background: var(--surface); border: 1.5px solid var(--line); font-weight: 600; }
.people button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--out); color: #fff; }
