/* =====================================================================
   ÉQUILIBRE — Styles (mobile d'abord, thèmes clair et sombre)
   ===================================================================== */
:root {
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #ccfbf1;
  --on-accent: #ffffff;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --income: #15803d;
  --expense: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft: #134e4a;
  --on-accent: #04211e;
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #1c2740;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #23304a;
  --income: #4ade80;
  --expense: #f87171;
  --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --accent: #2dd4bf; --accent-strong: #5eead4; --accent-soft: #134e4a; --on-accent: #04211e;
    --bg: #0b1120; --surface: #131c2e; --surface-2: #1c2740;
    --text: #e2e8f0; --muted: #94a3b8; --border: #23304a;
    --income: #4ade80; --expense: #f87171; --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Mise en page ---------- */
.screen {
  max-width: 560px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.topbar .sub { color: var(--muted); font-size: .9rem; }
.section { margin-top: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.section-head a, .link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem; background: none; border: 0; padding: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 10px; }

/* ---------- Carte solde ---------- */
.hero {
  background: linear-gradient(135deg, #0f766e, #0e7490);
  color: #fff; border: 0; padding: 20px;
}
.hero .label { opacity: .85; font-size: .9rem; }
.hero .big { font-size: 2rem; font-weight: 750; margin: 4px 0 14px; letter-spacing: -.02em; }
.hero .split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero .split > div { background: rgba(255,255,255,.14); border-radius: 12px; padding: 10px 12px; }
.hero .split .v { font-weight: 700; }

/* ---------- Comptes (défilement horizontal) ---------- */
.hscroll { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scroll-snap-type: x mandatory; margin: 0 -2px; }
.hscroll::-webkit-scrollbar { display: none; }
.acc-chip {
  flex: 0 0 auto; min-width: 140px; scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
  border-top: 4px solid var(--c, var(--accent)); text-align: left;
}
.acc-chip .n { font-size: .85rem; color: var(--muted); }
.acc-chip .b { font-weight: 700; margin-top: 2px; }

/* ---------- Listes ---------- */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 0; border-bottom: 1px solid var(--border); background: none; width: 100%; text-align: left;
}
.row:last-child { border-bottom: 0; }
button.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; display: block; }
.row .title, .row .meta { display: block; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; }
.ico {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 1.2rem;
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent);
}
.day-head { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; display: flex; justify-content: space-between; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .e { font-size: 2.2rem; }

/* ---------- Barres de progression ---------- */
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; width: var(--p, 0%); background: var(--income); border-radius: 99px; transition: width .4s; }
.bar.warn > span { background: var(--warn); }
.bar.over > span { background: var(--expense); }
.budget-line { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; color: var(--muted); margin-top: 6px; }

/* ---------- Habitudes ---------- */
.habit { display: flex; align-items: center; gap: 12px; }
.habit .main { flex: 1; min-width: 0; }
.check {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  border: 2.5px solid var(--c, var(--accent)); background: transparent;
  display: grid; place-items: center; font-size: 1.2rem; color: #fff; transition: transform .15s, background .2s;
}
.check.done { background: var(--c, var(--accent)); }
.check:active { transform: scale(.9); }
.check:disabled { opacity: .35; border-style: dashed; }
.week { display: flex; gap: 6px; margin-top: 10px; }
.dot {
  flex: 1; min-width: 0; border: 0; border-radius: 10px; padding: 6px 0;
  background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.dot b { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.dot.done b { background: var(--c, var(--accent)); }
.dot.off { opacity: .4; }
.dot.today { outline: 2px solid var(--c, var(--accent)); outline-offset: -2px; }
.streak { font-size: .82rem; color: var(--muted); }
.ring {
  --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center;
}
.ring > span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 650;
  background: var(--accent); color: var(--on-accent); min-height: 46px;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--expense); border: 1px solid var(--expense); }
.btn:disabled { opacity: .6; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; font-size: 1.1rem; }

.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--on-accent); font-size: 2rem; line-height: 1;
  box-shadow: 0 8px 24px rgba(15, 118, 110, .35); z-index: 20;
}

