/* Oursin — mobile d'abord. */

:root {
  /* Méditerranée : sable, bleu calanque, terracotta, soleil — l'oursin violet reste dans le logo */
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe1;
  --text: #1b2a35;
  --muted: #6a7680;
  --line: #e9e1d5;
  --accent: #1e4d78;
  --accent-2: #163b5e;
  --accent-soft: #e4ebf4;
  --on-accent: #ffffff;
  --terracotta: #d8694c;
  --soleil: #f2c14e;
  --pos: #2f7a4f;
  --pos-soft: #e4f1e7;
  --warn: #a8621b;
  --warn-soft: #fbeedd;
  --danger: #bf4b2c;
  --danger-soft: #fbe7e0;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgb(27 42 53 / .05), 0 6px 24px rgb(30 77 120 / .07);
  --tabbar-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1620;
    --surface: #152131;
    --surface-2: #1d2b3d;
    --text: #eef3f5;
    --muted: #98a8b2;
    --line: #28374a;
    --accent: #8fb6e0;
    --accent-2: #4f7fb0;
    --accent-soft: #1c2e45;
    --on-accent: #0d1620;
    --terracotta: #e8805e;
    --pos: #6cc895;
    --pos-soft: #16302a;
    --warn: #f2c14e;
    --warn-soft: #33290f;
    --danger: #f2876a;
    --danger-soft: #3a1e17;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 750; line-height: 1.15; }
h2 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
small, .petit { font-size: .82rem; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--danger); }
.icon { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 18px; height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Structure ------------------------------------------------------------ */

main { width: 100%; max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }
.page-tete { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; }
.page-tete h1 { flex: 1; min-width: 0; }
.page-tete .retour { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.surtitre { color: var(--muted); font-size: .9rem; font-weight: 500; margin-bottom: 2px; }
.pile > * + * { margin-top: 16px; }
section + section, .carte + .carte, .carte + section, section + .carte { margin-top: 16px; }

.tete-app { display: none; }

.carte { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.carte.plate { padding: 6px 0; }
.carte.plate > .section-tete { padding: 12px 18px 4px; }
.grille-accueil > * + * { margin-top: 16px; }
.section-tete { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-tete a { font-size: .9rem; font-weight: 600; }

/* --- Barre d'onglets (mobile) ------------------------------------------------ */

.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px 8px env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: start;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
@media (min-width: 600px) { .onglets { padding-left: calc(50vw - 280px); padding-right: calc(50vw - 280px); } }
.onglets a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: .7rem; font-weight: 600; }
.onglets a.actif { color: var(--accent); }
.onglets a.plus span.rond {
  display: grid; place-items: center; width: 52px; height: 52px; margin-top: -22px; border-radius: 18px;
  background: var(--terracotta); color: #fff; box-shadow: 0 8px 20px rgb(216 105 76 / .38);
}
.onglets a.plus .icon { width: 26px; height: 26px; stroke-width: 2.4; }

@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .onglets { display: none; }
  .tete-app {
    display: flex; align-items: center; gap: 28px; position: sticky; top: 0; z-index: 20;
    padding: 12px max(24px, calc((100vw - 1040px) / 2 + 16px));
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
  }
  .tete-app nav { display: flex; gap: 4px; flex: 1; }
  .tete-app nav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: .95rem; }
  .tete-app nav a.actif, .tete-app nav a:hover { color: var(--text); background: var(--surface); }
  .tete-app .bouton { height: 40px; background: var(--terracotta); color: #fff; }
  main { max-width: 1040px; padding-top: 24px; }
  main.etroit { max-width: 640px; }
  .grille-accueil { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; align-items: start; }
  .grille-accueil > * { margin: 0 !important; }
  .grille-accueil .large { grid-column: 1 / -1; }
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.02em; }
.logo img { width: 42px; height: 42px; margin: -8px -4px -8px -8px; }

/* --- Tableau de bord ---------------------------------------------------------- */

.hero {
  position: relative; overflow: hidden;
  background: radial-gradient(120% 140% at 100% 0%, #2b5f8e 0%, #1e4d78 45%, #12304f 100%);
  color: #fff; border-radius: 26px; padding: 22px 20px 20px;
  box-shadow: 0 16px 40px rgb(18 48 79 / .28);
}
@media (prefers-color-scheme: dark) { .hero { background: radial-gradient(120% 140% at 100% 0%, #2a5582 0%, #1b3f66 50%, #0f2640 100%); box-shadow: none; } }
.hero .surtitre { color: rgb(255 255 255 / .75); }
.hero-phrase { font-size: 1.12rem; line-height: 1.4; margin: 6px 0 18px; }
.hero-phrase strong { display: block; font-size: clamp(2.3rem, 12vw, 3rem); line-height: 1.05; font-weight: 800; letter-spacing: -.03em; margin: 2px 0 4px; }
.hero-phrase b { font-weight: 700; }
.jauge { position: relative; height: 14px; border-radius: 999px; background: rgb(255 255 255 / .18); display: flex; overflow: hidden; }
.jauge span { height: 100%; }
.jauge .j-depense { background: #fff; }
.jauge .j-avenir { background: repeating-linear-gradient(-45deg, rgb(255 255 255 / .55) 0 4px, rgb(255 255 255 / .3) 4px 8px); }
.jauge-repere { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 2px; background: var(--soleil); }
.jauge-cadre { position: relative; }
.legende { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .85rem; color: rgb(255 255 255 / .85); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }
.legende i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.hero-reste { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgb(255 255 255 / .18); display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hero-reste strong { font-size: 1.35rem; font-weight: 750; }
.hero.alerte .hero-reste strong { color: #ffd0cc; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--surface); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow); color: inherit; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .libelle { font-size: .82rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .valeur { font-size: 1.3rem; font-weight: 750; letter-spacing: -.02em; }
.stat small { color: var(--muted); }
a.stat:active { transform: scale(.98); }

.alerte-ligne { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.alerte-ligne .icon { flex: none; }
.alerte-ligne span { flex: 1; }

/* --- Listes ------------------------------------------------------------------------ */

.liste { list-style: none; margin: 0; padding: 0; }
.ligne { display: flex; align-items: center; gap: 12px; padding: 11px 18px; color: inherit; min-height: 60px; }
a.ligne:hover { background: var(--surface-2); }
.carte:not(.plate) .ligne { padding-left: 0; padding-right: 0; }
.bulle {
  flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px;
  background: var(--surface-2); font-size: 1.2rem; line-height: 1;
}
.bulle.vide { color: var(--muted); font-size: 1rem; font-weight: 700; border: 1.5px dashed var(--line); background: transparent; }
.ligne-texte { flex: 1; min-width: 0; }
.ligne-titre { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-sous { display: block; font-weight: 400; font-size: .83rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-montant { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.ligne-montant.pos { color: var(--pos); }
.ligne-montant small { display: block; font-weight: 500; color: var(--muted); }
.jour { position: sticky; top: 0; z-index: 1; padding: 14px 18px 6px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface); }
.jour span { float: right; text-transform: none; letter-spacing: 0; font-weight: 600; }
@media (min-width: 900px) { .jour { top: 65px; } }

.pastille { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.pastille.accent { background: var(--accent-soft); color: var(--accent); }
.pastille.warn { background: var(--warn-soft); color: var(--warn); }
.pastille.pos { background: var(--pos-soft); color: var(--pos); }

/* Barres de catégories */
.barre-cat { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.barre-cat span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.evol { font-size: .78rem; font-weight: 600; }
.evol.hausse { color: var(--danger); }
.evol.baisse { color: var(--pos); }

.vide-etat { text-align: center; padding: 28px 16px; color: var(--muted); }
.vide-etat .emoji { font-size: 2rem; display: block; margin-bottom: 6px; }

/* --- Mois ------------------------------------------------------------------------------ */

.selecteur-mois { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 16px; }
.selecteur-mois h1 { font-size: 1.5rem; text-align: center; flex: 1; }
.rond-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--surface); color: var(--text); box-shadow: var(--shadow); flex: none; }
.bilan { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.onglets-seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); margin-bottom: 12px; }
.onglets-seg a, .onglets-seg label { flex: 1; text-align: center; padding: 8px; border-radius: 10px; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; }
.onglets-seg a.actif, .onglets-seg label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.onglets-seg input { position: absolute; opacity: 0; pointer-events: none; }
.filtre-actif { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-bottom: 12px; }

/* --- Formulaires -------------------------------------------------------------------------- */

label, .champ { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select, textarea, .bouton, button {
  font: inherit; font-size: 16px; color: var(--text);
}
input[type=text], input[type=password], input[type=date], input[type=number], input[type=file], select, textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid transparent; background: var(--surface-2); outline: none; transition: border-color .15s, background .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: var(--surface); }
select { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%236f6a80' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 20px; height: 20px; margin: 0; flex: none; }

.bouton, button[type=submit], button.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 22px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-weight: 700; text-align: center;
  transition: transform .1s, filter .15s;
}
.bouton:active, button[type=submit]:active { transform: scale(.98); }
.bouton:hover, button[type=submit]:hover { filter: brightness(1.07); }
.bouton.secondaire, button.secondaire { background: var(--surface-2); color: var(--text); }
.bouton.danger, button.danger { background: var(--danger-soft); color: var(--danger); }
.bouton.petit, button.petit { min-height: 38px; padding: 0 14px; border-radius: 11px; font-size: .9rem; }
.bouton.bloc, button.bloc { width: 100%; }
button.lien { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-weight: 600; min-height: auto; }
button.lien:hover { color: var(--danger); }

form.formulaire { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.champ, label { min-width: 0; }
.case { flex-direction: row; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: var(--surface-2); color: var(--text); font-size: .95rem; font-weight: 500; cursor: pointer; }
.case small { display: block; color: var(--muted); font-weight: 400; }
.rangee { display: flex; gap: 10px; flex-wrap: wrap; }
.rangee > * { flex: 1 1 160px; }

/* Saisie rapide */
.montant-geant { display: flex; justify-content: center; align-items: baseline; gap: 6px; padding: 8px 0 4px; }
.montant-geant input {
  field-sizing: content; width: 5.2ch; min-width: 3ch; max-width: 100%; border: 0; background: transparent; text-align: center; min-height: 0; padding: 0;
  font-size: clamp(2.8rem, 16vw, 3.6rem); font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: var(--text);
}
.montant-geant input:focus { background: transparent; }
.montant-geant input::placeholder { color: var(--line); }
.montant-geant .devise { font-size: 2rem; font-weight: 700; color: var(--muted); }
.saisie[data-sens=entree] .montant-geant input { color: var(--pos); }

.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puces.defile { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.puces.defile::-webkit-scrollbar { display: none; }
.puce { position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 9px 14px; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: .9rem; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; user-select: none; }
.puce input { position: absolute; opacity: 0; pointer-events: none; }
.puce:has(input:checked), .puce.choisie { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.suggestion { color: var(--accent); font-weight: 700; }

.barre-action { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 5; display: flex; gap: 10px; padding-top: 8px; }
.barre-action > * { flex: 1; box-shadow: 0 8px 24px rgb(23 20 31 / .12); }
@media (min-width: 900px) { .barre-action { bottom: 16px; } }

/* --- Divers --------------------------------------------------------------------------------- */

.flash { display: flex; gap: 10px; align-items: flex-start; padding: 13px 16px; border-radius: 16px; margin-bottom: 14px; font-weight: 600; font-size: .95rem; background: var(--pos-soft); color: var(--pos); animation: apparait .25s ease-out; }
.flash.erreur { background: var(--danger-soft); color: var(--danger); }
@keyframes apparait { from { opacity: 0; transform: translateY(-6px); } }

.menu-liste .ligne { min-height: 58px; }
.menu-liste .bulle { background: var(--accent-soft); color: var(--accent); }
.chevron { color: var(--muted); }

details.repli > summary { list-style: none; cursor: pointer; font-weight: 600; color: var(--muted); padding: 6px 0; }
details.repli > summary::-webkit-details-marker { display: none; }
details.repli[open] > summary { margin-bottom: 10px; }

table.simple { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.simple th, table.simple td { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.simple th { color: var(--muted); font-size: .78rem; font-weight: 700; }
table.simple tr:last-child td { border-bottom: 0; }
table.simple .num { text-align: right; }

.connexion { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; margin-top: -12px; }
.connexion .carte { width: 100%; max-width: 380px; padding: 28px 24px; }
.connexion .logo { font-size: 1.5rem; margin-bottom: 6px; }
.connexion .carte { text-align: center; }
.connexion .logo { flex-direction: column; justify-content: center; gap: 0; font-size: 1.8rem; }
.connexion .logo img { width: 124px; height: 124px; margin: -20px 0 -4px; }
.connexion form { text-align: left; }

.emoji-champ { width: 72px !important; text-align: center; font-size: 1.4rem !important; padding: 8px !important; flex: none !important; }
.ligne-cat { display: flex; gap: 8px; align-items: center; }
.ligne-cat input[name=nom] { flex: 1; }

/* --- Courbe des soldes (palette validée : bleu = réel, orange = banque) --- */
:root { --serie-1: #2a78d6; --serie-2: #eb6834; --grille: #ece6dc; }
@media (prefers-color-scheme: dark) { :root { --serie-1: #3987e5; --serie-2: #d95926; --grille: #28374a; } }
.courbe-legende { display: flex; gap: 16px; font-size: .82rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.courbe-legende span { display: inline-flex; align-items: center; gap: 6px; }
.trait { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.trait.serie-1 { background: var(--serie-1); }
.trait.serie-2 { background: var(--serie-2); }
.courbe-zone { position: relative; }
.courbe svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.courbe .grille { stroke: var(--grille); stroke-width: 1; }
.courbe .zero { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.courbe .axe { fill: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.courbe .etiquette-fin { fill: var(--text); font-size: 10px; font-weight: 600; }
.courbe .ligne-courbe { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.courbe .ligne-courbe.serie-1 { stroke: var(--serie-1); }
.courbe .ligne-courbe.serie-2 { stroke: var(--serie-2); }
.courbe .point-fin { stroke: var(--surface); stroke-width: 2; }
.courbe .point-fin.serie-1 { fill: var(--serie-1); }
.courbe .point-fin.serie-2 { fill: var(--serie-2); }
.courbe .reticule { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.courbe .cible { fill: transparent; cursor: crosshair; }
.courbe [hidden] { display: none; }
.bulle-info {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none; z-index: 2;
  background: var(--text); color: var(--bg); border-radius: 10px; padding: 6px 10px; font-size: .78rem; line-height: 1.35; white-space: nowrap;
  box-shadow: 0 6px 18px rgb(0 0 0 / .18);
}
.bulle-info b { font-variant-numeric: tabular-nums; }
.bulle-info i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

.ligne-sous.commentaire { font-style: italic; }
textarea { resize: vertical; min-height: 0; line-height: 1.4; }
