/* Compta du foyer — mobile d'abord, clair/sombre automatique. */
:root {
  color-scheme: light;
  --bg: #f9f9f7; --card: #fcfcfb; --fg: #0b0b0b; --fg2: #52514e; --muted: #898781;
  --line: #e1e0d9; --base: #c3c2b7; --ring: rgba(11,11,11,.10);
  --accent: #2a78d6; --accent-fg: #fff; --accent-soft: #e6f0fc;
  --good: #0ca30c; --good-text: #006300; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --pos: #2a78d6; --neg: #e34948; --seq: #2a78d6;
  --r: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d; --card: #1a1a19; --fg: #f0efec; --fg2: #c3c2b7; --muted: #898781;
    --line: #2c2c2a; --base: #383835; --ring: rgba(255,255,255,.10);
    --accent: #3987e5; --accent-soft: #16263a; --good-text: #0ca30c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --pos: #3987e5; --neg: #e66767; --seq: #3987e5;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-size: 16px; line-height: 1.45; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
body.noscroll { overflow: hidden; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; line-height: 1.2; }
h2 { font-size: 1.08rem; margin: 0 0 .6em; }
p { margin: .4em 0; }
small { font-size: .8rem; }
.muted { color: var(--fg2); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bad { color: var(--critical); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: 1 / -1; }
.bul { padding-left: 1.2em; } .bul li { margin: .35em 0; }
.loading, .empty { text-align: center; color: var(--muted); padding: 40px 0; }
[hidden] { display: none !important; }

/* Formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--fg2); }
input, select, textarea { font: inherit; font-size: 16px; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 46px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); margin: 0; flex: none; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--fg); font-size: .95rem; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-size: .88rem; color: var(--fg2); padding: 0 4px; }
.bigfield { flex-direction: row; align-items: baseline; gap: 8px; }
.bigfield input { font-size: 2rem; font-weight: 700; text-align: right; padding: 8px 12px; }
.bigfield span { font-size: 1.2rem; color: var(--fg2); white-space: nowrap; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg label { flex: 1; flex-direction: row; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { flex: 1; text-align: center; padding: 9px 6px; border-radius: 10px; color: var(--fg2); font-weight: 600; font-size: .9rem; cursor: pointer; }
.seg input:checked + span { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px var(--ring); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

/* Boutons */
.btn { font: inherit; font-weight: 650; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 46px; cursor: pointer; background: var(--line); color: var(--fg); display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { color: var(--critical); }
.btn.danger:not(.ghost):not(.tiny) { background: var(--critical); color: #fff; }
.btn.big { width: 100%; font-size: 1.05rem; min-height: 54px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.tiny { min-height: 34px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.row.gap .btn { flex: 1; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: .92rem; padding: 8px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--critical); }
.icon { background: none; border: 0; font-size: 1.6rem; width: 44px; height: 44px; color: var(--fg); cursor: pointer; border-radius: 50%; }
.icon:disabled { opacity: .25; }
.filebtn { cursor: pointer; }

/* Structure */
#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; }
.people { display: flex; background: var(--line); border-radius: 999px; padding: 3px; }
.people button { font: inherit; font-size: .9rem; font-weight: 650; border: 0; background: transparent; color: var(--fg2); padding: 6px 14px; border-radius: 999px; cursor: pointer; min-height: 36px; }
.people button[aria-selected=true] { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px var(--ring); }
#app { max-width: 640px; margin: 0 auto; padding: 12px 14px; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; font: inherit; font-size: .7rem; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; cursor: pointer; min-height: 58px; }
.tabbar button span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabbar button[aria-current=page] { color: var(--accent); font-weight: 700; }
.tabbar button[aria-current=page] span { filter: none; opacity: 1; }
.fab { position: fixed; right: 18px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 21; width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin: 12px 0; }
.robanner { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 4px 0 8px; font-size: .92rem; }
.testflag { background: var(--critical); color: #fff; font-size: .7rem; font-weight: 800; padding: 2px 8px; border-radius: 6px; letter-spacing: .04em; display: inline-block; }
body.is-test #top { border-bottom: 3px solid var(--critical); }

/* Accueil */
.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 0 -6px; }
.monthnav b { text-transform: capitalize; font-size: 1.05rem; }
.hero { text-align: center; padding: 18px 12px 14px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); margin: 6px 0 12px; }
.hlabel { color: var(--fg2); margin: 0; font-size: .92rem; }
.hval { font-size: 2.6rem; font-weight: 800; margin: 2px 0 6px; letter-spacing: -.02em; }
.hstat { margin: 0; display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; font-size: .88rem; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; color: #0b0b0b; }
.badge.good { background: var(--good); color: #fff; }
.badge.warning { background: var(--warning); }
.badge.critical { background: var(--critical); color: #fff; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.tile span { font-size: .8rem; color: var(--fg2); }
.tile b { font-size: 1.25rem; }
.tile small { color: var(--muted); }
.tile.accent { border-color: var(--accent); }
.gauges, .dues, .advs, .plist, .txs, .hbars, .legend, .toggles, .log, .imp { list-style: none; margin: 0; padding: 0; }
.gauge { padding: 9px 0; }
.gauge + .gauge { border-top: 1px solid var(--line); }
.gtop { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.gtop .num { font-size: .9rem; }
.ico { width: 26px; text-align: center; flex: none; font-size: 1.15rem; }
.gbar { position: relative; height: 8px; background: var(--line); border-radius: 4px; }
.gbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--good); }
.gbar i.warning { background: var(--warning); }
.gbar i.critical { background: var(--critical); }
.gbar s { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--fg); opacity: .55; text-decoration: none; }
.dueitem, .prow, .tx { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.dueitem:first-child, .prow:first-child { border-top: 0; }
.dueitem small, .prow small, .tx small { display: block; color: var(--muted); font-size: .78rem; }
.dueitem.due .num { color: var(--critical); font-weight: 700; }
.prow .num small { display: inline; }
.prow.archived { opacity: .5; }
.adv { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.adv:first-child { border-top: 0; }
.adv p { margin: 2px 0 0; font-size: .9rem; color: var(--fg2); }
.st { flex: none; width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: .85rem; background: var(--line); }
.adv.critical .st, .callout.critical .st { background: var(--critical); color: #fff; }
.adv.warning .st, .callout.warning .st { background: var(--warning); color: #0b0b0b; }
.adv.good .st, .callout.good .st { background: var(--good); color: #fff; }
.adv.tip .st { background: var(--accent-soft); }

/* Opérations */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.filters input { grid-column: 1 / -1; }
.sums { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--fg2); }
.dayh { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 0 4px; }
.tx .right { text-align: right; }
.tx.income b { color: var(--good-text); }
.tx.zero { opacity: .45; }
.settle { display: block; }
.settle.due { color: var(--critical) !important; font-weight: 700; }
.settle.planned { color: var(--accent) !important; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.dl dt { color: var(--fg2); } .dl dd { margin: 0; }

/* Graphiques */
.hbars li { display: grid; grid-template-columns: minmax(0, 9.5em) 1fr auto; align-items: center; gap: 8px; padding: 6px 0; cursor: default; }
.hl { font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ht { height: 14px; display: block; }
.ht i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.hv { font-size: .86rem; text-align: right; }
.hv small { display: block; color: var(--muted); font-size: .72rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--fg2); margin-bottom: 8px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sw.pos { background: var(--pos); } .sw.neg { background: var(--neg); }
.sw.goalsw { height: 0; border-top: 2px dashed var(--fg2); border-radius: 0; width: 14px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--base); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .pos { fill: var(--pos); } .chart .neg { fill: var(--neg); }
.chart .cur { opacity: .55; }
.chart .goal { stroke: var(--fg2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .hit:hover rect:not([fill=transparent]) { filter: brightness(1.08); }
.tip-pop { position: fixed; z-index: 50; background: var(--fg); color: var(--bg); padding: 8px 10px; border-radius: 10px; font-size: .8rem; line-height: 1.5; pointer-events: none; max-width: 260px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tablewrap { overflow-x: auto; }
table.data { border-collapse: collapse; font-size: .8rem; width: 100%; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data td.num { text-align: right; }

/* Récap / plan */
table.recap { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.recap td { padding: 9px 0; border-bottom: 1px solid var(--line); }
.recap td.num { text-align: right; }
.recap tr.total td { font-weight: 800; font-size: 1.1rem; border-bottom: 0; }
.recap tr.total.neg td { color: var(--critical); }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.tip { background: var(--accent-soft); padding: 12px; border-radius: 12px; font-size: .92rem; }

/* Feuilles modales */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .15s; }
.sheet-wrap.open { opacity: 1; }
.sheet { position: relative; background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); transform: translateY(30px); transition: transform .18s; }
.sheet-wrap.open .sheet { transform: none; }
.sheet h2 { font-size: 1.25rem; padding-right: 40px; }
.sheet-x { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--line); color: var(--fg); font-size: 1rem; cursor: pointer; }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: .98rem; }
.codes li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; text-align: center; }
.codes code { font-family: ui-monospace, monospace; letter-spacing: .04em; }
.imp li { border-top: 1px solid var(--line); padding: 10px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.imp li > label { grid-column: 1 / -1; }
.imp small { display: block; color: var(--muted); }
.imp select { min-height: 40px; padding: 6px 8px; font-size: .88rem; }
.toggles li { padding: 8px 0; }
.log li { padding: 6px 0; border-top: 1px solid var(--line); font-size: .88rem; }
.log small { display: block; color: var(--muted); }

/* Connexion */
.auth { text-align: center; padding: 12vh 8px 20px; max-width: 420px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.auth-logo { width: 76px; height: 76px; border-radius: 22px; background: var(--accent); color: #fff; font-size: 2.6rem; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.auth h1 { margin: 0; }
.auth input { text-align: center; font-family: ui-monospace, monospace; font-size: 1.2rem; letter-spacing: .08em; }

/* Assistant */
.wizard { padding-bottom: 90px; }
.wprog { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.wprog i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.wstep { font-size: .8rem; color: var(--muted); margin: 0 0 10px; }
.witems { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.witem { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.witem.on { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.wline { display: flex; flex-direction: row; align-items: center; gap: 10px; color: var(--fg); font-size: 1rem; cursor: pointer; }
.wline small { display: block; color: var(--muted); font-size: .78rem; }
.witem .grid2 { margin-top: 12px; }
.budget { flex-direction: row; align-items: center; gap: 6px; flex: none; }
.budget input { width: 90px; text-align: right; font-weight: 700; }
.budget span { font-size: .8rem; }
.wlive { position: fixed; left: 0; right: 0; bottom: calc(70px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: center; max-width: 640px; margin: 0 auto; padding: 8px 16px; background: var(--accent-soft); font-size: .88rem; }
.wlive b { font-size: 1.05rem; } .wlive b.neg { color: var(--critical); }
.wnav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); max-width: 640px; margin: 0 auto; }
.wnav .btn { flex: 1; }
.wnav span { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--fg); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-size: .92rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--critical); color: #fff; }
.toast.good { background: var(--good-text); color: #fff; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}
@media (forced-colors: active) {
  .gbar i, .ht i, .chart rect { forced-color-adjust: none; }
}
