*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

/* ══════════ THÈMES ══════════ */
:root {
  /* clair (défaut) */
  --bg: #eef0f8;
  --text: #121528;
  --muted: rgba(18, 21, 40, .55);
  --faint: rgba(18, 21, 40, .08);
  --glass: rgba(255, 255, 255, .55);
  --glass-strong: rgba(255, 255, 255, .78);
  --glass-border: rgba(255, 255, 255, .9);
  --glass-shadow: 0 10px 40px -12px rgba(40, 46, 90, .25);
  --key: rgba(255, 255, 255, .7);
  --key-press: rgba(255, 255, 255, .95);
  --overlay: rgba(20, 22, 40, .28);
  --blob1: #a78bfa;
  --blob2: #38bdf8;
  --blob3: #f9a8d4;
  --blob-opacity: .55;
  --accent: #6d4aff;
  --accent2: #06b6d4;
  --danger: #e5484d;
  --ok: #16a34a;
  --wa: #25d366;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #07080f;
  --text: #f1f3ff;
  --muted: rgba(220, 226, 250, .55);
  --faint: rgba(255, 255, 255, .07);
  --glass: rgba(255, 255, 255, .055);
  --glass-strong: rgba(22, 24, 40, .72);
  --glass-border: rgba(255, 255, 255, .11);
  --glass-shadow: 0 10px 40px -12px rgba(0, 0, 0, .6);
  --key: rgba(255, 255, 255, .07);
  --key-press: rgba(255, 255, 255, .16);
  --overlay: rgba(0, 0, 0, .5);
  --blob1: #6d4aff;
  --blob2: #0891b2;
  --blob3: #be185d;
  --blob-opacity: .45;
  --accent: #8b6cff;
  --accent2: #22d3ee;
  --danger: #ff6369;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07080f;
    --text: #f1f3ff;
    --muted: rgba(220, 226, 250, .55);
    --faint: rgba(255, 255, 255, .07);
    --glass: rgba(255, 255, 255, .055);
    --glass-strong: rgba(22, 24, 40, .72);
    --glass-border: rgba(255, 255, 255, .11);
    --glass-shadow: 0 10px 40px -12px rgba(0, 0, 0, .6);
    --key: rgba(255, 255, 255, .07);
    --key-press: rgba(255, 255, 255, .16);
    --overlay: rgba(0, 0, 0, .5);
    --blob1: #6d4aff;
    --blob2: #0891b2;
    --blob3: #be185d;
    --blob-opacity: .45;
    --accent: #8b6cff;
    --accent2: #22d3ee;
    --danger: #ff6369;
    color-scheme: dark;
  }
}

/* ══════════ BASE ══════════ */
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .4s ease, color .4s ease;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.glass, .glass-strong {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
}
.glass-strong { background: var(--glass-strong); -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%); }

/* ══════════ FOND ══════════ */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: -1; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: var(--blob-opacity); transition: background .6s ease; }
.b1 { width: 60vmax; height: 60vmax; background: var(--blob1); top: -22vmax; left: -18vmax; animation: float1 22s ease-in-out infinite alternate; }
.b2 { width: 50vmax; height: 50vmax; background: var(--blob2); bottom: -20vmax; right: -18vmax; animation: float2 26s ease-in-out infinite alternate; }
.b3 { width: 34vmax; height: 34vmax; background: var(--blob3); top: 38%; left: 52%; opacity: calc(var(--blob-opacity) * .7); animation: float3 30s ease-in-out infinite alternate; }
@keyframes float1 { to { transform: translate(10vmax, 8vmax) scale(1.1); } }
@keyframes float2 { to { transform: translate(-8vmax, -10vmax) scale(1.15); } }
@keyframes float3 { to { transform: translate(-20vmax, -14vmax) scale(.9); } }
@media (prefers-reduced-motion: reduce) { .blob { animation: none; } }

/* ══════════ LAYOUT ══════════ */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 32px);
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 19px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 20px -6px var(--accent);
}
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }

.theme-switch { display: flex; padding: 4px; border-radius: 999px; gap: 2px; position: relative; }
.theme-switch button {
  width: 36px; height: 32px; border-radius: 999px; display: grid; place-items: center;
  color: var(--muted); transition: background .25s, color .25s;
}
.theme-switch button svg { width: 17px; height: 17px; }
.theme-switch button .fill { fill: currentColor; stroke: none; }
.theme-switch button[aria-checked="true"] { background: var(--key-press); color: var(--text); box-shadow: 0 2px 10px -4px rgba(0,0,0,.3); }