/* ---------- Navigation du bas ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.nav ul { list-style: none; margin: 0 auto; padding: 0; display: flex; max-width: 560px; height: var(--nav-h); }
.nav li { flex: 1; }
.nav a {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.nav a .i { font-size: 1.3rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.nav a[aria-current="page"] { color: var(--accent); }
.nav a[aria-current="page"] .i { filter: none; opacity: 1; }

/* ---------- Segments / sélecteurs ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.kind button[data-v="expense"][aria-pressed="true"] { color: var(--expense); }
.seg.kind button[data-v="income"][aria-pressed="true"] { color: var(--income); }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.month-nav strong { text-transform: capitalize; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- Formulaires ---------- */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 12px; padding: 12px 14px; min-height: 46px; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.input.amount { font-size: 1.8rem; font-weight: 750; text-align: center; letter-spacing: -.02em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.swatches, .emojis, .weekdays { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; background: var(--c); }
.swatches button[aria-pressed="true"] { border-color: var(--text); }
.emojis button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-size: 1.25rem; }
.emojis button[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.weekdays button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); font-weight: 700; font-size: .8rem; color: var(--muted); }
.weekdays button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.form-actions .btn { flex: 1; }
.error { color: var(--expense); font-size: .88rem; margin-top: 10px; min-height: 1em; }

/* ---------- Fenêtre modale (feuille du bas sur mobile) ---------- */
dialog#modal {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
  margin: auto auto 0; border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
}
dialog#modal::backdrop { background: rgba(2, 6, 23, .5); }
dialog#modal[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@media (min-width: 640px) { dialog#modal { margin: auto; border-radius: 22px; } }
.sheet { padding: 18px 18px calc(22px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: inherit; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--border); margin: 0 auto 12px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: .92rem;
  max-width: calc(100% - 32px); width: max-content; z-index: 100; transition: .25s; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.warn { background: #b45309; }
#toast.bad { background: #b91c1c; }

/* ---------- Écran de connexion / démarrage ---------- */
.splash, .auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; text-align: center; }
.logo-mark {
  width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #0f766e, #0e7490); color: #fff;
  display: grid; place-items: center; font-size: 2.2rem; font-weight: 800;
}
.auth form { width: 100%; max-width: 380px; text-align: left; }
.auth h1 { text-align: center; }
.auth .tagline { text-align: center; color: var(--muted); margin: 6px 0 18px; }
.demo-banner {
  background: var(--accent-soft); color: var(--text); border-radius: 12px;
  padding: 10px 12px; font-size: .85rem; margin-bottom: 14px;
}
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

/* =====================================================================
   V2 — Sous-onglets, épargne, dettes, planning, statistiques
   ===================================================================== */
.subtabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 14px; padding: 4px; margin-bottom: 16px; position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 15; box-shadow: var(--shadow); }
.subtabs a { flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 650; font-size: .88rem; white-space: nowrap; }
.subtabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.alert-card { margin-top: 14px; border-radius: var(--radius); overflow: hidden; border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border)); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.alert-card .row { border-bottom-color: color-mix(in srgb, var(--warn) 25%, var(--border)); }
.warn-text { color: var(--warn); font-weight: 600; }

a.card.mini { text-decoration: none; color: inherit; display: block; }
a.card.mini strong { display: block; font-size: 1.05rem; margin: 2px 0; }
.section.grid2 { display: grid; }

button.card.goal { display: block; width: 100%; text-align: left; color: inherit; margin-top: 10px; }
button.card.goal .title { font-weight: 650; }
button.card.goal .meta { color: var(--muted); font-size: .82rem; }
.bar.accent > span { background: var(--accent); }

.timeline .row { gap: 10px; }
.timeline .time { width: 46px; flex: 0 0 auto; font-weight: 700; font-size: .9rem; color: var(--muted); }
.timeline .row.is-done .title { text-decoration: line-through; color: var(--muted); }
.timeline .row.is-next { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.timeline .main { min-width: 0; }
.badge.accent { background: var(--accent); color: var(--on-accent); }

.check-line { display: flex !important; gap: 10px; align-items: center; }
.check-line input { width: 20px; height: 20px; accent-color: var(--accent); }
.check-line > span { margin: 0 !important; color: var(--text) !important; font-size: .95rem !important; }

.input.search { min-height: 42px; padding: 9px 14px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid .card { padding: 14px; margin: 0; }
.stat-grid .card + .card { margin-top: 0; }
.stat-grid strong { display: block; font-size: 1.1rem; margin-top: 2px; }

.donut-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.donut-center { font-weight: 750; font-size: 17px; fill: var(--text); }
.legend { list-style: none; margin: 0; padding: 0; width: 100%; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto 44px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.legend li:last-child { border-bottom: 0; }
.legend i { width: 12px; height: 12px; border-radius: 4px; }
.legend .muted { text-align: right; }
.dotl { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 8px; vertical-align: -1px; }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--border); stroke-dasharray: 3 4; }
svg.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
svg.heat { max-width: 300px; }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 8px; }
.heat-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.sheet-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.sheet-foot .icon-btn { width: 36px; height: 36px; font-size: .95rem; }
.timeline .time.expense { color: var(--expense); }
.grid2 > .card + .card, .section.grid2 > .card + .card { margin-top: 0; }

