:root {
  --bg: #f6f5f1; --card: #fff; --ink: #1c1e21; --mute: #7b7f86; --line: #e6e4dd;
  --in: #11825a; --in-bg: #e5f4ed; --out: #c23b2e; --out-bg: #fbe9e6; --accent: #1f3a5f;
  --r: 12px;
  --warn-bg: #fff4c7; --warn-bd: #e0a800; --warn-ink: #7a5600; --neg-bg: #ffe08a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { margin: 0; color: var(--ink); background: var(--bg);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.app { max-width: 760px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 8px max(16px, env(safe-area-inset-bottom)); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 10px; }
h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
h1::first-letter, .sheet h2::first-letter { text-transform: uppercase; }
.nav { width: 44px; height: 44px; border-radius: 50%; font-size: 28px; line-height: 1; color: var(--accent); background: var(--card); box-shadow: 0 0 0 1px var(--line); }
.nav:active { background: var(--line); }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.sum { background: var(--card); border-radius: var(--r); padding: 8px 7px 9px; text-align: left; box-shadow: 0 0 0 1px var(--line); min-width: 0; }
.sum span { display: block; font-size: 11px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.sum b { display: block; font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum.in b { color: var(--in); } .sum.out b { color: var(--out); }
.sum.end { background: var(--accent); } .sum.end span { color: #b9c6d8; } .sum.end b { color: #fff; }
.sum.end.watch { background: #f5c518; } .sum.end.watch span { color: #6b4e00; } .sum.end.watch b { color: #2b1f00; }
.sum.start { cursor: pointer; }

.dow, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.dow i { font-style: normal; font-size: 11px; color: var(--mute); text-align: center; padding: 2px 0 4px; font-weight: 600; }
.cell { min-height: 76px; background: var(--card); border-radius: 9px; padding: 4px 3px 3px; display: flex; flex-direction: column;
  text-align: right; box-shadow: 0 0 0 1px var(--line); overflow: hidden; min-width: 0; }
.cell.empty { background: transparent; box-shadow: none; cursor: default; }
.cell .d { font-size: 12px; font-weight: 650; text-align: left; padding-left: 2px; color: var(--mute); }
.cell .flow { font-size: 10px; line-height: 1.25; font-weight: 600; white-space: nowrap; opacity: .92; }
.cell .flow.in { color: var(--in); } .cell .flow.out { color: var(--out); }
.cell .bal { margin-top: auto; font-size: 12.5px; font-weight: 500; color: var(--mute); white-space: nowrap; letter-spacing: -.01em; }
.cell .bal.long { font-size: 11px; }
.cell.has { box-shadow: 0 0 0 1px #cfd3da; }
.cell.has .bal { color: var(--ink); font-weight: 800; font-size: 14.5px; }
.cell.has .bal.long { font-size: 12px; }
.cell.low { background: var(--warn-bg); }
.cell.neg { background: var(--neg-bg); }
.cell.low .bal, .cell.neg .bal { color: var(--warn-ink); font-weight: 800; }
.cell.first { box-shadow: 0 0 0 2px var(--warn-bd); }
.cell.today .d { color: #fff; background: var(--accent); border-radius: 8px; padding: 0 5px; align-self: flex-start; margin-left: 0; }
.cell.sel { box-shadow: 0 0 0 2px var(--accent); }
.cell:not(.empty):active { filter: brightness(.96); }

.foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px 0; min-height: 44px; }
.link { color: var(--accent); font-weight: 600; padding: 10px 6px; }
.warn { color: var(--out); font-size: 13px; }

.scrim { position: fixed; inset: 0; background: rgba(20,24,30,.38); z-index: 10; }
.sheet { position: fixed; z-index: 11; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 16px 16px max(20px, env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  max-width: 560px; margin: 0 auto; }
.sheet[hidden], .scrim[hidden] { display: none; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.sheet .after { font-size: 14px; color: var(--mute); }
.sheet .after b { color: var(--ink); } .sheet .after b.neg, .sheet .after b.low { color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 0 6px; }
.sheet .after b.neg { background: var(--neg-bg); }
.close { width: 44px; height: 44px; margin: -8px -8px 0 0; font-size: 22px; color: var(--mute); }

.txs { list-style: none; margin: 0 0 12px; padding: 0; }
.tx { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 10px; border-radius: 10px; text-align: left; min-height: 48px; }
.tx + .tx { margin-top: 2px; }
.tx:active { background: var(--bg); }
.tx .what { min-width: 0; display: grid; }
.tx .desc { overflow-wrap: anywhere; line-height: 1.3; } /* texte long : on lit tout, la journée a la place */
.tx .rep { font-size: 12px; color: var(--mute); }
.tx .amt { font-weight: 650; white-space: nowrap; }
.tx.in .amt { color: var(--in); } .tx.out .amt { color: var(--out); }
.tx.in { background: var(--in-bg); } .tx.out { background: var(--out-bg); }
.none { color: var(--mute); margin: 4px 0 14px; }

form { display: grid; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { min-height: 44px; border-radius: 8px; font-weight: 650; color: var(--mute); }
.seg button[aria-pressed="true"].in { background: var(--in); color: #fff; }
.seg button[aria-pressed="true"].out { background: var(--out); color: #fff; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
input { font: inherit; font-size: 16px; /* 16 px : évite le zoom d'iOS */ color: var(--ink); text-transform: none; letter-spacing: 0;
  min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.err { color: var(--out); font-size: 13px; min-height: 0; margin: 0; }
.row { display: flex; gap: 8px; }
.primary { flex: 1; min-height: 48px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 650; }
.danger { min-height: 48px; padding: 0 16px; border-radius: 12px; color: var(--out); background: var(--out-bg); font-weight: 650; }
.ghost { min-height: 48px; padding: 0 16px; border-radius: 12px; color: var(--mute); background: var(--bg); font-weight: 600; }

@media (min-width: 640px) {
  .app { padding-top: 28px; } h1 { font-size: 24px; }
  .cell { min-height: 98px; padding: 6px 8px 6px; } .cell .d { font-size: 13px; }
  .cell .flow { font-size: 12px; } .cell .bal { font-size: 15px; } .cell.has .bal { font-size: 17px; } .cell .bal.long, .cell.has .bal.long { font-size: 14px; }
  .sum b { font-size: 17px; } .sum { padding: 10px 12px; }
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 18px; max-height: 86vh; }
}
@media (max-width: 360px) { .cell .flow { font-size: 9.5px; } .cell .bal { font-size: 11.5px; } .cell.has .bal { font-size: 13px; } .cell .bal.long, .cell.has .bal.long { font-size: 10.5px; } .sum b { font-size: 13px; } }

.demo { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; text-align: center; }
.demo[hidden] { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; margin: 2px 4px 0; font-size: 12px; color: var(--mute); }
.legend { column-gap: 14px; }
.legend .k { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: -8px; }
.legend b { color: var(--ink); font-weight: 600; }
.legend .k.in { background: var(--in); } .legend .k.out { background: var(--out); } .legend .k.warn { background: #f5c518; }
.addlabel { margin: 4px 0 6px; font-size: 12px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.seg.big button { min-height: 52px; font-size: 17px; border-radius: 10px; }
.seg.big button.in { color: var(--in); } .seg.big button.out { color: var(--out); }
.seg.big button[aria-pressed="true"] { color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 22px; font-weight: 600; background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
.chip.in { background: var(--in-bg); color: var(--in); box-shadow: 0 0 0 1px #b9dfcd; }
.chip.out { background: var(--out-bg); color: var(--out); box-shadow: 0 0 0 1px #f0c4be; }
.chip.autre { background: #fff; color: var(--mute); }
.chip[aria-pressed="true"].in { background: var(--in); color: #fff; }
.chip[aria-pressed="true"].out { background: var(--out); color: #fff; }
.chip[aria-pressed="true"].autre { background: var(--ink); color: #fff; }
select { font: inherit; font-size: 16px; min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; color: var(--ink); text-transform: none; letter-spacing: 0; }
.seg.scope button { font-size: 14px; }
.seg.scope button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.hint { margin: 0; font-size: 13px; color: var(--mute); text-transform: none; letter-spacing: 0; }
@media (min-width: 640px) { .legend { font-size: 13px; } }

/* ---------- Vue journée : plein écran superposé ---------- */
body.lock { overflow: hidden; }
.app > .hint { margin: 14px 4px 0; text-align: center; }
.sheet.full { inset: 0; max-width: none; max-height: none; height: 100dvh; margin: 0; border-radius: 0; padding: 0; box-shadow: none; transform: none; overscroll-behavior: contain; }
.dayhead { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border-bottom: 1px solid var(--line); padding: max(8px, env(safe-area-inset-top)) 10px 8px; }
.dayhead .close { width: auto; height: 44px; margin: 0; padding: 0 10px; font-size: 16px; font-weight: 650; color: var(--accent); }
.dayhead .close::first-letter { text-transform: none; }
.dnavs { display: flex; gap: 8px; }
.dnav { width: 44px; height: 44px; border-radius: 50%; font-size: 24px; line-height: 1; color: var(--accent); background: var(--bg); }
.dnav:active { background: var(--line); }
.daybody { padding: 14px 16px max(28px, env(safe-area-inset-bottom)); }
.daybody h2 { margin: 0 0 14px; font-size: 26px; letter-spacing: -.015em; }
.daybody h2::first-letter { text-transform: uppercase; }
.ledger { border-radius: 16px; background: var(--bg); padding: 6px 16px 14px; }
.lrow { display: flex; align-items: baseline; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.lrow span { color: var(--mute); }
.lrow b { font-size: 17px; font-weight: 650; }
.lrow.start b { color: var(--mute); font-weight: 600; }
.lrow.in b { color: var(--in); } .lrow.out b { color: var(--out); }
.lrow.zero b { color: var(--mute); font-weight: 500; }
.lend { display: flex; flex-direction: column; gap: 2px; padding-top: 12px; }
.lend span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); }
.lend b { font-size: 44px; line-height: 1.05; font-weight: 800; letter-spacing: -.02em; align-self: flex-start; border-radius: 10px; }
.lend.low b, .lend.neg b { color: var(--warn-ink); background: var(--warn-bg); padding: 0 10px; margin-left: -10px; }
.lend.neg b { background: var(--neg-bg); }
.alert { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.35; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-bd); }
.alert.neg { background: var(--neg-bg); }
.sect { margin: 20px 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); }
.daybody .txs { margin-bottom: 4px; }
@media (min-width: 640px) {
  .sheet.full { inset: 3vh auto 3vh 50%; transform: translateX(-50%); width: min(680px, calc(100% - 32px)); height: auto; border-radius: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
  .dayhead { border-radius: 18px 18px 0 0; }
  .lend b { font-size: 52px; }
}
.daybody .addlabel { margin-top: 22px; }
@media (max-width: 340px) { .cell { padding: 4px 2px 3px; } .cell .bal { font-size: 10.5px; } .cell.has .bal { font-size: 11.5px; } .cell .bal.long, .cell.has .bal.long { font-size: 10px; } }

.sheet:focus { outline: none; }
.notice { margin: 10px 4px 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-bd); font-size: 14px; line-height: 1.35; }
.notice[hidden] { display: none; }
