:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --text: #17201b;
  --muted: #66716a;
  --line: #e3e8e4;
  --brand: #0f7b4f;
  --brand-2: #0b5e3c;
  --in: #11865a;
  --out: #c4402f;
  --warn: #c98a08;
  --info: #2f6fb3;
  --chip: #eef2ef;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #18201c; --text: #e8eee9; --muted: #95a29a; --line: #26302b;
    --brand: #2bb07a; --brand-2: #1e8a5d; --in: #3cc68a; --out: #ef6a58; --warn: #e5ad2e; --info: #6ea7e6;
    --chip: #222c27; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.in-txt { color: var(--in); }
.out-txt { color: var(--out); }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  max-width: 560px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.25rem; color: var(--brand); }
.topbar-sub { color: var(--muted); font-size: .9rem; text-align: right; }

.view { max-width: 560px; margin: 0 auto; padding: 4px 16px 24px; }

/* Cartes */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card h2 { font-size: 1.05rem; margin: 0 0 10px; }
.card h3 { font-size: .95rem; margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.section-t { font-size: 1.05rem; margin: 20px 4px 10px; }
.clickable { cursor: pointer; }
.link { color: var(--brand); font-weight: 600; margin-top: 6px; font-size: .9rem; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; margin: 0; }

/* Carte principale */
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; }
.hero-label { opacity: .85; font-size: .9rem; }
.hero-amt { font-size: 2.2rem; font-weight: 800; margin: 2px 0 12px; letter-spacing: -.5px; }
.hero-amt.neg { color: #ffd2cb; }
.hero-row { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; }
.hero-row b { display: block; font-size: 1.05rem; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.in { background: #9ef0c7; } .dot.out { background: #ffb3a7; }

/* Raccourcis */
.shortcuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shortcut {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip);
  transition: transform .08s;
}
.shortcut:active { transform: scale(.95); }
.shortcut.in { border-color: color-mix(in srgb, var(--in) 40%, var(--line)); }
.sc-ic { font-size: 1.5rem; }
.sc-l { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sc-a { font-weight: 700; font-size: .9rem; }

/* Opérations */
.tx-list, .leaks, .bars { list-style: none; margin: 0; padding: 0; }
.tx { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.tx:first-child { border-top: 0; }
.tx-ic { font-size: 1.35rem; width: 40px; height: 40px; border-radius: 12px; background: var(--chip); display: grid; place-items: center; flex-shrink: 0; }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-label { font-weight: 600; }
.tx-sub { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 700; white-space: nowrap; }
.tx-amt.in { color: var(--in); } .tx-amt.out { color: var(--out); }

/* Conseils */
.advice { display: flex; gap: 12px; border-left: 4px solid var(--info); }
.advice.alert { border-left-color: var(--out); }
.advice.tip { border-left-color: var(--warn); }
.advice.good { border-left-color: var(--in); }
.adv-ic { font-size: 1.5rem; line-height: 1; }
.adv-t { font-weight: 700; margin-bottom: 2px; }
.adv-x { color: var(--muted); font-size: .92rem; }

/* Score */
.score-card { display: flex; align-items: center; gap: 16px; }
.score-card > div { flex: 1; }
.ring { width: 110px; height: 110px; flex-shrink: 0; }
.ring-bg { fill: none; stroke: var(--chip); stroke-width: 12; }
.ring-fg { fill: none; stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray .5s; }
.ring-fg.good { stroke: var(--in); } .ring-fg.ok { stroke: var(--brand); } .ring-fg.warn { stroke: var(--warn); } .ring-fg.bad { stroke: var(--out); }
.ring-txt { font-size: 30px; font-weight: 800; fill: var(--text); }
.score-l { font-size: 1.3rem; font-weight: 800; margin-bottom: 6px; }
.score-l.good { color: var(--in); } .score-l.ok { color: var(--brand); } .score-l.warn { color: var(--warn); } .score-l.bad { color: var(--out); }
.kv { display: flex; justify-content: space-between; font-size: .92rem; padding: 2px 0; }
.kv.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }

/* Fuites */
.leaks li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.leaks li:first-child { border-top: 0; }
.leak-n { text-align: right; display: flex; flex-direction: column; font-size: .8rem; }
.leak-n b { font-size: 1rem; color: var(--out); }

/* Barres */
.bars li { padding: 6px 0; }
.bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; margin-bottom: 4px; }
.bar { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--out); border-radius: 4px; opacity: .85; }

/* Barre d'outils */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 140px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.pager { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: .92rem; }
.pager button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.pager button:disabled { opacity: .35; cursor: default; }

.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg.small button { padding: 6px 12px; font-size: .9rem; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg .seg-out.active { color: var(--out); }
.seg .seg-in.active { color: var(--in); }

/* Bouton + */
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(80px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(15,123,79,.4); z-index: 6;
}
.fab:active { transform: scale(.94); }

/* Barre du bas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { flex: 1; max-width: 140px; border: 0; background: none; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); }
.tabbar .ti { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--brand); font-weight: 700; }
.tabbar button.active .ti { filter: none; opacity: 1; }

/* Fenêtre d'ajout */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; opacity: 0; transition: opacity .2s; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .2s ease-out;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.quick-row { display: flex; gap: 8px; margin: 12px 0 8px; }
.quick-row input { flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); }
.mic { width: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); font-size: 1.2rem; }
.mic.on { background: var(--out); border-color: var(--out); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.amount-row { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 4px 0; }
.amount-row input {
  width: 100%; max-width: 260px; text-align: center; border: 0; background: none; outline: none;
  font-size: 2.6rem; font-weight: 800; color: var(--out);
  -moz-appearance: textfield;
}
.sheet.is-in .amount-row input { color: var(--in); }
.amount-row input::-webkit-outer-spin-button, .amount-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cur { font-size: 1.4rem; font-weight: 700; color: var(--muted); }

.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.chips button { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--chip); font-size: .85rem; font-weight: 600; }
.chips .chip-clear { color: var(--muted); font-weight: 400; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px; border: 2px solid transparent; background: var(--chip); }
.cat-ic { font-size: 1.4rem; }
.cat-l { font-size: .68rem; text-align: center; line-height: 1.15; color: var(--muted); }
.cat.active { border-color: var(--out); background: color-mix(in srgb, var(--out) 12%, var(--card)); }
.sheet.is-in .cat.active { border-color: var(--in); background: color-mix(in srgb, var(--in) 12%, var(--card)); }
.cat.active .cat-l { color: var(--text); font-weight: 600; }