/* ══════════ RÉSUMÉ ══════════ */
.summary { text-align: center; margin-top: 34px; }
.summary-label { font-size: 13px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 500; }
.summary-total { font-size: 46px; font-weight: 700; letter-spacing: -.03em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.summary-sub { font-size: 14px; color: var(--muted); }

/* ══════════ GROS BOUTON ══════════ */
.hero { display: grid; place-items: center; margin: 30px 0 26px; }
.big-btn {
  position: relative; width: 184px; height: 184px; border-radius: 50%;
  display: grid; place-items: center;
  transition: transform .2s cubic-bezier(.3,1.5,.6,1);
}
.big-btn:active { transform: scale(.94); }
.big-ring {
  position: absolute; inset: -14px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent2), var(--blob3), var(--accent));
  filter: blur(26px); opacity: .55;
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .big-ring { animation: none; } }
.big-core {
  position: relative; width: 100%; height: 100%; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #fff; font-weight: 600; font-size: 17px; letter-spacing: .01em;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.45), transparent 45%),
    linear-gradient(145deg, var(--accent), var(--accent2));
  border: 1px solid rgba(255,255,255,.35);
  box-shadow: inset 0 -10px 30px rgba(0,0,0,.18), inset 0 2px 1px rgba(255,255,255,.4), 0 20px 50px -18px var(--accent);
}
.big-core svg { width: 58px; height: 58px; stroke-width: 2.4; }

/* ══════════ ACTIONS ══════════ */
.actions { display: flex; justify-content: center; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 22px; border-radius: 999px;
  font-weight: 600; font-size: 15px;
  transition: transform .15s;
}
.pill:active { transform: scale(.96); }
.pill svg { width: 18px; height: 18px; }

/* ══════════ HISTORIQUE ══════════ */
.history { margin-top: 36px; }
.history-head { display: flex; align-items: center; gap: 8px; padding: 0 4px 10px; }
h2 { font-size: 18px; font-weight: 600; }
.count { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--faint); color: var(--muted); }

.group { margin-bottom: 14px; }
.group-head { display: flex; justify-content: space-between; padding: 6px 6px 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.group-head b { font-weight: 600; font-variant-numeric: tabular-nums; }
.group-card { border-radius: 22px; overflow: hidden; }

.item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; text-align: left;
  transition: background .15s;
}
.item + .item { border-top: 1px solid var(--faint); }
.item:active { background: var(--faint); }
.item-icon {
  width: 38px; height: 38px; border-radius: 13px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  opacity: .9;
}
.item-main { flex: 1; min-width: 0; }
.item-desc, .item-time { display: block; }
.item-desc { font-weight: 500; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-desc.none { color: var(--muted); font-style: italic; font-weight: 400; }
.item-time { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.item-amount { font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 30% { background: color-mix(in srgb, var(--accent) 22%, transparent); } }

.empty { border-radius: 22px; padding: 26px 20px; text-align: center; font-weight: 500; }
.empty .muted { color: var(--muted); font-weight: 400; font-size: 14px; margin-top: 4px; }

.reset-link {
  display: block; margin: 26px auto 0; padding: 8px 14px; border-radius: 999px;
  font-size: 13px; color: var(--muted); opacity: .8;
  transition: color .2s, background .2s;
}
.reset-link:active { color: var(--danger); background: var(--faint); }

/* ══════════ OVERLAYS / SHEETS ══════════ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; visibility: hidden;
  transition: opacity .3s ease, visibility 0s linear .3s;
}
.overlay.open { opacity: 1; pointer-events: auto; visibility: visible; transition: opacity .3s ease; }
.overlay.center { align-items: center; padding: 20px; }

.sheet {
  width: 100%; max-width: 480px;
  max-height: calc(100dvh - env(safe-area-inset-top) - 10px);
  overflow-y: auto; overscroll-behavior: contain;
  border-radius: 32px 32px 0 0;
  border-bottom: 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateY(100%);
  transition: transform .42s cubic-bezier(.2, .9, .25, 1);
}
.overlay.open .sheet { transform: none; }
@media (min-width: 520px) {
  .overlay:not(.center) { align-items: center; }
  .sheet { border-radius: 32px; border-bottom: 1px solid var(--glass-border); }
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--muted); opacity: .4; margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { font-size: 19px; font-weight: 600; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--faint); color: var(--muted); }
.icon-btn svg { width: 18px; height: 18px; }
.entry-date { font-size: 13px; color: var(--muted); min-height: 0; }
.entry-date:empty { display: none; }

/* Montant */
.amount {
  text-align: center; margin: 14px 0 12px;
  font-size: 58px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden;
}
.amount .ghost { opacity: .25; }
.amount .cur { font-size: .55em; font-weight: 600; margin-left: .12em; opacity: .7; }
.amount.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* Description */
.desc-wrap input {
  width: 100%; height: 50px; padding: 0 18px; border-radius: 16px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--key); border: 1px solid var(--glass-border);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.desc-wrap input::placeholder { color: var(--muted); }
.desc-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--faint); border: 1px solid var(--glass-border);
  transition: transform .15s;
}
.chip:active { transform: scale(.95); }