/* =====================================================================
   V3 — Responsive (mobile · tablette · ordinateur), connexion, partage, exports
   ===================================================================== */
html { -webkit-text-size-adjust: 100%; }
img, svg { max-width: 100%; }
.wrap { width: 100%; margin: 0 auto; }
.nav-brand, .nav-space { display: none; }
.nav a .l { line-height: 1.1; }
.logo-mark.sm { width: 38px; height: 38px; border-radius: 12px; font-size: 1.2rem; margin: 0; }
.logo-mark.lg { width: 84px; height: 84px; border-radius: 26px; font-size: 2.6rem; margin: 0 0 18px; background: rgba(255,255,255,.16); }
.topbar { flex-wrap: wrap; }
.topbar h1 { min-width: 0; overflow-wrap: anywhere; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.small-btn { min-height: 36px; padding: 7px 12px; font-size: .85rem; border-radius: 10px; flex: 0 0 auto; }
button.plain, .main.plain { background: none; border: 0; padding: 0; text-align: left; color: inherit; flex: 1; min-width: 0; }
.badge.ok { background: color-mix(in srgb, var(--income) 18%, transparent); color: var(--income); }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: 6px; }
.input.amount-sm { font-size: 1.25rem; font-weight: 700; }
.fs { border: 0; padding: 0; margin: 0; min-width: 0; }
.fs:disabled .input { opacity: .85; }
.readonly [data-action^="del-"], .readonly [data-action^="edit-goal"], .readonly [data-action^="edit-debt"] { display: none; }