.extra-row { display: flex; gap: 8px; margin: 12px 0; }
.extra-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); }
.extra-row input[type=date] { flex: 0 0 auto; max-width: 150px; }

.sheet-actions { display: flex; gap: 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); font-weight: 600; text-align: center; }
.btn-primary { flex: 1; background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-ghost { background: transparent; }
.btn.danger, .danger { color: var(--out); }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.field input { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); color: var(--text); }

/* Message bas */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 14px;
  background: #1d2621; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: #7fe0b2; font-weight: 700; padding: 0; }

.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

@media (max-width: 360px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .hero-amt { font-size: 1.9rem; }
}

/* ===== v0.2 : connexion, espaces Owner / Commercial ===== */
.login { margin-top: 24px; }
.login h1 { font-size: 1.4rem; margin: 0 0 4px; color: var(--brand); }
.login form { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.form-error { color: var(--out); font-size: .9rem; margin: 0; }
.btn.block, .block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; font-size: .85rem; padding: 0; }
select { font: inherit; color: var(--text); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); max-width: 100%; }
.field select, .field input { width: 100%; }

.sync { white-space: nowrap; }
.sync.offline, .sync.syncing { color: var(--warn); }
.sync.error, .sync.blocked { color: var(--out); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile-v { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.tile-v .small-v { font-size: 1rem; }
.tile-l { color: var(--muted); font-size: .85rem; }
.tile-s { color: var(--in); font-size: .8rem; font-weight: 600; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.btn-row .btn { flex: 1; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select { flex: 1; min-width: 140px; padding: 8px 10px; font-size: .9rem; }
.toolbar .btn { padding: 8px 14px; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.member { cursor: pointer; }
.member:active { opacity: .7; }
.flag { font-size: 1.5rem; width: 36px; text-align: center; flex-shrink: 0; }
.right { text-align: right; font-size: .9rem; white-space: nowrap; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: .75rem; font-weight: 700; white-space: nowrap; background: var(--chip); }
.chip.good { color: var(--in); background: color-mix(in srgb, var(--in) 14%, var(--card)); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, var(--card)); }
.chip.bad { color: var(--out); background: color-mix(in srgb, var(--out) 14%, var(--card)); }

.modal h2 { margin: 4px 0 12px; font-size: 1.2rem; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal .sheet-actions { margin-top: 14px; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; font-family: ui-monospace, Consolas, monospace; }
.pw-row .btn { padding: 8px 12px; }
.creds { background: var(--chip); border-radius: 12px; padding: 12px; white-space: pre-wrap; font-size: .95rem; user-select: all; }
.pay-form { display: grid !important; grid-template-columns: 1fr 1fr; gap: 6px !important; }
.pay-form input, .pay-form select { padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); min-width: 0; }
.pay-form button { grid-column: span 2; }
.action-list { margin-top: 16px; }
.tx.static { cursor: default; }
