/* ==========================================================================
   Budget — style inspiré d'Apple (sombre par défaut), même famille que Courses
   ========================================================================== */
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --card-2: #f0f0f3;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --green: #1f9d45;
  --green-soft: rgba(52, 199, 89, 0.14);
  --red: #d70015;
  --red-soft: rgba(255, 59, 48, 0.12);
  --orange: #b25000;
  --orange-soft: rgba(255, 149, 0, 0.16);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 22px;
  --blur-bg: rgba(245, 245, 247, 0.78);
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --text: #f5f5f7;
  --muted: #98989d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.16);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.16);
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.16);
  --shadow: none;
  --blur-bg: rgba(0, 0, 0, 0.72);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.hello { font-size: 13px; color: var(--muted); font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions form { margin: 0; }

.icon-btn, .theme-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--card-2); cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s ease, background .2s;
}
.icon-btn:active, .theme-toggle:active { transform: scale(.92); }
.icon-btn svg, .theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle.floating { position: fixed; top: calc(16px + env(safe-area-inset-top)); right: 16px; }

/* ---------- Contenu ---------- */
.container { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.label { font-size: 13px; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; white-space: nowrap; }
.chip-count { font-size: 13px; color: var(--muted); font-weight: 500; text-align: right; }
.link-btn { border: none; background: none; color: var(--accent); font-weight: 600; font-size: 15px; cursor: pointer; padding: 4px 0; white-space: nowrap; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.hint.small { font-size: 13px; margin-top: 10px; }
.empty { text-align: center; color: var(--muted); margin: 8px 0; font-size: 15px; }

/* Carte principale */
.hero { text-align: center; padding: 26px 20px 22px; }
.hero.compact { padding: 22px 20px 18px; }
.big {
  font-size: 46px; font-weight: 700; letter-spacing: -0.03em;
  margin: 4px 0 12px; font-variant-numeric: tabular-nums;
}
.big.neg { color: var(--red); }
.big { margin-bottom: 6px; }
.delta {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  background: var(--card-2); color: var(--muted);
}
.delta:empty { display: none; }
.sub { margin-top: 12px; font-size: 14px; color: var(--muted); }
.sub:empty { display: none; }
.sub strong { color: var(--text); font-weight: 600; }

/* Détail du calcul */
.calc { margin: 16px auto 0; max-width: 360px; text-align: left; }
.calc:empty { display: none; }
.calc-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; color: var(--muted); }
.calc-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; color: var(--text); font-weight: 600; }
.calc-row .plus { color: var(--green); }
.calc-row .minus { color: var(--text); }

