:root {
  --bg: #f5f5f4; --card: #fff; --text: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #0f766e; --accent-soft: #ccfbf1; --danger: #b91c1c; --warn-bg: #fef3c7; --warn: #92400e;
  --pos: #15803d; --neg: #b91c1c; --radius: 14px;
  --tab-h: calc(62px + env(safe-area-inset-bottom));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0c0a09; --card: #1c1917; --text: #f5f5f4; --muted: #a8a29e; --line: #292524;
    --accent: #2dd4bf; --accent-soft: #134e4a; --danger: #f87171; --warn-bg: #422006; --warn: #fcd34d;
    --pos: #4ade80; --neg: #f87171; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.02rem; margin: 0 0 .5rem; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.err { color: var(--danger); }
.warn { background: var(--warn-bg); color: var(--warn); padding: .6rem .8rem; border-radius: 10px; font-size: .9rem; }
.loading, .empty { color: var(--muted); padding: 1rem 0; text-align: center; }
.empty { padding: .25rem 0; text-align: left; }

.view { padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + 24px); max-width: 760px; margin: 0 auto; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; }
.bar h1 { flex: 1; }
.card .bar { margin-bottom: .5rem; }
.card .bar h2 { margin: 0; }
.back { font-size: 1.8rem; text-decoration: none; line-height: 1; padding: 0 .4rem 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .5rem; align-items: end; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } .grid3 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .6rem; color: var(--text); font-size: 1rem; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; width: 100%; min-height: 44px; }
input[type=checkbox] { width: 22px; min-height: 22px; accent-color: var(--accent); }
input[type=color] { padding: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px;
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: .35rem .75rem; font-size: .88rem; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: .5rem; cursor: pointer; }

.list { display: flex; flex-direction: column; gap: .5rem; }
.item { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem .8rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: inherit; text-decoration: none; }
.card .item { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .6rem 0; background: none; }
.card .item:last-of-type { border-bottom: 0; }
.right { text-align: right; white-space: nowrap; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: .05em; }
.pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.perdu { background: var(--line); color: var(--muted); }
.st { font-weight: 600; }
.st.prevue { color: var(--muted); } .st.payee { color: var(--pos); } .st.facturee { color: #b45309; }
.st.annulee { color: var(--danger); text-decoration: line-through; }

.filters { display: flex; gap: .5rem; margin-bottom: .8rem; }
.filters > * { flex: 1; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; color: var(--muted); border-radius: 8px; min-height: 36px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .4rem; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: .35rem .8rem; font: inherit; font-size: .88rem; }
.chips button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Agenda */
.weeknav { display: flex; align-items: center; gap: .4rem; margin-bottom: .6rem; }
.weeknav strong { flex: 1; text-align: center; font-size: .92rem; }
.day { margin-bottom: .9rem; }
.day h2 { font-size: .85rem; text-transform: capitalize; color: var(--muted); margin: 0 0 .35rem; }
.day.today h2 { color: var(--accent); }
.ev { display: flex; gap: .75rem; padding: .6rem .75rem; margin-bottom: .35rem; background: var(--card);
  border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; color: inherit; text-decoration: none; }
.ev .t { min-width: 5.6rem; font-variant-numeric: tabular-nums; font-size: .88rem; color: var(--muted); }
.ev.busy { background: transparent; border-style: dashed; border-left-style: solid; color: var(--muted); font-size: .9rem; }
details.ev { display: block; }
details.ev summary { display: flex; gap: .75rem; list-style: none; cursor: pointer; }
details.ev summary::-webkit-details-marker { display: none; }
.evbody { padding: .5rem 0 0 6.35rem; }
@media (max-width: 420px) { .evbody { padding-left: 0; } }

/* Prestation : répartition */
.split { background: var(--bg); border-radius: 10px; padding: .6rem .8rem; }
.split div { display: flex; justify-content: space-between; padding: .2rem 0; }

/* Comptes */
.hero { text-align: center; }
.hero strong { display: block; font-size: 2.1rem; color: var(--pos); margin: .15rem 0; }
.hero.neg strong { color: var(--neg); }
.table { display: flex; flex-direction: column; font-size: .92rem; }
.th, .tr { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: .4rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.th { color: var(--muted); font-size: .8rem; }
.tr > :not(:first-child), .th > :not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

.member { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.member.off { opacity: .5; }

/* Barre d'onglets */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tab-h); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); z-index: 10; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .68rem; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* Auth */
.auth { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 20px 40px; display: flex; flex-direction: column; gap: 1rem; text-align: center; }
.auth form { text-align: left; }
.auth-logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto; }
.qr { width: 200px; height: 200px; margin: 0 auto; background: #fff; padding: 8px; border-radius: 12px; }
.secret { word-break: break-all; font-size: .9rem; }
.steps { text-align: left; padding-left: 1.2rem; margin: 0; }
.code { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px); z-index: 50;
  background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 12px; max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: pop .2s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