/* Bandeau espace partagé */
.space-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: color-mix(in srgb, #8b5cf6 12%, var(--surface)); border: 1px solid color-mix(in srgb, #8b5cf6 35%, var(--border));
  border-radius: 14px; padding: 10px 12px; margin-bottom: 14px; font-size: .9rem;
}
.alert-card.invite { border-color: color-mix(in srgb, #8b5cf6 45%, var(--border)); background: color-mix(in srgb, #8b5cf6 10%, var(--surface)); }
.alert-card + .alert-card { margin-top: 10px; }

/* Choix de rôle / format */
.role-pick, .format-pick { display: grid; gap: 8px; }
.role-pick { grid-template-columns: 1fr 1fr; }
.role-pick button, .format-pick button {
  border: 1.5px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 12px; text-align: left; color: var(--text);
  display: flex; flex-direction: column; gap: 2px;
}
.format-pick button { flex-direction: row; align-items: center; gap: 12px; }
.format-pick .fi { font-size: 1.6rem; }
.role-pick small, .format-pick small { color: var(--muted); font-size: .8rem; display: block; }
.role-pick button[aria-pressed="true"], .format-pick button[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.export-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.export-tile { border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 12px 4px; font-weight: 650; font-size: .82rem; color: var(--text); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.export-tile span { font-size: 1.5rem; }
.export-tile:active { transform: scale(.97); }

/* Grilles de cartes */
.cards > .card, .cards > button.card { margin-top: 10px; }
.cols { display: flex; flex-direction: column; }
.cols > .col { display: contents; }
.cols.home .o1 { order: 1; } .cols.home .o2 { order: 2; } .cols.home .o3 { order: 3; } .cols.home .o4 { order: 4; } .cols.home .o5 { order: 5; }
.stat-grid.two { grid-template-columns: 1fr 1fr; }
.acc-chip.add { --c: var(--border); }

/* ---------- Page de connexion ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr; background: var(--bg); }
.login-brand { display: none; }
.login-main { display: grid; place-items: center; padding: calc(24px + env(safe-area-inset-top)) 18px 32px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); padding: 26px 22px; }
.login-card h2 { font-size: 1.5rem; margin-top: 6px; }
.login-card > .muted { margin: 4px 0 16px; }
.login-mobile-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 1.15rem; }
.login-mobile-brand .logo-mark { width: 42px; height: 42px; border-radius: 13px; font-size: 1.3rem; margin: 0; }
.pw { position: relative; }
.pw .input { padding-right: 48px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; font-size: 1.1rem; width: 38px; height: 38px; border-radius: 10px; }
.login-row { display: flex; justify-content: space-between; margin-top: 10px; font-size: .9rem; }
.demo-box { margin-top: 18px; background: var(--accent-soft); border-radius: 14px; padding: 12px; font-size: .86rem; }
.demo-box .btn { margin-top: 10px; }
.login-foot { text-align: center; margin: 16px 0 0; }

/* ---------- Petits téléphones ---------- */
@media (max-width: 370px) {
  .screen { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 1.3rem; }
  .hero .big { font-size: 1.6rem; }
  .hero .split { grid-template-columns: 1fr; }
  .nav a { font-size: .66rem; }
  .export-grid { grid-template-columns: repeat(2, 1fr); }
  .subtabs a { font-size: .8rem; padding: 8px 2px; }
  .stat-grid { grid-template-columns: 1fr; }
  .legend li { grid-template-columns: 12px 1fr auto; }
  .legend li .muted { display: none; }
  .role-pick { grid-template-columns: 1fr; }
  .timeline .time { width: 40px; font-size: .8rem; }
}

/* ---------- Tablettes (et grands téléphones en paysage) ---------- */
@media (min-width: 640px) {
  .screen { max-width: 760px; padding-left: 24px; padding-right: 24px; }
  .nav ul { max-width: 760px; }
  .fab { right: max(24px, calc(50% - 356px)); }
  .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
  .cards > .card, .cards > button.card { margin: 0; }
  .cards > .empty { grid-column: 1 / -1; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-grid.two { grid-template-columns: 1fr 1fr; }
  .donut-card { flex-direction: row; align-items: center; gap: 24px; }
  .donut-card .legend { flex: 1; }
  .format-pick { grid-template-columns: 1fr 1fr; }
  .acc-grid { flex-wrap: wrap; overflow: visible; }
  .acc-grid .acc-chip { flex: 1 1 160px; }
  dialog#modal { margin: auto; border-radius: 22px; max-height: 88vh; }
  dialog#modal.wide { max-width: 680px; }
  .login-card { padding: 34px 32px; }
}

/* ---------- Ordinateur : menu latéral + mise en page en colonnes ---------- */
@media (min-width: 1024px) {
  :root { --side: 248px; }
  body { font-size: 15.5px; }
  .nav {
    top: 0; bottom: 0; left: 0; right: auto; width: var(--side); height: 100vh;
    border-top: 0; border-right: 1px solid var(--border); background: var(--surface); backdrop-filter: none;
    padding: 22px 14px; display: flex; flex-direction: column; gap: 18px;
  }
  .nav-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 6px; }
  .nav ul { flex-direction: column; height: auto; max-width: none; gap: 4px; margin: 0; flex: 1; }
  .nav li { flex: 0 0 auto; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 14px; border-radius: 12px; font-size: .95rem; height: auto; color: var(--muted); }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
  .nav a .i { font-size: 1.15rem; }
  .nav-space { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; color: var(--text); font-weight: 600; text-align: left; }
  .nav-space .l { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .screen { max-width: none; margin: 0 0 0 var(--side); padding: 30px clamp(24px, 3.5vw, 56px) 80px; }
  .wrap { max-width: 1180px; }
  .topbar { margin-bottom: 20px; }
  h1 { font-size: 1.75rem; }
  .subtabs { position: static; max-width: 560px; }

  .cols { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 0 28px; align-items: start; }
  .cols > .col { display: block; min-width: 0; }
  .hero { display: grid; grid-template-columns: 1fr 1.2fr; align-items: center; gap: 0 24px; padding: 26px 28px; }
  .hero .label:first-child { grid-column: 1; }
  .hero .big { grid-column: 1; margin-bottom: 0; font-size: 2.3rem; }
  .hero .split { grid-column: 2; grid-row: 1 / span 2; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; align-items: start; }
  .settings > .section:first-child { margin-top: 22px; }
  .export-grid { grid-template-columns: repeat(4, 1fr); }
  .fab { right: 40px; bottom: 36px; }
  #toast { left: calc(50% + var(--side) / 2); bottom: 36px; }
  .row { padding: 13px 16px; }
  button.row:hover, button.card.goal:hover, .acc-chip:hover, .export-tile:hover { filter: brightness(.98); }
  :root[data-theme="dark"] button.row:hover { background: var(--surface-2); }

  /* Connexion : panneau de marque à gauche */
  .login { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .login-brand {
    display: flex; align-items: center; color: #fff; padding: 60px clamp(40px, 6vw, 96px);
    background: radial-gradient(circle at 15% 15%, rgba(255,255,255,.14), transparent 40%), linear-gradient(140deg, #0f766e, #0e7490 60%, #155e75);
  }
  .login-brand-in { max-width: 520px; }
  .login-brand h1 { font-size: 2.8rem; letter-spacing: -.02em; }
  .login-brand .lead { font-size: 1.2rem; opacity: .9; margin: 10px 0 34px; }
  .login-feats { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; }
  .login-feats li { display: flex; gap: 14px; align-items: flex-start; line-height: 1.4; opacity: .95; }
  .login-feats li > span { font-size: 1.4rem; width: 46px; height: 46px; border-radius: 14px; background: rgba(255,255,255,.14); display: grid; place-items: center; flex: 0 0 auto; }
  .login-mobile-brand { display: none; }
  .login-card { border: 0; box-shadow: none; background: transparent; max-width: 440px; }
}

/* ---------- Très grands écrans ---------- */
@media (min-width: 1500px) {
  .wrap { max-width: 1320px; }
  .stat-grid { gap: 14px; }
}

/* Paysage sur téléphone : la feuille modale prend toute la hauteur */
@media (max-height: 500px) and (orientation: landscape) {
  dialog#modal { max-height: 100vh; border-radius: 16px; }
  .login-main { padding-top: 12px; }
}

/* Impression (Ctrl+P) : pages propres */
@media print {
  .nav, .fab, #toast, .subtabs, .topbar-actions, .space-banner button { display: none !important; }
  .screen { margin: 0 !important; padding: 0 !important; max-width: none; }
  body { background: #fff; }
}
.alert-card.invite { margin: 0 0 14px; }
.alert-card + .hero { margin-top: 14px; }
@media (min-width: 640px) { .acc-grid .acc-chip.add { flex: 0 1 150px; } }
/* Récapitulatif 3 colonnes (Opérations) : s'adapte aux petits écrans */
.sum3 { margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sum3 > div:nth-child(2) { text-align: center; }
.sum3 > div:nth-child(3) { text-align: right; }
.sum3 strong { display: block; font-size: clamp(.82rem, 3.7vw, 1.05rem); white-space: normal; overflow-wrap: anywhere; line-height: 1.25; }
@media (max-width: 420px) { .sum3 { padding: 12px; gap: 6px; } }
.due-chip { margin-top: 8px; font-size: .8rem; padding: 5px 10px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip[data-quick][aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
/* Les lignes de détail chiffrées peuvent passer à la ligne sur petit écran */
.small.num, .meta.num, div.num.small { white-space: normal; }
.habit .main, .goal .main { min-width: 0; }

/* =====================================================================
   V4 — récurrences, reçus, verrouillage
   ===================================================================== */
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
/* Reçus */
.tx-extra { align-items: end; }
.att-box { min-height: 46px; display: flex; align-items: center; }
.att-add { display: inline-flex; align-items: center; gap: 6px; border: 1px dashed var(--border); border-radius: 12px; padding: 10px 12px; cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--accent); }
.att-chip { font-size: .88rem; display: flex; gap: 10px; flex-wrap: wrap; }
.file-drop { display: grid; place-items: center; border: 2px dashed var(--border); border-radius: 16px; padding: 28px 12px; cursor: pointer; font-weight: 650; color: var(--accent); margin: 12px 0; }
.file-drop input { display: none; }
.att-view img { width: 100%; border-radius: 12px; margin-bottom: 10px; }
.tx-flags { display: block; font-size: .72rem; text-align: right; opacity: .8; }

/* Écran de verrouillage */
.lock-screen { position: fixed; inset: 0; z-index: 1000; background: var(--bg); display: grid; place-items: center; padding: 24px; text-align: center; }
.lock-in { width: 100%; max-width: 320px; }
.lock-in h2 { margin: 6px 0 4px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 22px 0; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots i.on { background: var(--accent); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.keypad button { height: 64px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: 1.5rem; font-weight: 600; color: var(--text); width: 64px; justify-self: center; }
.keypad button:active { background: var(--accent-soft); }
.pin-in { letter-spacing: .4em; font-size: 1.3rem; text-align: center; }


/* =====================================================================
   V5 — Hors ligne
   ===================================================================== */
.net-pill {
  position: fixed; bottom: calc(var(--nav-h) + 26px + env(safe-area-inset-bottom)); left: max(16px, calc(50% - 264px)); z-index: 90;
  border: 0; border-radius: 99px; padding: 7px 14px; font-size: .8rem; font-weight: 650; color: #fff; background: #475569;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap;
}
.net-pill[hidden] { display: none; }
.net-pill.offline { background: #b45309; }
.net-pill.syncing { background: #0e7490; }
@media (min-width: 640px) { .net-pill { left: max(24px, calc(50% - 356px)); } }
@media (min-width: 1024px) { .net-pill { left: calc(var(--side) + 24px); bottom: 36px; } }
.sync-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: .88rem; }