/* Lignes (comptes, factures, revenus…) */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
  animation: fade .2s ease;
}
.rows li:last-child { border-bottom: none; }
.row-main {
  flex: 1; min-width: 0; cursor: pointer; padding: 3px 0; border: none; background: none;
  text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.row-text { min-width: 0; }
.row-name { font-size: 16px; overflow-wrap: anywhere; }
.row-meta { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row-amt { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row-amt small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.row-amt.plus { color: var(--green); }
.row-amt.neg { color: var(--red); }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--muted); background: none; display: grid; place-items: center;
  transition: background .15s, border-color .15s;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; color: #fff; opacity: 0; }
.done .check, .check.on { background: var(--green); border-color: var(--green); }
.done .check svg, .check.on svg { opacity: 1; }
.done .row-name { color: var(--muted); }
.done .row-amt { color: var(--muted); font-weight: 500; }

.acc-icon {
  flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.acc-icon.epargne { background: var(--green-soft); color: var(--green); }
.acc-icon svg { width: 19px; height: 19px; }

.fold-btn {
  width: 100%; margin-top: 8px; border: none; background: var(--card-2); cursor: pointer;
  border-radius: 12px; padding: 10px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 16px 0 2px; font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.group-head:first-child { margin-top: 4px; }
.group-head span:last-child { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* Pastilles de suggestion */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips:empty { display: none; }
.chip {
  border: none; cursor: pointer; border-radius: 999px; padding: 7px 13px;
  background: var(--card-2); font-size: 14px; font-weight: 500; transition: transform .12s;
}
.chip::before { content: "+ "; color: var(--accent); font-weight: 700; }
.chip:active { transform: scale(.95); }

/* Bouton + */
.fab {
  position: fixed; right: 20px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(0, 113, 227, .45);
  transition: transform .15s ease;
  z-index: 20;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* Fenêtres du bas */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--card-2); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 18px; font-size: 20px; text-align: center; }
.sheet-sub { margin: -12px 0 16px; text-align: center; color: var(--muted); font-size: 14px; }
.sheet-sub:empty { display: none; }
.sheet form { display: flex; flex-direction: column; gap: 12px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; padding-left: 4px; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 17px; color: var(--text);
  background: var(--card-2); border: 2px solid transparent; border-radius: 14px;
  padding: 14px 16px; outline: none; transition: border-color .2s; min-width: 0;
}
.field select {
  -webkit-appearance: none; appearance: none; padding-right: 36px; font-size: 16px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field-hint { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.field-hint:empty { display: none; }
.amount-wrap { position: relative; }
.amount-wrap input { font-size: 34px; font-weight: 700; text-align: center; padding: 14px 44px; font-variant-numeric: tabular-nums; }
.euro { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 26px; font-weight: 600; color: var(--muted); }
.form-error { color: var(--red); font-size: 14px; min-height: 18px; text-align: center; }

.segmented { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; }
.segmented button {
  flex: 1; border: none; background: none; cursor: pointer; border-radius: 10px;
  padding: 9px 6px; font-size: 15px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s;
}
.segmented button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
:root[data-theme="dark"] .segmented button.on { background: #48484a; }

.btn-primary, .btn-danger, .btn-ghost {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  font-size: 17px; font-weight: 600; cursor: pointer; transition: transform .12s, opacity .2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-ghost { background: none; color: var(--accent); padding: 11px; }
.btn-primary:active, .btn-danger:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; }

/* Messages */
.toast {
  position: fixed; left: 50%; bottom: calc(160px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 40; animation: fade .2s ease; white-space: nowrap;
}
.offline { background: var(--red-soft); color: var(--red); text-align: center; font-size: 13px; padding: 8px 16px; }
.alert { background: var(--red-soft); color: var(--red); padding: 12px 14px; border-radius: 12px; font-size: 14px; }
[hidden] { display: none !important; }

/* Page de connexion */
.login-page { padding-bottom: 0; }
.login-wrap {
  min-height: 100vh; min-height: 100dvh; max-width: 400px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px; text-align: center;
}
.login-logo { border-radius: 20px; margin-bottom: 14px; }
.login-wrap h1 { margin: 0; font-size: 34px; letter-spacing: -0.02em; }
.login-wrap .muted { margin: 6px 0 26px; }
.login-card { width: 100%; display: flex; flex-direction: column; gap: 14px; text-align: left; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative; flex: 1; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: none; cursor: pointer; padding: 6px 0;
  color: var(--muted); font-size: 11px; font-weight: 600; border-radius: 12px;
  transition: color .2s;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab:active { transform: scale(.95); }

@media (max-width: 360px) {
  .big { font-size: 38px; }
  .topbar h1 { font-size: 28px; }
}

/* ==========================================================================
   Écran principal
   ========================================================================== */
.hero-until { font-size: 15px; color: var(--muted); font-weight: 500; }
.hero .sub { margin-top: 10px; font-size: 15px; }
.sub.warn, .sub.warn strong { color: var(--red); }
.hero-q { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 4px 0 8px; }
#heroWithout .hint { margin-bottom: 18px; }
.btn-soft {
  display: block; width: 100%; margin-top: 16px; border: none; cursor: pointer; border-radius: 14px; padding: 13px;
  background: var(--accent-soft); color: var(--accent); font-size: 16px; font-weight: 600; transition: transform .12s;
}
.btn-soft:active { transform: scale(.98); }
.small-gap { margin: -8px 0 6px; }
.chip-count.strong { color: var(--text); font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; }
.add-line {
  display: block; width: 100%; margin-top: 12px; cursor: pointer; border-radius: 14px; padding: 12px;
  border: 1.5px dashed var(--line-strong); background: none; color: var(--accent); font-size: 15px; font-weight: 600;
}
.add-line:active { background: var(--accent-soft); }
#fixedSummary { margin-bottom: 14px; }
#fixedSummary:empty { display: none; }

/* ==========================================================================
   Assistant de démarrage
   ========================================================================== */
.wizard { padding-bottom: 40px; }
.wiz-progress { display: flex; gap: 6px; padding: 4px 4px 0; }
.wiz-progress span { flex: 1; height: 5px; border-radius: 3px; background: var(--card-2); transition: background .3s; }
.wiz-progress span.on { background: var(--accent); }
.wiz-card h2 { font-size: 24px; margin: 6px 0 6px; letter-spacing: -0.02em; }
.wiz-card > .hint { margin-bottom: 18px; }
.wiz-list { display: flex; flex-direction: column; gap: 8px; }
.wiz-row { background: var(--card-2); border-radius: 14px; transition: background .15s; }
.wiz-row.on { background: var(--accent-soft); }
.wiz-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px; border: none; background: none; cursor: pointer;
  padding: 12px 14px; text-align: left; font-size: 16px; font-weight: 500;
}
.wiz-name { flex: 1; }
.wiz-name-input, .mini-amount input, .wiz-fields select {
  font: inherit; color: var(--text); background: var(--card); border: 2px solid transparent;
  border-radius: 10px; outline: none; min-width: 0; transition: border-color .2s;
}
.wiz-name-input:focus, .mini-amount input:focus, .wiz-fields select:focus { border-color: var(--accent); }
.wiz-name-input { flex: 1; font-size: 16px; padding: 8px 10px; }
.wiz-fields { display: flex; gap: 8px; padding: 0 14px 12px 52px; }
.mini-amount { position: relative; flex: 1; min-width: 0; }
.mini-amount input { width: 100%; font-size: 17px; font-weight: 600; padding: 10px 30px 10px 12px; font-variant-numeric: tabular-nums; }
.mini-amount span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.wiz-fields select {
  flex: 1; font-size: 15px; padding: 10px 30px 10px 10px; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.wiz-actions { display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 360px) {
  .wiz-fields { padding-left: 14px; }
}