/* Pavé numérique */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.keypad button {
  height: 60px; border-radius: 18px;
  font-size: 26px; font-weight: 500;
  background: var(--key);
  border: 1px solid var(--glass-border);
  transition: background .12s, transform .12s;
  display: grid; place-items: center;
}
.keypad button:active, .keypad button.pressed { background: var(--key-press); transform: scale(.96); }
.keypad .k-alt { background: transparent; border-color: transparent; color: var(--muted); }
.keypad .k-alt svg { width: 26px; height: 26px; stroke-width: 1.8; }
.keypad button[data-k="."] { font-size: 32px; font-weight: 700; }

.sheet-foot { display: flex; gap: 10px; margin-top: 14px; }
.primary, .secondary, .danger, .danger-ghost {
  height: 56px; border-radius: 18px; font-weight: 600; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .15s, opacity .2s, filter .2s;
}
.primary:active, .secondary:active, .danger:active, .danger-ghost:active { transform: scale(.97); }
.primary {
  flex: 1; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 30px -12px var(--accent), inset 0 1px 0 rgba(255,255,255,.35);
}
.primary:disabled { opacity: .35; box-shadow: none; filter: grayscale(.4); cursor: default; }
.secondary { background: var(--key); border: 1px solid var(--glass-border); padding: 0 18px; }
.danger { background: var(--danger); color: #fff; }
.danger-ghost { padding: 0 18px; color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* Export */
.preview {
  margin-top: 14px; padding: 16px; border-radius: 18px;
  background: var(--key); border: 1px solid var(--glass-border);
  font-family: inherit; font-size: 14.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  max-height: 46dvh; overflow-y: auto;
  -webkit-user-select: text; user-select: text;
}
.export-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.export-actions .primary { flex: 1 1 100%; }
.export-actions .secondary { flex: 1; }
.primary.wa { background: linear-gradient(135deg, #25d366, #128c7e); box-shadow: 0 10px 30px -12px #25d366, inset 0 1px 0 rgba(255,255,255,.35); }

/* Dialogue */
.dialog {
  width: 100%; max-width: 340px; border-radius: 30px; padding: 26px 22px 20px; text-align: center;
  transform: scale(.9); opacity: 0;
  transition: transform .35s cubic-bezier(.3,1.4,.5,1), opacity .25s;
}
.overlay.open .dialog { transform: none; opacity: 1; }
.dialog-icon {
  width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 14px;
  display: grid; place-items: center; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}
.dialog-icon svg { width: 26px; height: 26px; }
.dialog h3 { font-size: 20px; font-weight: 600; }
.dialog p { color: var(--muted); font-size: 15px; margin-top: 6px; line-height: 1.45; }
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dialog-actions button { flex: 1; height: 50px; font-size: 16px; padding: 0 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 80;
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px 12px 20px; border-radius: 999px;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  font-weight: 500; font-size: 15px; white-space: nowrap;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px -10px rgba(0,0,0,.4);
  transition: transform .35s cubic-bezier(.2,.9,.25,1), opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast button { font-weight: 700; color: var(--accent2); padding: 4px 8px; }
:root:not([data-theme="dark"]) .toast button { color: #a5b4fc; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast button { color: var(--accent); } }
:root[data-theme="dark"] .toast button { color: var(--accent); }
