:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --line: rgba(60, 60, 67, .14);
  --fill: rgba(118, 118, 128, .12);
  --accent: #d62d20;
  --accent-soft: rgba(214, 45, 32, .1);
  --green: #1f9d55;
  --red: #d62d20;
  --tabbar: rgba(249, 249, 249, .88);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --accent: #ff453a;
    --accent-soft: rgba(255, 69, 58, .16);
    --green: #32d74b;
    --red: #ff453a;
    --tabbar: rgba(22, 22, 24, .88);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
body.no-tabs { padding-bottom: env(safe-area-inset-bottom); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 12px 4px 14px; }
h2 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin: 26px 16px 7px; letter-spacing: .02em; }
.foot { font-size: 13px; color: var(--muted); margin: 7px 16px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin: 0 -4px; }
.topbar a, .topbar button.link { color: var(--accent); text-decoration: none; background: none; border: 0; padding: 10px 4px; font-size: 17px; }
.topbar .title { font-weight: 600; }

/* Groupes façon Réglages iOS */
.group { background: var(--card); border-radius: 12px; overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 16px;
  position: relative; text-decoration: none; color: inherit; width: 100%; background: none; border: 0; text-align: left;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .sub { font-size: 14px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.row .val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row.chev::after { content: ""; width: 8px; height: 8px; border: solid #c4c4c7; border-width: 2px 2px 0 0; transform: rotate(45deg); margin-left: 4px; flex: none; }
.row:active.tap, a.row:active { background: var(--fill); }
.row.danger { color: var(--red); justify-content: center; }
.row.action { color: var(--accent); }

.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
.num { font-variant-numeric: tabular-nums; }
.money { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: #fff; background: var(--c, #8e8e93);
}

/* Carte du solde perso */
.hero { background: var(--card); border-radius: 16px; padding: 18px 18px 16px; }
.hero .lbl { color: var(--muted); font-size: 15px; }
.hero .big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.hero .todo { font-size: 15px; line-height: 1.5; }

.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 7px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.wrap { flex-wrap: wrap; }

/* Formulaires */
.field { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 16px; position: relative; }
.field + .field::before, .field + .row::before, .row + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.field label { width: 104px; flex: none; }
.field input, .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 8px 0; text-align: right; font-size: 17px;
  -webkit-appearance: none; appearance: none;
}
.field select { direction: rtl; color: var(--muted); }
.field input[type=date] { min-height: 34px; display: flex; justify-content: flex-end; color: var(--muted); }
.field input::-webkit-date-and-time-value { text-align: right; }
.amount-input { border: 0; outline: none; background: none; -webkit-appearance: none; appearance: none; font-size: 44px !important; font-weight: 700; text-align: center !important; padding: 14px 0 !important; width: 100%; }
.amount-wrap { background: var(--card); border-radius: 12px; padding: 6px 16px 10px; text-align: center; }
.amount-wrap .hint { color: var(--muted); font-size: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px 7px 7px;
  display: inline-flex; align-items: center; gap: 8px; font-size: 15px;
}
.chip .avatar { width: 24px; height: 24px; font-size: 11px; opacity: .45; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }
.chip.on .avatar { opacity: 1; }
.chiptools { display: flex; gap: 16px; padding: 0 16px 12px; font-size: 15px; }
.chiptools button { border: 0; background: none; color: var(--accent); padding: 0; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 15px; font-size: 17px; font-weight: 600;
  background: var(--accent); color: #fff; margin-top: 22px;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .4; }
.btn.ghost { background: var(--card); color: var(--accent); margin-top: 10px; }

.empty { text-align: center; color: var(--muted); padding: 36px 20px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--fill); color: var(--muted); }
.badge.ok { background: rgba(31, 157, 85, .14); color: var(--green); }
.badge.due { background: var(--accent-soft); color: var(--red); }

.mini-btn { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--card); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; border-bottom: .5px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
th { color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: 0; font-weight: 600; }

/* Écran connexion */
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; max-width: 380px; margin: 0 auto; padding: 24px; text-align: center; }
.login img { width: 88px; height: 88px; border-radius: 20px; margin: 0 auto 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); }
.login h1 { margin: 0 0 6px; font-size: 28px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login input { width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 15px; text-align: center; font-size: 18px; outline: none; }
.err { color: var(--red); font-size: 15px; margin-top: 12px; min-height: 20px; }

/* Barre d'onglets */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around; align-items: flex-start;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 10px; font-weight: 500; padding-top: 2px; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs svg circle { fill: currentColor; stroke: none; }
#tabs a.plus { flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff; justify-content: center; margin: -14px 6px 0; box-shadow: 0 4px 14px rgba(214, 45, 32, .4); }
#tabs a.plus svg { stroke-width: 2.6; }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 15px; max-width: 90vw; text-align: center;
}

/* Feuille de confirmation */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30; display: flex; align-items: flex-end; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.sheet .group { border-radius: 14px; margin-bottom: 8px; }
.sheet .msg { text-align: center; color: var(--muted); font-size: 13px; padding: 14px 16px; }
.sheet .row { justify-content: center; font-size: 20px; color: var(--accent); min-height: 56px; }
.sheet .row.cancel { font-weight: 600; }
.sheet .row.destroy { color: var(--red); }

.mt { margin-top: 16px; }
.center { text-align: center; }
