/* Lucide — styles. Thème clair/sombre automatique, pensé pour l'iPhone. */
:root {
  --bg: #f3f4f6; --card: #ffffff; --card-2: #f8f9fa; --text: #0b0f14; --muted: #6b7280; --faint: #9ca3af;
  --line: #e7e9ee; --accent: #0ca678; --accent-soft: #e6f7f0; --warn: #e8590c; --warn-soft: #fff1e6;
  --danger: #e03131; --danger-soft: #fdecec; --ink: #0b0f14; --ink-text: #f1f3f5; --ink-muted: #9aa4b2;
  --eye: #3ddc97; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 18px; --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --card: #151a21; --card-2: #1b2129; --text: #f1f3f5; --muted: #8b949e; --faint: #6e7681;
    --line: #232a33; --accent: #3ddc97; --accent-soft: #12302a; --warn: #ff922b; --warn-soft: #33220f;
    --danger: #ff6b6b; --danger-soft: #3a1717; --ink: #151a21; --ink-text: #f1f3f5; --ink-muted: #8b949e;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) 0 calc(var(--tab-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--accent); }
.neg-strong { color: var(--danger); }
.hidden { display: none !important; }

/* ─── Structure ─── */
#app { max-width: 560px; margin: 0 auto; padding: 8px 16px 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
h1.title { font-size: 28px; letter-spacing: -.02em; margin: 6px 2px 14px; }
h2.section { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 4px 10px; display: flex; justify-content: space-between; align-items: baseline; }
h2.section a, h2.section button { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--accent); font-weight: 600; text-decoration: none; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

/* ─── Disponible (carte principale) ─── */
.hero { background: var(--ink); color: var(--ink-text); border-radius: 24px; padding: 20px 20px 18px; position: relative; overflow: hidden; }
.hero .label { color: var(--ink-muted); font-size: 14px; font-weight: 500; display: flex; justify-content: space-between; }
.hero .amount { font-size: 52px; font-weight: 700; letter-spacing: -.035em; line-height: 1.05; margin: 6px 0 4px; }
.hero .amount.negative { color: #ff8787; }
.hero .per-day { color: var(--ink-muted); font-size: 15px; }
.hero .per-day b { color: var(--ink-text); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 5px 10px; border-radius: 999px; }
.chip.ok { background: rgba(61, 220, 151, .16); color: var(--eye); }
.chip.warn { background: rgba(255, 146, 43, .18); color: #ffa94d; }
.chip.over { background: rgba(255, 107, 107, .18); color: #ff8787; }
.hero .chip { margin-top: 14px; }
.split { display: flex; height: 10px; border-radius: 6px; overflow: hidden; margin: 16px 0 12px; background: rgba(255,255,255,.08); }
.split span { display: block; height: 100%; }
.split span + span { border-left: 2px solid var(--ink); }
.legend { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.legend .k { color: var(--ink-muted); display: flex; align-items: center; gap: 8px; }
.legend .k i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.legend .v { text-align: right; font-variant-numeric: tabular-nums; }
.legend .total { border-top: 1px solid rgba(255,255,255,.12); padding-top: 8px; font-weight: 600; color: var(--ink-text); }
.hero-toggle { color: var(--ink-muted); font-size: 13px; margin-top: 10px; display: inline-flex; gap: 4px; align-items: center; }

/* ─── Bandeaux ─── */
a.banner { text-decoration: none; color: inherit; }
.banner { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); margin-top: 10px; text-align: left; width: 100%; }
.banner .emoji { font-size: 22px; }
.banner .txt { flex: 1; font-size: 15px; }
.banner .txt small { display: block; color: var(--muted); font-size: 13px; }
.banner.warn { background: var(--warn-soft); }
.banner.danger { background: var(--danger-soft); }
.banner.accent { background: var(--accent-soft); }
.chev { color: var(--faint); font-size: 20px; }

/* ─── Objectifs ─── */
.goal { display: block; width: 100%; text-align: left; }
.goal .row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.goal .name .ic { font-size: 18px; }
.goal .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.gauge { position: relative; height: 10px; border-radius: 6px; background: var(--card-2); margin-top: 10px; overflow: visible; }
.gauge > span { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--accent); max-width: 100%; }
.gauge > i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .35; border-radius: 1px; }
.gauge.warn > span { background: var(--warn); }
.gauge.over > span { background: var(--danger); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--accent); }
.status-dot.warn { background: var(--warn); } .status-dot.over { background: var(--danger); }

/* ─── Listes d'opérations ─── */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; text-align: left; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx .ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; flex: none; }
.tx .main { flex: 1; min-width: 0; }
.tx .t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .a { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .a.in { color: var(--accent); }
.tx .pending { font-size: 11px; color: var(--warn); font-weight: 600; margin-left: 6px; }
.tx.unsorted .s { color: var(--warn); font-weight: 500; }
.day { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 6px 8px; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* ─── Sélecteur de période, recherche, filtres ─── */
.period { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 14px; padding: 6px; box-shadow: var(--shadow); }
.period button { width: 40px; height: 36px; border-radius: 10px; font-size: 20px; color: var(--text); }
.period button:disabled { opacity: .25; }
.period .p { font-weight: 600; text-transform: capitalize; }
.search { width: 100%; margin-top: 10px; padding: 11px 14px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 14px; white-space: nowrap; }
.chips button.on { background: var(--text); color: var(--bg); }
.totals { display: flex; gap: 10px; margin-top: 12px; }
.totals .card { flex: 1; padding: 12px 14px; margin: 0 !important; }
.totals .k { font-size: 12px; color: var(--muted); }
.totals .v { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }

/* ─── Stats ─── */
.donut-wrap { display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 0; }
.donut-center { position: absolute; text-align: center; pointer-events: none; }
.donut-center .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.donut-center .k { font-size: 13px; color: var(--muted); }
.cat-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; width: 100%; text-align: left; }
.cat-row + .cat-row { border-top: 1px solid var(--line); }
.cat-row .ic { font-size: 20px; text-align: center; }
.cat-row .n { font-weight: 500; }
.cat-row .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.cat-row .bar { grid-column: 2 / 4; height: 6px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.cat-row .bar span { display: block; height: 100%; border-radius: 4px; }
.cat-row .delta { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.cat-row .delta .up { color: var(--warn); font-weight: 600; } .cat-row .delta .down { color: var(--accent); font-weight: 600; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart-legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ─── Formulaires, réglages ─── */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 6px; font-weight: 500; }
.field small { display: block; color: var(--faint); font-size: 12px; margin: 6px 2px 0; }
.input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); outline: none; -webkit-appearance: none; appearance: none; min-height: 46px; }
.input:focus { border-color: var(--accent); }
.input-suffix { position: relative; }
.input-suffix::after { content: attr(data-suffix); position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 18px; border-radius: 14px; font-weight: 600; background: var(--text); color: var(--bg); min-height: 48px; }
.btn.block { width: 100%; }
.btn.accent { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.accent { color: #06140e; } }
.btn.ghost { background: var(--card-2); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 13px 0; width: 100%; text-align: left; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .main { flex: 1; min-width: 0; }
.set-row .main small { display: block; color: var(--muted); font-size: 13px; }
.set-row .end { color: var(--muted); font-variant-numeric: tabular-nums; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ─── Feuilles (bottom sheets) ─── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; opacity: 0; transition: opacity .2s; }
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); max-width: 560px; margin: 0 auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet.show { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 4px 0 4px; font-size: 20px; letter-spacing: -.01em; }
.sheet .sub { color: var(--muted); font-size: 14px; word-break: break-word; }
.sheet .big-amount { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 10px 0 2px; }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.cat-grid button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 14px; background: var(--card-2); font-size: 12px; line-height: 1.2; text-align: center; border: 2px solid transparent; }
.cat-grid button .e { font-size: 22px; }
.cat-grid button.on { border-color: var(--accent); background: var(--accent-soft); }
.rule-box { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--card-2); }
.rule-box .head { display: flex; align-items: center; gap: 12px; }
.rule-box .head .main { flex: 1; font-size: 14px; }
.rule-box .input { margin-top: 10px; background: var(--card); }
.rule-box small { display: block; color: var(--muted); margin-top: 6px; font-size: 12px; }
.type-cards { display: grid; gap: 8px; margin-top: 10px; }
.type-cards button { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 14px; background: var(--card-2); text-align: left; border: 2px solid transparent; }
.type-cards button.on { border-color: var(--accent); background: var(--accent-soft); }
.type-cards .e { font-size: 24px; }
.type-cards b { display: block; }
.type-cards small { color: var(--muted); font-size: 13px; }

/* ─── Barre d'onglets ─── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--faint); text-decoration: none; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--text); }
.tabbar a .badge { position: absolute; margin: -22px 0 0 22px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--warn); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }

/* ─── Connexion ─── */
.login { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.login img { width: 92px; height: 92px; border-radius: 22px; margin-bottom: 18px; }
.login h1 { margin: 0; font-size: 32px; letter-spacing: -.02em; }
.login p { color: var(--muted); margin: 6px 0 28px; }
.login form { width: 100%; max-width: 320px; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; }

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

.skeleton { background: linear-gradient(90deg, var(--card-2), var(--line), var(--card-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 12px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ─── Animation d'ouverture : l'œil s'ouvre, la pupille réagit, on plonge dedans ─── */
#splash { position: fixed; inset: 0; z-index: 100; background: #0b0f14; display: grid; place-items: center; overflow: hidden;
  transition: opacity .3s ease .42s; }
#splash .splash-wrap { width: min(46vw, 220px); transform-origin: 50% 50%; will-change: transform; }
#splash .splash-eye { display: block; width: 100%; height: auto; transform-origin: 50% 50%; animation: eye-open .8s cubic-bezier(.3, .7, .3, 1) both; }
#splash .splash-pupil { transform-box: fill-box; transform-origin: center; animation: pupil 1.2s ease both; }
@keyframes eye-open { 0%, 22% { transform: scaleY(.04); } 75% { transform: scaleY(1.07); } 100% { transform: scaleY(1); } }
@keyframes pupil { 0%, 50% { transform: scale(1); } 72% { transform: scale(.72); } 100% { transform: scale(1.15); } }
#splash.dive { opacity: 0; pointer-events: none; }
#splash.dive .splash-wrap { transform: scale(34); transition: transform .65s cubic-bezier(.7, 0, .84, 0); }
@media (prefers-reduced-motion: reduce) { #splash .splash-eye, #splash .splash-pupil { animation: none; } #splash.dive .splash-wrap { transform: none; } }

.tabbar a { font-size: 10px; }
.big-total { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; margin: 6px 2px 4px; font-size: 16px; }

/* ─── Refonte : lecture des dépenses ─── */
.meter { position: relative; height: 12px; border-radius: 7px; background: rgba(255,255,255,.1); margin: 18px 0 8px; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 7px; background: var(--eye); }
.meter > span.warn { background: #ffa94d; } .meter > span.over { background: #ff6b6b; }
.meter > i { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #fff; border-radius: 1px; opacity: .9; }
.meter-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-muted); }
.meter-legend b { color: var(--ink-text); }
.projection { margin-top: 12px; font-size: 14px; padding: 9px 12px; border-radius: 12px; background: rgba(255,255,255,.06); color: var(--ink-text); }
.projection.neg b { color: #ff8787; } .projection.pos b { color: var(--eye); }
.hero-details { margin-top: 12px; }
.hero-details summary { color: var(--ink-muted); font-size: 13px; cursor: pointer; list-style: none; }
.hero-details summary::after { content: ' ▾'; }
.hero-details[open] summary::after { content: ' ▴'; }
.hero-details .legend { margin-top: 10px; }
.cat-line { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; width: 100%; text-align: left; }
.cat-line + .cat-line { border-top: 1px solid var(--line); }
.cat-line .ic { font-size: 20px; width: 28px; text-align: center; padding-top: 1px; }
.cat-line .main { flex: 1; min-width: 0; display: block; }
.cat-line .row { display: flex; justify-content: space-between; gap: 8px; }
.cat-line .n { font-weight: 500; }
.cat-line .gauge { display: block; margin-top: 8px; height: 8px; }
.cat-line .s { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; }
.acc-strip { display: flex; justify-content: space-between; gap: 8px; text-decoration: none; color: inherit; }
.acc-strip span { display: flex; flex-direction: column; }
.acc-strip small { color: var(--muted); font-size: 12px; }
.acc-strip b { font-size: 18px; }
.legend.plain .k { color: var(--muted); }
.legend.plain .total { border-top-color: var(--line); color: var(--text); }
.mini-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 15px; gap: 10px; }
.mini-row + .mini-row { border-top: 1px solid var(--line); }
.link { color: var(--accent); font-size: 13px; font-weight: 600; }
.idea .row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.trend { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: end; padding: 9px 0; }
.trend + .trend { border-top: 1px solid var(--line); }
.trend .n { font-size: 14px; align-self: center; }
.trend .spark { display: flex; gap: 3px; align-items: flex-end; height: 30px; }
.trend .spark i { width: 7px; border-radius: 2px; display: block; }
.trend .v { text-align: right; min-width: 70px; font-weight: 600; font-size: 14px; display: flex; flex-direction: column; }
.trend .v small { font-size: 11px; font-weight: 600; }
.trend .v small.up { color: var(--warn); } .trend .v small.down { color: var(--accent); }
